Home > ctdcal > read_autosal_dat.m

read_autosal_dat

PURPOSE ^

read_autosal_dat - Read the *.dat files from the NOAA Ship Ron Brown autosal system.

SYNOPSIS ^

function salts = read_autosal_dat(this_file,std_water_batch_label,analysis_date)

DESCRIPTION ^

 read_autosal_dat - Read the *.dat files from the NOAA Ship  Ron Brown autosal system.
 
 CTD Calibration toolbox
 
 INPUT: 
   fileName: path and name of the *.dat file to be translated.

 OUTPUT:
   salts: sample structure containing the averaged autosal analysis.

 DESCRIPTION:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function salts  = read_autosal_dat(this_file,std_water_batch_label,analysis_date)
0002 % read_autosal_dat - Read the *.dat files from the NOAA Ship  Ron Brown autosal system.
0003 %
0004 % CTD Calibration toolbox
0005 %
0006 % INPUT:
0007 %   fileName: path and name of the *.dat file to be translated.
0008 %
0009 % OUTPUT:
0010 %   salts: sample structure containing the averaged autosal analysis.
0011 %
0012 % DESCRIPTION:
0013 %
0014 
0015 %
0016 % CHANGELOG:
0017 %   08-Jul-2004, Version 1.0
0018 %        * Initial version.
0019 %
0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0021 error(nargchk(3,3,nargin))
0022 
0023 % This meta-data parsing is specific to these files only....
0024 year = analysis_date(1);
0025 mnth = analysis_date(2);
0026 day = analysis_date(3);
0027 
0028 
0029 % First count the number of lines and pre allocated the output cell arrays.
0030 % This is only temporary since we will separate standards from salts later.
0031 nLines = count_lines(this_file);
0032 nLines = nLines - 1; % skip the header line.
0033 if isempty(nLines)
0034     disp(sprintf('Unable to open %s',this_file))
0035     disp('Passing control to the keyboard for troubleshooting.')
0036     keyboard
0037 else
0038 
0039     % Read entire file into vectors of cell arrays or doubles depending on format string.
0040     [sample_id_str,samp_nbr_str,tank_temp,...
0041     autosal_ratio,autosal_ratio_corr,...
0042     cond_ratio,salt,salt_stddev,...
0043     hours,minutes,seconds,niskin_btl_pos,remarks_str]=textread(this_file,...
0044         '%s %s %f %f %f %f %f %f %02d:%02d:%02d %f %s',...
0045         'headerlines',1,'delimiter','\t');
0046 
0047 end
0048 station_id = NaN.*ones(size(cond_ratio));
0049 samp_nbr = station_id;
0050 
0051 % Loop through the data and convert the strings to doubles and look for samples with problems
0052 cnt_lines = 0;
0053 cnt_standards = 0;
0054 cnt_salts = 0;
0055 for idx = 1:length(sample_id_str)
0056 
0057     cnt_lines = cnt_lines+1; %
0058 
0059     % This traps standard water analysis.
0060     if strcmp(sample_id_str{idx},std_water_batch_label)
0061         station_id(idx) = 1000;
0062     else
0063         station_id(idx) = str2num(sample_id_str{idx});
0064     end
0065     % NOTE: This requires that all samplebtlnbrs are numeric not alphanumeric.
0066     % There is one on the stc02 cruise
0067     if strcmp(samp_nbr_str{idx},'MG2')
0068         samp_nbr(cnt_lines) = 777;
0069     else
0070         samp_nbr(cnt_lines) = str2num(samp_nbr_str{idx});
0071     end
0072 
0073 end % while looping through this file
0074 
0075 % replacing the second standardization bottle number
0076 std_idx=find(samp_nbr==1000);
0077 end_idx=find(diff(std_idx)>1);
0078 end_idx=end_idx+1;
0079 samp_nbr(std_idx(end_idx):length(samp_nbr))=1001;
0080 %
0081 
0082 % Assemble the output structure.
0083 salts.station_id = station_id;
0084 salts.samp_nbr = samp_nbr;
0085 salts.tank_temp = tank_temp ;
0086 salts.autosal_ratio = autosal_ratio;
0087 salts.autosal_ratio_corr = autosal_ratio_corr;
0088 salts.cond_ratio = cond_ratio;
0089 salts.salt =salt ;
0090 salts.salt_stddev =salt_stddev ;
0091 salts.hours = hours;
0092 salts.minutes =minutes ;
0093 salts.seconds = seconds;
0094 salts.niskin_btl_pos = niskin_btl_pos;
0095 salts = trimstruct(salts);
0096 
0097 return
0098 
0099 
0100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0101 function out  = splitjoin(line)
0102 % splitjoin: Clean up a line of text for easier parsing.
0103 %
0104 
0105 line = ddewhite(line); % rm leading/trailing whitespace
0106 noTab = untabify(line); % The stc02 files are tab separated columns.
0107 if ~isempty(noTab)  % ...hopefully
0108     %noTab = del_dup_spaces(noTab);
0109     noTab = rstrrep(noTab,'  ',' ');
0110 end
0111 line = ddewhite(noTab); % clean ends again.
0112 line = strsplit(sprintf(' '),line); % this is overkill.
0113 line = strjoin(' ',line{:}); % but just in case...
0114 out = line;
0115 return
0116 
0117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0118 function out  = trimstruct(in)
0119 % trimstruct: Trim unused elements from preallocated arrays.
0120 %
0121 
0122 theNames = fieldnames(in);
0123 for idx = 1:length(theNames);
0124     theData = in.(theNames{idx});
0125     if iscell(theData)
0126         outData = {};
0127         for idxCell = 1:length(theData)
0128             if ~(isnan(theData{idxCell}) | isempty(theData{idxCell}))
0129                 outData{idxCell} = theData{idxCell};
0130             end
0131         end
0132         theData = outData;
0133     else
0134         theData(isnan(theData)) = [];
0135     end
0136     out.(theNames{idx}) = theData;
0137 end
0138 return
0139 
0140

Generated on Fri 08-Oct-2004 11:57:17 by m2html © 2003