Ignore:
Timestamp:
Apr 30, 2012, 6:46:45 PM (12 years ago)
Author:
sommeria
Message:

various bugs corrected. nc2struct_toolbox suppressed (correspond to obsolete versions of Matlab)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/check_field_structure.m

    r385 r404  
    44%
    55% OUTPUT:
    6 % DataOut: structure reproducing the input structure Data, with the additional elements:
    7 %           with fields:
    8 %
    9 %            .ListDimName: cell listing the names of the array dimensions
    10 %             .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
    11 %            .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
    12 %            .VarDimName: cell containing a cell of dimension names (in list .ListDimName) for each variable of .ListVarName
     6% DataOut: structure reproducing the input structure Data (TODO: suppress this output)
    137% errormsg: error message which is not empty when the input structure does not have the right form
    148%
     
    2216
    2317
    24 function [DataOut,errormsg]=check_field_structure(Data)
     18function [errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(Data)
    2519DataOut=[]; %default
    2620errormsg=[];
     
    4539    return
    4640end
    47 if isfield(Data,'DimValue')
    48     Data=rmfield(Data,'DimValue');
    49 end
     41% if isfield(Data,'DimValue')
     42%     Data=rmfield(Data,'DimValue');
     43% end
    5044nbdim=0;
    51 Data.ListDimName={};
     45ListDimName={};
    5246
    5347%% main loop on the list of variables
     
    10397    for idim=1:numel(DimCell) %loop on the coordinates of variable #ivar
    10498        DimName=DimCell{idim};
    105         iprev=find(strcmp(DimName,Data.ListDimName),1);%look for dimension name DimName in the current list
     99        iprev=find(strcmp(DimName,ListDimName),1);%look for dimension name DimName in the current list
    106100        if isempty(iprev)% append the dimension name to the current list
    107101            nbdim=nbdim+1;
     
    110104                RangeTest(nbdim)=1; %to be updated for a later variable 
    111105            end
    112             Data.DimValue(nbdim)=sizvar(idim);
    113             Data.ListDimName{nbdim}=DimName;
     106            DimValue(nbdim)=sizvar(idim);
     107            ListDimName{nbdim}=DimName;
    114108            DimIndex=[DimIndex nbdim];
    115109        else % DimName is detected in the current list of dimension names
    116             if ~isequal(Data.DimValue(iprev),sizvar(idim))
    117                 if isequal(Data.DimValue(iprev),2)&& RangeTest(iprev)  % the dimension has been already detected as a range [min max]
    118                     Data.DimValue(iprev)=sizvar(idim); %update with actual value
     110            if ~isequal(DimValue(iprev),sizvar(idim))
     111                if isequal(DimValue(iprev),2)&& RangeTest(iprev)  % the dimension has been already detected as a range [min max]
     112                    DimValue(iprev)=sizvar(idim); %update with actual value
    119113                elseif ~testrange               
    120114                    errormsg=['dimension declaration inconsistent with the size =[' num2str(sizvar) '] for ' VarName];
     
    125119        end
    126120    end
    127     Data.VarDimIndex{ivar}=DimIndex;
     121    VarDimIndex{ivar}=DimIndex;
    128122end
    129123DataOut=Data;
Note: See TracChangeset for help on using the changeset viewer.