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

improvement of calc-field and combination of two fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/find_field_cells.m

    r514 r515  
    1919%      .scalar: scalar field (default)
    2020%      .coord: vector of indices of coordinate variables corresponding to matrix dimensions
     21%
     22%      .FieldRequest= 'interp', 'derivatives' indicate whether interpolation  or derivatives (tps) is needed to calculate the requested field
     23%      .FieldNames = cell of fields to calculate from the fied cell
     24%
    2125% errormsg: error message
    2226%   
     
    4953%     GNU General Public License (file UVMAT/COPYING.txt) for more details.for input in proj_field and plot_field
    5054%    group the variables  into 'fields' with common dimensions
    51 %------------------------------------------------------------------------
    52 % function  [CellVarIndex,NbDim,CellVarType,errormsg]=find_field_cells(Data)
    53 %
    54 % OUTPUT:
    55 % CellVaxIndex: cell whose elements are arrays of indices in the list data.ListVarName 
    56 %              CellvarIndex{i} represents a set of variables with the same dimensions
    57 % NbDim: array with the length of CellVarIndex, giving its  space dimension
    58 % CellVarType: cell array of structures with fields
    59 %      .coord_x, y, z: indices (in .ListVarname) of variables representing  unstructured coordinates x, y, z
    60 %      .vector_x,_y,_z: indices of variables giving the vector components x, y, z
    61 %      .warnflag: index of warnflag
    62 %      .errorflag: index of error flag
    63 %      .ancillary: indices of ancillary variables
    64 %      .image   : B/W image, (behaves like scalar)
    65 %      .color : color image, the last index, which is not a coordinate variable, represent the 3 color components rgb
    66 %      .discrete: like scalar, but set of data points without continuity, represented as dots in a usual plot, instead of continuous lines otherwise
    67 %      .scalar: scalar field (default)
    68 %      .coord: vector of indices of coordinate variables corresponding to matrix dimensions
    69 % errormsg: error message
    70 %   
    71 % INPUT:
    72 % Data: structure representing fields, output of check_field_structure
    73 %            .ListVarName: cell array listing the names (cahr strings) of the variables
    74 %            .VarDimName: cell array of cells containing the set of dimension names for each variable of .ListVarName
    75 %            .VarAttribute: cell array of structures containing the variable attributes:
    76 %                     .VarAttribute{ilist}.key=value, where ilist is the variable
    77 %                     index, key is the name of the attribute, value its value (char string or number)
    78 %
    79 % HELP:
    80 % to get the dimensions of arrays common to the field #icell
    81 %         VarIndex=CellVarIndex{icell}; % list of variable indices
    82 %         DimIndex=Data.VarDimIndex{VarIndex(1)} % list of dimensions for each variable in the cell #icell
    83 %
    84 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    85 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    86 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    87 %     This file is part of the toolbox UVMAT.
    88 %
    89 %     UVMAT is free software; you can redistribute it and/or modify
    90 %     it under the terms of the GNU General Public License as published by
    91 %     the Free Software Foundation; either version 2 of the License, or
    92 %     (at your option) any later version.
    93 %
    94 %     UVMAT is distributed in the hope that it will be useful,
    95 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    96 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    97 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    98 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    9955
    10056function [CellVarIndex,NbDim,CellVarType,errormsg]=find_field_cells(Data)
    10157CellVarIndex={};
    10258
    103 NbDim=[];
    10459CellVarType=[];
    10560errormsg=[];
     
    10863
    10964NbDim=[];
    110 ivardim=0;
    11165VarDimIndex=[];
    11266VarDimName={};
     
    11670end
    11771
    118 %% role of variables
     72%% role of variables and list of requested operations
    11973Role=num2cell(blanks(nbvar));%initialize a cell array of nbvar blanks
     74FieldRequest=regexprep(Role,' ',''); % fieldRequest set to '' by default
     75Operation=cell(size(Role)); % fieldRequest set to {} by default
     76CheckSub=zeros(size(Role));% =1 for fields to substract
    12077Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default
    12178if isfield(Data,'VarAttribute')
     
    12481            Role{ivar}=Data.VarAttribute{ivar}.Role;
    12582        end
     83        if isfield(Data.VarAttribute{ivar},'FieldRequest')
     84            FieldRequest{ivar}=Data.VarAttribute{ivar}.FieldRequest;
     85        end
     86        if isfield(Data.VarAttribute{ivar},'Operation')
     87            Operation{ivar}=Data.VarAttribute{ivar}.Operation;
     88        end
     89        if isfield(Data.VarAttribute{ivar},'CheckSub')
     90            CheckSub(ivar)=Data.VarAttribute{ivar}.CheckSub;
     91        end
    12692    end
    12793end
    12894
    12995%% loop on the list of variables, group them by common dimensions
     96CellVarType=cell(1,length(CellVarIndex));
    13097for ivar=1:nbvar
    13198    if ischar(Data.VarDimName{ivar})
     
    146113        icell=icell+1;
    147114        CellVarIndex{icell}=ivar;%put the current variable index in the new cell
    148         NbDim(icell)=numel(DimCell);%default
    149     end
    150    
    151     %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
     115        NbDim(icell)=numel(DimCell);%default   
     116        CellVarType{icell}=[];
     117    end
     118    if ~isempty(FieldRequest{ivar})
     119       CellVarType{icell}.FieldRequest=FieldRequest{ivar};
     120    end
     121    if ~isempty(Operation{ivar})
     122       CellVarType{icell}.Operation=Operation{ivar};
     123    end
     124    if CheckSub(ivar)
     125    CellVarType{icell}.CheckSub=1;
     126    end
    159127end
    160128
     
    163131ind_dim_var_cell=find(checksinglecell);
    164132%CoordType(ind_dim_var_cell)='dim_var';% to be used in output
     133%VarDimIndex=cell(size(ind_dim_var_cell));
     134VarDimName=cell(size(ind_dim_var_cell));
    165135for icoord=1:numel(ind_dim_var_cell)
    166 VarDimIndex(icoord)=CellVarIndex{ind_dim_var_cell(icoord)};
    167 VarDimName{icoord}=Data.VarDimName{VarDimIndex(icoord)}{1};
     136    VarDimIndex(icoord)=CellVarIndex{ind_dim_var_cell(icoord)};
     137    VarDimName{icoord}=Data.VarDimName{VarDimIndex(icoord)}{1};
    168138end
    169139
     
    201171
    202172index_remove=[];
    203 CellVarType=cell(1,length(CellVarIndex));
    204173for icell=1:length(CellVarIndex)
    205174    if checksinglecell(icell)
     
    262231                    coord(idim)=VarDimIndex(ind_coord);
    263232                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
    270233            end
    271234            NbDim(icell)=numel(find(coord));
Note: See TracChangeset for help on using the changeset viewer.