% routine to put MOCNESS tow on xsections

% get the matrix "d" of MOCNESS info
% with:  lat lon sta haul day hhmm code s/e(0/1)
%   in:   1   2  3   4    5   6    7    8
readmoc;

    hm=input('How many MOCNESS do you want overlyed?');
%hm=2;
if hm==0;return;end;

coh=menu('What?','Cod','Haddock','both');
%  coh=1;
%  disp('Cod')
%  dotc=questdlg('What color dot?','m','k','g');
dotc='r';
disp(['Hardcoded to dot color = ',dotc]);
%  wf=questdlg('Which form?','(no./net)  ','(no./100m3)');
wf='(no./100m3)'

clear ssf dd2f

[nr,nc]=size(yadcp);
load isobath60;

for i=1:hm;
 
  dfn=input('Enter MOCNESS haul#: ');
  idd=find(d(:,4)==dfn);
  dd=d(idd,:);
  df=[df dd];

%  find the cross-sectional distance of start & stop
  refx=2;
  if refx==1;

    if yadcp(1,2)>yadcp(nr,2);
       dd1=dist(yadcp(1,2),yadcp(1,1),dd(1,1),dd(1,2));
       dd2=dist(yadcp(1,2),yadcp(1,1),dd(2,1),dd(2,2));
    else;
       dd1=dist(yadcp(nr,2),yadcp(nr,1),dd(1,1),dd(1,2));
       dd2=dist(yadcp(nr,2),yadcp(nr,1),dd(2,1),dd(2,2));
    end;

  elseif refx==2; 
%  find dist based 60m isobath
    disp('Hardcoded to reference 60m isobath');
    reflat=interp1(lon60,lat60,dd(2,2));
    ddd=dist(reflat,dd(2,2),dd(2,1),dd(2,2));
    if reflat<dd(2,1);ddd=-ddd;end;
    dd2=ddd;
  end;
   
   dd2f=[dd2f; dd2*ones(6,1)];
   
%  plot a seasaw line
   midway=(dd2+dd1)/2;
   hold on;

%  plot haul pth?
%   plot([dd1 midway dd2],[0 dmax 0],'r','linewidth',2)

%  generate catch matrix
   yr='97';
%  sta=input('station #?','s');
   sta='both';
   eval(['load /home3/ocn/jmanning/gbs',yr,'/moc/s',sta,'.dat;']);
   ss=eval(['s',sta]);

%  extract this haul
   ss=ss(find(ss(:,2)==dfn),:);

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

   ssf=[ssf; ss];


% post MOCNESS numbers
    text(dd2,-10,['M',num2str(ss(1,2))],...
    'horizontalalignment','center' ,'verticalalignment','bottom',...
    'color','r','fontsize',14);
%  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;

if coh==1;
    sizesym(dd2f,ssf(:,4),ssf(:,5),1,.6,dotc);
    text(10,-56,'Cod','color',dotc,'fontsize',18)
elseif coh==2;
    sizesym(dd2f,ssf(:,4),ssf(:,6),1,.5,dotc);
    text(5,-56,'Haddock','color',dotc,'fontsize',18)
elseif coh==3;
    sizesym(dd2f,ssf(:,4),ssf(:,5)+ssf(:,6),1,.5,dotc);
    text(10,-60,'Larvae','color',dotc,'fontsize',18)
end;
  text(5,-60,wf,'color',dotc,'fontsize',16)

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

%end;

      