parseSonTekVMT

PURPOSE ^

PARSESONTEK reads MAT file output from RSL for use in VMT

SYNOPSIS ^

function A = parseSonTekVMT(fullName)

DESCRIPTION ^

PARSESONTEK reads MAT file output from RSL for use in VMT
 Currently only supports RSL v3.60 or earlier
 NO WARRANTY OR GUARANTEE OF FUNCTIONALITY

 Dave Mueller, USGS
 Frank L. Engel, USGS

 Last modified: 04/23/2014
 
 SEE ALSO:

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function A = parseSonTekVMT(fullName)
0002 %PARSESONTEK reads MAT file output from RSL for use in VMT
0003 % Currently only supports RSL v3.60 or earlier
0004 % NO WARRANTY OR GUARANTEE OF FUNCTIONALITY
0005 %
0006 % Dave Mueller, USGS
0007 % Frank L. Engel, USGS
0008 %
0009 % Last modified: 04/23/2014
0010 %
0011 % SEE ALSO:
0012 
0013 % filesep     = '\';
0014 % fullName    = [pathname filesep filename{1}];
0015 
0016 load (fullName)
0017 
0018 if strcmpi(Setup.velocityReference, 'System')
0019     errordlg({'VMT does not support Beam Coordinates.';
0020         '';
0021         'Re-export mat-file in RiverSurveyorLive';
0022         'using BT, GGA, or VTG velocity reference'},'Velocity Reference Error');
0023     error('parseSonTekVMT: VMT does not support Beam Coordinates.')
0024 end
0025 
0026 % For RSL versions <1.5, the variable units were included in the field
0027 % names. Check to see if units are in field names, if so ensure SI units
0028 % and rename.
0029 is_in_eng_units     = isfield(Summary,'Depth_ft');
0030 is_in_si_units      = isfield(Summary,'Depth_m');
0031 if is_in_eng_units || is_in_si_units
0032 [...
0033     BottomTrack,...
0034     GPS,...
0035     Processing,...
0036     RawGPSData,...
0037     Setup,...
0038     Summary,...
0039     System,...
0040     Transformation_Matrices,...
0041     WaterTrack,...
0042     ] = fixOldMatFiles(...
0043     BottomTrack,...
0044     GPS,...
0045     Processing,...
0046     RawGPSData,...
0047     Setup,...
0048     Summary,...
0049     System,...
0050     Transformation_Matrices,...
0051     WaterTrack);
0052 end
0053     
0054 
0055 % Create the output structures
0056 [Sup,Wat,Nav,Sensor,Q] = initStructures(...
0057     BottomTrack,...
0058     GPS,...
0059     Processing,...
0060     RawGPSData,...
0061     Setup,...
0062     Summary,...
0063     System,...
0064     Transformation_Matrices,...
0065     WaterTrack);
0066 
0067 
0068 %%%%%%%%%%%%%%
0069 % PARSE DATA %
0070 %%%%%%%%%%%%%%
0071 
0072 % Setup units conversion
0073 if strcmpi(Summary.Units.Depth,'ft')
0074     cf                  = 1./3.281; % conversion factor
0075     System.Temperature  = (System.Temperature-32)*5/9;
0076 else
0077     cf                  = 1; % conversion factor (for m)
0078     cf2                 = 1;   % conversion factor (for m)
0079 end
0080 
0081 % Only use in transect data, omit the edge measurements
0082 idx = find(System.Step==3);
0083 
0084 % Suplemental Data
0085 Sup.nBins       = size(WaterTrack.Velocity,1);
0086 Sup.binSize_cm  = repmat(System.Cell_Size(idx)'.*100.*cf,Sup.nBins,1);
0087 Sup.bins        = repmat(Sup.nBins,size(idx));
0088 Sup.blank_cm    = Setup.screeningDistance.*100.*cf;
0089 Sup.draft_cm    = Setup.sensorDepth.*100.*cf;
0090 Sup.noe         = length(idx);
0091 switch Setup.velocityReference
0092     case 0
0093         Sup.vRef = 'System';
0094     case 1
0095         Sup.vRef = 'BT';
0096     case 2
0097         Sup.vRef = 'GGA';
0098     case 3
0099         Sup.vRef = 'VTG';
0100 end
0101 Sup.units = repmat('cm',Sup.noe,1);
0102 Sup.timeElapsed_sec = [0; cumsum(diff(System.Time(idx)))];
0103 Sup.ensNo = idx;
0104 
0105 % Water track data
0106 %cellSizeAll = repmat(Sup.binSize_cm',Sup.nBins,1);
0107 top_of_cells        = System.Cell_Start(idx).*cf.*100; % in cm
0108 Wat.binDepth        =...
0109     ((repmat((1:Sup.nBins)',1,Sup.noe)-0.5).*...
0110     Sup.binSize_cm+repmat(top_of_cells',Sup.nBins,1))/100; % in meters
0111 Wat.vEast           =...
0112     squeeze(WaterTrack.Velocity(:,1,idx)).*cf.*100; % in cm/s
0113 Wat.vNorth          =...
0114     squeeze(WaterTrack.Velocity(:,2,idx)).*cf.*100; % in cm/s
0115 Wat.vVert           =...
0116     squeeze(WaterTrack.Velocity(:,3,idx)).*cf.*100; % in cm/s
0117 Wat.vError          =... 
0118     squeeze(WaterTrack.Vel_StdDev(:,4,idx)).*cf.*100; % in cm/s
0119 Wat.vMag            =...
0120     sqrt(Wat.vEast.^2 + Wat.vNorth.^2 + Wat.vVert.^2).*100; % in cm/s
0121 Wat.vDir            =...
0122     ari2geodeg(atan2(Wat.vNorth,Wat.vEast).*180/pi);
0123 
0124 % Navigation data
0125 Nav.bvEast          = Summary.Boat_Vel(idx,1).*cf.*100; % in cm/s
0126 Nav.bvNorth         = Summary.Boat_Vel(idx,2).*cf.*100; % in cm/s
0127 Nav.bvVert          = Summary.Boat_Vel(idx,3).*cf.*100; % in cm/s
0128 Nav.depth           = BottomTrack.BT_Beam_Depth(idx,:).*cf; % in m
0129 Nav.dsDepth         = BottomTrack.VB_Depth(idx).*cf; % in m
0130 Nav.altitude        = GPS.Altitude(idx).*cf; % in m
0131 Nav.altitudeChng    = [0; diff(Nav.altitude)];
0132 Nav.lat_deg         = GPS.Latitude(idx);
0133 Nav.long_deg        = GPS.Longitude(idx);
0134 Nav.nSats           = GPS.Satellites(idx);
0135 Nav.hdop            = GPS.HDOP(idx);
0136 Nav.totDistEast     = Summary.Track(idx,1).*cf; % in m
0137 Nav.totDistNorth    = Summary.Track(idx,2).*cf; % in m
0138 Nav.length          = ...
0139     hypot(...
0140     Nav.totDistNorth-Nav.totDistNorth(1),...
0141     Nav.totDistEast-Nav.totDistEast(1));
0142 
0143 % Sensor data
0144 % Check if using RSL v3.70 by seeing if there is a separate Compass
0145 % structure
0146 if exist('Compas','var') % [sic], Sontek spelled it wrong, this is a v 3.60 mat-file
0147     Sensor.pitch_deg    = Compas.Pitch(idx);
0148     Sensor.roll_deg     = Compas.Roll(idx);
0149     Sensor.heading_deg  = System.Heading(idx);
0150     Sensor.temp_degC    = System.Temperature(idx);
0151 else
0152     Sensor.pitch_deg    = System.Pitch(idx);
0153     Sensor.roll_deg     = System.Roll(idx);
0154     Sensor.heading_deg  = System.Heading(idx);
0155     Sensor.temp_degC    = System.Temperature(idx);
0156 end
0157 % Discarge data
0158 Q.startDist     = repmat(Setup.Edges_0__DistanceToBank.*cf,Sup.noe,1);
0159 Q.endDist       = repmat(Setup.Edges_1__DistanceToBank.*cf,Sup.noe,1);
0160 Q.bot           = Summary.Bottom_Q(idx).*cf.^3;
0161 Q.top           = Summary.Top_Q(idx).*cf.^3;
0162 switch Setup.startEdge
0163     case 0 % left bank
0164         Q.start = Summary.Left_Q.*cf.^3;
0165         Q.end   = Summary.Right_Q.*cf.^3;
0166     case 1 % right bank
0167         Q.start = Summary.Right_Q.*cf.^3;
0168         Q.end   = Summary.Left_Q.*cf.^3;
0169 end
0170 Q.meas      = Summary.Middle_Q.*cf.^3;
0171 
0172 % Deal Result to A structure
0173 A.Sup       = Sup;
0174 A.Wat       = Wat;
0175 A.Nav       = Nav;
0176 A.Sensor    = Sensor;
0177 A.Q         = Q;
0178 
0179 
0180 %%%%%%%%%%%%%%%%
0181 % SUBFUNCTIONS %
0182 %%%%%%%%%%%%%%%%
0183 function varargout = fixOldMatFiles(varargin)
0184 disp('fixOldMatFiles is not implemented yet, use RSL v1.5 or greater.')
0185 
0186 % oldField = 'quux';
0187 % newField = 'corge';
0188 % [a.(newField)] = a.(oldField);
0189 % a = rmfield(a,oldField);
0190 % disp(a)
0191 
0192 function [Sup,Wat,Nav,Sensor,Q] = initStructures(varargin)
0193 BottomTrack             = varargin{1};
0194 GPS                     = varargin{2};
0195 Processing              = varargin{3};
0196 RawGPSData              = varargin{4};
0197 Setup                   = varargin{5};
0198 Summary                 = varargin{6};
0199 System                  = varargin{7};
0200 Transformation_Matrices = varargin{8};
0201 WaterTrack              = varargin{9};
0202 
0203 idx  = find(System.Step==3);
0204 noe  = length(idx);
0205 bins = size(WaterTrack.Velocity,1);
0206 
0207 % Initialize Data Structure.
0208 Sup=struct( 'absorption_dbpm',nan(noe,1),...
0209     'bins',repmat(bins,noe,1),...
0210     'binSize_cm',nan(noe,1),...
0211     'nBins',nan(1),...
0212     'blank_cm',nan(1),...
0213     'draft_cm',nan(1),...
0214     'ensNo',nan(noe,1),...
0215     'nPings',nan(1),...
0216     'noEnsInSeg',nan(noe,1),...
0217     'noe',nan(1),...
0218     'note1',blanks(80),...
0219     'note2',blanks(80),...
0220     'intScaleFact_dbpcnt',nan(noe,1),...
0221     'intUnits',repmat(blanks(5),noe,1),...
0222     'vRef',repmat(blanks(4),noe,1),...
0223     'wm',nan(1),...
0224     'units',repmat(blanks(2),noe,1),...
0225     'year',nan(noe,1),...
0226     'month',nan(noe,1),...
0227     'day',nan(noe,1),...
0228     'hour',nan(noe,1),...
0229     'minute',nan(noe,1),...
0230     'second',nan(noe,1),...
0231     'sec100',nan(noe,1),...
0232     'timeElapsed_sec',nan(noe,1),...
0233     'timeDelta_sec100',nan(1));
0234 
0235 Wat=struct( 'binDepth',nan(bins,noe),...
0236     'backscatter',nan(bins,noe,4),...
0237     'vDir',nan(bins,noe),...
0238     'vMag',nan(bins,noe),...
0239     'vEast',nan(bins,noe),...
0240     'vError',nan(bins,noe),...
0241     'vNorth',nan(bins,noe),...
0242     'vVert',nan(bins,noe),...
0243     'percentGood',nan(bins,noe));
0244 
0245 Nav=struct( 'bvEast',nan(noe,1),...
0246     'bvError',nan(noe,1),...
0247     'bvNorth',nan(noe,1),...
0248     'bvVert',nan(noe,1),...
0249     'depth',nan(noe,4),...
0250     'dsDepth',nan(noe,1),...
0251     'dmg',nan(noe,1),...
0252     'length',nan(noe,1),...
0253     'totDistEast',nan(noe,1),...
0254     'totDistNorth',nan(noe,1),...
0255     'altitude',nan(noe,1),...
0256     'altitudeChng',nan(noe,1),...
0257     'gpsTotDist',nan(noe,1),...
0258     'gpsVariable',nan(noe,1),...
0259     'gpsVeast',nan(noe,1),...
0260     'gpsVnorth',nan(noe,1),...
0261     'lat_deg',nan(noe,1),...
0262     'long_deg',nan(noe,1),...
0263     'nSats',nan(noe,1),...
0264     'hdop',nan(noe,1));
0265 
0266 Sensor=struct(  'pitch_deg',nan(noe,1),...
0267     'roll_deg',nan(noe,1),...
0268     'heading_deg',nan(noe,1),...
0269     'temp_degC',nan(noe,1));
0270 
0271 Q=struct(   'endDepth',nan(noe,1),...
0272     'endDist',nan(noe,1),...
0273     'bot',nan(noe,1),...
0274     'end',nan(noe,1),...
0275     'meas',nan(noe,1),...
0276     'start',nan(noe,1),...
0277     'top',nan(noe,1),...
0278     'unit',nan(bins,noe),...
0279     'startDepth',nan(noe,1),...
0280     'startDist',nan(noe,1));
0281 
0282 Sup.noe = noe;
0283 
0284 % % Read in Selected Files
0285 % % Initialize the data structure
0286 % z = length(zFileName);
0287 % A = initStructure(z);
0288 %
0289 % % Begin master loop
0290 % for zi=1:z
0291 %     % Open data file, determine input type by extension
0292 %     [~, ~, ext] = fileparts(zFileName{zi});
0293 %     fileName = fullfile(zPathName,zFileName{zi});
0294 %
0295 %     switch ext
0296 %         case '.mat' % SonTek
0297 %             try
0298 %              [A(zi)]=parseSonTekVMT(fileName);
0299 %
0300 %             catch err
0301 %                 erstg = {'                                                      ',...
0302 %                     'An unknown error occurred when reading the SonTek file.'};
0303 %                 if isdeployed
0304 %                     errLogFileName = fullfile(pwd,...
0305 %                         ['errorLog' datestr(now,'yyyymmddHHMMSS') '.txt']);
0306 %                     msgbox({erstg;...
0307 %                         ['  Error code: ' err.identifier];...
0308 %                         ['Error details are being written to the following file: '];...
0309 %                         errLogFileName},...
0310 %                         'VMT Status: Unexpected Error',...
0311 %                         'error');
0312 %                     fid = fopen(errLogFileName,'W');
0313 %                     fwrite(fid,err.getReport('extended','hyperlinks','off'));
0314 %                     fclose(fid);
0315 %                     rethrow(err)
0316 %                 else
0317 %                     msgbox(['An unexpected error occurred. Error code: ' err.identifier],...
0318 %                         'VMT Status: Unexpected Error',...
0319 %                         'error');
0320 %                     rethrow(err);
0321 %                 end
0322 %             end
0323 %         otherwise
0324 %     end
0325 % end
0326 %
0327 %
0328 % % Create a name for any user saved results
0329 % switch ext
0330 %     case '.mat'
0331 %         % Save data with data/time prefix/suffix from the SonTek
0332 %         % filenames
0333 %         file_root_name = zFileName{1}(1:8);     % date string
0334 %         start_num      = zFileName{1}(9:end-4);   % time string
0335 %         end_num        = zFileName{end}(9:end-4); % time string
0336 %         savefile       = [file_root_name '_' start_num '_' end_num '.mat'];
0337 %         A(1).probeType = 'M9';
0338 %     otherwise
0339 %
0340 % end
0341 % save_dir = fullfile(zPathName,'VMTProcFiles');
0342 % [~,mess,~] = mkdir(save_dir);
0343 % % disp(mess)
0344 %
0345 %
0346 % savefile = fullfile(save_dir,savefile);
0347 
0348 %%%%%%%%%%%%%%%%%%%%%%
0349 % Embedded Functions %
0350 %%%%%%%%%%%%%%%%%%%%%%
0351

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