% routine to plot MOCNESS vertical info w/sizesym
%yr=questdlg('what year?','93','94');
yr='93'
ra=4;
subplot(2,1,1)
%load data
eval(['load /home3/ocn/jmanning/gbs',yr,'/gregs/strat',yr,'c.dat']);
eval(['ss=strat',yr,'c;']);

%   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);

%st=input('Start time (yd): ');
st=floor(min(sstime))
%et=input('end time (yd): ');
et=ceil(max(sstime))

%coh=questdlg('What?','Cod','Haddock','both');
coh='Cod'
% dotc=questdlg('What color dot?','m','k','g');
%dotc='g';
%disp(['Hardcoded to dot color = ',dotc]);

wf='Weighted Mean Depth';

ss(:,15:20)=-1*ss(:,15:20);

sizef=[' Small';'Medium';' Large';'MG Dep']; 

hold on;

% plot running Ave of the three size distributions
for ks=1:3;
  dotc=['c',int2str(ks)];
% calculate a running average
  [yf,ff]=runave(sstime,ss(:,17+ks),ra,0,0,1);
  keyboard
% calulate an hourly wmd depth based on this point average
  hrtime=min(ff):1/24:max(ff);
  wmdhr=interp1(ff,yf,hrtime);
  hrlywmd=[hrtime' wmdhr];
  if ks==2;
    eval(['save /home3/ocn/jmanning/gbs',yr,'/hrlywmd',coh,yr,'.dat hrlywmd -ascii']);
  end;
  plot(hrtime,wmdhr,'.','markersize',10*ks-2,'color',dotc);

%  plot(ff,yf,'linewidth',3*ks-2,'color',dotc);
% Label each line
%  xxx=min(ff)-.1,yyy=yf(1);ha='right';
%  else;xxx=max(ff),yyy=yf(length(yf));ha='left';end;
%  text(xxx,yyy,sizef(ks,:),'color',dotc,...
%  'fontsize',16,'horizontalalignment',ha);
%caculate running average strat in case we need it
  eval(['[yf',num2str(ks),',ff]=runave(sstime,ss(:,5+ks),ra,0,0,1)']);
end;
  plot(ff,-1*yf3,'linestyle','-','linewidth',9,'color','b');
%  text(min(ff),-1*yf3(1),'MG Dep','color','b',...
%  'fontsize',16,'horizontalalignment','right');

hl=legend(sizef);
%set(hl,'position',[ 0.15          0.40          0.11          0.19])
set(hl,'xcolor',[0 0 0])
set(hl,'ycolor',[0 0 0])

% plot the three size distributions
for ks=1:3;
  dotc=['c',int2str(ks)];
%  sizesym(sstime,ss(:,17+ks),ss(:,14+ks),2,.75,dotc);
end;


% post title & MOCNESS numbers
%  title([sizef(wsize,:),' ',coh,' ',wf],'fontsize',18)
  text(st+1,-3,['May 19',yr,' (1m MOCNESS Haul #s)'],...
   'horizontalalignment','left','verticalalignment','bottom')
  for kk=1:nr;
    mocn=num2str(ss(kk,1));
    text(sstime(kk),-6,mocn(3:4),...
    'horizontalalignment','center' ,'verticalalignment','bottom',...
    'fontsize',6);
  end;
  title([wf,' (',num2str(ra),'-pt. running average)'],'fontsize',18)
  text(mean(sstime),-40,coh,'fontsize',20);
%wvar=menu('which other variable?','tide','strat');
wvar=2;
if wvar==1;
% Calulate tide
  th=floor(st):1/24:ceil(et);
  nh=length(th);
  yy=str2num(yr);
  [u,v]=detide(-67.98*ones(nh,1),40.8*ones(nh,1),(yy-94)*(365*24)+th*24);

% interp u onto moc time
  um=interp1(th,u,sstime);

  [ax,pl,ylab]=plotyy(th,u*100,sstime,ss(:,18),...
  'Weighted Mean Depth (m)',[0 0 0 st et  -40 40 minnnan(wmd) maxnnan(wmd)]);
  set(ylab,'fontsize',18)
  set(pl(1),'color','b');
  set(pl(2),'visible','off');

elseif wvar==2;
% plot symbol size according to strenth of strat
  dotc='b';
%  sizesym(sstime,-1*ss(:,8),-1*ss(:,7),2,.75,'b');
%  sizesym(sstime,-10*ones(nr,1),ss(:,6),2,.75,'c');

  [ax,pl,ylab]=plotyy(ff,yf2,sstime,ss(:,18),...
  'Weighted Mean Depth (m)',[0 0 0 141 147 min(ss(:,7)) max(ss(:,7)) -50 0]);
  set(pl(1),'color','m','linewidth',3,'linestyle','--');
  axes(ax(1));
    text(max(ff),yf2(length(yf2))-.025,'Max Grad','color','m',...
  'fontsize',14,'horizontalalignment','center','verticalalignment','top');

  set(pl(2),'visible','off');
  set(ax(1),'ycolor','m')
%  ylabel('Max Density Gradient <30m (sigmat units)',...
%        'color','m','fontsize',16);
end;

% put in fill for day night

%reduce ticks
%set(gca,'xtick',[st:(et-st)/4:et]);
yy=str2num(yr);
set(gca,'xticklabels','');
xlabel('')
%yd2calab(yy); 
%axes(hl)
%set(gca,'position',[0.13 0.581098 0.725 0.40902])
%set(gca,'box','on')

subplot(2,1,2)
%load data
eval(['load /home3/ocn/jmanning/gbs',yr,'/gregs/strat',yr,'h.dat']);
eval(['ss=strat',yr,'h;']);

%   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);

