Changeset 56 for trunk/src/nc2struct.m
- Timestamp:
- Mar 17, 2010, 1:30:15 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/nc2struct.m
r55 r56 3 3 % The corresponding dimensions and variable attributes are then extracted 4 4 %---------------------------------------------------------------------- 5 % function [Data,var_detect,ichoice]=nc2struct(nc, ListVarName)5 % function [Data,var_detect,ichoice]=nc2struct(nc,varargin) 6 6 % 7 7 % OUTPUT: … … 19 19 %INPUT: 20 20 % nc: name of a netcdf file (char string) or netcdf object 21 % ListVarName: optional list of variable names to select (cell array of char strings {'VarName1', 'VarName2',...} ) 22 % if ListVarName=[] or {}, no variables is read (only global attributes and lists of dimensions, variables and attriburtes) 21 % additional arguments: 22 % -in the absence of other arguments, all the fields are read 23 % -a cell array, ListVarName, of char strings {'VarName1', 'VarName2',...} ) 24 % if ListVarName=[] or {}, no variables is read (only global attributes) 23 25 % if ListVarName is absent, or = '*', ALL the variables are read. 24 26 % if ListVarName is a cell array with n lines, the set of variables 25 27 % will be sought by order of priority in the list, while output names will be set by the first line 28 % - the string 'ListGlobalAttribute' followed by a list of attribute names: reads only these attributes (fast reading) 26 29 % 27 30 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA … … 42 45 43 46 function [Data,var_detect,ichoice]=nc2struct(nc,varargin) 44 List=varargin; 47 45 48 if isempty(varargin) 46 List{1}='*';49 varargin{1}='*'; 47 50 end 48 % if ~exist('ListVarName','var')49 % ListVarName='*';50 % end51 51 hhh=which('netcdf.open');% look for built-in matlab netcdf library 52 52 … … 69 69 end 70 70 % short reading of global attributes 71 if isequal( List{1},'ListGlobalAttribute')72 for ilist=2:numel( List)71 if isequal(varargin{1},'ListGlobalAttribute') 72 for ilist=2:numel(varargin) 73 73 try 74 valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'), List{ilist});74 valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist}); 75 75 catch 76 76 valuestr=[]; 77 77 end 78 eval(['Data.' List{ilist} '=valuestr;'])78 eval(['Data.' varargin{ilist} '=valuestr;']) 79 79 end 80 80 netcdf.close(nc) … … 83 83 84 84 % reading of variables, including attributes 85 ListVarName= List{1};85 ListVarName=varargin{1}; 86 86 [ndims,nvars,ngatts]=netcdf.inq(nc);%nbre of dimensions, variables, attributes 87 87
Note: See TracChangeset
for help on using the changeset viewer.