poly = [69892 448566
	68095.4 446496
	67599.1 446975
	69199 449062
	69934.8 448703];

poly = [66677 446001
	69747.6 450085
	70558.7 449549
	67401.2 445711
	66734.9 446305];

ncfile = 'Delflandsekust.nc';
nc_dump(ncfile)

%% get data
%-----------------
datathinning = 4;
[X, Y, Z, T] = getDataFromNetCDFGrid('ncfile', ncfile, 'starttime', now, 'searchwindow', -100, 'polygon', poly, 'stride', [1 datathinning datathinning]);

%% plot X, Y and Z
%-----------------
   figure(1);clf; thinning=1;
   
   %% plot
   pcolorcorcen(X(1:thinning:end,1:thinning:end),...
                Y(1:thinning:end,1:thinning:end),...
                Z(1:thinning:end,1:thinning:end));
   hold on; ph = plot(poly(:,1), poly(:,2)); set(ph,'linewidth',2)
   
   %% layout
   colorbar;
   
   axis    equal
   axis    tight
   box     on
   
   title   ('z-values available in polygon')
   tickmap ('xy','texttype','text','format','%0.1f')
   
%% plot X, Y and T
%-----------------
   figure(2); clf; thinning=1;
   
   %% find unqiue date values
   v = unique(T(find(~isnan(T))));
   if length(v)==1
       v=[v(1) - 1 v];
   end
   nv = length(v);
   
   %% make matrix so you can plot index of unique values
   V=T;
   for iv=1:nv
       mask = (T==v(iv));
       V(mask)=iv;
   end
   
   %% plot
   pcolorcorcen(X(1:thinning:end,1:thinning:end),...
                Y(1:thinning:end,1:thinning:end),...
                V(1:thinning:end,1:thinning:end));
   hold on; ph = plot(poly(:,1), poly(:,2)); set(ph,'linewidth', 2)
   
   %% layout
   caxis   ([1-.5 nv+.5])
   colormap(clrmap(jet,nv)); % clrmap: thank you Bert Jagers
   [ax,c1] =  colorbarwithtitle('',1:nv+1);
   set(ax,'yticklabel',datestr(v,1))

   axis    equal
   axis    tight
   box     on
   
   title   ('timestamps of z-values available in polygon')
   tickmap ('xy','texttype','text','format','%0.1f')
   
