Home > ctdcal > read_autosal_stc02.m

read_autosal_stc02

PURPOSE ^

read_autosal_stc02: autosal analyses from the stc02 *n.txt and *.raw files

SYNOPSIS ^

function [standards,salts] = read_autosal_stc02(fName)

DESCRIPTION ^

 read_autosal_stc02: autosal analyses from the stc02 *n.txt and *.raw files

 AOML/PhOD CTDCalibration toolbox.

 USAGE: [standards,salts] = read_autosal_stc02(fileName)
 
 INPUT: 
  fileName (string): path and name of input txt file.  The corresponding input 
         *.raw file Actually, the name contains only
         the initial stub minus the trainlin g"n" in the case of the txt files and minus 
        the extension.  e.g. on the stc02 cruise files of the form 020314.raw and 020314n.txt 
         were generated by the autosal analysis system.
 
 OUTPUT: standards and salts are both structures containing the results
 of the autosal analysis of the salinity sample bottles from the stc02 
 cruise. See below for definitions of the fields

 ERRORS: If the files cannot be found on the matlab path, a warning is generated
         and the output variables are returned as empty.  No errors are generated.
 
 DESCRIPTION: The values of conductivity are read from the *.txt and *.raw files.  
 the raw files contain ten readings per line which are averaged to give one mean
 value in the txt files.  This program reads the metadata from the txt files but uses
 the raw readings, not the averaged values of conductivity.  The raw readings are checked
 for outliers using a robust algorithm and the new means and standard deviations are
 returned as a standard autosal sample bottle data structure.  See below.
 
 AUTHOR: Derrick Snowden
         NOAA/AOML/PhOD
         Tue May 11 12:24:35 EDT 2004
 
 SEE ALSO: init_bottle_struct.m provides the template data structure for all sample bottle
 data used in the CTDCalib toolbox.  Refer to that file or type

 >> init_bottle_struct

 from the Matlab prompt.

 DEPENDENCIES:
   CTDCalib toolbox.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [standards,salts]  = read_autosal_stc02(fName)
