%  PlotSigGrid.m
%     Plot 3d grid of values from a cruise
%     interpolated onto density surfaces
%
%      define to load depth grid
% loaddep=1;
% loadcoast=1;
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;
PlotRange=[-50 550 -50 350];

plotDep=1;
plotT=0;
plotPT=0;
plotS=0;
plotO2=0;

CruiseName='NBP0103';
%CruiseName='NBP0104';

if loaddep
%                    load etopo2 for west Ant Pen region
%                    loads variables londep, latdep, zdep, xdep, ydep
  load wap.etopo2.mat;
  loaddep=0;
end
if loadcoast
%                    load coastline for west Ant Pen region
%                    loads variables xcoast ycoast
  load wap3_coast_xy.mat;
  loadcoast=0;
end
load([CruiseName '.gridstns.mat']);
load([CruiseName '.siggrid.mat']);

[m nsig]=size(siglevels);
[n,nx]=size(xi);
[n,ny]=size(yi);
[xxi,yyi]=meshgrid(xi,yi);

if plotDep
   for isig=1:nsig
     figure
     i=find(~isnan(DepSigGrid(:,:,isig)) & DepSigGrid(:,:,isig) > 1);
     if(~isempty(i))
       [Con,Han]=contour(xxi,yyi,DepSigGrid(:,:,isig));
       clabel(Con,Han);
     else
       text(250,200,'Density surface does not occur')
     end
     title(['Depth of sigma ' num2str(siglevels(isig))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(PTsig(isig,:)));
     plot(xgrid(i),ygrid(i),'r*');
     i=find(isnan(DepSigGrid(:,:,isig)));
     plot(xxi(i),yyi(i),'go');
     plot(xcoast,ycoast);
     text(50,0,CruiseName)
     hold off
  end
end

if plotT
   for isig=1:nsig
     figure
     i=find(~isnan(TonSigGrid(:,:,isig)));
     if(~isempty(i))
       [Con,Han]=contour(xxi,yyi,TonSigGrid(:,:,isig));
       clabel(Con,Han);
     else
       text(250,200,'Density surface does not occur')
     end
     title(['Gridded Temp on sigma ' num2str(siglevels(isig))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(PTsig(isig,:)));
     plot(xgrid(i),ygrid(i),'r*');
     i=find(isnan(DepSigGrid(:,:,isig)));
     plot(xxi(i),yyi(i),'go');
     plot(xcoast,ycoast);
     text(50,0,CruiseName)
     hold off
  end
end
if plotPT
   for isig=1:nsig
     figure
     i=find(~isnan(PTonSigGrid(:,:,isig)));
     if(~isempty(i))
       [Con,Han]=contour(xxi,yyi,PTonSigGrid(:,:,isig));
       clabel(Con,Han);
     else
       text(250,200,'Density surface does not occur')
     end
     title(['Gridded Pot Temp on sigma ' num2str(siglevels(isig))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(PTsig(isig,:)));
     plot(xgrid(i),ygrid(i),'r*');
     i=find(isnan(DepSigGrid(:,:,isig)));
     plot(xxi(i),yyi(i),'go');
     plot(xcoast,ycoast);
     text(50,0,CruiseName)
     hold off
  end
end
if plotS
   for isig=1:nsig
     figure
     i=find(~isnan(SonSigGrid(:,:,isig)));
     if(~isempty(i))
       [Con,Han]=contour(xxi,yyi,SonSigGrid(:,:,isig));
       clabel(Con,Han);
     else
       text(250,200,'Density surface does not occur')
     end
     title(['Gridded Salinity on sigma ' num2str(siglevels(isig))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(Ssig(isig,:)));
     plot(xgrid(i),ygrid(i),'r*');
     i=find(isnan(DepSigGrid(:,:,isig)));
     plot(xxi(i),yyi(i),'go');
     plot(xcoast,ycoast);
     text(50,0,CruiseName)
     hold off
  end
end
if plotO2
   for isig=1:nsig
     figure
     i=find(~isnan(O2onSigGrid(:,:,isig)));
     if(~isempty(i))
       [Con,Han]=contour(xxi,yyi,o2units*O2onSigGrid(:,:,isig));
       clabel(Con,Han);
     else
       text(250,200,'Density surface does not occur')
     end
     title(['Gridded Oxygen on sigma ' num2str(siglevels(isig))]);
     axis(PlotRange);
     hold on;
     i=find(~isnan(Ssig(isig,:)));
     plot(xgrid(i),ygrid(i),'r*');
     i=find(isnan(DepSigGrid(:,:,isig)));
     plot(xxi(i),yyi(i),'go');
     plot(xcoast,ycoast);
     text(50,0,CruiseName)
     hold off
  end
end

