[1] | 1 | function theResult = uigetvar(self) |
---|
| 2 | |
---|
| 3 | % ncitem/uigetvar -- Get a NetCDF variable via dialog. |
---|
| 4 | % uigetvar(self) returns one variable from the NetCDF file |
---|
| 5 | % associated with self, an "ncitem" object, selected from |
---|
| 6 | % a list-dialog. The returned item is an "ncvar" object, |
---|
| 7 | % or the empty-matrix [] if no variable is selected. |
---|
| 8 | |
---|
| 9 | % Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. |
---|
| 10 | % All Rights Reserved. |
---|
| 11 | % Disclosure without explicit written consent from the |
---|
| 12 | % copyright owner does not constitute publication. |
---|
| 13 | |
---|
| 14 | % Version of 01-Dec-1997 13:20:58. |
---|
| 15 | |
---|
| 16 | if nargin < 1, help(mfilename), return, end |
---|
| 17 | |
---|
| 18 | result = []; |
---|
| 19 | |
---|
| 20 | theParent = parent(parent(self)); |
---|
| 21 | theFilename = name(theParent); |
---|
| 22 | f = find(theFilename == filesep); |
---|
| 23 | if any(f) |
---|
| 24 | theFilename(1:f(length(f))) = ''; |
---|
| 25 | end |
---|
| 26 | |
---|
| 27 | theVars = var(self); |
---|
| 28 | theVarnames = ncnames(theVars); |
---|
| 29 | if ~isempty(theVarnames) |
---|
| 30 | thePrompt = {'Select Variable From', 'NetCDF File', ['"' theFilename '"']}; |
---|
| 31 | theSelection = listdlg('ListString', theVarnames, ... |
---|
| 32 | 'SelectionMode', 'single', ... |
---|
| 33 | 'PromptString', thePrompt); |
---|
| 34 | if any(theSelection) |
---|
| 35 | result = theVars{theSelection}; |
---|
| 36 | end |
---|
| 37 | else |
---|
| 38 | disp(' ## No variables available.') |
---|
| 39 | end |
---|
| 40 | |
---|
| 41 | if nargout > 0 |
---|
| 42 | theResult = result; |
---|
| 43 | else |
---|
| 44 | ncans(result) |
---|
| 45 | end |
---|