   cru='oc303'
  for i=[2:22];
      if i<10;sta='00';else;sta='0';end;
      fid=fopen(['/data5/jmanning/ctd/cnv/oc303/',cru,sta,num2str(i),'.cnv'],'r');
      mark='888888';
      while length(mark)>5;
        mark=fgetl(fid);
      end;
      d=fscanf(fid,'%f',inf);
      eval(['d',num2str(i),'=(reshape(d,11,length(d)/11))'';']);
%     rid of scan number or choose desired variables
      disp('Note: we have switched variables here for oc303.')
      eval(['d=[d',num2str(i),'(:,1:3) d',num2str(i),'(:,5) d',num2str(i),'(:,7) d',num2str(i),'(:,6)];']);


% HERE'S where we cut off the upcast  but use the top values
      d2=d(find(diff(d(:,1))>0),:);
      d3=[d(find(diff(d(:,1))<0),:);d(length(d),:)];
      

% HERE"S where we use upcast values
      clf;
      maxd=40;
      disp('Click where you want cutoff and press return')
      plotyy(-1*d(1:maxd,1),d(1:maxd,3),-1*d(1:maxd,1),d(1:maxd,4))
      title(['cast# ',num2str(i)]);
      [cut,x]=ginput;
      cut=-1*cut;
      id=find(d2(:,1)<cut);
      for kk=1:id(length(id));
        id3=find(d3(:,1)==d2(kk,1));
        d2(kk,2:4)=d3(id3,2:4);
      end;
      hold on;
      plot(-1*d2(1:maxd,1),d2(1:maxd,3),'linewidth',2,'color','g');
      pthis;
      pause(2)
      

        
     
      heads=['SEABIRD 911 Cast (first downcasts)                          ';...
             '------------------------------------------------------------';...
             'press    temp_ctd    sal_ctd  sigmat  flvolt light_tran_v   '];

      fploopy(d2,['/data1/jgofs/',cru,'/',cru,sta,num2str(i),'.asc'],'o',heads)
  end;