%  PlotGrid.m
%     Plot a 3d grid of values from a cruise
%     1000 m is depth interval 19
%
CruiseName='NBP0103';
%CruiseName='NBP0104';

ptcl=[-2 -1.8 -1.6 -1.4 -1.2 -1 -0.8 -0.6 -0.45 -0.2 0 .2 .4 .6 .8 1 1.2 1.4 1.6 1.8 2];
scl=[32.2 32.4 32.6 32.8 33 33.2 33.4 33.6 33.8 34 34.2 34.4 34.6 34.7 34.8];

o2units=1/44.626;

plotIndex=0;
plotPT=1;
plotT=0;
plotS=0;
plotO2=0;
PlotRange=[-50 550 -50 350];

load([CruiseName '.gridstns.mat']);
load([CruiseName '.depgrid.mat']);

[ndep,n]=size(stddepgrid);
[n,nx]=size(xi);
[n,ny]=size(yi);
[xxi,yyi]=meshgrid(xi,yi);

if plotIndex
  figure
%  cl=[1 5 10 11 12 13 14 15 16 17 18 19];
%  [Con,Han]=contour(xxi,yyi,nzgrid,cl);
  [Con,Han]=contour(xxi,yyi,nzgrid);
  clabel(Con,Han);
  title('deepest index on 20 km grid ');
  axis(PlotRange);
  hold on;
  plot(xgrid,ygrid,'r*');
  hold off
end

if plotT
   for idep=1:ndep
     figure
     [Con,Han]=contour(xxi,yyi,ptgrid(:,:,idep));
     clabel(Con,Han);
     title(['Gridded Temp at depth ' num2str(stddep(idep))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(t(idep,:)));
     plot(xgrid(i),ygrid(i),'r*');
     text(50,0,CruiseName)
     hold off
  end
end
if plotPT
   for idep=1:ndep
     figure
     [Con,Han]=contour(xxi,yyi,ptgrid(:,:,idep));
     clabel(Con,Han);
     title(['Gridded Pot Temp at depth ' num2str(stddep(idep))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(pt(idep,:)));
     plot(xgrid(i),ygrid(i),'r*');
     text(50,0,CruiseName)
     hold off
  end
end
if plotS
   for idep=1:ndep
     figure
     [Con,Han]=contour(xxi,yyi,sgrid(:,:,idep));
     clabel(Con,Han);
     title(['Gridded Salinity at depth ' num2str(stddep(idep))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(s(idep,:)));
     plot(xgrid(i),ygrid(i),'r*');
     text(50,0,CruiseName)
     hold off
  end
end

if plotO2
   for idep=1:ndep
     figure
     [Con,Han]=contour(xxi,yyi,o2units*o2grid(:,:,idep));
     clabel(Con,Han);
     title(['Gridded Oxygen (ml/l) at depth ' num2str(stddep(idep))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(o2(idep,:)));
     plot(xgrid(i),ygrid(i),'r*');
     text(50,0,CruiseName)
     hold off
  end
end

