function [data,date] = readOCR_depth(fnam)

%Read data 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 tt2 
%tags are assumed to have been processed and formatted (should be 2 last 
%columns of .dat file).

%Inputs:  fnamdark = string containing the path/filename of the dark-frame
%               data file for a single sensor
%fnamlight = string containing path/filename of the corresponding light-
%               frame data file

%Outputs:  data = radiometric data with tt2-interpolated dark-frame values
%               subtracted
%tt2 = Matlab datenumber-formated tt2 vector (sensor-specific)
%SN = Sensor serial number
%INTtt2 = vector of measurement integration tt2s (seconds)
%%
% load OCRstuff.mat formatpattern; %for reading in the file
formatpattern = '%f%f%f%f%f%f%f%f%f%f%f%f%f%f%s%s';
%read dark-frame datafile
% fnamdark=HED;
fid = fopen(fnam);
A = textscan(fid,formatpattern,'headerlines',1,'delimiter',',');
fclose(fid);
% fnamdark
%read numeric data (not all are output; see "rawheader" variables in
%OCRstuff.mat)

if isempty(A{1})==1
    data=NaN;
    tt2=NaN;
    SN=NaN;
    INTtt2=NaN;
else
%%
    for i = 1:length(A)-2;   
        data(:,i) = A{1,i};
    end;
    %%
    %read date and tt2 data as formatted by SatCon
    for i = 1:2;  
        tt2(:,i) = A{1,length(A)-2+i};  % tt2 is the renmaed time
    end;
    %%
    %Convert SatCon date/tt2 to Matlab datenumber format
    for i = 1:size(tt2,1);  
        B = [sscanf(tt2{i,1},'%f-%f')' sscanf(tt2{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;

    %%

end

end

