# VMT_ProcessTransectsV3_new_display

## PURPOSE

Not used by current version

## SYNOPSIS

function [A,V] = VMT_ProcessTransectsV3_new_display(h,z,A,V,setends)

## DESCRIPTION

     Not used by current version
    This routine acts as a driver program to process multiple transects at a
    single cross-section for velocity mapping.

## CROSS-REFERENCE INFORMATION

This function calls:

- VMT_GridData2MeanXS Generates a uniformly spaced grid for the mean cross section and

This function is called by:

## SUBFUNCTIONS

- function [A,V] = VMT_MapEns2MeanXSV2(h,z,A,V,setends)
- function [A,V] = VMT_GridData2MeanXS(h,z,A,V)
- function mypostcallback_zoom(obj,evd)
- function mypostcallback_pan(obj,evd)
- function [A,V] = VMT_CompMeanXS_old(z,A,V)
- function [A,V] = VMT_CompMeanXS_UVW(z,A,V)
- function [A,V] = VMT_CompMeanXS_PriSec(z,A,V)
- function [V] = VMT_RozovskiiV2(V,A)

## SOURCE CODE

    0001 function [A,V] = VMT_ProcessTransectsV3_new_display(h,z,A,V,setends)
    0002 % Not used by current version
    0003 %This routine acts as a driver program to process multiple transects at a
    0004 %single cross-section for velocity mapping.
    0005
    0006 %V2 adds the cpability to set the endpoints of the mean cross section
    0007
    0008 %V3 adds the Rozovskii computations for secondary flow. 8/31/09
    0009
    0010 %Among other things, it:
    0011
    0012 % Determines the best fit mean cross-section line from multiple transects
    0013 % Map ensembles to mean c-s line
    0014 % Determine uniform mean c-s grid for vector interpolating
    0015 % Determine location of mapped ensemble points for interpolating
    0016 % Interpolate individual transects onto uniform mean c-s grid
    0017 % Average mapped mean cross-sections from individual transects together
    0018 % Rotate velocities into u, v, and w components
    0019
    0020
    0021 %(adapted from code by J. Czuba)
    0022
    0023 %P.R. Jackson, USGS, 12-9-08
    0024
    0025 disp('Processing Data...')
    0026 warning off
    0027 %% Map ensembles to mean cross-section
    0028
    0029 VMT_MapEns2MeanXSV2(h,z,A,V,setends);
    0030
    0031 %% Grid the measured data along the mean cross-section
    0032 %[A,V] = VMT_GridData2MeanXS(z,A,V);
    0033 VMT_GridData2MeanXS(h,z,A,V);
    0034
    0035 %% Computes the mean data for the mean cross-section
    0036 %[A,V] = VMT_CompMeanXS(z,A,V);
    0037 [A,V] = VMT_CompMeanXS_old(z,A,V);
    0038
    0039 %% Decompose the velocities into u, v, and w components
    0040 [A,V] = VMT_CompMeanXS_UVW(z,A,V);
    0041
    0042 %% Decompose the velocities into primary and secondary components
    0043 [A,V] = VMT_CompMeanXS_PriSec(z,A,V);
    0044
    0045 %% Perform the Rozovskii computations
    0046 V = VMT_RozovskiiV2(V,A);
    0047
    0048
    0049 %==========================================================================
    0050 function [A,V] = VMT_MapEns2MeanXSV2(h,z,A,V,setends)
    0051
    0052 %This routine fits multiple transects at a single location with a single
    0053 %line and maps individual ensembles to this line. Inputs are number of files (z) and data matrix (Z)(see ReadFiles.m).
    0054 %Output is the updated data matrix with new mapped variables.
    0055
    0056 %V2 adds the capability to set the endpoints of the mean cross section
    0057
    0058 %(adapted from code by J. Czuba)
    0059
    0060 %P.R. Jackson, USGS, 12-9-08
    0061
    0062
    0063
    0064 %% Determine the best fit mean cross-section line from multiple transects
    0065 % initialize vectors for concatenation
    0066
    0067 x = [];
    0068 y = [];
    0069 % figure(1); clf
    0070 figure(h)
    0071 % hf = VMT_CreatePlotDisplay('shiptracks');
    0072 set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1])
    0073 for zi = 1:z
    0074
    0075     % concatenate coords into a single column vector for regression
    0076     x = cat(1,x,A(zi).Comp.xUTM);
    0077     y = cat(1,y,A(zi).Comp.yUTM);
    0078
    0079 %     figure(1); hold on
    0080     figure(h); hold on
    0081     plot(A(zi).Comp.xUTMraw,A(zi).Comp.yUTMraw,'b'); hold on
    0082 end
    0083
    0084 if setends  %Gets a user text file with fixed cross section end points
    0085
    0086     defaultpath = 'C:\';
    0087     endspath = [];
    0088     if exist('\VMT\LastDir.mat') == 2
    0089         load('VMT\LastDir.mat');
    0090         if exist(endspath) == 7
    0091             [file,endspath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Endpoint Text File',endspath);
    0092         else
    0093             [file,endspath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Endpoint Text File',defaultpath);
    0094         end
    0095     else
    0096         [file,endspath] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Endpoint Text File',defaultpath);
    0097     end
    0098
    0099     if ischar(file)
    0100         infile = [endspath file];
    0101         %[file,path] = uigetfile({'*.txt;*.csv','All Text Files'; '*.*','All Files'},'Select Endpoint Text File');
    0102         %infile = [path file];
    0103         disp('Loading Endpoint File...' );
    0104         disp(infile);
    0105         data = dlmread(infile);
    0106         x = data(:,1);
    0107         y = data(:,2);
    0108         %     figure(1); hold on
    0109         figure(h); hold on
    0110         plot(x,y,'go','MarkerSize',10); hold on
    0111     end
    0112 end
    0113
    0114 % find the equation of the best fit line
    0115 xrng = max(x) - min(x);
    0116 yrng = max(y) - min(y);
    0117 if xrng >= yrng %Fit based on coordinate with larger range of values (original fitting has issues with N-S lines because of repeated X values), PRJ 12-12-08
    0118     [P,~] = polyfit(x,y,1);
    0119 %     figure(1); hold on
    0120     figure(h); hold on
    0121     plot(x,polyval(P,x),'g-')
    0122 else
    0123     [P,~] = polyfit(y,x,1);
    0124 %     figure(1); hold on
    0125     figure(h); hold on
    0126     plot(polyval(P,y),y,'g-')
    0127 end
    0128
    0129 clear x y stats whichstats zi
    0130
    0131 %% Map ensembles to mean c-s line
    0132 % Determine the point (mapped ensemble point) where the equation of the
    0133 % mean cross-section line intercepts a line perpendicular to the mean
    0134 % cross-section line passing through an ensemble from an individual
    0135 % transect (see notes for equation derivation)
    0136
    0137 for zi = 1 : z
    0138     A(zi).Comp.xm = ((A(zi).Comp.xUTM-V.m.*V.b+V.m.*A(zi).Comp.yUTM)...
    0139         ./(V.m.^2+1));
    0140     A(zi).Comp.ym = ((V.b+V.m.*A(zi).Comp.xUTM+V.m.^2.*A(zi).Comp.yUTM)...
    0141         ./(V.m.^2+1));
    0142 end
    0143
    0144 %Plot data to check
    0145 % xensall = [];
    0146 % yensall = [];
    0147 for zi = 1 : z
    0148   plot(A(zi).Comp.xm,A(zi).Comp.ym,'b.')
    0149 %   xensall = [xensall; A(zi).Comp.xm];
    0150 %   yensall = [yensall; A(zi).Comp.ym];
    0151 end
    0152 xlabel('UTM Easting (m)')
    0153 ylabel('UTM Northing (m)')
    0154 box on
    0155 grid on
    0156
    0157 %==========================================================================
    0158 function [A,V] = VMT_GridData2MeanXS(h,z,A,V)
    0159
    0160 %This routine generates a uniformly spaced grid for the mean cross section and
    0161 %maps (interpolates) individual transects to this grid.
    0162
    0163 %(adapted from code by J. Czuba)
    0164
    0165 %P.R. Jackson, USGS, 12-9-08
    0166
    0167 %% User Input
    0168
    0169 xgdspc = A(1).hgns; %Horizontal Grid node spacing in meters  (vertical grid spacing is set by bins)
    0170
    0171 % Determine the distance between the mean cross-section endpoints
    0172
    0173 % Determine the angle the mean cross-section makes with the
    0174 % x-axis (longitude)
    0175 % Plot mean cross-section line
    0176 if V.m >= 0
    0177
    0178 %     figure(1); hold on
    0179     figure(h); hold on
    0180     plot([V.xe V.xw],[V.yn V.ys],'ks'); hold on
    0181
    0182     plot(V.mcsX,V.mcsY,'k+'); hold on
    0183     plot(V.mcsX(1),V.mcsY(1),'y*'); hold on
    0184
    0185 elseif V.m < 0
    0186
    0187 %     figure(1); hold on
    0188     figure(h); hold on
    0189     plot([V.xe V.xw],[V.ys V.yn],'ks'); hold on
    0190
    0191     plot(V.mcsX,V.mcsY,'k+'); hold on
    0192     plot(V.mcsX(1),V.mcsY(1),'y*'); hold on
    0193
    0194 end
    0195
    0196 % figure(1)
    0197 figure(h)
    0198 set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1])
    0199
    0200 % Format the ticks for UTM and allow zooming and panning
    0201 % figure(1)
    0202 figure(h)
    0203 ticks_format('%6.0f','%8.0f'); %formats the ticks for UTM
    0204 hdlzm_fig1 = zoom;
    0205 set(hdlzm_fig1,'ActionPostCallback',@mypostcallback_zoom);
    0206 set(hdlzm_fig1,'Enable','on');
    0207 hdlpn_fig1 = pan;
    0208 set(hdlpn_fig1,'ActionPostCallback',@mypostcallback_pan);
    0209 set(hdlpn_fig1,'Enable','on');
    0210
    0211
    0212 %% Determine location of mapped ensemble points for interpolating
    0213 % For all transects
    0214
    0215 %A = VMT_DxDyfromLB(z,A,V); %Computes dx and dy
    0216
    0217 %% Interpolate individual transects onto uniform mean c-s grid
    0218 % Fill in uniform grid based on individual transects mapped onto the mean
    0219 % cross-section by interpolating between adjacent points
    0220
    0221 %% Embedded functions
    0222 function mypostcallback_zoom(obj,evd)
    0223 ticks_format('%6.0f','%8.0f'); %formats the ticks for UTM (when zooming)
    0224
    0225 function mypostcallback_pan(obj,evd)
    0226 ticks_format('%6.0f','%8.0f'); %formats the ticks for UTM (when panning)
    0227
    0228 %==========================================================================
    0229 function [A,V] = VMT_CompMeanXS_old(z,A,V)
    0230 %==========================================================================
    0231 function [A,V] = VMT_CompMeanXS_UVW(z,A,V)
    0232 %==========================================================================
    0233 function [A,V] = VMT_CompMeanXS_PriSec(z,A,V)
    0234
    0235 %==========================================================================
    0236 function [V] = VMT_RozovskiiV2(V,A)
    0237