Ignore:
Timestamp:
Nov 29, 2010, 9:55:54 AM (14 years ago)
Author:
sommeria
Message:

bug repair in netcdf file reading, dealing with unavailable variables, + cleaning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/nc2struct_toolbox.m

    r56 r140  
    11%'nc2struct_toolbox': transform a netcdf file in a corresponding matlab structure, USE OLD NETCDF LIBRARY
     2% it reads all the global attributes and all variables, or a selected list.
     3% The corresponding dimensions and variable attributes are then extracted
    24%----------------------------------------------------------------------
    3 % function [Data,var_detect,ichoice]=nc2struct_toolbox(nc,ListField)
     5% function [Data,var_detect,ichoice]=nc2struct_toolbox(nc,varargin)
    46%
    57% OUTPUT:
    68%  Data: structure containing all the information of the netcdf file (or netcdf object)
    7 %           with fields:
    8 %    .ListGlobalAttribute: cell listing the names of the global attributes
    9 %        .Att_1,Att_2... : values of the global attributes
    10 %            .ListDimName: cell listing the names of the array dimensions
    11 %               .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
    12 %            .ListVarName: cell listing the names of the variables
    13 %            .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
    14 %            .VarDimName: cell containing a cell of dimension names (in list .ListDimName) for each variable of .ListVarName
    15 %           .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
    16 %        .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
    17 %  var_detect: vector with same length as ListVarName, with 1 for each detected variable and 0 else.
    18 %  ichoice: = line
    19 %
     9%           with (optional)fields:
     10%                    .ListGlobalAttribute: cell listing the names of the global attributes
     11%                    .Att_1,Att_2... : values of the global attributes
     12%                    .ListVarName: list of variable names to select (cell array of  char strings {'VarName1', 'VarName2',...} )
     13%                    .VarDimName: list of dimension names for each element of .ListVarName (cell array of string cells)                         
     14%                    .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
     15%                    .ListDimName=list of dimension (added information, not requested for field description)
     16%                    .DimValue= vlalues of dimensions (added information, not requested for field description)
     17%  var_detect: vector with same length as the cell array ListVarName, = 1 for each detected variable and 0 else.
     18%            var_detect=[] in the absence of input cell array
     19%  ichoice: index of the selected line in the case of multiple choice
     20%        (cell array of varible names with multiple lines) , =[] by default
    2021%INPUT:
    21 %     nc:      name of a netcdf file (char string) or netcdf object   
    22 % ListField: optional list of variable names to select (cell array of  char strings {'VarName1', 'VarName2',...} )
    23 %         if ListField is absent or ='*', ALL the attributes and variables are read.  %     
    24 %        if  ListField='ListGlobalAttribute', followed by the arguments 'name1', name2'..., only thes global attributes will be read (short option)
    25 %        if  ListField=[] or{}, no variables is read (only global attributes and lists of vdimensions, variables and attriburtes)
    26 %        if ListField is a cell array with n lines, the set of variables
    27 %                        will be sought by order of priority in the list, while output names will be set by the first line
     22%  nc:  name of a netcdf file (char string) or netcdf object   
     23%  additional arguments:
     24%       -no additional arguments: all the variables of the netcdf fiel are read.
     25%       -a cell array, ListVarName, made of  char strings {'VarName1', 'VarName2',...} )
     26%         if ListVarName=[] or {}, no variables is read (only global attributes)
     27%         if ListVarName is absent, or = '*', ALL the variables of the netcdf file are read.
     28%         if ListVarName is a cell array with n lines, the set of variables will be sought by order of priority
     29%                  in the list, while output names will be set by the first line
     30%        - the string 'ListGlobalAttribute' followed by a list of attribute  names: reads only these attributes (fast reading)
    2831%
    2932%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     
    203206        for idim=1:length(dim_name)% find the index of the current dimension in the list of dimensions
    204207            if isequal(dim_name{idim},var_dim_name)
    205                 Data.VarDimIndex{ivar}(ivardim)=idim;
     208                VarDimIndex{ivar}(ivardim)=idim;
    206209                used(idim)=1;
    207210                break
     
    240243end
    241244for ivar=1:length(var_read)
    242     Data.VarDimIndex{ivar}=(old2new(Data.VarDimIndex{ivar}));
    243     Data.VarDimName{ivar}=(Data.ListDimName(Data.VarDimIndex{ivar}));
     245    VarDimIndex{ivar}=(old2new(VarDimIndex{ivar}));
     246    Data.VarDimName{ivar}=(Data.ListDimName(VarDimIndex{ivar}));
    244247end
    245248%variable values
Note: See TracChangeset for help on using the changeset viewer.