clf
% routine to plot MOCNESS vertical info w/sizesym
%yr=questdlg('what year?','94','95','97');
yr='97';
%sta=input('station #?','s');
sta='155';
eval(['load /home3/ocn/jmanning/gbs',yr,'/moc/s',sta,'.dat;']);
ss=eval(['s',sta]);;

   st=input('Enter start yearday: ');
   et=input('Enter end yearday: ');
%  st=132;
%  et=135;
%  st=min(ss(:,1));
%  et=max(ss(:,1));
  yi=ss(:,4);
  id=find(ss(:,4)>-100);
 coh=menu('What?','Cod','Haddock','both');
%  coh=1;
%  disp('Cod')
% dotc=questdlg('What color dot?','m','k','g');
  dotc='g';
  disp(['Hardcoded to dot color = ',dotc]);
% wf=questdlg('Which form?','(no./net)  ','(no./100m3)');
  wf='(no./100m3)'
  if yr=='95';
    if wf=='no./100m3';
%     standardize these
      ss(:,5)=ss(:,5)./ss(:,7)*100;
      ss(:,6)=ss(:,6)./ss(:,7)*100;
    end;
  end;

% make them negative so "sizesym" draws them as circle
  ss(:,5:6)=-1*ss(:,5:6);

  subplot(2,1,1);
  if coh==1;
    sizesym(ss(id,1),ss(id,4),ss(id,5),1,.6,dotc);
    text(st+(et-st)/20,-40,'Cod','color','g','fontsize',18)
  elseif coh==2;
    sizesym(ss(id,1),ss(id,4),ss(id,6),1,.5,dotc);
    text(st+(et-st)/20,-40,'Haddock','color','g','fontsize',18)
  elseif coh==3;
    sizesym(ss(id,1),ss(id,4),ss(id,5)+ss(id,6),1,.5,dotc);
    text(st+(et-st)/20,-40,'Larvae','color','g','fontsize',18)
  end;
  text(st+(et-st)/30,-55,wf,'color','g','fontsize',16)

% post MOCNESS numbers
  idn=find(diff(ss(id,2))~=0);
  for kk=1:length(idn);
    text(ss(idn(kk),1),0,num2str(ss(idn(kk),2)),...
    'horizontalalignment','center' ,'verticalalignment','bottom');
  end;
  text(ss(length(ss),1),0,num2str(ss(length(ss),2)),...
      'horizontalalignment','center' ,'verticalalignment','bottom');
%  text(ss(1,1)-.1,0,'MOC1#','horizontalalignment','right',...
%     ,'verticalalignment','bottom')
end;

% Calculate Weighted Mean Depths
if coh==3;
% add the two
  ss(:,5)=ss(:,5)+ss(:,6);
  coh=1;
end;

wmd(1)=meannnan(ss(1:idn(1),4).*ss(1:idn(1),4+coh))./...
    (meannnan(ss(1:idn(1),4+coh)));
for j=2:length(idn);
  wmd(j)=(meannnan(ss(idn(j-1)+1:idn(j),4).*ss(idn(j-1)+1:idn(j),4+coh)))./...
           (meannnan(ss(idn(j-1)+1:idn(j),4+coh)));
end;
wmd(length(idn)+1)=meannnan(ss(idn(length(idn))+1:length(ss),4).*ss(idn(length(idn))+1:length(ss),4+coh))./...
    (meannnan(ss(idn(length(idn))+1:length(ss),4+coh)));

%plot wmd
hh=plot([ss(idn,1); ss(length(ss),1)],wmd,'r-','linewidth',2)
text(st+(et-st)/30,-30,'weighted mean depth','color','r','fontsize',16)

axis([st et -60 0]);

ylabel('Depth (m)')
text(st,10,['Drifter Station ',sta,' (1m MOCNESS Haul #s)'])
%yd2calab(str2num(yr));
set(gca,'xticklabels',[],'box','on')
%,'position',[.1 .55 .5 .4],'box','on');


subplot(2,1,2);

% plot calculated  tide?
calctide='no '
if calctide=='yes';
  th=st:1/24:et;
  nh=length(th);
  [u,v]=detide(-67.98*ones(nh,1),40.8*ones(nh,1),th*24+(str2num(yr)-94)*365*24+floor((str2num(yr)-92)/4)*24);
  plot(th,u*100,'m-',th,v*100,'c--','linewidth',3);
% add label at onbank tide
  id2d=find(diff(diff(u))==min(diff(diff(u))));
  text([th(id2d+1) th(id2d+1)+(12.4/24)],[u(id2d+1)*100 u(id2d+1)*100],...
  'On-bank','fontsize',10,'rotation',90,...
  'horizontalalignment','center' ,'verticalalignment','bottom');
end;


% add drifter u&v
% assumes one has run "overmoc.m" to get the current jgf version in "yy"
[ud,vd,spd,jdn]=ll2uv(yy(:,1),yy(:,3),yy(:,2));
hold on;
plot(jdn,ud,'b',jdn,vd,'y','linewidth',1);
% add label at onbank tide
  idd=find(jdn>=st&jdn<=et);
  [udra,jdra]=runave(jdn(idd)',ud(idd)',12,0,0,1);
  [d1,jd1]=runave(jdra,diff(udra),12,0,0,1);
  [d2,jd2]=runave(jd1,diff(d1),12,0,0,1); 
  id2d=find(d2==min(d2));
  text([jdra(id2d+2)-(12.4/24) jd2(id2d+2) jdra(id2d+2)+(12.4/24)],...
  [udra(id2d+2) udra(id2d+2) udra(id2d+2)],...
  'On-bank','fontsize',10,'rotation',90,...
  'horizontalalignment','left' ,'verticalalignment','middle');

ylabel('Drifter "200a" Speed (cm/s)')
legend('e/w','n/s');
%reduce ticks
axis([st et -50 50]);
%set(gca,'xtick',[st:(et-st)/4:et]);
yd2calab(str2num(yr)); 
set(gca,'box','on')