# ExtractMCS

## PURPOSE

%

## SYNOPSIS

function [y,elev,wse] = ExtractMCS

## DESCRIPTION

    %
    Loads and plots the mean cross section bathymetry for a series of files
    from .mat files output from VMT.  Flips XS if looking upstream so all XS
    should be oriented looking DS.

## CROSS-REFERENCE INFORMATION

This function calls:

- nansum NANSUM Sum, ignoring NaNs.

This function is called by:

## SOURCE CODE

    0001 function [y,elev,wse] = ExtractMCS
    0002
    0003 %%
    0004 %Loads and plots the mean cross section bathymetry for a series of files
    0005 %from .mat files output from VMT.  Flips XS if looking upstream so all XS
    0006 %should be oriented looking DS.
    0007
    0008 %P.R. Jackson, USGS, 7/16/09
    0009
    0010 %% Load the files
    0011
    0012 % Prompt user for directory containing files
    0013 zPathName = uigetdir('','Select the Directory Containing Processed Data Files (*.mat)');
    0014 Files = dir(zPathName);
    0015 allFiles = {Files.name};
    0016 filefind=strfind(allFiles,'.mat')';
    0017 filesidx=nan(size(filefind,1),1);
    0018 for i=1:size(filefind,1)
    0019     filesidx(i,1)=size(filefind{i},1);
    0020 end
    0021 filesidx=find(filesidx>0);
    0022 files=allFiles(filesidx);
    0023
    0024 % Allow user to select which files are to be processed
    0025 selection = listdlg('ListSize',[300 300],'ListString', files,'Name','Select Data Files');
    0026 zFileName = files(selection);
    0027
    0028 % Determine number of files to be processed
    0029 if  isa(zFileName,'cell')
    0030     zf=size(zFileName,2);
    0031     zFileName = sort(zFileName);
    0032 else
    0033     zf=1;
    0034     zFileName={zFileName}
    0035 end
    0036
    0037 %%
    0038 figure(1); clf
    0039 clrs = colormap(jet(zf));
    0040 for i = 1:zf
    0041     wse(i)= input(['Water surface elevation (meters) for file ' zFileName{i} ' = ']);
    0042     load([zPathName '\' zFileName{i}]);
    0043
    0044     %Check the XS to see if it needs to be flipped
    0045     %Find the direction of primary discharge (flip if necessary)
    0046     binwidth  = diff(V.mcsDist,1,2);
    0047     binwidth  = horzcat(binwidth(:,1), binwidth);
    0048     binheight = diff(V.mcsDepth,1,1);
    0049     binheight = vertcat(binheight, binheight(1,:));
    0050     flux = nansum(nansum(V.u./100.*binwidth.*binheight)); %Not a true measured discharge because of averaging, smoothing, etc. but close
    0051
    0052     if flux < 0; %abs(pdmin) > abs(pdmax)
    0053         flipxs = 1;
    0054     else
    0055         flipxs = 0;
    0056     end
    0057     if ~flipxs
    0058         y{i} = V.mcsDist(1,:);
    0059     else
    0060         y{i} = max(V.mcsDist(1,:)) - V.mcsDist(1,:);
    0061     end
    0062     elev{i} = wse(i) - V.mcsBed;
    0063     plot(y{i},elev{i},'-','Color',clrs(i,:)); hold on
    0064 end
    0065 %set(gca,'YDir','reverse')
    0066 xlabel('Distance (m)')
    0067 ylabel('Elevation (m)')
    0068 legend(zFileName,'Interpreter','none')