0002 % read_autosal_stc02: autosal analyses from the stc02 *n.txt and *.raw files
0003 %
0004 % AOML/PhOD CTDCalibration toolbox.
0005 %
0006 % USAGE: [standards,salts] = read_autosal_stc02(fileName)
0007 %
0008 % INPUT:
0009 %  fileName (string): path and name of input txt file.  The corresponding input
0010 %         *.raw file Actually, the name contains only
0011 %         the initial stub minus the trainlin g"n" in the case of the txt files and minus
0012 %        the extension.  e.g. on the stc02 cruise files of the form 020314.raw and 020314n.txt
0013 %         were generated by the autosal analysis system.
0014 %
0015 % OUTPUT: standards and salts are both structures containing the results
0016 % of the autosal analysis of the salinity sample bottles from the stc02
0017 % cruise. See below for definitions of the fields
0018 %
0019 % ERRORS: If the files cannot be found on the matlab path, a warning is generated
0020 %         and the output variables are returned as empty.  No errors are generated.
0021 %
0022 % DESCRIPTION: The values of conductivity are read from the *.txt and *.raw files.
0023 % the raw files contain ten readings per line which are averaged to give one mean
0024 % value in the txt files.  This program reads the metadata from the txt files but uses
0025 % the raw readings, not the averaged values of conductivity.  The raw readings are checked
0026 % for outliers using a robust algorithm and the new means and standard deviations are
0027 % returned as a standard autosal sample bottle data structure.  See below.
0028 %
0029 % AUTHOR: Derrick Snowden
0030 %         NOAA/AOML/PhOD
0031 %         Tue May 11 12:24:35 EDT 2004
0032 %
0033 % SEE ALSO: init_bottle_struct.m provides the template data structure for all sample bottle
0034 % data used in the CTDCalib toolbox.  Refer to that file or type
0035 %
0036 % >> init_bottle_struct
0037 %
0038 % from the Matlab prompt.
0039 %
0040 % DEPENDENCIES:
0041 %   CTDCalib toolbox.
0042 
0043 error(nargchk(1,1,nargin));
0044 
0045 % This function is specific to the STC02 cruise.
0046 cruiseid = 'stc02';
0047 % Standard data structure templates
0048 standardsTmp = makeStruct;
0049 saltsTmp = standardsTmp;
0050 
0051 % Initialize to empty arrays in case of errors along the way.
0052 standards = [];
0053 salts = standards;
0054 
0055 % Try to find the input files
0056 [rawPath,rawName,ext,versn] = fileparts( fName);
0057 rawName(end) = ''; % remove the trailing n from the *.txt files
0058 rawName = fullfile(rawPath,[rawName '.raw']);
0059 if ~(exist(fName)==2) || ~(exist(rawName)==2)
0060     warning(['Unable to resolve the path to ',fName,'.  See register_cruise and manage_path']);
0061     return % Exit gracefully and pass empty data back to user.
0062 end
0063 
0064 % Open txt file for reading only.
0065 [txtFid,message] = fopen(fName,'r');
0066 if txtFid <=0
0067     disp(message)
0068     warning(['Unable to open ',fName,'.'])
0069     return % Exit gracefully and pass empty data back to user.
0070 end
0071 
0072 % The raw file has a simple format. Read it all at once.
0073 % Read the entire *.raw file.  The format string may need to be changed for different cruises.
0074 [s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 hh mm ss] = textread(rawName,'%f %f %f %f %f %f %f %f %f %f %2d:%2d:%2d','headerlines',1)
0075 
0076 % Combine the 10 raw samples into one sample matrix
0077 rawSamples = [s1 s2 s3 s4 s5 s6 s7 s8 s9 s10];
0078 rawTime = [hh mm ss];
0079 
0080 % Read the first line of column headings and discard
0081 line = fgetl(txtFid);
0082 txtHeadings = {'SampleID'  ,    'NiskinBottleNum' ,  'SampleBottleNum',  'TankTemp' ,  'AutosalRatio' ,  'CorrectionToAutosalRatio' ,   'CorrectedConductivityRatiox2'  ,  'CorrectedPracticalSalinity' ,  'StandardDeviationSample' ,   'Time'  ,  'NiskinBottlePos'};
0083 
0084 % Read through to the end of the file. Is the current line a standard or a sample.
0085 % If it is a sample, does it contain a valid sampleID
0086 while ~feof(txtFid)
0087     line = fgetl(txtFid);
0088     nCols = count_space_separated_cols(line);
0089 
0090     if nCols == 11
0091         [sampID,niskinNum,sampBtlNum,tankTemp,autosalRatio,autosalRatioCor,twiceCondRatio,salt,sample_std,  time, niskinBtlPos] = strread(line,'%s %d %d %f %f %f %f %f %2d:%2d:%2d %f')
0092     elseif nCols == 10
0093         [niskinNum,sampBtlNum,tankTemp,autosalRatio,autosalRatioCor,twiceCondRatio,salt,sample_std,  time, niskinBtlPos] = strread(line,' %d %d %f %f %f %f %f %2d:%2d:%2d %f')
0094     end
0095 
0096     keyboard
0097     
0098     % BUG: It looks like the logic above doesn't even apply below.  ie sampID is not used.  print out example file and delete what ever is wrong!
0099     match the fieldnames below to the ones in sample_struct 
0100     
0101     
0102     
0103     if ~all(isdigits(sampID)) %standards
0104         standardsTmp.SampleID(cnt) = 1000;
0105         standardsTmp.NiskinBottleNum(cnt) =  double(NiskinBottleNum);
0106         standardsTmp.SampleBottleNum(cnt) = double(SampleBottleNum) ;
0107         standardsTmp.TankTemp(cnt) = double(TankTemp) ;
0108         standardsTmp.AutosalRatio(cnt) = double(AutosalRatio) ;
0109         standardsTmp.CorrectionToAutosalRatio(cnt) = double(CorrectionToAutosalRatio) ;
0110         standardsTmp.CorrectedConductivityRatiox2(cnt)= double(CorrectedConductivityRatiox2);
0111         standardsTmp.CorrectedPracticalSalinity(cnt)=double(CorrectedPracticalSalinity)  ;
0112         standardsTmp.StandardDeviationSample(cnt)=double(StandardDeviationSample) ;
0113         standardsTmp.Time(cnt)= makeDatenum(year,mm,dd,Time);
0114         standardsTmp.NiskinBottlePos(cnt)= double(NiskinBottlePos);
0115         standardsTmp.Remarks{cnt} =  Remarks;
0116         if strcmp(lower(Remarks),'disregard')
0117             standardsTmp.QCFlag(cnt) =  4;
0118         else
0119             standardsTmp.QCFlag(cnt) =  1;
0120         end
0121     else % actuall salt sample
0122         saltsTmp.SampleID(cnt) = 1000;
0123         saltsTmp.NiskinBottleNum(cnt) =  double(NiskinBottleNum);
0124         saltsTmp.SampleBottleNum(cnt) = double(SampleBottleNum) ;
0125         saltsTmp.TankTemp(cnt) = double(TankTemp) ;
0126         saltsTmp.AutosalRatio(cnt) = double(AutosalRatio) ;
0127         saltsTmp.CorrectionToAutosalRatio(cnt) = double(CorrectionToAutosalRatio) ;
0128         saltsTmp.CorrectedConductivityRatiox2(cnt)= double(CorrectedConductivityRatiox2);
0129         saltsTmp.CorrectedPracticalSalinity(cnt)=double(CorrectedPracticalSalinity)  ;
0130         saltsTmp.StandardDeviationSample(cnt)=double(StandardDeviationSample) ;
0131         saltsTmp.Time(cnt)= makeDatenum(year,mm,dd,Time);
0132         saltsTmp.NiskinBottlePos(cnt)= double(NiskinBottlePos);
0133         saltsTmp.Remarks{cnt} =  Remarks;
0134         if strcmp(lower(Remarks),'disregard')
0135             saltsTmp.QCFlag(cnt) =  4;
0136         else
0137             saltsTmp.QCFlag(cnt) =  1;
0138         end
0139     end
0140 cnt = cnt + 1;    
0141 end % while feof
0142     
0143 return
0144 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0145 function nCols = count_space_separated_cols(line);
0146 % Count the number of space separated columns in a string.
0147 %
0148 i = 1;
0149 while line
0150     [junk,line] = strtok(line,' ');
0151     i = i + 1;
0152 end
0153 nCols = i-1;
0154 return
0155 
0156 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0157 function [theCell]  = parseToCell(line,nCols)
0158 % parseToCell: Parse the line into individual elements of a cell array.
0159 %
0160 i = 1;
0161 theCell = cell(nCols,1);
0162 while line
0163     [theCell{i},line] = strtok(line,' ');
0164     i=i+1;
0165 end
0166 return
0167 
0168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0169 function idx  = getTimeCol(theCell)
0170 % getTimeCol: Check which column contains the time string
0171 %
0172 idx=[];
0173 for i = 1:length(theCell)
0174     if any(strcmp(theCell{i},':'))
0175         idx = i;
0176         return
0177     end
0178 end
0179 return
0180 
0181 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0182 function autosal  = makeStruct
0183 % makeStruct: template of output structure
0184 %
0185 
0186 autosal.SampleID =  [];
0187 autosal.NiskinBottleNum   =   [];
0188 autosal.SampleBottleNum   =   [];
0189 autosal.TankTemp   =   [];
0190 autosal.AutosalRatio   =    [];
0191 autosal.CorrectionToAutosalRatio   =    [];
0192 autosal.CorrectedConductivityRatiox2   =    [];
0193 autosal.CorrectedPracticalSalinity   =    [];
0194 autosal.StandardDeviationSample   =    [];
0195 autosal.Time   =    [];
0196 autosal.NiskinBottlePos   =   [];
0197 autosal.Remarks  =   {};
0198 autosal.QCFlag = [];
0199 
0200 return
0201 
0202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0203 function dt = makeDatenum(yr,mm,dd,Time)
0204 % makeDatenum:
0205 %
0206 dt = datenum(yr,mm,dd) + datenum(Time,13);
0207 
0208 return
0209 
0210

Generated on Thu 16-Sep-2004 15:33:00 by m2html © 2003