Changeset 527 for trunk/src/nc2struct.m


Ignore:
Timestamp:
Aug 20, 2012, 11:12:46 PM (12 years ago)
Author:
sommeria
Message:

various bugs corrected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/nc2struct.m

    r517 r527  
    9696   
    9797    %%  -------- read all global attributes (constants)-----------
    98     att_key={};%default
    99 %     iatt_g=0;
    10098    Data.ListGlobalAttribute={};%default
     99    att_key=cell(1,ngatts);%default
    101100    for iatt=1:ngatts
    102101        keystr= netcdf.inqAttName(nc,netcdf.getConstant('NC_GLOBAL'),iatt-1);
     
    117116        catch ME
    118117            att_key{iatt}=['attr_' num2str(iatt)];
    119             eval(['Data.' att_key{iatt} '=[];'])
     118            Data.(att_key{iatt})=[];
    120119        end
    121120    end
     
    123122
    124123    %%  -------- read dimension names-----------
    125     ListDimNameNetcdf={};
    126     dim_value=[];
     124    ListDimNameNetcdf=cell(1,ndims);
     125    dim_value=zeros(1,ndims);
    127126    for idim=1:ndims %loop on the dimensions of the netcdf file
    128127        [ListDimNameNetcdf{idim},dim_value(idim)] = netcdf.inqDim(nc,idim-1);%get name and value of each dimension
     
    133132 
    134133    %%  -------- read names of variables -----------
    135     ListVarNameNetcdf={}; %default
    136     dimids={};
    137     nbatt=[];
     134    ListVarNameNetcdf=cell(1,nvars); %default
     135    dimids=cell(1,nvars);
     136    nbatt=zeros(1,nvars);
    138137    for ncvar=1:nvars %loop on the variables of the netcdf file
    139138        %get name, type, dimensions and attribute numbers of each variable
     
    146145    else   %select input variables, if requested by the input ListVarName
    147146        ind_remove=[];
    148         for ivar=1:numel(ListVarName) % check redondancy
    149             if ~isempty(find(strcmp(ListVarName{ivar},ListVarName(1:ivar-1))))
    150                 ind_remove=[ind_remove ivar];
    151             end
    152         end
    153         if ~isempty(ind_remove)
    154             ListVarName(ind_remove)=[];
    155         end           
     147        check_keep=ones(1,size(ListVarName,2));
     148        for ivar=1:size(ListVarName,2) % check redondancy of variable names
     149            if ~isempty(find(strcmp(ListVarName{1,ivar},ListVarName(1:ivar-1)), 1))
     150                check_keep(ivar)=0;% the variable #ivar is already in the list
     151            end
     152        end
     153        ListVarName=ListVarName(:,logical(check_keep));         
    156154        sizvar=size(ListVarName);
    157155        testmulti=(sizvar(1)>1);%test for multiple choice of variable ranked by order of priority
Note: See TracChangeset for help on using the changeset viewer.