VMT_ReadFiles_SonTek

PURPOSE ^

Read in multiple MAT output files from SonTek RSL v1.5-3.60.

SYNOPSIS ^

function [zPathName,zFileName,savefile,A,z] = VMT_ReadFiles_SonTek(zPathName,zFileName)

DESCRIPTION ^

 Read in multiple MAT output files from SonTek RSL v1.5-3.60.

 Added save path functionality (PRJ, 6-23-10)
 (adapted from code by J. Czuba)

 See also: parseSonTekVMT (utils folder)

 Frank L. Engel, USGS
 Last modified: 03/27/2014

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [zPathName,zFileName,savefile,A,z] = VMT_ReadFiles_SonTek(zPathName,zFileName)
0002 % Read in multiple MAT output files from SonTek RSL v1.5-3.60.
0003 %
0004 % Added save path functionality (PRJ, 6-23-10)
0005 % (adapted from code by J. Czuba)
0006 %
0007 % See also: parseSonTekVMT (utils folder)
0008 %
0009 % Frank L. Engel, USGS
0010 % Last modified: 03/27/2014
0011 
0012 
0013 
0014 %% Read in multiple MAT files Files
0015 % This program reads in multiple ASCII text files into a single structure.
0016 
0017 if ischar(zFileName)
0018     zFileName = {zFileName};
0019 elseif iscellstr(zFileName)
0020     zFileName = sort(zFileName);       
0021 end
0022 %msgbox('Loading Data...','VMT Status','help','replace')
0023 
0024 %% Read in Selected Files
0025 % Initialize the data structure
0026 z = length(zFileName);
0027 A = initStructure(z);
0028 
0029 % Begin master loop
0030 for zi=1:z
0031     % Open txt data file
0032     fileName = fullfile(zPathName,zFileName{zi});
0033 
0034 
0035     % parseSonTekVMT reads the data from an RSL MAT output file and puts
0036     % the data in a Matlab data structure with major groups of:
0037     % Sup - supporing data
0038     % Wat - water data
0039     % Nav - navigation data including GPS.
0040     % Sensor - Sensor data
0041     % Q - discharge related data
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 %         if ishandle(h_waitbar)
0049 %             waitbar(zi/z,h_waitbar,new_message)
0050 %         else
0051 %             h_waitbar = waitbar(zi/z,new_message,'Name','Loading Files');
0052 %         end
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     % Check the units to ensure they are metric
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 % Get rid of the waitbar
0100 % if ishandle(h_waitbar)
0101 %     delete(h_waitbar)
0102 % end
0103 
0104 % Save data returned by tfile to .mat with same prefix as ASCII
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 % disp(mess)
0115 
0116 savefile = [date{1} '_s' time{1} '_e' time{end} '.mat'];
0117 savefile = fullfile(save_dir,savefile);
0118 
0119 %%%%%%%%%%%%%%%%%%%%%%
0120 % Embedded Functions %
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             % [EOF] initStructure

Generated on Thu 21-Aug-2014 10:40:31 by m2html © 2005