Ignore:
Timestamp:
Jul 25, 2012, 1:41:52 AM (9 years ago)
Author:
sommeria
Message:

various improvements: read input parameters for civ. Order of panels rationalised.
rationalisation in find_field_indices
simplification of default PARAM.xml, suppress unneeded information.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_field_indices.m

    r494 r501  
    117117
    118118%% role of variables
    119 Role=mat2cell(blanks(nbvar),1,ones(1,nbvar));%initialize a cell array of nbvar blanks
     119Role=num2cell(blanks(nbvar));%initialize a cell array of nbvar blanks
    120120Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default
    121121if isfield(Data,'VarAttribute')
     
    129129%% loop on the list of variables, group them by common dimensions
    130130for ivar=1:nbvar
     131    if ischar(Data.VarDimName{ivar})
     132        Data.VarDimName{ivar}=Data.VarDimName(ivar);%transform char chain into cell
     133    end
    131134    DimCell=Data.VarDimName{ivar}; %dimensions associated with the variable #ivar
    132     if ischar(DimCell)
    133         DimCell={DimCell};
    134         Data.VarDimName{ivar}={Data.VarDimName{ivar}};%transform char chain into cell
    135     end
    136135    testnewcell=1;
    137136    for icell_prev=1:numel(CellVarIndex)%detect whether the dimensions of ivar fit with an existing cell
    138137        PrevVarIndex=CellVarIndex{icell_prev};%list of variable indices in cell # icell_prev
    139         PrevDimName=Data.VarDimName{PrevVarIndex(1)};%list of corresponding variable names
    140         if isequal(PrevDimName,DimCell)
     138        PrevDimCell=Data.VarDimName{PrevVarIndex(1)};%list of corresponding variable names
     139        if isequal(PrevDimCell,DimCell)
    141140            CellVarIndex{icell_prev}=[CellVarIndex{icell_prev} ivar];% add variable index #ivar to the cell #icell_prev
    142141            testnewcell=0; %existing cell detected
     
    146145    if testnewcell
    147146        icell=icell+1;
    148         CellVarIndex{icell}=ivar;%put the current variabl index in the new cell
     147        CellVarIndex{icell}=ivar;%put the current variable index in the new cell
     148        NbDim(icell)=numel(DimCell);%default
    149149    end
    150150   
    151151    %look for dimension variables
    152     if numel(DimCell)==1% if the variable has a single dimension
    153         if strcmp(DimCell{1},Data.ListVarName{ivar}) || strcmp(Role{ivar},'dimvar')
    154             ivardim=ivardim+1;
    155             VarDimIndex(ivardim)=ivar;%index of the variable
    156             VarDimName{ivardim}=DimCell{1};%name of the dimension
    157         end
    158     end
     152%     if numel(DimCell)==1% if the variable has a single dimension
     153%         if strcmp(DimCell{1},Data.ListVarName{ivar}) %|| strcmp(Role{ivar},'dimvar')
     154%             ivardim=ivardim+1;
     155%             VarDimIndex(ivardim)=ivar;%index of the variable
     156%             VarDimName{ivardim}=DimCell{1};%name of the dimension
     157%         end
     158%     end
     159end
     160
     161%% find dimension variables
     162checksinglecell=cellfun(@numel,CellVarIndex)==1 & NbDim==1;% find isolated cells with a single dimension
     163ind_dim_var_cell=find(checksinglecell);
     164%CoordType(ind_dim_var_cell)='dim_var';% to be used in output
     165for icoord=1:numel(ind_dim_var_cell)
     166VarDimIndex(icoord)=CellVarIndex{ind_dim_var_cell(icoord)};
     167VarDimName{icoord}=Data.VarDimName{VarDimIndex(icoord)}{1};
    159168end
    160169
     
    162171ListRole={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','vector_x_tps','vector_y_tps','warnflag','errorflag',...
    163172    'ancillary','image','color','discrete','scalar','coord_tps'};% rmq vector_x_tps and vector_y_tps to be replaced by vector_x and vector_y
    164 NbDim=zeros(size(CellVarIndex));%default
     173% NbDim=zeros(size(CellVarIndex));%default
    165174
    166175for ilist=1:numel(ListRole)
     
    171180    VarType.subrange_tps=[];
    172181    VarType.nbsites_tps=[];
     182    select=zeros(1,numel(VarType.coord_tps));
    173183    for ifield=1:numel(VarType.coord_tps)
    174         select(ifield)=0;
    175184        DimCell=Data.VarDimName{VarType.coord_tps(ifield)};
    176185        if numel(DimCell)==3
     
    194203CellVarType=cell(1,length(CellVarIndex));
    195204for icell=1:length(CellVarIndex)
     205    if checksinglecell(icell)
     206        continue
     207    end
    196208    VarIndex=CellVarIndex{icell};%set of variable indices with the same dim
    197209    check_remove=0;
     
    212224            return
    213225        end
     226        % case of x cordinate marked as a dimension variable (var name=dimension name)
     227        if isempty(CellVarType{icell}.coord_x)
     228            var_dim_index=find(strcmp(DimCell{1},Data.ListVarName(VarIndex)));
     229            if ~isempty(var_dim_index)
     230                CellVarType{icell}.coord_x=VarIndex(var_dim_index);
     231            end
     232        end         
    214233        if numel(CellVarType{icell}.errorflag)>1
    215234            errormsg='multiply defined error flag in the same cell';
     
    239258        if  ~test_coord && ~isempty(VarDimName)
    240259            for idim=1:numel(DimCell)   %loop on the dimensions of the variables in cell #icell
    241                 for ivardim=1:numel(VarDimName)
    242                     if strcmp(VarDimName{ivardim},DimCell{idim})
    243                         coord(idim)=VarDimIndex(ivardim);
    244                         break
    245                     end
     260                ind_coord=find(strcmp(DimCell{idim},VarDimName));
     261                if ~isempty(ind_coord)
     262                    coord(idim)=VarDimIndex(ind_coord);
    246263                end
     264%                 for ivardim=1:numel(VarDimName)
     265%                     if strcmp(VarDimName{ivardim},DimCell{idim})
     266%                         coord(idim)=VarDimIndex(ivardim);
     267%                         break
     268%                     end
     269%                 end
    247270            end
    248271            NbDim(icell)=numel(find(coord));
Note: See TracChangeset for help on using the changeset viewer.