0001 function [standards,salts] = read_autosal_stc02(fName)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 error(nargchk(1,1,nargin));
0044
0045
0046 cruiseid = 'stc02';
0047
0048 standardsTmp = makeStruct;
0049 saltsTmp = standardsTmp;
0050
0051
0052 standards = [];
0053 salts = standards;
0054
0055
0056 [rawPath,rawName,ext,versn] = fileparts( fName);
0057 rawName(end) = '';
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
0062 end
0063
0064
0065 [txtFid,message] = fopen(fName,'r');
0066 if txtFid <=0
0067 disp(message)
0068 warning(['Unable to open ',fName,'.'])
0069 return
0070 end
0071
0072
0073
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
0077 rawSamples = [s1 s2 s3 s4 s5 s6 s7 s8 s9 s10];
0078 rawTime = [hh mm ss];
0079
0080
0081 line = fgetl(txtFid);
0082 txtHeadings = {'SampleID' , 'NiskinBottleNum' , 'SampleBottleNum', 'TankTemp' , 'AutosalRatio' , 'CorrectionToAutosalRatio' , 'CorrectedConductivityRatiox2' , 'CorrectedPracticalSalinity' , 'StandardDeviationSample' , 'Time' , 'NiskinBottlePos'};
0083
0084
0085
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
0099 match the fieldnames below to the ones in sample_struct
0100
0101
0102
0103 if ~all(isdigits(sampID))
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
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
0142
0143 return
0144
0145 function nCols = count_space_separated_cols(line);
0146
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
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
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
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
0205
0206 dt = datenum(yr,mm,dd) + datenum(Time,13);
0207
0208 return
0209
0210