0001 function salts = read_autosal_dat(this_file,std_water_batch_label,analysis_date)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 error(nargchk(3,3,nargin))
0022
0023
0024 year = analysis_date(1);
0025 mnth = analysis_date(2);
0026 day = analysis_date(3);
0027
0028
0029
0030
0031 nLines = count_lines(this_file);
0032 nLines = nLines - 1;
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
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
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
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
0066
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
0074
0075
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
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
0103
0104
0105 line = ddewhite(line);
0106 noTab = untabify(line);
0107 if ~isempty(noTab)
0108
0109 noTab = rstrrep(noTab,' ',' ');
0110 end
0111 line = ddewhite(noTab);
0112 line = strsplit(sprintf(' '),line);
0113 line = strjoin(' ',line{:});
0114 out = line;
0115 return
0116
0117
0118 function out = trimstruct(in)
0119
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