VMT_BuildCustomFlatFile

PURPOSE ^

--- THE VELOCITY MAPPING TOOLBOX ---

SYNOPSIS ^

function varargout = VMT_BuildCustomFlatFile(varargin)

DESCRIPTION ^

 --- THE VELOCITY MAPPING TOOLBOX ---
 VMT_BUILDCUSTOMFLATFILE is a sub-GUI of VMT which allows the user to
 create custom CSV flatfiles of VMT outputs.
__________________________________________________________________________
 Frank L. Engel, U.S. Geological Survey, Illinois Water Science Center
 (fengel@usgs.gov)

 Code contributed by P.R. Jackson, D. Parsons, D. Mueller, and J. Czuba.
__________________________________________________________________________
 
 VMT_BUILDCUSTOMFLATFILE creates a interactive dual-listbox with sort
 controls. This basic GUI allows users to select items in populated
 listbox (AvailableItems), and move them to a Selected List of Items
 (SelectedItems). The user can move any or all items freely from box to
 box. Additionally, the user can sort items in the Selected Items listbox.
 
 This GUI can be customized and tied to software outputs. One potential
 use is to generate custom output files, where the user can specify
 exactly what variables are needed in the output file.
 
 Written by: Frank L. Engel, USGS ILWSC
 Last Modified: 2014-04-09

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = VMT_BuildCustomFlatFile(varargin)
0002 % --- THE VELOCITY MAPPING TOOLBOX ---
0003 % VMT_BUILDCUSTOMFLATFILE is a sub-GUI of VMT which allows the user to
0004 % create custom CSV flatfiles of VMT outputs.
0005 %__________________________________________________________________________
0006 % Frank L. Engel, U.S. Geological Survey, Illinois Water Science Center
0007 % (fengel@usgs.gov)
0008 %
0009 % Code contributed by P.R. Jackson, D. Parsons, D. Mueller, and J. Czuba.
0010 %__________________________________________________________________________
0011 %
0012 % VMT_BUILDCUSTOMFLATFILE creates a interactive dual-listbox with sort
0013 % controls. This basic GUI allows users to select items in populated
0014 % listbox (AvailableItems), and move them to a Selected List of Items
0015 % (SelectedItems). The user can move any or all items freely from box to
0016 % box. Additionally, the user can sort items in the Selected Items listbox.
0017 %
0018 % This GUI can be customized and tied to software outputs. One potential
0019 % use is to generate custom output files, where the user can specify
0020 % exactly what variables are needed in the output file.
0021 %
0022 % Written by: Frank L. Engel, USGS ILWSC
0023 % Last Modified: 2014-04-09
0024 
0025 % Begin initialization code - DO NOT EDIT
0026 gui_Singleton = 1;
0027 gui_State = struct('gui_Name',       mfilename, ...
0028                    'gui_Singleton',  gui_Singleton, ...
0029                    'gui_OpeningFcn', @VMT_BuildCustomFlatFile_OpeningFcn, ...
0030                    'gui_OutputFcn',  @VMT_BuildCustomFlatFile_OutputFcn, ...
0031                    'gui_LayoutFcn',  [] , ...
0032                    'gui_Callback',   []);
0033 if nargin && ischar(varargin{1})
0034     gui_State.gui_Callback = str2func(varargin{1});
0035 end
0036 
0037 if nargout
0038     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0039 else
0040     gui_mainfcn(gui_State, varargin{:});
0041 end
0042 % End initialization code - DO NOT EDIT
0043 
0044 
0045 % --- Executes just before VMT_BuildCustomFlatFile is made visible.
0046 function VMT_BuildCustomFlatFile_OpeningFcn(hObject, eventdata, handles, varargin)
0047 % This function has no output args, see OutputFcn.
0048 % hObject    handle to figure
0049 % eventdata  reserved - to be defined in a future version of MATLAB
0050 % handles    structure with handles and user data (see GUIDATA)
0051 % varargin   command line arguments to VMT_BuildCustomFlatFile (see VARARGIN)
0052 
0053 % Choose default command line output for VMT_BuildCustomFlatFile
0054 handles.output = hObject;
0055 
0056 % Update handles structure
0057 guidata(hObject, handles);
0058 
0059 % Initialize the GUI parameters:
0060 % ------------------------------
0061 guiparams = createGUIparams;
0062 
0063 % Store the application data
0064 % --------------------------
0065 setappdata(handles.figure1,'guiparams',guiparams)
0066 
0067 % Initialize the GUI:
0068 % -------------------
0069 initGUI(handles)
0070 
0071 % UIWAIT makes VMT_BuildCustomFlatFile wait for user response (see UIRESUME)
0072 % uiwait(handles.figure1);
0073 
0074 
0075 % --- Outputs from this function are returned to the command line.
0076 function varargout = VMT_BuildCustomFlatFile_OutputFcn(hObject, eventdata, handles) 
0077 % varargout  cell array for returning output args (see VARARGOUT);
0078 % hObject    handle to figure
0079 % eventdata  reserved - to be defined in a future version of MATLAB
0080 % handles    structure with handles and user data (see GUIDATA)
0081 
0082 % Get default command line output from handles structure
0083 varargout{1} = handles.output;
0084 
0085 
0086 % --- Executes on selection change in AvailableItems.
0087 function AvailableItems_Callback(hObject, eventdata, handles)
0088 % hObject    handle to AvailableItems (see GCBO)
0089 % eventdata  reserved - to be defined in a future version of MATLAB
0090 % handles    structure with handles and user data (see GUIDATA)
0091 
0092 % Hints: contents = cellstr(get(hObject,'String')) returns AvailableItems contents as cell array
0093 %        contents{get(hObject,'Value')} returns selected item from AvailableItems
0094 
0095 % --- Executes on selection change in SelectedItems.
0096 function SelectedItems_Callback(hObject, eventdata, handles)
0097 % hObject    handle to SelectedItems (see GCBO)
0098 % eventdata  reserved - to be defined in a future version of MATLAB
0099 % handles    structure with handles and user data (see GUIDATA)
0100 
0101 % Hints: contents = cellstr(get(hObject,'String')) returns SelectedItems contents as cell array
0102 %        contents{get(hObject,'Value')} returns selected item from SelectedItems
0103 
0104 
0105 % --- Executes on button press in AddSelected.
0106 function AddSelected_Callback(hObject, eventdata, handles)
0107 % hObject    handle to AddSelected (see GCBO)
0108 % eventdata  reserved - to be defined in a future version of MATLAB
0109 % handles    structure with handles and user data (see GUIDATA)
0110 
0111 % See what's already in each listbox
0112 AvailableItems = get(handles.AvailableItems,'string');
0113 SelectedItems  = get(handles.SelectedItems, 'string');
0114 
0115 % See what's selected in the Available Items listbox
0116 idx            = get(handles.AvailableItems,'value');
0117 SelectedStr    = AvailableItems(idx);
0118 NotSelectedStr = AvailableItems(~ismember(AvailableItems,SelectedStr));
0119 
0120 % Push SelectedStr into Selected Items and remove from Available Items
0121 set(handles.SelectedItems,  'String', vertcat(SelectedItems,SelectedStr))
0122 set(handles.AvailableItems, 'String', NotSelectedStr)
0123 
0124 % Deselect Items in both boxes
0125 set(handles.AvailableItems, 'Value', [])
0126 set(handles.SelectedItems,  'Value', [])
0127 
0128 % Set the enable for the export button
0129 set_enable(handles,'itemsareselected')
0130 
0131 
0132 % --- Executes on button press in AddAll.
0133 function AddAll_Callback(hObject, eventdata, handles)
0134 % hObject    handle to AddAll (see GCBO)
0135 % eventdata  reserved - to be defined in a future version of MATLAB
0136 % handles    structure with handles and user data (see GUIDATA)
0137 
0138 % See what's already in each listbox
0139 AvailableItems = get(handles.AvailableItems,'string');
0140 SelectedItems  = get(handles.SelectedItems, 'string');
0141 
0142 % Push AvailableItems into Selected Items and remove from Available Items
0143 set(handles.SelectedItems,  'String', vertcat(SelectedItems,AvailableItems))
0144 set(handles.AvailableItems, 'String', [])
0145 
0146 % Deselect Items in both boxes
0147 set(handles.AvailableItems, 'Value', [])
0148 set(handles.SelectedItems,  'Value', [])
0149 
0150 % Set the enable for the export button
0151 set_enable(handles,'itemsareselected')
0152 
0153 
0154 % --- Executes on button press in RemoveSelected.
0155 function RemoveSelected_Callback(hObject, eventdata, handles)
0156 % hObject    handle to RemoveSelected (see GCBO)
0157 % eventdata  reserved - to be defined in a future version of MATLAB
0158 % handles    structure with handles and user data (see GUIDATA)
0159 
0160 % See what's already in each listbox
0161 AvailableItems = get(handles.AvailableItems,'string');
0162 SelectedItems  = get(handles.SelectedItems, 'string');
0163 
0164 % See what's selected in the Selected Items listbox
0165 idx            = get(handles.SelectedItems,'value');
0166 SelectedStr    = SelectedItems(idx);
0167 NotSelectedStr = SelectedItems(~ismember(SelectedItems,SelectedStr));
0168 
0169 % Push SelectedStr into Available Items and remove from Selected Items
0170 set(handles.AvailableItems,'String', vertcat(AvailableItems,SelectedStr))
0171 set(handles.SelectedItems, 'String', NotSelectedStr)
0172 
0173 % Deselect Items in both boxes
0174 set(handles.AvailableItems, 'Value', [])
0175 set(handles.SelectedItems,  'Value', [])
0176 
0177 % Set the enable for the export button
0178 if isempty(NotSelectedStr)
0179     set_enable(handles,'noitemsselected')
0180 end
0181 
0182 
0183 % --- Executes on button press in RemoveAll.
0184 function RemoveAll_Callback(hObject, eventdata, handles)
0185 % hObject    handle to RemoveAll (see GCBO)
0186 % eventdata  reserved - to be defined in a future version of MATLAB
0187 % handles    structure with handles and user data (see GUIDATA)
0188 
0189 % See what's already in each listbox
0190 AvailableItems = get(handles.AvailableItems,'string');
0191 SelectedItems  = get(handles.SelectedItems, 'string');
0192 
0193 % Push SelectedItems into Available Items and remove from Selected Items
0194 set(handles.AvailableItems,'String', vertcat(AvailableItems,SelectedItems))
0195 set(handles.SelectedItems, 'String', [])
0196 
0197 % Deselect Items in both boxes
0198 set(handles.AvailableItems, 'Value', [])
0199 set(handles.SelectedItems,  'Value', [])
0200 
0201 % Set the enable for the export button
0202 set_enable(handles,'noitemsselected')
0203 
0204 
0205 % --- Executes on button press in MoveUp.
0206 function MoveUp_Callback(hObject, eventdata, handles)
0207 % hObject    handle to MoveUp (see GCBO)
0208 % eventdata  reserved - to be defined in a future version of MATLAB
0209 % handles    structure with handles and user data (see GUIDATA)
0210 
0211 % See what's already in each listbox
0212 AvailableItems = get(handles.AvailableItems,'string');
0213 SelectedItems  = get(handles.SelectedItems, 'string');
0214 
0215 % See what's selected in the Selected Items listbox
0216 idx            = get(handles.SelectedItems,'value');
0217 SelectedStr    = SelectedItems(idx);
0218 NotSelectedStr = SelectedItems(~ismember(SelectedItems,SelectedStr));
0219 
0220 % Re-sort
0221 if idx > 1 % top item not selected
0222     top    = SelectedItems(1:idx-1);
0223     bot    = SelectedItems(idx+1:end);
0224     sorted = vertcat(top(1:end-1),SelectedStr,top(end),bot);
0225 
0226     % Move the list items
0227     set(handles.SelectedItems,'String',sorted)
0228     
0229     % Follow Selected
0230     set(handles.SelectedItems,'Value', idx-1)
0231 end
0232     
0233 
0234 % --- Executes on button press in MoveDown.
0235 function MoveDown_Callback(hObject, eventdata, handles)
0236 % hObject    handle to MoveDown (see GCBO)
0237 % eventdata  reserved - to be defined in a future version of MATLAB
0238 % handles    structure with handles and user data (see GUIDATA)
0239 
0240 % See what's already in each listbox
0241 AvailableItems = get(handles.AvailableItems,'string');
0242 SelectedItems  = get(handles.SelectedItems, 'string');
0243 
0244 % See what's selected in the Selected Items listbox
0245 idx            = get(handles.SelectedItems,'value');
0246 SelectedStr    = SelectedItems(idx);
0247 NotSelectedStr = SelectedItems(~ismember(SelectedItems,SelectedStr));
0248 
0249 % Re-sort
0250 if idx < length(SelectedItems) % last item not selected
0251     top    = SelectedItems(1:idx-1);
0252     bot    = SelectedItems(idx+1:end);
0253     sorted = vertcat(top,bot(1),SelectedStr,bot(2:end));
0254 
0255     % Move the list items
0256     set(handles.SelectedItems,'String',sorted)
0257     
0258     % Follow Selected
0259     set(handles.SelectedItems,'Value', idx+1)
0260 end
0261 
0262 
0263 % --- Executes on button press in SaveCSVFile.
0264 function SaveCSVFile_Callback(hObject, eventdata, handles)
0265 % hObject    handle to SaveCSVFile (see GCBO)
0266 % eventdata  reserved - to be defined in a future version of MATLAB
0267 % handles    structure with handles and user data (see GUIDATA)
0268 guiparams      = getappdata(handles.figure1,'guiparams');
0269 guiprefs       = guiparams.prefs;
0270 SelectedItems  = get(handles.SelectedItems, 'string');
0271 % msgbox(vertcat({'The following Item(s) are sellected:'},SelectedItems))
0272 
0273 % Check if there is a default output location in prefs, if not, initialize
0274 % one
0275 if ispref('VMT','csvexport')
0276     csvexport = getpref('VMT','csvexport');
0277     if exist(csvexport.path,'dir')
0278         guiprefs.csvexport_path = csvexport.path;
0279     else
0280         guiprefs.csvexport_path = pwd;
0281     end
0282     if exist(fullfile(csvexport.path,csvexport.file),'file')
0283         guiprefs.csvexport_file = csvexport.file;
0284     else
0285         guiprefs.csvexport_file = '';
0286     end
0287 else % Initialize csvexport
0288     guiprefs.csvexport_path = pwd;
0289     guiprefs.csvexport_file = '';
0290     
0291     csvexport.path = pwd;
0292     csvexport.file = '';
0293     setpref('VMT','csvexport',csvexport)
0294 end
0295 
0296 % If a single cross-section is loaded, then just create the output,
0297 % otherwise, process multiple before creating output.
0298 switch guiparams.gp_vmt.gui_state
0299     case 'fileloaded'
0300         % Find selected items within the list of available items
0301         Lia = ismember(...
0302             guiparams.available_variables_ascii(:,1),...
0303             SelectedItems);
0304         vars = guiparams.available_variables_ascii(Lia,2);
0305         
0306         % Build the output data (no header)
0307         outdata = [];
0308         maxr1 = size(guiparams.gp_vmt.V.mcsX,1);
0309         for i = 1:length(vars)
0310             if any(strfind(vars{i},'Roz')) % Use different logic to access Roz struct
0311                 Roz = regexp(vars{i},'\.','split');
0312                 [r,c] = size(guiparams.gp_vmt.V.Roz.(Roz{end}));
0313                 maxr2 = size(guiparams.gp_vmt.V.Roz.up,1);
0314                 if r == maxr1
0315                     outdata(:,i) = guiparams.gp_vmt.V.Roz.(Roz{end})(:);
0316                 else
0317                     outdata(:,i) = reshape(repmat(guiparams.gp_vmt.V.Roz.(Roz{end}),maxr2,1),maxr2*c,1);
0318                 end
0319             else
0320                 [r,c] = size(guiparams.gp_vmt.V.(vars{i}));
0321                 if r == maxr1
0322                     outdata(:,i) = guiparams.gp_vmt.V.(vars{i})(:);
0323                 else
0324                     outdata(:,i) = reshape(repmat(guiparams.gp_vmt.V.(vars{i}),maxr1,1),maxr1*c,1);
0325                 end
0326             end
0327         end
0328         
0329         % Header
0330         outheader = SelectedItems';
0331         
0332         % Change NaNs to -9999
0333         outdata(isnan(outdata)) = -9999;
0334               
0335         % Prompt user where to save the output file
0336         [the_file,the_path] = ...
0337             uiputfile({'*.csv','Comma Separated Values File (*.csv)'}, ...
0338             'Choose where to save the output CSV file', ...
0339             fullfile(guiprefs.csvexport_path,guiprefs.csvexport_file));
0340         
0341         if ischar(the_file) % User did not hit cancel
0342             % Write the file
0343             str1 = repmat('%s, ',1,i); str1 = str1(1:end-2);
0344             str2 = repmat('%f, ',1,i); str2 = str2(1:end-2);
0345             headformat = [str1 '\n'];
0346             dataformat = [str2 '\n'];
0347             fid = fopen(fullfile(the_path,the_file),'w');
0348             fprintf(fid,headformat,outheader{:});
0349             fprintf(fid,dataformat,outdata');
0350             fclose(fid);
0351             
0352             % Update preferences
0353             csvexport.path = the_path;
0354             csvexport.file = the_file;
0355             setpref('VMT','csvexport',csvexport)
0356         end
0357         
0358         
0359     case 'multiplematfiles'
0360         % Have to load each mat file, so give user feedback
0361         hwait = waitbar(0,'Processing multiple input files, please be patient...');
0362         
0363         % Find selected items within the list of available items
0364         Lia = ismember(...
0365             guiparams.available_variables_multi_mat(:,1),...
0366             SelectedItems);
0367         vars = guiparams.available_variables_multi_mat(Lia,2);
0368                 
0369         % Preallocation
0370         drng          = [guiparams.gp_vmt.depth_range_min guiparams.gp_vmt.depth_range_max];
0371         windowSize    = guiparams.gp_vmt.smoothing_window_size;
0372         QuiverSpacing = guiparams.gp_vmt.vector_spacing_plan_view;
0373         
0374         % Load and process each file, and retain selected variables
0375         % The output should be the same as what the quiver spacing
0376         % indicates
0377         zf = length(guiparams.gp_vmt.mat_file);
0378         for n = 1:zf
0379             waitbar(n/(zf+1),hwait)
0380             load(fullfile(guiparams.gp_vmt.mat_path,guiparams.gp_vmt.mat_file{n}))
0381             
0382             
0383             if ~isempty(drng)
0384                 indx = find(V.mcsDepth(:,1) < drng(1) | V.mcsDepth(:,1) > drng(2));
0385                 
0386                 %Set all data outside depth range to nan
0387                 V.mcsX(indx,:) = nan;
0388                 V.mcsY(indx,:) = nan;
0389                 V.mcsEast(indx,:) = nan;
0390                 V.mcsNorth(indx,:) = nan;
0391                 clear indx
0392             end
0393             
0394             %Compute mean positions
0395             V.mcsX1 = nanmean(V.mcsX,1);
0396             V.mcsY1 = nanmean(V.mcsY,1);
0397             
0398             %Compute the depth (or layer) averaged velocity (new method)
0399             V.mcsEast1  = VMT_LayerAveMean(V.mcsDepth,V.mcsEast);
0400             V.mcsNorth1 = VMT_LayerAveMean(V.mcsDepth,V.mcsNorth);
0401             
0402             %Smooth using a running mean defined by WindowSize (averages
0403             %'2*windowsize+1' ensembles together (centered on node (boxcar filter))
0404             if windowSize == 0
0405                 V.mcsX1sm     = V.mcsX1;
0406                 V.mcsY1sm     = V.mcsY1;
0407                 V.mcsEast1sm  = V.mcsEast1;
0408                 V.mcsNorth1sm = V.mcsNorth1;
0409             else
0410                 V.mcsEast1sm  = nanmoving_average(V.mcsEast1,windowSize);  %added 1-7-10, prj
0411                 V.mcsNorth1sm = nanmoving_average(V.mcsNorth1,windowSize);
0412                 V.mcsX1sm     = V.mcsX1;
0413                 V.mcsY1sm     = V.mcsY1;
0414             end
0415             
0416             % Screen for locations that don't have valid ensembles
0417             for zi = 1 : z
0418                 Mag(:,:,zi) = A(zi).Comp.mcsMag(:,:);
0419                 %Mag(:,:,zi) = A(zi).Clean.vMag(:,:);
0420             end
0421             numavg = nansum(~isnan(Mag),3);
0422             numavg(numavg==0) = NaN;
0423             enscnt = nanmean(numavg,1);
0424             [I,J] = ind2sub(size(enscnt),find(enscnt>=1));  %Changed to 1 from 2 (PRJ, 12-12-08)
0425             et = windowSize+J(1):QuiverSpacing:J(end);
0426             
0427             if n == 1
0428                 %table(1:493,1:7)=NaN;
0429                 lenp = 0;
0430             end
0431             
0432             % Dump output to aggregating table
0433             len = length(V.mcsX1sm(1,et));
0434             table(lenp+1:len+lenp,1)=V.mcsX1sm(1,et);
0435             table(lenp+1:len+lenp,2)=V.mcsY1sm(1,et);
0436             table(lenp+1:len+lenp,3)=V.mcsDist(1,et);
0437             table(lenp+1:len+lenp,4)=V.mcsBed(1,et);
0438             table(lenp+1:len+lenp,5)=V.mcsBedElev(1,et);
0439             table(lenp+1:len+lenp,6)=nanmean(V.mcsEast1sm(:,et),1);
0440             table(lenp+1:len+lenp,7)=nanmean(V.mcsNorth1sm(:,et),1);
0441             lenp = length(V.mcsX1sm(1,et))+lenp;
0442             
0443             clear A V z Mag numavg et enscnt I J   
0444         end
0445         
0446         % Compute velocity mag and dir
0447         table(:,8)=sqrt(table(:,6).^2+table(:,7).^2);
0448         table(:,9)=ari2geodeg(atan2(table(:,7),table(:,6))*180/pi);
0449                 
0450         % Header
0451         outheader = SelectedItems';
0452         i = length(outheader);
0453         
0454         % Retain only selected items in table, and change NaNs to -9999
0455         outdata = table(:,Lia);
0456         outdata(isnan(outdata)) = -9999;
0457         
0458         % Prompt user where to save the output file
0459         [the_file,the_path] = ...
0460             uiputfile({'*.csv','Comma Separated Values File (*.csv)'}, ...
0461             'Choose where to save the output CSV file', ...
0462             fullfile(guiprefs.csvexport_path,guiprefs.csvexport_file));
0463         
0464         if ischar(the_file) % User did not hit cancel
0465             % Write the file
0466             str1 = repmat('%s, ',1,i); str1 = str1(1:end-2);
0467             str2 = repmat('%f, ',1,i); str2 = str2(1:end-2);
0468             headformat = [str1 '\n'];
0469             dataformat = [str2 '\n'];
0470             fid = fopen(fullfile(the_path,the_file),'w');
0471             fprintf(fid,headformat,outheader{:});
0472             fprintf(fid,dataformat,outdata');
0473             fclose(fid);
0474             
0475             % Update preferences
0476             csvexport.path = the_path;
0477             csvexport.file = the_file;
0478             setpref('VMT','csvexport',csvexport)
0479         end
0480         
0481     otherwise
0482 end
0483 
0484 % Take care of waitbar if used
0485 if exist('hwait','var') && ishandle(hwait)
0486     waitbar(1,hwait)
0487     delete(hwait)
0488 end
0489 
0490 
0491 function [guiparams] = createGUIparams
0492 
0493 % Get the VMT current state for use by the sub-GUI
0494 % ------------------------------------------------
0495 hVMTgui                 = getappdata(0,'hVMTgui');
0496 guiparams_vmt           = getappdata(hVMTgui,'guiparams');
0497 guiprefs_vmt            = getappdata(hVMTgui,'guiprefs');
0498 guiparams.gp_vmt        = guiparams_vmt;
0499 guiparams.prefs         = guiprefs_vmt;
0500 
0501 % Lists of avalialible variables
0502 guiparams.available_variables  = {};
0503 guiparams.selected_variables   = {};
0504 guiparams.available_variables_ascii = {...
0505 ... Label                       Fieldname ...    
0506     'X'                         'mcsX';...
0507     'Y'                         'mcsY';...
0508     'Z'                         'mcsDepth';...
0509     'Distance'                  'mcsDist';...
0510     'Bed depth'                 'mcsBed';...
0511     'Bed elevation'             'mcsBedElev';...
0512     'East velocity'             'mcsEast';...
0513     'North velocity'            'mcsNorth';...
0514     'Up velocity'               'mcsVert';...
0515     'Velocity magnitude'        'mcsMag';...
0516     'Velocity direction'        'mcsDir';...
0517     'U velocity'                'u';...
0518     'V velocity'                'v';...
0519     'W velocity'                'w';...
0520     'Backscatter (smooth)'      'mcsBack';...
0521     'U (zsd) velocity'          'vp';...
0522     'V (zsd) velocity'          'vs';...
0523     'U (roz) velocity'          'Roz.up';...
0524     'V (roz) velocity'          'Roz.us';...
0525     'U (smoothed) vel'          'uSmooth';...
0526     'V (smoothed) vel'          'vSmooth';...
0527     'W (smoothed) vel'          'wSmooth';...
0528     'U (zsd,smoothed) vel'      'vpSmooth';...
0529     'V (zsd,smoothed) vel'      'vsSmooth';...
0530     'U (roz,smoothed) vel'      'Roz.upSmooth';...
0531     'V (roz,smoothed) vel'      'Roz.usSmooth';...
0532     'Backscatter (smooth)'      'mcsBackSmooth';...
0533     'Vel Direction (smooth)'    'mcsDirSmooth';...
0534     };
0535 guiparams.available_variables_single_mat = {...
0536 ... Label                       Fieldname ...    
0537     'X'                         'mcsX';...
0538     'Y'                         'mcsY';...
0539     'Z'                         'mcsDepth';...
0540     'Distance'                  'mcsDist';...
0541     'Bed depth'                 'mcsBed';...
0542     'Bed elevation'             'mcsBedElev';...
0543     'East velocity'             'mcsEast';...
0544     'North velocity'            'mcsNorth';...
0545     'Up velocity'               'mcsVert';...
0546     'Velocity magnitude'        'mcsMag';...
0547     'Velocity direction'        'mcsDir';...
0548     'U velocity'                'u';...
0549     'V velocity'                'v';...
0550     'W velocity'                'w';...
0551     'Backscatter (smooth)'      'mcsBack';...
0552     'U (zsd) velocity'          'vp';...
0553     'V (zsd) velocity'          'vs';...
0554     'U (roz) velocity'          'Roz.up';...
0555     'V (roz) velocity'          'Roz.us';...
0556     'U (smoothed) vel'          'uSmooth';...
0557     'V (smoothed) vel'          'vSmooth';...
0558     'W (smoothed) vel'          'wSmooth';...
0559     'U (zsd,smoothed) vel'      'vpSmooth';...
0560     'V (zsd,smoothed) vel'      'vsSmooth';...
0561     'U (roz,smoothed) vel'      'Roz.upSmooth';...
0562     'V (roz,smoothed) vel'      'Roz.usSmooth';...
0563     'Backscatter (smooth)'      'mcsBackSmooth';...
0564     'Vel Direction (smooth)'    'mcsDirSmooth';...
0565     };
0566 guiparams.available_variables_multi_mat = {...
0567 ... Label                       Fieldname ...    
0568     'X'                         'mcsX';...
0569     'Y'                         'mcsY';...
0570     ...'Z'                         'mcsDepth';...
0571     'Distance'                  'mcsDist';...
0572     'Bed depth'                 'mcsBed';...
0573     'Bed elevation'             'mcsBedElev';...
0574     'Layer-avg east vel'        'davE';...
0575     'Layer-avg north vel'       'davN';...
0576     'Velocity magnitude'        'Vmag';...
0577     'Velocity direction'        'Vdir';...
0578     };
0579 guiparams.available_variables_nodata  = {};
0580 
0581 
0582 % % Check if VMT has a processed file in memory. If not, display message
0583 % % asking user to process some data
0584 % if isempty(guiparams.gp_vmt.mat_file) && ~isempty(guiparams.gp_vmt.data_files) && ~isempty(guiparams.gp_vmt.V) % ASCII Loaded
0585 %     msgbox('ASCII Loaded')
0586 %     guiparams.state = 'ascii_loaded';
0587 %     %set_enable(handles,'ascii')
0588 % elseif ~isempty(guiparams.gp_vmt.mat_file)
0589 %     if ischar(guiparams.gp_vmt.mat_file) % Single MAT file loaded
0590 %         msgbox('Single MAT loaded')
0591 %         guiparams.state = 'single_mat_loaded';
0592 %         %set_enable(handles,'single-mat')
0593 %     elseif iscell(guiparams.gp_vmt.mat_file) % Multiple MAT files loaded
0594 %         msgbox('Multiple MAT files loaded')
0595 %         guiparams.state = 'multiple_mat_loaded';
0596 %         %set_enable(handles,'multi-mat')
0597 %     end
0598 % elseif isempty(guiparams.gp_vmt.V) % Nothing loaded, stop
0599 %     msgbox('Nothing loaded, aborting.')
0600 %     guiparams.state = 'nothing_loaded';
0601 %     %set_enable(handles,'nodata')
0602 % end
0603 
0604 
0605 % Grab the currently loaded variables and put them into the list
0606 
0607 % --------------------------------------------------------------------
0608 function initGUI(handles)
0609 % Initialize the UI controls in the GUI.
0610 
0611 guiparams = getappdata(handles.figure1,'guiparams');
0612 
0613 % Update the GUI:
0614 % ---------------
0615 switch guiparams.gp_vmt.gui_state
0616     case 'fileloaded'
0617         set_enable(handles,'ascii')
0618     case 'multiplematfiles'
0619         set_enable(handles,'multi-mat')
0620     case 'init'
0621         set_enable(handles,'nodata')
0622     otherwise
0623         set_enable(handles,'nodata')
0624 end
0625 % [EOF] initGUI
0626 
0627 
0628 % --------------------------------------------------------------------
0629 function set_enable(handles,enable_state)
0630 
0631 % Get the application data
0632 guiparams = getappdata(handles.figure1,'guiparams');
0633 
0634 % Preload variables to list in Available Items box
0635 switch enable_state
0636     case 'ascii'
0637         % See what's already in each listbox
0638         AvailableItems = get(handles.AvailableItems,'string');
0639         SelectedItems  = get(handles.SelectedItems, 'string');
0640         
0641         % Update items based on state
0642         set(handles.AvailableItems, 'string', guiparams.available_variables_ascii(:,1))
0643         set(handles.SelectedItems,  'string', {})
0644     case 'single-mat'
0645         % See what's already in each listbox
0646         AvailableItems = get(handles.AvailableItems,'string');
0647         SelectedItems  = get(handles.SelectedItems, 'string');
0648         
0649         % Update items based on state
0650         set(handles.AvailableItems, 'string', guiparams.available_variables_single_mat(:,1))
0651         set(handles.SelectedItems,  'string', {})
0652     case 'multi-mat'
0653         % See what's already in each listbox
0654         AvailableItems = get(handles.AvailableItems,'string');
0655         SelectedItems  = get(handles.SelectedItems, 'string');
0656         
0657         % Update items based on state
0658         set(handles.AvailableItems, 'string', guiparams.available_variables_multi_mat(:,1))
0659         set(handles.SelectedItems,  'string', {})
0660     case 'nodata'
0661         % See what's already in each listbox
0662         AvailableItems = get(handles.AvailableItems,'string');
0663         SelectedItems  = get(handles.SelectedItems, 'string');
0664         
0665         % Update items based on state
0666         set(handles.AvailableItems, 'string', guiparams.available_variables_nodata)
0667         set(handles.SelectedItems,  'string', {})
0668     case 'itemsareselected'
0669         set(handles.SaveCSVFile,'enable','on')
0670     case 'noitemsselected'
0671         set(handles.SaveCSVFile,'enable','off')
0672 end
0673 
0674 % Save the application data
0675 setappdata(handles.figure1,'guiparams',guiparams);

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