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