yr=94;
path(path,'/home3/ocn/jmanning/atsee/saga')
npan=2;

% sometimes need two files
if yr==93;
  st=141.5;et=147.5;
  load /data5/jmanning/ctd/jgofout/al9306/nmfs_ctd_1993a
  x1=lyd;y1=press;z1=temp;s1=sal;c1=cast;lat1=lat;lon1=lon;
  load /data5/jmanning/ctd/jgofout/al9306/nmfs_ctd_1993b
  lyd=[x1;lyd];press=[y1;press];temp=[z1;temp];sal=[s1;sal];cast=[c1;cast];
      lat=[lat1;lat];lon=[lon1;lon];
  yrday0_gmt=lyd+4/24-1;
elseif yr==94;
  st=140.5;et=146.5;
  load /data5/jmanning/ctd/jgofout/al9403/nmfs_ctd_1994all

%%%%%%%%%%%  WARNING: DOUBLE CHECK YEARDAY
  lyd=yrday1_local;
  yrday0_gmt=lyd+4/24-1;

elseif yr==95;
  if sta==188;
    load /data5/jmanning/ctd/jgofout/sj9507/nmfs_ctd_1995_188
    yrday0_gmt=yrday1_gmt;
  elseif sta==197;
    load /data5/jmanning/ctd/jgofout/sj9507/nmfs_ctd_1995
  end;
elseif yr==97;
   if sta==82;
     load /data5/jmanning/ctd/jgofout/oc301/nmfs_ctd_82
   else;
      load /data5/jmanning/ctd/jgofout/oc303/nmfs_ctdsb
   end;
   temp=temp_ctd;
   sal=sal_ctd;
   clear sigmat;
end;

%%%%%%%%%%%%%%%%%%   Delimit CTD Data  %%%%%%%%%%%%%%%%%%

% subsample
disp([num2str(length(cast)), ' points']);
%npts=input('Number of ctd pts to skip?');
npts=2;
disp(['HARDCODED to skip every ',num2str(npts),' points']);

% correct yrday1_local to yrday0_gmt (if necessary subtract 1)
% differs each year

x=yrday0_gmt(1:npts:length(yrday0_gmt));
y=-1*press(1:npts:length(yrday0_gmt));
z=temp(1:npts:length(yrday0_gmt));
s=sal(1:npts:length(yrday0_gmt));
c=cast(1:npts:length(yrday0_gmt));
lat=lat(1:npts:length(yrday0_gmt));
lon=lon(1:npts:length(yrday0_gmt));


% rid of NaN's
id=find(isnan(x)~=1);
x=x(id);y=y(id);z=z(id);c=c(id);s=s(id);lat=lat(id);lon=lon(id);

% Choose casts & build the new collection of data
%cvec=input('Enter cast number vector: ');
%if yr==93;;cvec=[6:12 40:50 53:64 159:163];
if yr==93;
  cvec=[6:12 53:64 159:163];
elseif yr==94;
  cvec=[1:11 61:73];
elseif yr==95;
  if sta==188;
    cvec=[1 3:6];
  else;
    cvec=[49:1:55 57];
  end
elseif yr==97;
  if sta==82;
    cvec=[2:14 18:19];
  else;
    cvec=[2 4:7 9:11];
  end;
end;
%if yr==93;cvec=[ 53:64 ];elseif yr==94;cvec=[1:7 61:73];end
%if yr==93;cvec=[ 53:64 ];elseif yr==94;cvec=[61:73];end

for k=1:length(cvec);
  id=find(c==cvec(k));
  if k==1;
    xn=x(id);yn=y(id);zn=z(id);sn=s(id);cn=c(id);latn=lat(id);lonn=lon(id);
  else;
    xn=[xn;x(id)];yn=[yn;y(id)];zn=[zn;z(id)];sn=[sn;s(id)];cn=[cn;c(id)];latn=[latn;lat(id)];lonn=[lonn;lon(id)];;
  end;
end;
x=xn;y=yn;z=zn;s=sn;c=cn;lat=latn;lon=lonn;

