0001 function [zPathName,zFileName,savefile,A,z] = VMT_ReadFiles_SonTek(zPathName,zFileName)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 if ischar(zFileName)
0018 zFileName = {zFileName};
0019 elseif iscellstr(zFileName)
0020 zFileName = sort(zFileName);
0021 end
0022
0023
0024
0025
0026 z = length(zFileName);
0027 A = initStructure(z);
0028
0029
0030 for zi=1:z
0031
0032 fileName = fullfile(zPathName,zFileName{zi});
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 try
0044 [A(zi)]=parseSonTekVMT(fileName);
0045
0046 [~,file_name,extension] = fileparts(fileName);
0047 new_message = strrep(['Loading file ' file_name extension],'_','\_');
0048
0049
0050
0051
0052
0053
0054 catch err
0055
0056 erstg = {' ',...
0057 'An unknown error occurred when reading the ASCII file.',...
0058 'Occasionally this occurs due to a corrupt ASCII file with',...
0059 'formatting errors. Please regenerate the ASCII file and ',...
0060 'retry loading into VMT. An error may also occur if there ',...
0061 'are white spaces or special characters (e.g. *?<>|) in ',...
0062 'the filenames or paths. Ensure no such spaces or ',...
0063 'characters exist and try loading the files again.'};
0064
0065 if isdeployed
0066 errLogFileName = fullfile(pwd,...
0067 ['errorLog' datestr(now,'yyyymmddHHMMSS') '.txt']);
0068 msgbox({erstg;...
0069 [' Error code: ' err.identifier];...
0070 ['Error details are being written to the following file: '];...
0071 errLogFileName},...
0072 'VMT Status: Unexpected Error',...
0073 'error');
0074 fid = fopen(errLogFileName,'W');
0075 fwrite(fid,err.getReport('extended','hyperlinks','off'));
0076 fclose(fid);
0077 rethrow(err)
0078 else
0079 msgbox(['An unexpected error occurred. Error code: ' err.identifier],...
0080 'VMT Status: Unexpected Error',...
0081 'error');
0082 rethrow(err);
0083 end
0084 end
0085
0086
0087
0088 if ~strcmp(A(zi).Sup.units(1,:),'cm')
0089 erstg = {' ',...
0090 'Units in ASCII file are not metric. VMT only accepts data'...
0091 'in metric units. Please change the units in WinRiver II'...
0092 'and export your ASCII files again before reloading into VMT.'};
0093 errordlg([zFileName(zi) erstg],'VMT Status','replace');
0094 error('VMT:unitsChk', 'Input not in metic units')
0095 end
0096
0097 end
0098
0099
0100
0101
0102
0103
0104
0105 [file_root_name,the_rest] = strtok(zFileName,'.');
0106 for i = 1:length(zFileName)
0107 d1 = file_root_name{i};
0108 date{i} = d1(1:8);
0109 time{i} = d1(9:end);
0110 end
0111
0112 save_dir = fullfile(zPathName,'VMTProcFiles');
0113 [~,mess,~] = mkdir(save_dir);
0114
0115
0116 savefile = [date{1} '_s' time{1} '_e' time{end} '.mat'];
0117 savefile = fullfile(save_dir,savefile);
0118
0119
0120
0121
0122
0123 function A = initStructure(z)
0124 Sup = struct('absorption_dbpm',{}, ...
0125 'bins',{}, ...
0126 'binSize_cm',{}, ...
0127 'nBins',{}, ...
0128 'blank_cm',{}, ...
0129 'draft_cm',{}, ...
0130 'ensNo',{}, ...
0131 'nPings',{}, ...
0132 'noEnsInSeg',{}, ...
0133 'noe',{}, ...
0134 'note1',{}, ...
0135 'note2',{}, ...
0136 'intScaleFact_dbpcnt',{}, ...
0137 'intUnits',{}, ...
0138 'vRef',{}, ...
0139 'wm',{}, ...
0140 'units',{}, ...
0141 'year',{}, ...
0142 'month',{}, ...
0143 'day',{}, ...
0144 'hour',{}, ...
0145 'minute',{}, ...
0146 'second',{}, ...
0147 'sec100',{}, ...
0148 'timeElapsed_sec',{}, ...
0149 'timeDelta_sec100',{});
0150 Wat = struct('binDepth',{}, ...
0151 'backscatter',{}, ...
0152 'vDir',{}, ...
0153 'vMag',{}, ...
0154 'vEast',{}, ...
0155 'vError',{}, ...
0156 'vNorth',{}, ...
0157 'vVert',{}, ...
0158 'percentGood',{});
0159 Nav = struct('bvEast',{}, ...
0160 'bvError',{}, ...
0161 'bvNorth',{}, ...
0162 'bvVert',{}, ...
0163 'depth',{}, ...
0164 'dsDepth',{}, ...
0165 'dmg',{}, ...
0166 'length',{}, ...
0167 'totDistEast',{}, ...
0168 'totDistNorth',{}, ...
0169 'altitude',{}, ...
0170 'altitudeChng',{}, ...
0171 'gpsTotDist',{}, ...
0172 'gpsVariable',{}, ...
0173 'gpsVeast',{}, ...
0174 'gpsVnorth',{}, ...
0175 'lat_deg',{}, ...
0176 'long_deg',{}, ...
0177 'nSats',{}, ...
0178 'hdop',{});
0179 Sensor = struct('pitch_deg',{}, ...
0180 'roll_deg',{}, ...
0181 'heading_deg',{}, ...
0182 'temp_degC',{});
0183 Q = struct('endDepth',{}, ...
0184 'endDist',{}, ...
0185 'bot',{}, ...
0186 'end',{}, ...
0187 'meas',{}, ...
0188 'start',{}, ...
0189 'top',{}, ...
0190 'unit',{}, ...
0191 'startDepth',{}, ...
0192 'startDist',{});
0193 A(z).Sup = Sup;
0194 A(z).Wat = Wat;
0195 A(z).Nav = Nav;
0196 A(z).Sensor = Sensor;
0197 A(z).Q = Q;
0198
0199