0001 function [A,V,log_text] = VMT_MapEns2MeanXSV2(z,A,setends)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 x = [];
0021 y = [];
0022
0023
0024 for zi = 1 : z
0025
0026
0027 x=cat(1,x,A(zi).Comp.xUTM);
0028 y=cat(1,y,A(zi).Comp.yUTM);
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 mVe(zi) = nanmean(nanmean(A(zi).Clean.vEast,1));
0047 mVn(zi) = nanmean(nanmean(A(zi).Clean.vNorth,1));
0048
0049 end
0050
0051
0052 if setends
0053 [x,y] = loadUserSetEndpoints();
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 end
0064
0065
0066 mfdVe = mean(mVe);
0067 mfdVn = mean(mVn);
0068 V.mfd = ari2geodeg((atan2(mfdVn, mfdVe))*180/pi);
0069
0070
0071 xw = min(x); xe = max(x);
0072 ys = min(y); yn = max(y);
0073 xrng = xe - xw;
0074 yrng = yn - ys;
0075
0076 if xrng >= yrng
0077 [P,S] = polyfit(x,y,1);
0078
0079
0080 V.m = P(1);
0081 V.b = P(2);
0082 dx = xe-xw;
0083 dy = polyval(P,xe)-polyval(P,xw);
0084 else
0085 [P,S] = polyfit(y,x,1);
0086
0087
0088 V.m = 1/P(1);
0089 V.b = -P(2)/P(1);
0090 dx = polyval(P,yn)-polyval(P,ys);
0091 dy = yn-ys;
0092
0093
0094
0095
0096
0097 end
0098
0099
0100
0101 dl = sqrt(dx^2+dy^2);
0102
0103
0104 if V.m >= 0
0105 V.theta = ari2geodeg(atand(V.m));
0106 elseif V.m < 0
0107 V.theta = ari2geodeg(atand(V.m));
0108 end
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118 N = [-dy/sqrt(dx^2+dy^2)...
0119 dx/sqrt(dx^2+dy^2)];
0120
0121
0122
0123
0124 arimfddeg = geo2arideg(V.mfd);
0125 [xmfd,ymfd] = pol2cart(arimfddeg*pi/180,1);
0126 M = [xmfd ymfd];
0127
0128
0129
0130 vdif = acos(dot(N,M)/(norm(N)*norm(M)))*180/pi;
0131
0132
0133
0134 if vdif >= 90
0135 N = -N;
0136 end
0137
0138
0139
0140 midy = ys+abs(yrng)/2;
0141 midx = xw+xrng/2;
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 V.phi = ari2geodeg(cart2pol(N(1),N(2))*180/pi);
0152
0153 clear x y stats whichstats zi
0154
0155
0156
0157
0158
0159
0160
0161 for zi = 1 : z
0162
0163 A(zi).Comp.xm = ((A(zi).Comp.xUTM-V.m.*V.b+V.m.*A(zi).Comp.yUTM)...
0164 ./(V.m.^2+1));
0165 A(zi).Comp.ym = ((V.b+V.m.*A(zi).Comp.xUTM+V.m.^2.*A(zi).Comp.yUTM)...
0166 ./(V.m.^2+1));
0167
0168
0169 end
0170
0171
0172
0173 xensall = [];
0174 yensall = [];
0175 for zi = 1 : z
0176
0177 xensall = [xensall; A(zi).Comp.xm];
0178 yensall = [yensall; A(zi).Comp.ym];
0179 end
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192 Dmat = [xensall yensall];
0193 if xrng > yrng
0194 Dmat = sortrows(Dmat,1);
0195 else
0196 Dmat = sortrows(Dmat,2);
0197 end
0198 dxall = diff(Dmat(:,1));
0199 dyall = diff(Dmat(:,2));
0200 densall = sqrt(dxall.^2 + dyall.^2);
0201 V.meddens = median(densall);
0202 V.stddens = std(densall);
0203
0204
0205
0206
0207
0208 msg_string = {['Median Spacing Between Mapped Ensembles = ' num2str(V.meddens) ' m'],...
0209 ['Standard Deviation of Spacing Between Mapped Ensembles = ' num2str(V.stddens) ' m'],...
0210 ['Recommended Grid Node Spacing > ' num2str(V.meddens + V.stddens) ' m']};
0211
0212 log_text = {...
0213 [' Median Spacing Between Mapped Ensembles = ' num2str(V.meddens) ' m'];...
0214 [' Standard Deviation of Spacing Between Mapped Ensembles = ' num2str(V.stddens) ' m'];...
0215 [' Recommended Grid Node Spacing > ' num2str(V.meddens + V.stddens) ' m']};
0216
0217
0218
0219
0220
0221
0222
0223 V.xe = mean(A(1).Comp.xm);
0224 V.ys = mean(A(1).Comp.ym);
0225 V.xw = mean(A(1).Comp.xm);
0226 V.yn = mean(A(1).Comp.ym);
0227
0228 for zi = 1 : z
0229
0230 V.xe = max(max(A(zi).Comp.xm),V.xe);
0231 V.ys = min(min(A(zi).Comp.ym),V.ys);
0232 V.xw = min(min(A(zi).Comp.xm),V.xw);
0233 V.yn = max(max(A(zi).Comp.ym),V.yn);
0234
0235 end
0236
0237
0238 V.dx = V.xe-V.xw;
0239 V.dy = V.yn-V.ys;
0240 V.dl = sqrt(V.dx.^2+V.dy.^2);
0241
0242
0243
0244
0245 V = setStation(V);
0246
0247
0248
0249
0250 A = interpBadGPS(A,V,z);
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261 function [x,y] = loadUserSetEndpoints()
0262 defaultpath = 'C:\';
0263 endspath = [];
0264 if 0
0265 load('VMT\LastDir.mat');
0266 if exist(endspath) == 7
0267 [file,endspath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Endpoint Text File',endspath);
0268 else
0269 [file,endspath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Endpoint Text File',defaultpath);
0270 end
0271 else
0272 [file,endspath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Endpoint Text File',defaultpath);
0273 end
0274 infile = [endspath file];
0275
0276
0277 disp('Loading Endpoint File...' );
0278 disp(infile);
0279 data = dlmread(infile);
0280 x = data(:,1);
0281 y = data(:,2);
0282
0283 function A = interpBadGPS(A,V,z)
0284 for zi = 1 : z
0285
0286
0287 A(zi).Comp.dx = abs(V.xLeftBank - A(zi).Comp.xm);
0288 A(zi).Comp.dy = abs(V.yLeftBank - A(zi).Comp.ym);
0289
0290
0291
0292
0293 A(zi).Comp.dl = sqrt(A(zi).Comp.dx.^2+A(zi).Comp.dy.^2);
0294
0295
0296 [A(zi).Comp.dlsort,A(zi).Comp.vecmap] = sort(A(zi).Comp.dl,'ascend');
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317 chk(:,1)=[1; diff(A(zi).Comp.dlsort)];
0318
0319
0320 A(zi).Comp.sd = (chk==0) > 0;
0321
0322
0323 if any(A(zi).Comp.sd)
0324
0325
0326 [I,J] = ind2sub(size(A(zi).Comp.sd),find(A(zi).Comp.sd==1));
0327 df=diff(I);
0328 numberBreaks=sum(df>1)+1;
0329 [I2,J2] = ind2sub(size(df),find(df>1));
0330
0331 idxBeginBracket(1)=(I(1)-1);
0332
0333 for n = 2 : numberBreaks
0334 idxBeginBracket(n)=(I(I2(n-1)+1)-1);
0335 end
0336
0337 for n = 1 : numberBreaks -1
0338 idxEndBracket(n)=(I(I2(n))+1);
0339 end
0340
0341 idxEndBracket(numberBreaks)=I(end)+1;
0342
0343
0344 A(zi).Comp.dlsortgpsfix = A(zi).Comp.dlsort;
0345
0346 for i = 1 : numberBreaks
0347 for j = idxBeginBracket(i)+1 : idxEndBracket(i)-1
0348
0349 if idxBeginBracket(i) > 0 && idxEndBracket(i) < length(A(zi).Nav.lat_deg)
0350
0351 den=(idxEndBracket(i)-idxBeginBracket(i));
0352 num2=j-idxBeginBracket(i);
0353 num1=idxEndBracket(i)-j;
0354
0355 A(zi).Comp.dlsortgpsfix(j,1)=...
0356 (num1/den).*A(zi).Comp.dlsort(idxBeginBracket(i))+...
0357 (num2/den).*A(zi).Comp.dlsort(idxEndBracket(i));
0358
0359 end
0360
0361
0362 if idxEndBracket(i) > length(A(zi).Nav.lat_deg)
0363
0364 numex=idxEndBracket(i)-length(A(zi).Nav.lat_deg);
0365
0366 A(zi).Comp.dlsortgpsfix(j,1)=numex.*...
0367 (A(zi).Comp.dlsort(idxBeginBracket(i))-...
0368 A(zi).Comp.dlsort(idxBeginBracket(i)-1))+...
0369 A(zi).Comp.dlsort(idxBeginBracket(i));
0370 end
0371 end
0372 end
0373
0374
0375 else
0376 A(zi).Comp.dlsortgpsfix = A(zi).Comp.dlsort;
0377 end
0378
0379
0380
0381
0382
0383
0384
0385 A(zi).Comp.itDist = repmat(A(zi).Comp.dlsortgpsfix',size(A(zi).Wat.binDepth,1),1);
0386 A(zi).Comp.itDepth = A(zi).Wat.binDepth(:,A(zi).Comp.vecmap);
0387
0388
0389 clear I I2 J J2 bg chk df ed i j nbrk xUTM yUTM n zi...
0390 den num2 num1 numex
0391
0392 end
0393
0394 function V = setStation(V)
0395 if V.phi > 0 && V.phi < 90
0396 V.xLeftBank = V.xw;
0397 V.yLeftBank = V.yn;
0398 V.xRightBank = V.xe;
0399 V.yRightBank = V.ys;
0400 elseif V.phi > 90 && V.phi < 180
0401 V.xLeftBank = V.xe;
0402 V.yLeftBank = V.yn;
0403 V.xRightBank = V.xw;
0404 V.yRightBank = V.ys;
0405 elseif V.phi > 180 && V.phi < 270
0406 V.xLeftBank = V.xe;
0407 V.yLeftBank = V.ys;
0408 V.xRightBank = V.xw;
0409 V.yRightBank = V.yn;
0410 elseif V.phi > 270 && V.phi < 360
0411 V.xLeftBank = V.xw;
0412 V.yLeftBank = V.ys;
0413 V.xRightBank = V.xe;
0414 V.yRightBank = V.yn;
0415 elseif V.phi == 0
0416 V.xLeftBank = V.xw;
0417 V.yLeftBank = V.yn;
0418 V.xRightBank = V.xe;
0419 V.yRightBank = V.ys;
0420 elseif V.phi == 90
0421 V.xLeftBank = V.xe;
0422 V.yLeftBank = V.yn;
0423 V.xRightBank = V.xw;
0424 V.yRightBank = V.ys;
0425 elseif V.phi == 180
0426 V.xLeftBank = V.xe;
0427 V.yLeftBank = V.yn;
0428 V.xRightBank = V.xw;
0429 V.yRightBank = V.ys;
0430 elseif V.phi == 270
0431 V.xLeftBank = V.xe;
0432 V.yLeftBank = V.ys;
0433 V.xRightBank = V.xw;
0434 V.yRightBank = V.yn;
0435 end