function [sastime,ROLL,PITCH,MAGX,MAGY,MAGZ] = readSASaux(sasfnam);

%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 THSformatpattern;

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

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

%read date and time data
for i = 1:2;
    time(:,i) = A{1,9+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
sastime = date;  %Matlab datenumber
ROLL = data(:,3);
PITCH = data(:,4);
MAGX = data(:,6);
MAGY = data(:,7);
MAGZ = data(:,8);
