source: trunk/src/find_field_cells.m @ 1082

Last change on this file since 1082 was 1078, checked in by sommeria, 5 years ago

various updates

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