% set sc=1 to skip contours;
sc=0;

   
% Now the nsec contours
nsec=2;  
for ksec=1:nsec;
  subplot(npan,1,ksec);

% Change parameters relative to section #
% make it density in second section
% choose contour levels and cbar levels

  if ksec==1;
    var='temperature';
    v=[7.:.2:10.];
    ci=.1;cl=.2;
  elseif ksec==2;z=sigmat(s,z)-1000;
    var='sigma-t';
%    v=[25.0:.1:25.7];
    v=[25.0:.1:26.0];
    ci=.025;cl=.05;
  end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   GRID DATA  &&&&&&&&&&&&&&&&&&&&&&&

% gd=menu('Grid data?','use griddata',...
%                         'use sagas mincurvi',...
%                         'use sagas kriging',...
%                         'use sagas objmap',...
%                          'none');       
  gd=4;

  [zi,xi,yi]=gridopts(x,y,z,gd,25,.5,[3 5],[32 8 500 1/3 1]);

%%%%%%%%%%%%%%%%%%%%% DEFINE METHOD OF CONTOURING %%%%%%%%%%%%%%%%%%

% ptype=menu('Plot type?','pcolor & contour','econtour','contourf');
  ptype=2;

%%%%%%%%%%%%%%%%%%%%%%%%%%  Do the Contouring Now %%%%%%%%%%%%%%%%


  if ptype==1;
	pcolor(yrday_gmt(1:ncasts) ,pmatrix(1:maxmax,innlonxmax),zz(1:maxmax,1:ncasts));
	hold on
	cs=contour(yrday_gmt(1:ncasts) ,pmatrix(1:maxmax,innlonxmax),zz(1:maxmax,1:ncasts),v);
	clabel(cs,'manual')
    shading interp
  elseif ptype==2;
    disp('Hardconlond to use EXTCONTOUR.');
    if gd<=4;
%      wop=menu('what?','color shade','line contour');
       wop=1;
        if wop==1;
          disp('Hardcoded to color shades');
	  econtour(xi,yi,zi,v,'label',140,'fill','color','k','fontsize',10);
        else;
	  econtour(xi,yi,zi,v,'label',140,'color','g','fontsize',10);
        end;
    else;
	  econtour(yrday_gmt(1:ncasts),pmatrix(1:maxmax,innlonxmax),zz(1:maxmax,1:ncasts),v,'fill');
    end;
%    caxis([min(v) max(v)]);
%    cbar(gca,'h',ci,cl);
  elseif ptype==3;
    disp('Hardconlond to use CONTOURF.');
    cbarjm(gca,'v',ci,cl,v);
    if gd<=4;
	  contourf(xi,yi,zi,v);
    else;
%         note that contourf does not accept NaNs so we set bottm temp to
      for kl=1:ncasts;
        idl=find(isnan(zz(:,kl))==1);
        zz(idl,kl)=zz(maxpindex(kl),kl)*ones(length(idl),1);
      end;
      contourf(yrday_gmt(1:ncasts),pmatrix(1:maxmax,indexmax),zz(1:maxmax,1:ncasts),v);
    end;
  end;

%%%%%%%%%%%%%%%%  Blankout bottom %%%%%%%%%%%%%%%%%%%%%

  maxy=-80;
  id=find(diff(c)~=0);
% find bottom values for this subset
  idbot=[id; length(c)];
  yblk=[y(idbot)+5; maxy; maxy; y(idbot(1))+5];
  xblk=[x(idbot); et; floor(st);floor(st)];
  hold on;
  fill(xblk,yblk,'w');


