function[p,bp,battv,batti,cpDateTimeNum, PID_u, state,sedhome,sednext]= parseEngData( inFile )

inFID = fopen(inFile);
%outFID = fopen(strcat(inFile, 'EngData.txt'), 'w');
%header = ['Date\tTime\tState\tComment\tDepth\t' ...
%            'CTD Pressure\tCTD Temperature\tCTD Salinity\t' ...
%            'FLBB FL\tFLBB BB\t' ...
%            'O2 Conc (uM)\tO2 Air Sat (%%)\tO2 Temperature (degC)\tO2 Cal Phase (Deg)\t' ...
%            'O2 TCPhase (deg)\tO2 C1RPh (deg)\tO2 C2RPh (deg)\tO2 C1 Amp(mV)\t' ...
%            'O2 C2Amp (mV)\tO2 RawTEmp (mV)\r\n'];
%fprintf(outFID, header);                

profileIndex= 1;
PIDIndex = 1;
SEDhomeIndex=1;
SEDnextIndex=1;

doplots=0;

MAXi=50000;
MAXSED=120;

p = NaN(1,MAXi);
bp = NaN(1,MAXi);
battv = NaN(1,MAXi);
batti = NaN(1,MAXi);
%cpDate = NaN(1,MAXi);
%cpTime = NaN(1,MAXi);
cpDateTimeNum = NaN(1,MAXi);
format longg,cpDateTimeNum;
PID_u = NaN(1,MAXi);
state = NaN(1,MAXi);
sedhome = NaN(1,MAXSED);
format longg,sedhome;
sednext = NaN(1,MAXSED);
format longg,sednext;

%get the header line
inString = fgets(inFID);
    
while ~feof(inFID)
    inString = fgets(inFID);
    inFields = strsplit(inString, '\t', 'CollapseDelimiters', false);
    
    %get date, time, and state
    
    state(PIDIndex) = state_finder(inFields{4});
    cpDateTimeNum(PIDIndex) = datenum(strcat(inFields{2}, 'T', inFields{3}));
    
      if (strfind(inFields{5}, 'Scend ') > 0);
        if(length(inFields) >= 8)
            %disp(inString);
            %disp(inFields{26});
            p(PIDIndex) = -1*str2double(inFields{6});
            bp(PIDIndex) = str2double(inFields{7});
            battv(PIDIndex) = str2double(inFields{8});
            batti(PIDIndex) = str2double(inFields{34});
            i12v(PIDIndex) = str2double(inFields{35});
            %PID_SP(PIDIndex) = str2double(inFields{26});
            %PID_PV(PIDIndex) = str2double(inFields{27});
            %PID_Y1(PIDIndex) = str2double(inFields{28});
            %PID_Y2(PIDIndex) = str2double(inFields{29});
            %PID_I(PIDIndex) = str2double(inFields{30});
            %PID_v(PIDIndex) = str2double(inFields{31});
            %PID_u(PIDIndex) = str2double(inFields{32});
            %disp(PID_u(PIDIndex));
            %PID_uCPS(PIDIndex) = str2double(inFields{33});
            
            %cpDate(PIDIndex, :) = inFields{2};
            %cpTime(PIDIndex, :) = inFields{3};
            
            
            
           % numCommas = length(strfind(inFields{10}, ','));
           % if(numCommas == 2)
%                 cpFields = strsplit(inFields{10}, ',', 'CollapseDelimiters', false);

%                 cpState(cpIndex, :) = inFields{4};
%                 cpComment(cpIndex, :) = inFields{5};
%                 cpDepth(cpIndex) = -str2double(inFields{6});
%                 cpP(cpIndex) = str2double(cpFields{1});
%                 cpT(cpIndex) = str2double(cpFields{2});
%                 cpS(cpIndex) = str2double(cpFields{3});
%                 
% 
%            % end
%                 fprintf(outFID, '%s\t%s\t%s\t%s\t%f\t%f\t%f\t%f\r\n', ...
%                     cpDate(cpIndex,:), cpTime(cpIndex,:), cpState(cpIndex,:), cpComment(cpIndex,:), ...
%                     cpDepth(cpIndex), cpP(cpIndex), cpT(cpIndex), cpS(cpIndex));
%                 cpIndex = cpIndex + 1;
           
        end
      end
    if (strfind(inFields{5},'Vel PID') > 0)
       if(length(inFields) >= 8)
           PID_u(PIDIndex) = str2double(inFields{33});
       end
    end

    if (strfind(inFields{5},'SedTrap Message') > 0)
        disp(inString);
       if(strfind(inFields{40},'position') > 0)
           sednext(SEDnextIndex) = cpDateTimeNum(PIDIndex);
           SEDnextIndex = SEDnextIndex+1;
       else
           sedhome(SEDhomeIndex) = cpDateTimeNum(PIDIndex);
           SEDhomeIndex = SEDhomeIndex+1;      
       end
    end
    
    PIDIndex = PIDIndex+1;
    
end

if (doplots)
 [ax,h1,h2]=plotyy(1:size(p,2),p,1:size(bp,2),bp);
 ylabel('Depth(m)');           % puts a label on the left axis
 axes(ax(2))                  % makes the 2nd yaxis the current axis.
 ylabel('Bellows Position');    % puts a label on the right axis.
 grid on;
 
 figure(2);
  [ax,h1,h2]=plotyy(1:size(p,2),p,1:size(battv,2),battv);
 ylabel('Depth(m)');           % puts a label on the left axis
 axes(ax(2))                  % makes the 2nd yaxis the current axis.
 ylabel('BattV');    % puts a label on the right axis.
 grid on;
 
  figure(3);
  [ax,h1,h2]=plotyy(1:size(p,2),p,1:size(batti,2),batti);
 ylabel('Depth(m)');           % puts a label on the left axis
 axes(ax(2))                  % makes the 2nd yaxis the current axis.
 ylabel('BattI');    % puts a label on the right axis.
 grid on;
 
   figure(4);
  [ax,h1,h2]=plotyy(1:size(p,2),p,1:size(i12v,2),i12v);
 ylabel('Depth(m)');           % puts a label on the left axis
 axes(ax(2))                  % makes the 2nd yaxis the current axis.
 ylabel('12V I');    % puts a label on the right axis.
 grid on;
end
end 