Changeset 404 for trunk/src/check_field_structure.m
- Timestamp:
- Apr 30, 2012, 6:46:45 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/check_field_structure.m
r385 r404 4 4 % 5 5 % 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) 13 7 % errormsg: error message which is not empty when the input structure does not have the right form 14 8 % … … 22 16 23 17 24 function [ DataOut,errormsg]=check_field_structure(Data)18 function [errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(Data) 25 19 DataOut=[]; %default 26 20 errormsg=[]; … … 45 39 return 46 40 end 47 if isfield(Data,'DimValue')48 Data=rmfield(Data,'DimValue');49 end41 % if isfield(Data,'DimValue') 42 % Data=rmfield(Data,'DimValue'); 43 % end 50 44 nbdim=0; 51 Data.ListDimName={};45 ListDimName={}; 52 46 53 47 %% main loop on the list of variables … … 103 97 for idim=1:numel(DimCell) %loop on the coordinates of variable #ivar 104 98 DimName=DimCell{idim}; 105 iprev=find(strcmp(DimName, Data.ListDimName),1);%look for dimension name DimName in the current list99 iprev=find(strcmp(DimName,ListDimName),1);%look for dimension name DimName in the current list 106 100 if isempty(iprev)% append the dimension name to the current list 107 101 nbdim=nbdim+1; … … 110 104 RangeTest(nbdim)=1; %to be updated for a later variable 111 105 end 112 D ata.DimValue(nbdim)=sizvar(idim);113 Data.ListDimName{nbdim}=DimName;106 DimValue(nbdim)=sizvar(idim); 107 ListDimName{nbdim}=DimName; 114 108 DimIndex=[DimIndex nbdim]; 115 109 else % DimName is detected in the current list of dimension names 116 if ~isequal(D ata.DimValue(iprev),sizvar(idim))117 if isequal(D ata.DimValue(iprev),2)&& RangeTest(iprev) % the dimension has been already detected as a range [min max]118 D ata.DimValue(iprev)=sizvar(idim); %update with actual value110 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 119 113 elseif ~testrange 120 114 errormsg=['dimension declaration inconsistent with the size =[' num2str(sizvar) '] for ' VarName]; … … 125 119 end 126 120 end 127 Data.VarDimIndex{ivar}=DimIndex;121 VarDimIndex{ivar}=DimIndex; 128 122 end 129 123 DataOut=Data;
Note: See TracChangeset
for help on using the changeset viewer.