function [auxtime,SN,COND,MPRDEPTH,TILTX,TILTY,WTEMP,PTARE] = readprofileraux(auxfnam,headerfnam);

%Read auxiliary data from profiler into Matlab.  Data files are assumed to 
%have already been converted to comma-delimited text and calibration and 
%immersion coefficients applied in SatCon.  One header line is assumed (to 
%ensure this, UNcheck "extra output header information" in SatCon 
%parameters), and time tags are assumed to have been processed and formatted 
%(should be 2 last columns of .dat file).

%Inputs:  auxfnam = string containing path/filename of profiler datafile
%         headerfnam = string containing path/filename of text file with logfile
%               header information (as output from SatCon)

%Outputs:  auxtime = Matlab datenumber-formatted time vector for aux data
%SN = serial number
%COND = conductivity data, mS/cm
%MPRDEPTH = depth at pressure sensor (in the nose of the profiler), meters
%TILTX,TILTY = tilt in both directions, degrees
%WTEMP = water temperature, degrees Celsius

%NO PRESSURE-TARE CORRECTION OR EXTREME-TILT FILTERING ARE APPLIED HERE

load OCRstuff.mat MPRformatpattern;

%read in auxiliary datafile
fid = fopen(auxfnam);
A = textscan(fid,MPRformatpattern,'headerlines',1,'delimiter',',');
fclose(fid);

%read numeric data (not all are output--see MPR068_rawheader in
%OCRstuff.mat for detail)
for i = 1:14;
    data(:,i) = A{1,i};
end;

%read date and time data
for i = 1:2;
    time(:,i) = A{1,14+i};
end;

%Convert SatCon date/time to Matlab datenumber format
for i = 1:length(time);
    B = [sscanf(time{i,1},'%f-%f')' sscanf(time{i,2},'%f:%f:%f')'];
    C = datevec(datenum([B(1) 0 B(2)]));
    C(4:6) = [B(3) B(4) B(5)];
    date(i,1) = datenum(C);
end;

%Write aux data to output variables
auxtime = date;  %Matlab datenumber
SN = data(1,1);
COND = data(:,6);  %mS/cm
MPRDEPTH = data(:,7);  %meters
TILTX = data(:,8);  %degrees
TILTY = data(:,9);  %degrees
WTEMP = data(:,11);  %degrees Celsius

%Read in logfile header data
fid = fopen(headerfnam);
D = textscan(fid,'%s');
fclose(fid);
D = D{1,1};

%Find the line with the pressure-tare value (not sure if this can be
%hard-coded)
for i = 1:length(D);
    E{i,1} = sscanf(D{i,1},'PRESSURE-TARE,%f');
end;
for i = 1:length(E);
    if ~isempty(E{i,1});
        PTARE = E{i,1};  %meters?
    end;
end;