function [xpsi,ypsi,xb,yb]=getgrid(cdf)
%function [xpsi,ypsi,xb,yb]=getgrid(cdf)
%
% get the locations of the grid cell boundaries
%
% xpsi,ypsi matrices containing upper right corners of cell
% xb,yb = grid boundaries
[d,x,y]=kslice(cdf,'depth');
[nx,ny]=size(d);
% average four centers to get corners

x1=x(1:nx-1,1:ny-1);
x2=x(2:nx,1:ny-1);
x3=x(2:nx,2:ny);
x4=x(1:nx-1,2:ny);

y1=y(1:nx-1,1:ny-1);
y2=y(2:nx,1:ny-1);
y3=y(2:nx,2:ny);
y4=y(1:nx-1,2:ny);

%ind=find(isnan(d));
%x(ind)=x(ind)*nan;
%y(ind)=y(ind)*nan;
%xpsi=reshape(gmean([x1(:)'; x2(:)'; x3(:)'; x4(:)'])',nx-1,ny-1);
%ypsi=reshape(gmean([y1(:)'; y2(:)'; y3(:)'; y4(:)'])',nx-1,ny-1);
xpsi=reshape(mean([x1(:)'; x2(:)'; x3(:)'; x4(:)'])',nx-1,ny-1);
ypsi=reshape(mean([y1(:)'; y2(:)'; y3(:)'; y4(:)'])',nx-1,ny-1);

plot(xpsi,ypsi,'g-',xpsi',ypsi','g-') 
xb=[x(:,1); x(nx-1,:)'; flipud(x(:,ny-1)); flipud(x(1,:)')];
yb=[y(:,1); y(nx-1,:)'; flipud(y(:,ny-1)); flipud(y(1,:)')];

