[581] | 1 | %'find_field_cells': analyse the field structure for input in uvmat functions, grouping the variables into 'fields' with common coordinates |
---|
[514] | 2 | %------------------------------------------------------------------------ |
---|
[530] | 3 | % function [CellInfo,NbDim,errormsg]=find_field_cells(Data) |
---|
[514] | 4 | % |
---|
| 5 | % OUTPUT: |
---|
[530] | 6 | % CellInfo: cell of structures describing field cells |
---|
| 7 | % .CoordType: type of coordinates for each field cell = 'scattered','grid','tps'; |
---|
| 8 | % .CoordIndex: array of the indices of the variables representing the coordinates (in the order z,y,x) |
---|
| 9 | % .CoordSize: array of the nbre of values for each coordinate in a grid, nbre of points in the unstructured case |
---|
[581] | 10 | % .NbCentres_tps: |
---|
[530] | 11 | % .SubRange_tps |
---|
| 12 | % .VarIndex: arrays of the variable indices in the field cell |
---|
| 13 | % .VarIndex_ancillary: indices of ancillary variables |
---|
| 14 | % _color : color image, the last index, which is not a coordinate variable, represent the 3 color components rgb |
---|
| 15 | % _discrete: like scalar, but set of data points without continuity, represented as dots in a usual plot, instead of continuous lines otherwise |
---|
| 16 | % _errorflag: index of error flag |
---|
| 17 | % _image : B/W image, (behaves like scalar) |
---|
| 18 | % _vector_x,_y,_z: indices of variables giving the vector components x, y, z |
---|
| 19 | % _warnflag: index of warnflag |
---|
[1045] | 20 | % .DimIndex |
---|
[581] | 21 | % .ProjModeRequest= 'interp_lin', 'interp_tps' indicate whether lin interpolation or derivatives (tps) is needed to calculate the requested field |
---|
[576] | 22 | % .FieldName = operation to be performed to finalise the field cell after projection |
---|
[530] | 23 | % .SubCheck=0 /1 indicate that the field must be substracted (second entry in uvmat) |
---|
| 24 | % NbDim: array with the length of CellVarIndex, giving the space dimension of each field cell |
---|
[514] | 25 | % errormsg: error message |
---|
| 26 | % |
---|
| 27 | % INPUT: |
---|
| 28 | % Data: structure representing fields, output of check_field_structure |
---|
[575] | 29 | % .ListGlobalAttributes |
---|
[514] | 30 | % .ListVarName: cell array listing the names (cahr strings) of the variables |
---|
| 31 | % .VarDimName: cell array of cells containing the set of dimension names for each variable of .ListVarName |
---|
| 32 | % .VarAttribute: cell array of structures containing the variable attributes: |
---|
| 33 | % .VarAttribute{ilist}.key=value, where ilist is the variable |
---|
| 34 | % index, key is the name of the attribute, value its value (char string or number) |
---|
[575] | 35 | % .Attr1, .Attr2.... |
---|
| 36 | % case of actual data: |
---|
| 37 | % .Var1, .Var2... |
---|
| 38 | % case of data structure, without the data themselves |
---|
| 39 | % .LisDimName: list of dimension names |
---|
| 40 | % .DimValue: list of corresponding dimension values |
---|
[514] | 41 | % HELP: |
---|
| 42 | % to get the dimensions of arrays common to the field #icell |
---|
| 43 | % VarIndex=CellVarIndex{icell}; % list of variable indices |
---|
| 44 | % DimIndex=Data.VarDimIndex{VarIndex(1)} % list of dimensions for each variable in the cell #icell |
---|
[809] | 45 | |
---|
| 46 | %======================================================================= |
---|
[1027] | 47 | % Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[809] | 48 | % http://www.legi.grenoble-inp.fr |
---|
| 49 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
[514] | 50 | % |
---|
| 51 | % This file is part of the toolbox UVMAT. |
---|
[809] | 52 | % |
---|
[514] | 53 | % UVMAT is free software; you can redistribute it and/or modify |
---|
[809] | 54 | % it under the terms of the GNU General Public License as published |
---|
| 55 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 56 | % or (at your option) any later version. |
---|
| 57 | % |
---|
[514] | 58 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 59 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 60 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[809] | 61 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 62 | %======================================================================= |
---|
| 63 | |
---|
[514] | 64 | % group the variables into 'fields' with common dimensions |
---|
| 65 | |
---|
[530] | 66 | function [CellInfo,NbDim,errormsg]=find_field_cells(Data) |
---|
[1045] | 67 | CellInfo={};%default output |
---|
[530] | 68 | NbDim=0; |
---|
[535] | 69 | errormsg=''; |
---|
[530] | 70 | if ~isfield(Data,'ListVarName'), errormsg='the list of variables .ListVarName is missing';return;end |
---|
| 71 | if ~isfield(Data,'VarDimName'), errormsg='the list of dimensions .VarDimName is missing';return;end |
---|
[581] | 72 | nbvar=numel(Data.ListVarName);%number of variables in the field structure |
---|
[530] | 73 | if ~isequal(numel(Data.VarDimName),nbvar), errormsg='.ListVarName and .VarDimName have unequal length';return;end |
---|
[535] | 74 | % check the existence of variable data |
---|
| 75 | check_var=1; |
---|
| 76 | for ilist=1:numel(Data.ListVarName) |
---|
| 77 | if ~isfield(Data,Data.ListVarName{ilist}) |
---|
[1009] | 78 | check_var=0;% dimensions of array defined, but the corresponding array is not given |
---|
[535] | 79 | break |
---|
[530] | 80 | end |
---|
| 81 | end |
---|
[514] | 82 | |
---|
[515] | 83 | %% role of variables and list of requested operations |
---|
[530] | 84 | %ListRole={'coord_x','coord_y','coord_z','vector_x','vector_y','vector_z','vector_x_tps','vector_y_tps','warnflag','errorflag',... |
---|
| 85 | % 'ancillary','image','color','discrete','scalar','coord_tps'};% rmq vector_x_tps and vector_y_tps to be replaced by vector_x and vector_y |
---|
[514] | 86 | Role=num2cell(blanks(nbvar));%initialize a cell array of nbvar blanks |
---|
[581] | 87 | ProjModeRequest=regexprep(Role,' ',''); % fieldRequest set to '' by default |
---|
[576] | 88 | FieldName=cell(size(Role)); % fieldRequest set to {} by default |
---|
[515] | 89 | CheckSub=zeros(size(Role));% =1 for fields to substract |
---|
[1045] | 90 | %Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default |
---|
[514] | 91 | if isfield(Data,'VarAttribute') |
---|
| 92 | for ivar=1:numel(Data.VarAttribute) |
---|
| 93 | if isfield(Data.VarAttribute{ivar},'Role') |
---|
| 94 | Role{ivar}=Data.VarAttribute{ivar}.Role; |
---|
| 95 | end |
---|
[581] | 96 | if isfield(Data.VarAttribute{ivar},'ProjModeRequest') |
---|
| 97 | ProjModeRequest{ivar}=Data.VarAttribute{ivar}.ProjModeRequest; |
---|
[515] | 98 | end |
---|
[576] | 99 | if isfield(Data.VarAttribute{ivar},'FieldName') |
---|
| 100 | FieldName{ivar}=Data.VarAttribute{ivar}.FieldName; |
---|
[515] | 101 | end |
---|
| 102 | if isfield(Data.VarAttribute{ivar},'CheckSub') |
---|
| 103 | CheckSub(ivar)=Data.VarAttribute{ivar}.CheckSub; |
---|
| 104 | end |
---|
[514] | 105 | end |
---|
| 106 | end |
---|
| 107 | |
---|
[1045] | 108 | %% detect fields with different roles |
---|
| 109 | ind_scalar=find(strcmp('scalar',Role)); |
---|
| 110 | ind_errorflag=find(strcmp('errorflag',Role)); |
---|
| 111 | ind_image=find(strcmp('image',Role)); |
---|
| 112 | ind_vector_x=[find(strcmp('vector_x',Role)) find(strcmp('vector_x_tps',Role))]; |
---|
| 113 | if ~isempty(ind_vector_x) |
---|
| 114 | ind_vector_y=[find(strcmp('vector_y',Role)) find(strcmp('vector_y_tps',Role))]; |
---|
| 115 | ind_vector_z=find(strcmp('vector_z',Role)); |
---|
| 116 | ind_warnflag=find(strcmp('warnflag',Role)); |
---|
| 117 | ind_ancillary=find(strcmp('ancillary',Role)); |
---|
| 118 | end |
---|
| 119 | ind_discrete=find(strcmp('discrete',Role)); |
---|
| 120 | ind_coord_x=find(strcmp('coord_x',Role)); |
---|
| 121 | ind_coord_y=find(strcmp('coord_y',Role)); |
---|
| 122 | ind_coord_z=find(strcmp('coord_z',Role)); |
---|
| 123 | ind_coord_tps=find(strcmp('coord_tps',Role)); |
---|
| 124 | check_string=cellfun(@ischar,Data.VarDimName)==1; |
---|
| 125 | index_string=find(check_string); |
---|
| 126 | for ivar=index_string |
---|
| 127 | Data.VarDimName{ivar}={Data.VarDimName{ivar}};%transform char strings into cells |
---|
| 128 | end |
---|
| 129 | check_coord_names= cellfun(@numel,Data.VarDimName)==1; |
---|
| 130 | check_coord_raster=false(size(check_coord_names));% check variables describing regular mesh (raster coordinates), from two values, min and max. |
---|
| 131 | if check_var |
---|
| 132 | for ivar=find(check_coord_names) |
---|
| 133 | if numel(Data.(Data.ListVarName{ivar}))==2 |
---|
| 134 | check_coord_raster(ivar)=true; |
---|
[530] | 135 | end |
---|
[514] | 136 | end |
---|
[1045] | 137 | else |
---|
| 138 | for ivar=find(check_coord_names) |
---|
| 139 | DimIndex=find(strcmp(Data.VarDimName{ivar},Data.ListDimName)); |
---|
| 140 | if Data.DimValue(DimIndex)==2 |
---|
| 141 | check_coord_raster(ivar)=true; |
---|
[514] | 142 | end |
---|
| 143 | end |
---|
[530] | 144 | end |
---|
| 145 | |
---|
[581] | 146 | |
---|
[1045] | 147 | %% initate cells around each scalar field |
---|
| 148 | index_remove=[]; |
---|
| 149 | cell_nbre=numel(ind_scalar)+numel(ind_vector_x); |
---|
| 150 | flag_remove=false(1,cell_nbre); |
---|
| 151 | NbDim=zeros(1,cell_nbre); |
---|
| 152 | index_coord_x=zeros(size(ind_coord_x)); |
---|
| 153 | for icell=1:numel(ind_scalar) |
---|
| 154 | CellInfo{icell}.VarType='scalar'; |
---|
| 155 | CellInfo{icell}.VarIndex_scalar=ind_scalar(icell); |
---|
| 156 | CellInfo{icell}.VarIndex=ind_scalar(icell); |
---|
| 157 | DimCell_var=Data.VarDimName{ind_scalar(icell)};% cell of dimension names for ivar_coord_x(icell) |
---|
| 158 | %look for errorflag |
---|
| 159 | for ivar=ind_errorflag |
---|
| 160 | DimCell=Data.VarDimName{ivar}; |
---|
| 161 | if isequal(DimCell,DimCell_var) |
---|
| 162 | CellInfo{icell}.VarIndex(2)=ivar; |
---|
| 163 | CellInfo{icell}.VarIndex_errorflag=ivar; |
---|
| 164 | break |
---|
[530] | 165 | end |
---|
[514] | 166 | end |
---|
| 167 | end |
---|
| 168 | |
---|
[1045] | 169 | %% initate cells around each vector field |
---|
| 170 | for icell=numel(ind_scalar)+1:cell_nbre |
---|
| 171 | CellInfo{icell}.VarType='vector'; |
---|
| 172 | CellInfo{icell}.VarIndex(1)=ind_vector_x(icell-numel(ind_scalar)); |
---|
| 173 | CellInfo{icell}.VarIndex_vector_x=ind_vector_x(icell-numel(ind_scalar)); |
---|
| 174 | DimCell_var=Data.VarDimName{ind_vector_x(icell-numel(ind_scalar))};% cell of dimension names for ivar_coord_x(icell) |
---|
| 175 | % look for the associated y vector component |
---|
| 176 | nbvar=1; |
---|
| 177 | for ivar=ind_vector_y |
---|
| 178 | DimCell=Data.VarDimName{ivar}; |
---|
| 179 | if isequal(DimCell,DimCell_var) |
---|
| 180 | CellInfo{icell}.VarIndex(2)=ivar; |
---|
| 181 | nbvar=2; |
---|
| 182 | CellInfo{icell}.VarIndex_vector_y=ivar; |
---|
| 183 | break |
---|
[514] | 184 | end |
---|
| 185 | end |
---|
[1045] | 186 | if ~isfield(CellInfo{icell},'VarIndex_vector_y') |
---|
| 187 | flag_remove(icell)=true;% no vector_y found , mark cell to remove |
---|
| 188 | end |
---|
| 189 | % look for the associated z vector component |
---|
| 190 | for ivar=ind_vector_z |
---|
| 191 | DimCell=Data.VarDimName{ivar}; |
---|
| 192 | if isequal(DimCell,DimCell_var) |
---|
| 193 | CellInfo{icell}.VarIndex(3)=ivar; |
---|
| 194 | nbvar=3; |
---|
| 195 | break |
---|
| 196 | end |
---|
| 197 | end |
---|
| 198 | %look for the vector color scalar (ancillary) |
---|
| 199 | for ivar=ind_ancillary |
---|
| 200 | DimCell=Data.VarDimName{ivar}; |
---|
| 201 | if isequal(DimCell,DimCell_var) |
---|
| 202 | nbvar=nbvar+1; |
---|
| 203 | CellInfo{icell}.VarIndex(nbvar)=ivar; |
---|
| 204 | CellInfo{icell}.VarIndex_ancillary=ivar; |
---|
| 205 | break |
---|
| 206 | end |
---|
| 207 | end |
---|
| 208 | %look for warnflag |
---|
| 209 | for ivar=ind_warnflag |
---|
| 210 | DimCell=Data.VarDimName{ivar}; |
---|
| 211 | if isequal(DimCell,DimCell_var) |
---|
| 212 | nbvar=nbvar+1; |
---|
| 213 | CellInfo{icell}.VarIndex(nbvar)=ivar; |
---|
| 214 | CellInfo{icell}.VarIndex_warnflag=ivar; |
---|
| 215 | break |
---|
| 216 | end |
---|
| 217 | end |
---|
| 218 | %look for errorflag |
---|
| 219 | for ivar=ind_errorflag |
---|
| 220 | DimCell=Data.VarDimName{ivar}; |
---|
| 221 | if isequal(DimCell,DimCell_var) |
---|
| 222 | nbvar=nbvar+1; |
---|
| 223 | CellInfo{icell}.VarIndex(nbvar)=ivar; |
---|
| 224 | CellInfo{icell}.VarIndex_errorflag=ivar; |
---|
| 225 | break |
---|
| 226 | end |
---|
| 227 | end |
---|
[514] | 228 | end |
---|
| 229 | |
---|
[1045] | 230 | %% find coordinates for each cell around field variables, scalars or vectors |
---|
| 231 | for icell=1:cell_nbre |
---|
| 232 | CellInfo{icell}.CoordType=''; |
---|
| 233 | ind_var=CellInfo{icell}.VarIndex(1); |
---|
| 234 | DimCell_var=Data.VarDimName{ind_var};% cell of dimension names for ivar_coord_x(icell) |
---|
| 235 | if ~check_var |
---|
| 236 | for idim=1:numel(DimCell_var) |
---|
| 237 | CellInfo{icell}.DimIndex(idim)=find(strcmp(DimCell_var{idim},Data.ListDimName)); |
---|
| 238 | end |
---|
[514] | 239 | end |
---|
[1045] | 240 | %look for z scattered coordinates |
---|
| 241 | if isempty(ind_coord_z) |
---|
| 242 | NbDim(icell)=2; |
---|
| 243 | CellInfo{icell}.CoordIndex=[0 0]; |
---|
[530] | 244 | else |
---|
[1045] | 245 | NbDim(icell)=3; |
---|
| 246 | CellInfo{icell}.CoordIndex=[0 0 0]; |
---|
| 247 | for ivar=ind_coord_z |
---|
| 248 | DimCell=Data.VarDimName{ivar}; |
---|
| 249 | if isequal(DimCell,DimCell_var) |
---|
| 250 | CellInfo{icell}.CoordType='scattered'; |
---|
| 251 | CellInfo{icell}.CoordIndex(1)=ivar; |
---|
| 252 | CellInfo{icell}.ZName=Data.ListVarName{ivar}; |
---|
| 253 | CellInfo{icell}.ZIndex=ivar; |
---|
| 254 | break |
---|
| 255 | end |
---|
| 256 | end |
---|
[530] | 257 | end |
---|
[1045] | 258 | % look for y coordinate |
---|
| 259 | for ivar=ind_coord_y |
---|
| 260 | % detect scattered y coordinates, variable with the same dimension(s) as the field variable considered |
---|
| 261 | DimCell=Data.VarDimName{ivar}; |
---|
| 262 | if isequal(DimCell,DimCell_var) |
---|
| 263 | CellInfo{icell}.CoordType='scattered'; |
---|
| 264 | CellInfo{icell}.CoordIndex(NbDim(icell)-1)=ivar; |
---|
| 265 | CellInfo{icell}.YName=Data.ListVarName{ivar}; |
---|
| 266 | CellInfo{icell}.YIndex=ivar; |
---|
| 267 | break |
---|
| 268 | end |
---|
[514] | 269 | end |
---|
[1045] | 270 | |
---|
| 271 | %look for x coordinates |
---|
| 272 | if strcmp(CellInfo{icell}.CoordType,'scattered') |
---|
| 273 | for ivar=ind_coord_x |
---|
| 274 | DimCell=Data.VarDimName{ivar}; |
---|
| 275 | if isequal(DimCell,DimCell_var) |
---|
| 276 | CellInfo{icell}.CoordIndex(NbDim(icell))=ivar; |
---|
| 277 | CellInfo{icell}.XName=Data.ListVarName{ivar}; |
---|
| 278 | CellInfo{icell}.XIndex=ivar; |
---|
| 279 | break |
---|
| 280 | end |
---|
| 281 | end |
---|
| 282 | end |
---|
| 283 | if isfield(CellInfo{icell},'ZName') |
---|
| 284 | if isfield(CellInfo{icell},'YName')&& isfield(CellInfo{icell},'XName') |
---|
| 285 | continue %scattered coordinates OK |
---|
| 286 | end |
---|
| 287 | else |
---|
| 288 | if isfield(CellInfo{icell},'YName') |
---|
| 289 | if isfield(CellInfo{icell},'XName') |
---|
| 290 | NbDim(icell)=2; |
---|
| 291 | continue %scattered coordinates OK |
---|
| 292 | end |
---|
| 293 | else |
---|
| 294 | if isfield(CellInfo{icell},'XName'); % only one coordinate x, switch vector field to 1D plot |
---|
| 295 | for ind=1:numel(CellInfo{icell}.VarIndex) |
---|
| 296 | Role{CellInfo{icell}.VarIndex(ind)}='coord_y'; |
---|
[535] | 297 | end |
---|
[1045] | 298 | continue |
---|
[535] | 299 | end |
---|
[514] | 300 | end |
---|
[530] | 301 | end |
---|
[1045] | 302 | |
---|
| 303 | %look for grid coordinates |
---|
| 304 | if isempty(CellInfo{icell}.CoordType) |
---|
| 305 | NbDim(icell)=numel(DimCell_var); |
---|
| 306 | CellInfo{icell}.DimOrder=[]; |
---|
| 307 | if NbDim(icell)==3 |
---|
| 308 | %coord z |
---|
| 309 | for ivar=ind_coord_z |
---|
| 310 | if check_coord_names(ivar) |
---|
| 311 | DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var)); |
---|
| 312 | check_coord=~isempty(DimRank); |
---|
| 313 | elseif check_coord_raster(ivar) |
---|
| 314 | DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var)); |
---|
| 315 | check_coord=~isempty(DimRank); |
---|
| 316 | end |
---|
| 317 | % check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{1}))||...% coord varbable |
---|
| 318 | % (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{1})); % rasrewr coord defined by min and max |
---|
| 319 | if check_coord |
---|
| 320 | CellInfo{icell}.CoordType='grid'; |
---|
| 321 | CellInfo{icell}.CoordIndex(1)=ivar; |
---|
| 322 | CellInfo{icell}.ZName=Data.ListVarName{ivar}; |
---|
| 323 | CellInfo{icell}.ZIndex=ivar; |
---|
| 324 | CellInfo{icell}.DimOrder=DimRank; |
---|
| 325 | break |
---|
| 326 | end |
---|
| 327 | end |
---|
[514] | 328 | end |
---|
[1045] | 329 | for ivar=ind_coord_y |
---|
[1048] | 330 | if check_coord_names(ivar) |
---|
[1045] | 331 | DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var)); |
---|
| 332 | check_coord=~isempty(DimRank); |
---|
| 333 | elseif check_coord_raster(ivar) |
---|
| 334 | DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var)); |
---|
| 335 | check_coord=~isempty(DimRank); |
---|
| 336 | end |
---|
| 337 | % check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)-1}))||...% coord variable |
---|
| 338 | % (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)-1})); % rasrewr coord defined by min and max |
---|
| 339 | if check_coord |
---|
| 340 | CellInfo{icell}.CoordType='grid'; |
---|
| 341 | CellInfo{icell}.CoordIndex(NbDim(icell)-1)=ivar; |
---|
| 342 | CellInfo{icell}.YName=Data.ListVarName{ivar}; |
---|
| 343 | CellInfo{icell}.YIndex=ivar; |
---|
| 344 | CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank]; |
---|
| 345 | break |
---|
| 346 | end |
---|
| 347 | end |
---|
| 348 | for ivar=ind_coord_x |
---|
| 349 | if check_coord_names(ivar) |
---|
| 350 | DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var)); |
---|
| 351 | check_coord=~isempty(DimRank); |
---|
| 352 | elseif check_coord_raster(ivar) |
---|
| 353 | DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var)); |
---|
| 354 | check_coord=~isempty(DimRank); |
---|
| 355 | end |
---|
| 356 | % check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)}))||...% coord variable |
---|
| 357 | % (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)})); % raster coord defined by min and max |
---|
| 358 | if check_coord |
---|
| 359 | CellInfo{icell}.CoordIndex(NbDim(icell))=ivar; |
---|
| 360 | CellInfo{icell}.XName=Data.ListVarName{ivar}; |
---|
| 361 | CellInfo{icell}.XIndex=ivar; |
---|
| 362 | CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank]; |
---|
| 363 | break |
---|
| 364 | end |
---|
| 365 | end |
---|
[530] | 366 | end |
---|
[1045] | 367 | %look for tps coordinates |
---|
| 368 | for ivar=ind_coord_tps |
---|
| 369 | DimCell=Data.VarDimName{ivar}; |
---|
| 370 | if numel(DimCell)==3 && strcmp(DimCell{1},DimCell_var{1}) |
---|
| 371 | CellInfo{icell}.CoordType='tps'; |
---|
| 372 | CellInfo{icell}.CoordIndex=ivar; |
---|
| 373 | if check_var |
---|
| 374 | NbDim(icell)=size(Data.(Data.ListVarName{ivar}),2); |
---|
| 375 | else |
---|
| 376 | DimIndex=find(strcmp(Data.VarDimName{ivar},Data.ListDimName)); |
---|
| 377 | NbDim(icell)= Data.DimValue(DimIndex); |
---|
| 378 | end |
---|
| 379 | for ivardim=1:numel(Data.VarDimName) |
---|
| 380 | if strcmp(Data.VarDimName{ivardim},DimCell{3}) |
---|
| 381 | CellInfo{icell}.NbCentres_tps= ivardim;% nbre of sites for each tps subdomain |
---|
| 382 | elseif strcmp(Data.VarDimName{ivardim}{1},DimCell{2}) && numel(Data.VarDimName{ivardim})>=3 && strcmp(Data.VarDimName{ivardim}{3},DimCell{3}) |
---|
| 383 | CellInfo{icell}.SubRange_tps=ivardim;% subrange definiton for tps |
---|
| 384 | end |
---|
| 385 | end |
---|
| 386 | end |
---|
| 387 | break |
---|
[530] | 388 | end |
---|
| 389 | end |
---|
| 390 | |
---|
[1045] | 391 | %% get number of coordinate points for each cell |
---|
| 392 | if check_var |
---|
| 393 | for icell=1:numel(CellInfo) |
---|
| 394 | switch CellInfo{icell}.CoordType |
---|
| 395 | case 'scattered' |
---|
| 396 | CellInfo{icell}.CoordSize=numel(Data.(CellInfo{icell}.XName)); |
---|
| 397 | case 'grid' |
---|
[1048] | 398 | VarName=Data.ListVarName{CellInfo{icell}.VarIndex(1)}; |
---|
[1045] | 399 | if NbDim(icell)==3 |
---|
[1048] | 400 | CellInfo{icell}.CoordSize=[size(Data.(VarName),3) size(Data.(VarName),2) size(Data.(VarName),1)]; |
---|
[1045] | 401 | else |
---|
[1048] | 402 | CellInfo{icell}.CoordSize=[size(Data.(VarName),2) size(Data.(VarName),1)]; |
---|
[1045] | 403 | end |
---|
| 404 | case 'tps' |
---|
| 405 | NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); |
---|
| 406 | CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1); |
---|
| 407 | end |
---|
[569] | 408 | end |
---|
[1045] | 409 | else |
---|
| 410 | for icell=1:numel(CellInfo) |
---|
| 411 | CellInfo{icell}.CoordSize=size(Data.DimValue(CellInfo{icell}.DimIndex)); |
---|
| 412 | end |
---|
[569] | 413 | end |
---|
[1045] | 414 | % |
---|
| 415 | % %% loop on the tps coordinate sets |
---|
| 416 | % |
---|
| 417 | % for icell_tps=1:numel(ind_coord_tps) |
---|
| 418 | % check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell |
---|
| 419 | % check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected |
---|
| 420 | % DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable |
---|
| 421 | % icell=numel(CellInfo)+icell_tps; % new field cell index |
---|
| 422 | % CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the tps coordinate variable |
---|
| 423 | % if numel(DimCell)==3 |
---|
| 424 | % VarDimName=Data.VarDimName(~check_select); |
---|
| 425 | % for ivardim=1:numel(VarDimName) |
---|
| 426 | % if strcmp(VarDimName{ivardim},DimCell{3}) |
---|
| 427 | % CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain |
---|
| 428 | % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected |
---|
| 429 | % elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3}) |
---|
| 430 | % CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps |
---|
| 431 | % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected |
---|
| 432 | % elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable |
---|
| 433 | % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected |
---|
| 434 | % end |
---|
| 435 | % end |
---|
| 436 | % end |
---|
| 437 | % CellInfo{icell}.CoordType='tps'; |
---|
| 438 | % CellInfo{icell}.VarIndex=find(check_cell); |
---|
| 439 | % if check_var |
---|
| 440 | % NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); |
---|
| 441 | % CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3); |
---|
| 442 | % else |
---|
| 443 | % check_index_1= strcmp(DimCell{1},Data.ListDimName); |
---|
| 444 | % check_index_2= strcmp(DimCell{2},Data.ListDimName); |
---|
| 445 | % NbDim(icell)=Data.DimValue(check_index_2); |
---|
| 446 | % if numel(DimCell)>=3 |
---|
| 447 | % check_index_3= strcmp(DimCell{3},Data.ListDimName); |
---|
| 448 | % CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3); |
---|
| 449 | % end |
---|
| 450 | % end |
---|
| 451 | % check_select=check_select|check_cell; |
---|
| 452 | % end |
---|
[530] | 453 | |
---|
[1045] | 454 | |
---|
| 455 | %% cell for ordinary plots |
---|
| 456 | iremove=false(1,numel(ind_coord_y)); |
---|
| 457 | for ilist=1:numel(ind_coord_y)% remove the y coordinates which have been used yet in scalar or vector fields |
---|
| 458 | for icell=1:numel(CellInfo) |
---|
| 459 | if isfield(CellInfo{icell},'YIndex')&& isequal(CellInfo{icell}.YIndex,ind_coord_y(ilist)) |
---|
| 460 | iremove(ilist)=true; |
---|
| 461 | continue |
---|
| 462 | end |
---|
| 463 | end |
---|
| 464 | end |
---|
| 465 | ind_coord_y(iremove)=[]; |
---|
| 466 | if ~isempty(ind_coord_x) |
---|
| 467 | y_nbre=zeros(1,numel(ind_coord_x)); |
---|
| 468 | for icell=1:numel(ind_coord_x) |
---|
| 469 | Cell1DPlot{icell}.VarType='1DPlot'; |
---|
| 470 | Cell1DPlot{icell}.XIndex=ind_coord_x(icell); |
---|
| 471 | Cell1DPlot{icell}.XName=Data.ListVarName{ind_coord_x(icell)}; |
---|
[1048] | 472 | Cell1DPlot{icell}.YIndex=[]; |
---|
| 473 | Cell1DPlot{icell}.YIndex_discrete=[]; |
---|
[1045] | 474 | DimCell_x=Data.VarDimName{ind_coord_x(icell)}; |
---|
[1048] | 475 | for ivar=ind_coord_y |
---|
[1045] | 476 | DimCell=Data.VarDimName{ivar}; |
---|
[1049] | 477 | if numel(DimCell_x)==1 && strcmp(DimCell_x{1},DimCell{1}) |
---|
[1045] | 478 | y_nbre(icell)=y_nbre(icell)+1; |
---|
| 479 | Cell1DPlot{icell}.YIndex(y_nbre(icell))=ivar; |
---|
| 480 | end |
---|
| 481 | end |
---|
[1048] | 482 | for ivar=ind_discrete |
---|
| 483 | DimCell=Data.VarDimName{ivar}; |
---|
| 484 | if numel(DimCell)==1 && strcmp(DimCell_x{1},DimCell{1}) |
---|
| 485 | y_nbre(icell)=y_nbre(icell)+1; |
---|
| 486 | Cell1DPlot{icell}.YIndex_discrete(y_nbre(icell))=ivar; |
---|
| 487 | end |
---|
| 488 | end |
---|
[1045] | 489 | end |
---|
[1048] | 490 | Cell1DPlot(y_nbre==0)=[]; |
---|
[1045] | 491 | CellInfo=[CellInfo Cell1DPlot]; |
---|
| 492 | NbDim=[NbDim ones(1,numel(Cell1DPlot))]; |
---|
| 493 | end |
---|
| 494 | |
---|
[530] | 495 | %% document roles of non-coordinate variables |
---|
| 496 | for icell=1:numel(CellInfo) |
---|
[1045] | 497 | if isfield(CellInfo{icell},'VarIndex') |
---|
| 498 | VarIndex=CellInfo{icell}.VarIndex; |
---|
| 499 | for ivar=VarIndex |
---|
| 500 | % if isfield(CellInfo{icell},['VarIndex_' Role{ivar}]) |
---|
| 501 | % CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar]; |
---|
| 502 | % else |
---|
| 503 | % CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar; |
---|
| 504 | % end |
---|
| 505 | if ~isempty(ProjModeRequest{ivar}) |
---|
| 506 | CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar}; |
---|
| 507 | end |
---|
| 508 | if ~isempty(FieldName{ivar}) |
---|
| 509 | CellInfo{icell}.FieldName=FieldName{ivar}; |
---|
| 510 | end |
---|
| 511 | if CheckSub(ivar)==1 |
---|
| 512 | CellInfo{icell}.CheckSub=1; |
---|
| 513 | end |
---|
[514] | 514 | end |
---|
| 515 | end |
---|
| 516 | end |
---|
[1045] | 517 | % for icell=ind_coord_tps |
---|
| 518 | % VarIndex=CellInfo{icell}.VarIndex; |
---|
| 519 | % for ivar=VarIndex |
---|
| 520 | % if isfield(CellInfo{icell},['VarIndex_' Role{ivar}]) |
---|
| 521 | % CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar]; |
---|
| 522 | % else |
---|
| 523 | % CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar; |
---|
| 524 | % end |
---|
| 525 | % if ~isempty(ProjModeRequest{ivar}) |
---|
| 526 | % CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar}; |
---|
| 527 | % end |
---|
| 528 | % if ~isempty(FieldName{ivar}) |
---|
| 529 | % CellInfo{icell}.FieldName=FieldName{ivar}; |
---|
| 530 | % end |
---|
| 531 | % if CheckSub(ivar)==1 |
---|
| 532 | % CellInfo{icell}.CheckSub=1; |
---|
| 533 | % end |
---|
| 534 | % end |
---|
| 535 | % end |
---|
| 536 | |
---|
| 537 | |
---|
| 538 | |
---|
| 539 | % |
---|
| 540 | % %% analyse vector fields |
---|
| 541 | % if ~isempty(ind_vector_x) && ~isempty(ind_vector_y) |
---|
| 542 | % if numel(ind_vector_x)>1 |
---|
| 543 | % errormsg='multiply defined vector x component' |
---|
| 544 | % return |
---|
| 545 | % end |
---|
| 546 | % DimCell_vec=Data.VarDimName{ind_vector_x};% cell of dimension names for ivar_coord_x(icell) |
---|
| 547 | % if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension |
---|
| 548 | % DimCell_y=Data.VarDimName{ind_vector_y};% cell of dimension names for ivar_coord_x(icell) |
---|
| 549 | % if ischar(DimCell_y),DimCell_y={DimCell_y};end % transform char to cell for a single dimension |
---|
| 550 | % if ~isequal(DimCell,DimCell_y) |
---|
| 551 | % errormsg='inconsistent x and y vector components'; |
---|
| 552 | % return |
---|
| 553 | % end |
---|
| 554 | % %look for coordinates |
---|
| 555 | % for ivar=ind_coord_y |
---|
| 556 | % DimCell=Data.VarDimName{ivar}; |
---|
| 557 | % if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension |
---|
| 558 | % if isequal(DimCell,DimCell_vec) |
---|
| 559 | % CoordType='scattered'; |
---|
| 560 | % coordy=ivar; |
---|
| 561 | % else |
---|
| 562 | % if isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{1}) |
---|
| 563 | % CoordType='grid'; |
---|
| 564 | % coordy=ivar; |
---|
| 565 | % elseif ~isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{2}) |
---|
| 566 | % CoordType='grid'; |
---|
| 567 | % coordy=ivar; |
---|
| 568 | % coordz=ind_coord_z; |
---|
| 569 | % end |
---|
| 570 | % end |
---|
| 571 | % |
---|
| 572 | % %% find scattered (unstructured) coordinates |
---|
| 573 | % ivar_coord_x=find(strcmp('coord_x',Role));%find variables with Role='coord_x' |
---|
| 574 | % check_select=false(1,nbvar); |
---|
| 575 | % check_coord=false(1,nbvar); |
---|
| 576 | % CellInfo=cell(1,numel(ivar_coord_x)); |
---|
| 577 | % NbDim=zeros(1,numel(ivar_coord_x)); |
---|
| 578 | % % loop on unstructured coordinate x -> different field cells |
---|
| 579 | % for icell=1:numel(ivar_coord_x) |
---|
| 580 | % DimCell=Data.VarDimName{ivar_coord_x(icell)};% cell of dimension names for ivar_coord_x(icell) |
---|
| 581 | % if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension |
---|
| 582 | % % look for variables sharing dimension(s) with ivar_coord_x(icell) |
---|
| 583 | % check_cell=zeros(numel(DimCell),nbvar); |
---|
| 584 | % for idim=1:numel(DimCell);% for each variable with role coord_x, look at which other variables contain the same dimension |
---|
| 585 | % for ivar=1:nbvar |
---|
| 586 | % check_cell(idim,ivar)=max(strcmp(DimCell{idim},Data.VarDimName{ivar})); |
---|
| 587 | % end |
---|
| 588 | % end |
---|
| 589 | % check_cell=sum(check_cell,1)==numel(DimCell);%logical array=1 for variables belonging to the current cell |
---|
| 590 | % VarIndex=find(check_cell);% list of detected variable indices |
---|
| 591 | % if ~(numel(VarIndex)==1 && numel(DimCell)==1)% exclude case of isolated coord_x variable (treated later) |
---|
| 592 | % if ~(numel(VarIndex)==1 && numel(DimCell)>1)% a variable is associated to coordinate |
---|
| 593 | % CellInfo{icell}.CoordIndex=ivar_coord_x(icell); |
---|
| 594 | % % size of coordinate var |
---|
| 595 | % if check_var |
---|
| 596 | % CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)})); |
---|
| 597 | % else |
---|
| 598 | % for idim=1:numel(DimCell) |
---|
| 599 | % check_index= strcmp(DimCell{idim},Data.ListDimName); |
---|
| 600 | % CellInfo{icell}.CoordSize(idim)=Data.DimValue(check_index); |
---|
| 601 | % end |
---|
| 602 | % CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize); |
---|
| 603 | % end |
---|
| 604 | % % ind_scalar=find(strcmp('scalar',Role(VarIndex))); |
---|
| 605 | % % ind_vector_x=find(strcmp('vector_x',Role(VarIndex))); |
---|
| 606 | % % ind_vector_y=find(strcmp('vector_y',Role(VarIndex))); |
---|
| 607 | % ind_y=find(strcmp('coord_y',Role(VarIndex))); |
---|
| 608 | % if numel([ind_scalar ind_vector_x ind_vector_y])==0 |
---|
| 609 | % % if numel(VarIndex)==2||isempty(ind_y)% no variable, except possibly y |
---|
| 610 | % NbDim(icell)=1; |
---|
| 611 | % else |
---|
| 612 | % CellInfo{icell}.CoordType='scattered'; |
---|
| 613 | % ind_z=find(strcmp('coord_z',Role(VarIndex))); |
---|
| 614 | % if numel(VarIndex)==3||isempty(ind_z)% no z variable, except possibly as a fct z(x,y) |
---|
| 615 | % CellInfo{icell}.CoordIndex=[VarIndex(ind_y) CellInfo{icell}.CoordIndex]; |
---|
| 616 | % NbDim(icell)=2; |
---|
| 617 | % else |
---|
| 618 | % CellInfo{icell}.CoordIndex=[VarIndex(ind_z) CellInfo{icell}.CoordIndex]; |
---|
| 619 | % NbDim(icell)=3; |
---|
| 620 | % end |
---|
| 621 | % end |
---|
| 622 | % end |
---|
| 623 | % CellInfo{icell}.VarIndex=VarIndex; |
---|
| 624 | % check_select=check_select|check_cell; |
---|
| 625 | % end |
---|
| 626 | % end |
---|
| 627 | % |
---|
| 628 | % %% look for tps coordinates |
---|
| 629 | % ivar_remain=find(~check_select);% indices of remaining variables (not already selected) |
---|
| 630 | % check_coord_tps= strcmp('coord_tps',Role(~check_select)); |
---|
| 631 | % ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates |
---|
| 632 | % |
---|
| 633 | % % loop on the tps coordinate sets |
---|
| 634 | % for icell_tps=1:numel(ivar_tps) |
---|
| 635 | % check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell |
---|
| 636 | % check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected |
---|
| 637 | % DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable |
---|
| 638 | % icell=numel(CellInfo)+icell_tps; % new field cell index |
---|
| 639 | % CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the tps coordinate variable |
---|
| 640 | % if numel(DimCell)==3 |
---|
| 641 | % VarDimName=Data.VarDimName(~check_select); |
---|
| 642 | % for ivardim=1:numel(VarDimName) |
---|
| 643 | % if strcmp(VarDimName{ivardim},DimCell{3}) |
---|
| 644 | % CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain |
---|
| 645 | % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected |
---|
| 646 | % elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3}) |
---|
| 647 | % CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps |
---|
| 648 | % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected |
---|
| 649 | % elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable |
---|
| 650 | % check_cell(ivar_remain(ivardim))=1;% mark the variable as selected |
---|
| 651 | % end |
---|
| 652 | % end |
---|
| 653 | % end |
---|
| 654 | % CellInfo{icell}.CoordType='tps'; |
---|
| 655 | % CellInfo{icell}.VarIndex=find(check_cell); |
---|
| 656 | % if check_var |
---|
| 657 | % NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2); |
---|
| 658 | % CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3); |
---|
| 659 | % else |
---|
| 660 | % check_index_1= strcmp(DimCell{1},Data.ListDimName); |
---|
| 661 | % check_index_2= strcmp(DimCell{2},Data.ListDimName); |
---|
| 662 | % NbDim(icell)=Data.DimValue(check_index_2); |
---|
| 663 | % if numel(DimCell)>=3 |
---|
| 664 | % check_index_3= strcmp(DimCell{3},Data.ListDimName); |
---|
| 665 | % CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3); |
---|
| 666 | % end |
---|
| 667 | % end |
---|
| 668 | % check_select=check_select|check_cell; |
---|
| 669 | % end |
---|
| 670 | % |
---|
| 671 | % |
---|
| 672 | % |
---|
| 673 | % % determine dimension sizes |
---|
| 674 | % CoordSize=zeros(size(ListCoordIndex)); |
---|
| 675 | % for ilist=1:numel(ListCoordIndex) |
---|
| 676 | % if iscell(ListDimName{ilist}) |
---|
| 677 | % ListDimName(ilist)=ListDimName{ilist};%transform cell to string |
---|
| 678 | % end |
---|
| 679 | % if check_var% if the list of dimensions has been directly defined, no variable data available |
---|
| 680 | % CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist |
---|
| 681 | % else |
---|
| 682 | % check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the index in the list of dimensions |
---|
| 683 | % CoordSize(ilist)=Data.DimValue(check_index);% find the corresponding dimension value |
---|
| 684 | % end |
---|
| 685 | % if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only |
---|
| 686 | % ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name |
---|
| 687 | % end |
---|
| 688 | % end |
---|
| 689 | % end |
---|
| 690 | % end |
---|
| 691 | % |
---|
| 692 | % |
---|
| 693 | % |
---|
| 694 | % %% suppress empty cells or cells with a single coordinate variable |
---|
| 695 | % check_remove=false(size(CellInfo)); |
---|
| 696 | % for icell=1:numel(check_remove) |
---|
| 697 | % if isempty(CellInfo{icell})||(numel(CellInfo{icell}.VarIndex)==1 && numel(check_coord)>=icell && check_coord(icell)) |
---|
| 698 | % check_remove(icell)=1; |
---|
| 699 | % end |
---|
| 700 | % end |
---|
| 701 | % CellInfo(check_remove)=[]; |
---|
| 702 | % NbDim(check_remove)=[]; |
---|
| 703 | % |
---|
| 704 | % |
---|