%%%%%%%%%%%%%%%%  Fix Axis & Label %%%%%%%%%%%%%%
  axis([floor(st) et maxy 0])
  if ksec==1;
    h=text(mean(x),10,'CTD Stations','horizontalalignment','center');
    disp('Hardcoded to title only top most section')
    id=find(diff(c)~=0);
    id=[id; length(c)];
    plot(x(id)',ones(length(id),1)*(-1.),'w+');
    skip=2;
    for i=1:skip:length(id);
      h=text(x(id(i))',3.,num2str(c(id(i))));
      set(h,'FontSize',8,'HorizontalAlignment','center',...
       'verticalAlignment','bottom')      
    end
   set(gca,'xticklabels','')
  elseif ksec==nsec;
    id=find(diff(c)~=0);
    id=[id; length(c)];
    plot(x(id)',ones(length(id),1)*(-1.),'w+');
    ylabel('Depth(m)')
    text(st,-75,['Stratified Site 19',num2str(yr)],'color','k'); 
    yd2calab(yr)
  end;
%  set(gca,'xticklabels','')
  text(st+.5,-40,var,'fontsize',16);
  hgt=.17;
  if yr==93;
%    set(gca,'position',[aap(1)    aap(2)-hgt*ksec+hgt    0.60    hgt])
  elseif yr==94;
%    set(gca,'position',[aap(1)    aap(2)-hgt*ksec-.04    0.61    hgt])
  elseif yr==95;
    set(gca,'position',[aap(1)    aap(2)-hgt*ksec-.04    aap(3)    hgt])
  elseif yr==97;
    set(gca,'position',[aap(1)    aap(2)-hgt*ksec-.05    aap(3)    hgt])
  end;

% end of multiple contour panels
end;

% post biology on sigmat plot
  if yr<93;
    eval(['load /home3/ocn/jmanning/gbs',num2str(yr),'/gregs/strat',num2str(yr),'c.dat']);
    eval(['ss=strat',num2str(yr),'c']);
    hold on;
    coh=questdlg('What?','Cod','Haddock','both');
    dotc=questdlg('What color dot?','m','k','g');
%    wf=questdlg('Which form?','no./net','no./10m2');
    wf='no./10m2';
%   calculate gmt yrday0_gmt
    [nr,nc]=size(ss);
    sstime=julian(ss(:,3),ss(:,4),ss(:,2)-1900,0*ones(nr,1))+ss(:,5)+4/24*ones(nr,1);
    ss(:,15:17)=-1*ss(:,15:18);
    sizesym(sstime,ss(:,18),ss(:,15),2,.5,dotc);
    text(floor(st)+(et-st)/20,mean(yi),coh,'color','w','fontsize',18)
    text(floor(st)+(et-st)/30,-50,wf,'color','w','fontsize',16)

  elseif yr==95;
    eval(['load /home3/ocn/jmanning/gbs95/moc/s',num2str(sta),'.pre']);
    eval(['ss=s',num2str(sta)]);
    hold on;
    
    id=find(ss(:,4)>-100);
    coh=menu('What?','Cod','Haddock','both');
    dotc=questdlg('What color dot?','m','k','g');
    wf=questdlg('Which form?','no./net','no./100m3');
    if wf=='no./100m3';
%      standardize these
       ss(:,5)=ss(:,5)./ss(:,7)*100;
       ss(:,6)=ss(:,6)./ss(:,7)*100;
    end;
    ss(:,5:6)=-1*ss(:,5:6);
    if coh==1;
      sizesym(ss(id,1),ss(id,4),ss(id,5),2,.5,dotc);
      text(floor(st)+(et-st)/20,mean(yi),'Cod','color','w','fontsize',18)
    elseif coh==2;
      sizesym(ss(id,1),ss(id,4),ss(id,6),2,.5,dotc);
      text(floor(st)+(et-st)/20,mean(yi),'Haddock','color','w','fontsize',18)
    elseif coh==3;
      sizesym(ss(id,1),ss(id,4),ss(id,5)+ss(id,6),2,.5,dotc);
      text(floor(st)+(et-st)/20,mean(yi),'Larvae','color','w')
    end;
    text(floor(st)+(et-st)/30,-50,wf,'color','w','fontsize',16)
  end;

elseif sc==1;
% end of contouring skip
  disp('************  WARNING *************')
  disp(' HARD CODED TO NOT SKIP THE GRIDDING & CONTOURING');
end;
orient tall

