function getprepdata_bobparse(imdir,cruise,fn)

global b b_column_headings


cr=setstr(13);
lf=setstr(10);

vprdata=0;

%input raw data filename, determine the number of lines,
%  and parse the data using readparse2cshscript, the script that runs the c routine readparse2

[status1 nlines] = dos(['cat ' imdir fn ' | wc -l ']);
ndata=floor(sscanf(nlines,'%d')/30/7)-2;% number of data points to parse 
                                        % i.e. every 30th group of 7 lines in fn
%ndata=floor(sscanf(nlines,'%d')/1/7)-10;% number of data points to parse 
                                        % i.e. every group of 7 lines in fn
%unix([imdir 'readparse2cshscript ' imdir fn ' ' num2str(ndata)]); % does last 1800 30th groups of data i.e. ~ 3 hr moving window for 3hz data.

cmd = ['c:\plgui\sbin\bobparse2' ' ' imdir fn ' ' num2str(ndata,5) ' ' '30'];dos(cmd);

%unix([imdir 'readparse3cshscript ' imdir fn ' ' num2str(ndata,5)]); % does all 30th groups of data in file

%unix([imdir 'readparseallcshscript ' imdir fn ' ' num2str(ndata)]); % does all groups of data in file

clear vprdata;

%Load data file

load .\temp;

  %23 columns contain: yr,mon,dy,lhr,lmin,lsec,hr,mn,sc,frame,pcodelat,pcodelon,chirpz,roll,pitch,
  %       flowcount,tempcount(17),saltcount(18),fluorv(19),transv(20),altim(21)ls,press(22),light(23),
  %       vprlatd(24),vprlatm(25),vprlond(26),vprlonm(27)
  %Do calculations on variables
  
  
  %Pressure
  p=(vprdata(:,22)*13.5381+0.0305)*10;

  %for ccbay
  if strcmp(cruise,'ast0003') | strcmp(cruise,'ast9903'),
      j=find(p<100);p=p(j);
      vprdata=vprdata(j,:);
  end

  %ut
  ut=(vprdata(:,7)+vprdata(:,8)/60+vprdata(:,9)/3600+(vprdata(:,10)/30)/3600);


%  datecorrection;
  dn=daynum(vprdata(:,1),vprdata(:,2),vprdata(:,3))-daynum(vprdata(:,1),1,1);
  dtime=dn+ut/24;

  %correct zero and negative time changes.
  idx=find(diff(dtime)<=0);
  if ~isempty(idx),
      mdt=median(diff(dtime));
      for k=1:length(idx),
          dtime(idx(k)+1)=dtime(idx(k))+mdt;
      end
  end
  
  
  
  pcodelat=fix(vprdata(:,11)/100)+((vprdata(:,11)/100-fix(vprdata(:,11)/100))*100)/60;
  pcodelon=fix(vprdata(:,12)/100)+((vprdata(:,12)/100-fix(vprdata(:,12)/100))*100)/60;
  
%  pcodelat=correctoutliers(pcodelat);
%  pcodelon=correctoutliers(pcodelon);
  
  pcodelon=-pcodelon;%for western hemisphere
  

  %Calculate latitude and longitude from vpr gps data. NOTE:  Although the names of the variables
  %are "pcodelat" and "pcodelon", these are really data from the VPR DGPS unit

%  pcodelat=vprdata(:,24)+vprdata(:,25)/60;
%  pcodelon=vprdata(:,26)+vprdata(:,27)/60;

  %Pitch and Roll
t=vprdata(:,17);
s=vprdata(:,18);
fluo=vprdata(:,19);
lptr=vprdata(:,20);
alt=vprdata(:,21);
roll=vprdata(:,14);
pitch=vprdata(:,15);
flow=vprdata(:,16);
bz=vprdata(:,13);

  %Run stca
  if strcmp(cruise(1:5),'en323'),
      lptr_tmp=lptr;
  end
  [p,t,theta,s,sigma,fluo,lptr]=stca_bobparse(p,t,s,fluo,lptr,cruise);%note this routine also sets p(p<0)=0; 
  if strcmp(cruise(1:5),'en323'),
      lptr=lptr_tmp;
      clear lptr_tmp;
  end
  light=(vprdata(:,23)*16.715);
  dtime=dtime(:);
  p=-p;%make depth negative

b=[dtime pcodelat pcodelon p t s sigma fluo lptr light bz flow roll pitch alt];
b_column_headings=str2mat('1  time           Decimal yearday in GMT starting with Jan 1 as day 0', ...
                          '2  latitude       From ship GPS, negative values are Western hemisphere',...
                          '3  longitude      Longitude (from ship GPS), negative values are Southern hemisphere',...
                          '4  depth          Depth of VPR in negative meters from VPR CTD',...
                          '5  temperature    Temperature of seawater in oC from VPR CTD',...
                          '6  salinity       Salinity (unitless~=PSU and o/oo) from VPR CTD',...
                          '7  density        Seawater density as Sigma-t, computed from t, s, and p',...
                          '8  fluorescence   ug Chla/liter',...
                          '9  turbidity      Optical backscatter (Formazin turbidity units)',...
                          '10 PAR            Downwelling light from PAR sensor, micro Einsteins/cm2/sec',...
                          '11 Bottom Depth   in meters, from ship fathometer',...
                          '12 flow           from Flowmeter on VPR (needs in situ calibration)',...
                          '13 roll           Roll angle, (degrees, positive: roll to right?)',...
                          '14 pitch          Pitch angle, (degrees, positive up)',...
                          '15 altitude       from altimeter, meters off bottom, >99 is out of range');