%st=input('Start time (yd): ');
st=floor(min(sstime))
%et=input('end time (yd): ');
et=ceil(max(sstime))

%coh=questdlg('What?','Cod','Haddock','both');
coh='Haddock'
% dotc=questdlg('What color dot?','m','k','g');
%dotc='g';
%disp(['Hardcoded to dot color = ',dotc]);

wf='Weighted Mean Depth';

ss(:,15:20)=-1*ss(:,15:20);


hold on;

% plot running Ave of the three size distributions
for ks=1:3;
  dotc=['c',int2str(ks)];
% calculate a running average
  [yf,ff]=runave(sstime,ss(:,17+ks),ra,0,0,1);
%  plot(ff,yf,'linewidth',3*ks-2,'color',dotc);

% calulate an hourly wmd depth based on this point average
  hrtime=min(ff):1/24:max(ff);
  wmdhr=interp1(ff,yf,hrtime);
  hrlywmd=[hrtime' wmdhr];
  if ks==2;
    eval(['save /home3/ocn/jmanning/gbs',yr,'/hrlywmd',coh,yr,'.dat hrlywmd -ascii']);
  end;
  plot(hrtime,wmdhr,'.','markersize',10*ks-2,'color',dotc);

%caculate running average strat in case we need it
  eval(['[yf',num2str(ks),',ff]=runave(sstime,ss(:,5+ks),ra,0,0,1)']);
end;
  plot(ff,-1*yf3,'linestyle','-','linewidth',9,'color','b');

%sizef=['   Small Haddock';'  Medium Haddock';'   Large Haddock';'Dep Max Grad    ']; 
%hl=legend(sizef);

% plot the three size distributions
for ks=1:3;
  dotc=['c',int2str(ks)];
%  sizesym(sstime,ss(:,17+ks),ss(:,14+ks),2,.75,dotc);
end;


% post title & MOCNESS numbers
%  title([sizef(wsize,:),' ',coh,' ',wf],'fontsize',18)
%  text(st+.25,maxnnan(ss(:,18))+3,['May 19',yr,' (1m MOCNESS Haul #s)'],...
%   'horizontalalignment','left','verticalalignment','top')
%  for kk=1:nr;
%    mocn=num2str(ss(kk,1));
%    text(sstime(kk),maxnnan(ss(:,18)),mocn(3:4),...
%    'horizontalalignment','center' ,'verticalalignment','top',...
%    'fontsize',6);
%  end;
%  title([wf,' (6-pt. running average)'],'fontsize',18)
  text(mean(sstime),-40,coh,'fontsize',20);

%wvar=menu('which other variable?','tide','strat');
wvar=2;
if wvar==1;
% Calulate tide
  th=floor(st):1/24:ceil(et);
  nh=length(th);
  yy=str2num(yr);
  [u,v]=detide(-67.98*ones(nh,1),40.8*ones(nh,1),(yy-94)*(365*24)+th*24);

% interp u onto moc time
  um=interp1(th,u,sstime);

  [ax,pl,ylab]=plotyy(th,u*100,sstime,ss(:,18),...
  'weighted mean depth (m)',[0 0 0 st et  -40 40 minnnan(wmd) maxnnan(wmd)]);
  set(ylab,'fontsize',18)
  set(pl(1),'color','b');
  set(pl(2),'visible','off');

elseif wvar==2;
% plot symbol size according to strenth of strat
  dotc='b';
%  sizesym(sstime,-1*ss(:,8),-1*ss(:,7),2,.75,'b');
%  sizesym(sstime,-10*ones(nr,1),ss(:,6),2,.75,'c');

  [ax,pl,ylab]=plotyy(ff,yf2,sstime,ss(:,18),...
  'Weighted Mean Depth (m)',[0 0 0 141 147 min(ss(:,7)) max(ss(:,7)) -50 0]);
  set(pl(1),'linestyle','--','color','m','linewidth',3);
  set(pl(2),'visible','off');
  set(ax(1),'ycolor','m')
  ylabel('Max Density Gradient <30m (sigmat units)',...
        'color','m','fontsize',14);
end;

% put in fill for day night

%reduce ticks
%set(gca,'xtick',[st:(et-st)/4:et]);
yy=str2num(yr);
yd2calab(yy); 
%axes(hl)

%set(gca,'position',[0.13 0.1581098 0.725 0.40902]) 
%set(gca,'box','on')
%set(ax(2),'position',[0.13 0.1581098 0.725 0.40902])
%set(ax(2),'box','on')

