Changeset 56 for trunk/src/nc2struct.m


Ignore:
Timestamp:
Mar 17, 2010, 1:30:15 PM (14 years ago)
Author:
sommeria
Message:

uvmat: edit vector button activated
debugging and cleaning after modifications made with the windows version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/nc2struct.m

    r55 r56  
    33% The corresponding dimensions and variable attributes are then extracted
    44%----------------------------------------------------------------------
    5 % function [Data,var_detect,ichoice]=nc2struct(nc,ListVarName)
     5% function [Data,var_detect,ichoice]=nc2struct(nc,varargin)
    66%
    77% OUTPUT:
     
    1919%INPUT:
    2020%     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)
    2325%         if ListVarName is absent, or = '*', ALL the variables are read.
    2426%        if ListVarName is a cell array with n lines, the set of variables
    2527%                        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)
    2629%
    2730%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     
    4245   
    4346function [Data,var_detect,ichoice]=nc2struct(nc,varargin)
    44 List=varargin;
     47
    4548if isempty(varargin)
    46     List{1}='*';
     49    varargin{1}='*';
    4750end
    48 % if ~exist('ListVarName','var')
    49 %     ListVarName='*';
    50 % end
    5151hhh=which('netcdf.open');% look for built-in matlab netcdf library
    5252
     
    6969    end
    7070    % 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)
    7373            try
    74             valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),List{ilist});
     74            valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),varargin{ilist});
    7575            catch
    7676                valuestr=[];
    7777            end
    78             eval(['Data.' List{ilist} '=valuestr;'])
     78            eval(['Data.' varargin{ilist} '=valuestr;'])
    7979        end
    8080        netcdf.close(nc)
     
    8383
    8484    % reading of variables, including attributes
    85     ListVarName=List{1}; 
     85    ListVarName=varargin{1}; 
    8686    [ndims,nvars,ngatts]=netcdf.inq(nc);%nbre of dimensions, variables, attributes
    8787   
Note: See TracChangeset for help on using the changeset viewer.