0001 function [A] = VMT_MBBathy(z,A,savefile,beamAng,magVar,wsedata,saveaux)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 try
0018
0019 if isstruct(wsedata)
0020 if length(wsedata.elev) == 1
0021
0022 wsefiletype = 0;
0023 else
0024
0025 wsefiletype = 1;
0026 end
0027 else
0028
0029 warning off
0030 wsedata.elev = wsedata;
0031 wsefiletype = 0;
0032 warning on
0033 end
0034
0035
0036
0037 for zi = 1 : z
0038
0039
0040
0041
0042
0043 if wsefiletype
0044
0045 enstime = datenum([A(zi).Sup.year+2000 A(zi).Sup.month A(zi).Sup.day...
0046 A(zi).Sup.hour A(zi).Sup.minute (A(zi).Sup.second+A(zi).Sup.sec100./100)]);
0047
0048
0049 if 0
0050 obs_start = datestr(wsedata.obstime(1))
0051 obs_end = datestr(wsedata.obstime(end))
0052
0053 ens_start = datestr(enstime(1))
0054 ens_end = datestr(enstime(end))
0055 end
0056
0057
0058 wse = interp1(wsedata.obstime,wsedata.elev,enstime);
0059
0060 if 0
0061 figure(1); hold on
0062 plot(enstime,wse,'k-')
0063 datetick('x',13)
0064 ylabel('WSE, in meters')
0065 end
0066 else
0067 wse = wsedata.elev;
0068 end
0069
0070
0071 [exyz] = depthxyz(A(zi).Nav.depth,A(zi).Sup.draft_cm,...
0072 A(zi).Sensor.pitch_deg,A(zi).Sensor.roll_deg,...
0073 A(zi).Sensor.heading_deg,beamAng,...
0074 'm',A(zi).Comp.xUTMraw,A(zi).Comp.yUTMraw,wse,A(zi).Sup.ensNo);
0075
0076
0077 if saveaux
0078 auxmat = [A(zi).Sup.year+2000 A(zi).Sup.month A(zi).Sup.day...
0079 A(zi).Sup.hour A(zi).Sup.minute (A(zi).Sup.second+A(zi).Sup.sec100./100) ...
0080 A(zi).Sensor.heading_deg A(zi).Sensor.pitch_deg A(zi).Sensor.roll_deg ...
0081 repmat(zi,size(A(zi).Sup.year))];
0082 auxmat2 = [];
0083 for i = 1:length(A(zi).Sup.ensNo);
0084 dum = repmat(auxmat(i,:),4,1);
0085 auxmat2 = cat(1,auxmat2,dum);
0086 end
0087 clear auxmat dum enstime wse
0088 end
0089
0090
0091 idxmbb = find(~isnan(exyz(:,4))& ~isnan(exyz(:,2)));
0092 if zi==1
0093 zmbb=[exyz(idxmbb,1) exyz(idxmbb,2)...
0094 exyz(idxmbb,3) exyz(idxmbb,4)];
0095 if saveaux
0096 auxmbb = auxmat2(idxmbb,:);
0097 end
0098 else
0099 zmbb=cat(1,zmbb,[exyz(idxmbb,1)...
0100 exyz(idxmbb,2) exyz(idxmbb,3) exyz(idxmbb,4)]);
0101 if saveaux
0102 auxmbb = cat(1,auxmbb,auxmat2(idxmbb,:));
0103 end
0104 end
0105
0106 A(zi).Comp.exyz = exyz(idxmbb,:);
0107
0108
0109 clear idxmbb exyz;
0110
0111 end
0112
0113
0114
0115
0116 if 1
0117
0118
0119 outfile = [savefile(1:end-4) '.csv'];
0120 if saveaux
0121 outmat = [zmbb auxmbb];
0122 ofid = fopen(outfile, 'wt');
0123 outcount = fprintf(ofid,'EnsNo, Easting_WGS84_m, Northing_WGS84_m, Elev_m, Year, Month, Day, Hour, Minute, Second, Heading_deg, Pitch_deg, Roll_deg, Transect\n');
0124 outcount = fprintf(ofid,'%6.0f, %14.2f, %14.2f, %8.2f, %4.0f, %2.0f, %2.0f, %2.0f, %2.0f, %2.2f, %3.3f, %3.3f, %3.3f, %3.0f\n',outmat');
0125 fclose(ofid);
0126 else
0127 outmat = zmbb;
0128 ofid = fopen(outfile, 'wt');
0129 outcount = fprintf(ofid,'EnsNo, Easting_WGS84_m, Northing_WGS84_m, Elev_m\n');
0130 outcount = fprintf(ofid,'%6.0f, %14.2f, %14.2f, %8.2f\n',outmat');
0131 fclose(ofid);
0132 end
0133
0134 end
0135 catch err
0136 if isdeployed
0137 errLogFileName = fullfile(pwd,...
0138 ['errorLog' datestr(now,'yyyymmddHHMMSS') '.txt']);
0139 msgbox({['An unexpected error occurred. Error code: ' err.identifier];...
0140 ['Error details are being written to the following file: '];...
0141 errLogFileName},...
0142 'VMT Status: Unexpected Error',...
0143 'error');
0144 fid = fopen(errLogFileName,'W');
0145 fwrite(fid,err.getReport('extended','hyperlinks','off'));
0146 fclose(fid);
0147 rethrow(err)
0148 else
0149 msgbox(['An unexpected error occurred. Error code: ' err.identifier],...
0150 'VMT Status: Unexpected Error',...
0151 'error');
0152 rethrow(err);
0153 end
0154 end