function getprepdata_newfish(imdir,cruise,fn);

global b b_column_headings

%Load data file

v=version;v=str2num(v(1:3));
if v==5.3,%matlab version 5.3
    eval(['vprdata=load(''' imdir fn ''');']);
    %the following adds a first column of zeros to the earlier vprlog files that dont have vprtimestamp
    %this way we can use the same parsing code.
    if size(vprdata,2)==15,
        vprdata=[zeros(size(vprdata,1),1) vprdata];
    end
elseif v>6 & v<8,%tested with matlab version 6.1 and 6.5
%     eval(['vprdata=load(''' imdir fn ''','' '');']);%1st way:  matlab 6.5 can load and ignore #IO
%     eval(['vprdata=dlmread(''' imdir fn ''','' '');']);%2nd way:  new way of loading data
     eval(['vprdata=load(''' imdir fn ''','' '');'],['vprdata=dlmread(''' imdir fn ''','' '');']);%try 1st then 2nd way
    %the following adds a first column of zeros to the earlier vprlog files that dont have vprtimestamp
    %this way we can use the same parsing code.
    vprdata=vprdata(20:end,:);
    idx=find(vprdata(:,3)~=-1);
    vprdata=vprdata(idx,:);
    if size(vprdata,2)==15,
        vprdata=[zeros(size(vprdata,1),1) vprdata];
    end
    vprdata=vprdata((vprdata(:,16)~=0),:);%gets rid of "short" rows, i.e., those with 0 placed in last column by dlmread
else
    disp('Matlab version not 5.3 or 6.x');
    return;
end


% 16 columns contain:

  % 1  vprtimestamp
  % 2  gmt in  hhmmss.sss (from ship gps via serial cable)
  % 3  date  in ddmmyy 
  % 4  latitude (ddmm.mmmm) (from ship gps via serial cable)
  % 5  longitude (ddmm.mmmm) (from ship gps via serial cable)
  % 6  bottom depth (meters; from ship via serial cable)
  % 7  alt 
  % 8  roll 
  % 9  pitch 
  %10  flow 
  %11  fluor
  %12  Light 
  %13  optical backscatter (obs) 
  %14  cond 
  %15  temp 
  %16  vprdepth 

%Do calculations on variables
vprdata=vprdata(2:end,:);
%Parse out hours, minutes, seconds, %0.0001 corrects for roundoff
ut=floor(vprdata(:,2)/10000+0.0001)+...
    floor((vprdata(:,2)/10000-floor(vprdata(:,2)/10000))*100+0.0001)/60+...
    floor((vprdata(:,2)/100-floor(vprdata(:,2)/100))*100+0.0001)/3600;

%Date parsing
if vprdata(1,3) < 1000000,
    idx=find(vprdata(:,3)==-1);%finds date=-1 and replaces it with date from previous line.
    if ~isempty(idx),
        if idx(1)==1,
            vprdata(1,3)=vprdata(2,3);
        else
            vprdata(idx,3)=vprdata(idx-1,3);
        end
    end
    dn=daynum(round((vprdata(:,3)/100-fix(vprdata(:,3)/100))*100),...
        floor((vprdata(:,3)/10000-floor(vprdata(:,3)/10000))*100),...
        floor(vprdata(:,3)/10000))-...
        daynum(round((vprdata(:,3)/100-fix(vprdata(:,3)/100))*100),1,1);
else
    dn=daynum(round((vprdata(:,3)/10000-fix(vprdata(:,3)/10000))*10000),...
        floor((vprdata(:,3)/1000000-floor(vprdata(:,3)/1000000))*100),...
        floor(vprdata(:,3)/1000000))-...
        daynum(round((vprdata(:,3)/10000-fix(vprdata(:,3)/10000))*10000),1,1);
end

%Calculated decimal day
dtime=dn+ut/24;clear dn ut

if strcmp(cruise,'AL206'),dtime=dtime+27/86400;end%offset to match DECK time and GPS time
if strcmp(fn,'06211125.y06'),dtime=dtime-27/86400;end%offset to match DECK time and GPS time for kn182_15

%correct zero and negative time changes % formulated using AL206 data
idx=find(diff(dtime)<=0);
mdt=median(diff(dtime));
while ~isempty(idx),
    for k=1:length(idx),
        dtime(idx(k)+1)=dtime(idx(k))+mdt;
    end
    idx=find(diff(dtime)<=0);
end

%correct for erroneous day increase just before midnight (from oc470_3)
idx=[];
idx=find((diff(dtime)>1)&(diff(dtime)<(1+10/86400)));
if ~isempty(idx),
    for j=1:length(idx)
        dtime((idx(j)+1):end)=dtime((idx(j)+1):end)-1;
    end
end

%Parse lat and long and calculate as decimal
lat=fix(vprdata(:,4)/100)+((vprdata(:,4)/100-fix(vprdata(:,4)/100))*100)/60;
lon=fix(vprdata(:,5)/100)+((vprdata(:,5)/100-fix(vprdata(:,5)/100))*100)/60;

%Assign environmental variables from input file to our regular names
p=vprdata(:,16);
t=vprdata(:,15);

co=vprdata(:,14);co(co<0)=0;%gets rid of negative values eg. when ctd is out of water.
fluo=vprdata(:,11);
obs=vprdata(:,13);
light=sqrt(vprdata(:,12))*0.02;
alt=vprdata(:,7);
roll=vprdata(:,8);
pitch=vprdata(:,9);
flow=vprdata(:,10);
vprdepth=vprdata(:,16);
bz=-vprdata(:,6);
bz(bz>=0)=nan;
% for j=6:size(vprdata,1);
%    avebz=mean(bz((j-5):(j-1)));
%    if (bz(j)-avebz)>(0-avebz)/2,
%       bz(j)=bz(j-1);
%    end
% end

  %Run stca (modified for new flying fish VPR system w/ seabird ctd, in this case co is
  %already converted to salinity in the vprlog files
[p,t,theta,s,sigma]=stca_newfish(p,t,co);%note this routine also sets p(p<0)=0;

dtime=dtime(:);
p=-p;%make depth negative

b=[dtime lat lon p t s sigma fluo obs 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');
