  function [y]=adcpprof(jdw1,jdw2,mode,sec);
%
%  function [y]=adcpprof(jdw1,jdw2,mode);
%  
%   y=[xx yy z bbotd u v uf vf jd]  where uf and vf are detide w/julios
%   jdw1=first fractional yearday in yd0gmt form;
%   jdw2=second
%   mode=2;
%   sec= the section of data that may be already in .mat form
%
%  routine to plot adcp data in different ways
%
%  mode=1 means vertical profiles
%  mode=2 means contoured cross-sections
%  mode=3 means plot a time series of vertically averaged data
%
%  NOTE: ADCP julian day as read is referenced to Jan 1, 1994 
%    but the input data is reference to 1995

%  NOTE: THIS ROUTINE IS CALLED FROM "MOVEC.M", "PROCESS.M", "VERSEC.M" 

%make "kk" the increment of data and "k" the flag that data has been found
 kk=0;
  k=0;

if nargin>3;
  eval(['load /data5/jmanning/adcp/sj9507/sec',num2str(sec)]);
else;

% read the eight adcp files until this period is covered
  for j=1:8;
    if k~=99;
      k=k+1;
      eval(['load /data5/jmanning/adcp/sj9507/transj9507',num2str(j)]);
      disp(['searching transj9507',num2str(j)])

%     find out if there is any records in this file we need
      if jdw2<min(djul-365)|jdw1>max(djul-365);
%        case to skip this file
%        disp(['skip file ',num2str(j)]);

      else

        disp('  found some...');
%       find the desired rows of the header file
        id=find(djul-365>=jdw1&djul-365<jdw2);

        if id~=[];

%         load the associated profile data
          eval(['load /data5/jmanning/adcp/sj9507/profsj9507',num2str(j)]);

          for ip=1:length(id);
            x=lon(id(ip));
            y=lat(id(ip));
            botd=dep(id(ip));

%           calculate depth averaged tide
%           detide w/julios routine which requires time in hours since 1/1/94
            [ut,vt]=detide(x,y,djul(id(ip))*24);

%           find the desired profile data by matching decimal yearday
            id2=find(djulp==djul(id(ip)));
            if ip==1;
              xx=x*ones(length(id2),1);
              yy=y*ones(length(id2),1);
              bbotd=botd*ones(length(id2),1);
              z=zp(id2);
              u=up(id2);
              v=vp(id2);
%             remove depth averaged tide
              uf=u-ut;
              vf=v-vt;
              yd=djulp(id2)-365;
            else;
              xx=[xx; x*ones(length(id2),1)];
              yy=[yy; y*ones(length(id2),1)];
              bbotd=[bbotd; botd*ones(length(id2),1)];
              z=[z; zp(id2)];
              u=[u; up(id2)];
              v=[v; vp(id2)];
              uf=[uf; up(id2)-ut*100];
              vf=[vf; vp(id2)-vt*100];
              yd=[yd; djulp(id2)-365];
            end;
            k=99;
          end;
        end;
      end;
    end;
  end;
end;
%   done finding ADCP data for this time period 


% mode=1 profiles
  
if mode==1;
% make profile of good points (std<10)
  id3=find(abs(u)<200);
  if id3~=[]&std(u)<10;
    plot(u(id3),-1*z(id3),'r.','markersize',20)
    hold on;
    plot(v(id3),-1*z(id3),'w.','markersize',20)
    [date]=calday(95,jdw-365);
    if date(3)==11&date(4)==0; disp(['jdw',num2str(jdw-365)]); end;
    title(['May ',num2str(date(3)),' ',num2str(date(4)),' GMT @ ',num2str(y(1)),'N and ',num2str(x(1)),'W']);
    ylabel(['Depth (m)']);
    text(-75,-70,['bottom depth = ',num2str(floor(botd)),'m']);
    text(-75,-90,'E/W (red) and N/S (black) current cm/sec')
    axis([-100 100 -100 0]);
  end;

end;
%    end of loop to plot profiles


if mode==2;
% make contoured cross-section given
  y=[xx yy z bbotd u v uf vf yd];
  figure(2);
  subplot(2,1,1)
   plot(xx,yy);
   hold on;
   plot(xx(1),yy(1),'r.','markersize',40);
   set(gca,'aspectratio',[1 .78]);
  subplot(2,1,2);
   plot(yd,u,yd,uf);
%   yd2calab(95);
  figure(1);
end;

if mode==3;
% load vertically averaged data
  disp('Hardcoded to Use hourly averaged adcp here')     
  load /data5/jmanning/adcp/sj9507/tranhsj9507;

% find this yearday
  ya=th/24-365;
  ua=uth;
  va=vth;

% plot the time series in Figure 2;
  figure(2)
  plot(ya,ua,ya,va,'--','linewidth',3);
  lyd;
  title('ADCP hourly vbar')
end;