source: trunk/src/find_field_cells.m @ 1057

Last change on this file since 1057 was 1057, checked in by sommeria, 6 years ago

reading color images repaired

File size: 32.4 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%       .DimIndex
21%      .ProjModeRequest= 'interp_lin', 'interp_tps' indicate whether lin interpolation  or derivatives (tps) is needed to calculate the requested field
22%      .FieldName = operation to be performed to finalise the field cell after projection
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
25% errormsg: error message
26%   
27% INPUT:
28% Data: structure representing fields, output of check_field_structure
29%            .ListGlobalAttributes
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)
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
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
45
46%=======================================================================
47% Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
48%   http://www.legi.grenoble-inp.fr
49%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
50%
51%     This file is part of the toolbox UVMAT.
52%
53%     UVMAT is free software; you can redistribute it and/or modify
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%
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
61%     GNU General Public License (see LICENSE.txt) for more details.
62%=======================================================================
63
64%    group the variables  into 'fields' with common dimensions
65
66function [CellInfo,NbDim,errormsg]=find_field_cells(Data)
67CellInfo={};%default output
68NbDim=0;
69errormsg='';
70if ~isfield(Data,'ListVarName'), errormsg='the list of variables .ListVarName is missing';return;end
71if ~isfield(Data,'VarDimName'), errormsg='the list of dimensions .VarDimName is missing';return;end
72nbvar=numel(Data.ListVarName);%number of variables in the field structure
73if ~isequal(numel(Data.VarDimName),nbvar), errormsg='.ListVarName and .VarDimName have unequal length';return;end
74% check the existence of variable data
75check_var=1;
76for ilist=1:numel(Data.ListVarName)
77    if ~isfield(Data,Data.ListVarName{ilist})
78        check_var=0;% dimensions of array defined, but the corresponding array is not given
79        break
80    end
81end
82
83%% role of variables and list of requested operations
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
86Role=num2cell(blanks(nbvar));%initialize a cell array of nbvar blanks
87ProjModeRequest=regexprep(Role,' ',''); % fieldRequest set to '' by default
88FieldName=cell(size(Role)); % fieldRequest set to {} by default
89CheckSub=zeros(size(Role));% =1 for fields to substract
90%Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default
91if 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
96        if isfield(Data.VarAttribute{ivar},'ProjModeRequest')
97            ProjModeRequest{ivar}=Data.VarAttribute{ivar}.ProjModeRequest;
98        end
99        if isfield(Data.VarAttribute{ivar},'FieldName')
100            FieldName{ivar}=Data.VarAttribute{ivar}.FieldName;
101        end
102        if isfield(Data.VarAttribute{ivar},'CheckSub')
103            CheckSub(ivar)=Data.VarAttribute{ivar}.CheckSub;
104        end
105    end
106end
107
108%% detect  fields with different roles
109ind_scalar=find(strcmp('scalar',Role));
110ind_errorflag=find(strcmp('errorflag',Role));
111ind_image=find(strcmp('image',Role));
112ind_vector_x=[find(strcmp('vector_x',Role)) find(strcmp('vector_x_tps',Role))];
113if ~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));
118end
119ind_discrete=find(strcmp('discrete',Role));
120ind_coord_x=find(strcmp('coord_x',Role));
121ind_coord_y=find(strcmp('coord_y',Role));
122ind_coord_z=find(strcmp('coord_z',Role));
123ind_coord_tps=find(strcmp('coord_tps',Role));
124check_string=cellfun(@ischar,Data.VarDimName)==1;
125index_string=find(check_string);
126for ivar=index_string
127    Data.VarDimName{ivar}={Data.VarDimName{ivar}};%transform char strings into cells
128end
129check_coord_names= cellfun(@numel,Data.VarDimName)==1;
130check_coord_raster=false(size(check_coord_names));% check variables describing regular mesh (raster coordinates), from two values, min and max.
131if check_var
132    for ivar=find(check_coord_names)
133        if numel(Data.(Data.ListVarName{ivar}))==2
134            check_coord_raster(ivar)=true;
135        end
136    end
137else
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;
142        end
143    end
144end
145
146
147%% initate cells around each scalar field
148index_remove=[];
149cell_nbre=numel(ind_scalar)+numel(ind_vector_x);
150flag_remove=false(1,cell_nbre);
151NbDim=zeros(1,cell_nbre);
152index_coord_x=zeros(size(ind_coord_x));
153for 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
165        end
166    end
167end
168
169%% initate cells around each vector field
170for 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
184        end
185    end
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
228end
229
230%% find coordinates for each cell around field variables, scalars or vectors
231for 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
239    end
240    %look for z scattered coordinates
241    if isempty(ind_coord_z)
242        NbDim(icell)=2;
243        CellInfo{icell}.CoordIndex=[0 0];
244    else
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
257    end
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
269    end
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';
297                end
298                continue
299            end
300        end
301    end
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            if strcmp(DimCell_var{3},'rgb')
309                NbDim(icell)=2;% case of color images
310            else
311                %coord z
312                for ivar=ind_coord_z
313                    if check_coord_names(ivar)
314                        DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var));
315                        check_coord=~isempty(DimRank);
316                    elseif check_coord_raster(ivar)
317                        DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var));
318                        check_coord=~isempty(DimRank);
319                    end
320                    %                 check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{1}))||...% coord varbable
321                    %                     (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{1})); % rasrewr coord defined by min and max
322                    if check_coord
323                        CellInfo{icell}.CoordType='grid';
324                        CellInfo{icell}.CoordIndex(1)=ivar;
325                        CellInfo{icell}.ZName=Data.ListVarName{ivar};
326                        CellInfo{icell}.ZIndex=ivar;
327                        CellInfo{icell}.DimOrder=DimRank;
328                        break
329                    end
330                end
331            end
332        end
333        for ivar=ind_coord_y
334            if check_coord_names(ivar)
335                DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var));
336                check_coord=~isempty(DimRank);
337            elseif check_coord_raster(ivar)
338                DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var));
339                check_coord=~isempty(DimRank);
340            end
341            %             check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)-1}))||...% coord variable
342            %                 (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)-1})); % rasrewr coord defined by min and max
343            if check_coord
344                CellInfo{icell}.CoordType='grid';
345                CellInfo{icell}.CoordIndex(NbDim(icell)-1)=ivar;
346                CellInfo{icell}.YName=Data.ListVarName{ivar};
347                CellInfo{icell}.YIndex=ivar;
348                CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank];
349                break
350            end
351        end
352        for ivar=ind_coord_x
353            if check_coord_names(ivar)
354                DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var));
355                check_coord=~isempty(DimRank);
356            elseif check_coord_raster(ivar)
357                DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var));
358                check_coord=~isempty(DimRank);
359            end
360            %             check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)}))||...% coord variable
361            %                 (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)})); % raster coord defined by min and max
362            if check_coord
363                CellInfo{icell}.CoordIndex(NbDim(icell))=ivar;
364                CellInfo{icell}.XName=Data.ListVarName{ivar};
365                CellInfo{icell}.XIndex=ivar;
366                CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank];
367                break
368            end
369        end
370    end
371    %look for tps coordinates
372    for ivar=ind_coord_tps
373        DimCell=Data.VarDimName{ivar};
374        if  numel(DimCell)==3 && strcmp(DimCell{1},DimCell_var{1})
375            CellInfo{icell}.CoordType='tps';
376            CellInfo{icell}.CoordIndex=ivar;
377            if check_var
378                NbDim(icell)=size(Data.(Data.ListVarName{ivar}),2);
379            else
380                DimIndex=find(strcmp(Data.VarDimName{ivar},Data.ListDimName));
381                NbDim(icell)= Data.DimValue(DimIndex);
382            end
383            for ivardim=1:numel(Data.VarDimName)
384                if strcmp(Data.VarDimName{ivardim},DimCell{3})
385                    CellInfo{icell}.NbCentres_tps= ivardim;% nbre of sites for each tps subdomain
386                elseif strcmp(Data.VarDimName{ivardim}{1},DimCell{2}) && numel(Data.VarDimName{ivardim})>=3 && strcmp(Data.VarDimName{ivardim}{3},DimCell{3})
387                    CellInfo{icell}.SubRange_tps=ivardim;% subrange definiton for tps
388                end
389            end
390        end
391        break
392    end
393end
394
395%% get number of coordinate points for each cell
396if check_var
397    for icell=1:numel(CellInfo)
398        switch CellInfo{icell}.CoordType
399            case 'scattered'
400                CellInfo{icell}.CoordSize=numel(Data.(CellInfo{icell}.XName));
401            case 'grid'
402                VarName=Data.ListVarName{CellInfo{icell}.VarIndex(1)};
403                if NbDim(icell)==3
404                    CellInfo{icell}.CoordSize=[size(Data.(VarName),3) size(Data.(VarName),2) size(Data.(VarName),1)];
405                else
406                    CellInfo{icell}.CoordSize=[size(Data.(VarName),1) size(Data.(VarName),2)];
407                end
408            case 'tps'
409                NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
410                CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1);
411        end
412    end
413else
414    for icell=1:numel(CellInfo)
415        CellInfo{icell}.CoordSize=size(Data.DimValue(CellInfo{icell}.DimIndex));
416    end
417end
418%
419% %% loop on the tps coordinate sets
420%
421%     for icell_tps=1:numel(ind_coord_tps)
422%         check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell
423%         check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected
424%         DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable
425%         icell=numel(CellInfo)+icell_tps; % new field cell index
426%         CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the  tps coordinate variable
427%         if numel(DimCell)==3
428%             VarDimName=Data.VarDimName(~check_select);
429%             for ivardim=1:numel(VarDimName)
430%                 if strcmp(VarDimName{ivardim},DimCell{3})
431%                     CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain
432%                     check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
433%                 elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3})
434%                     CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps
435%                     check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
436%                 elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable
437%                     check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
438%                 end
439%             end
440%         end
441%         CellInfo{icell}.CoordType='tps';
442%         CellInfo{icell}.VarIndex=find(check_cell);
443%         if check_var
444%             NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
445%             CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);
446%         else
447%             check_index_1= strcmp(DimCell{1},Data.ListDimName);
448%             check_index_2= strcmp(DimCell{2},Data.ListDimName);
449%             NbDim(icell)=Data.DimValue(check_index_2);
450%             if numel(DimCell)>=3
451%                 check_index_3= strcmp(DimCell{3},Data.ListDimName);
452%                 CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3);
453%             end
454%         end
455%         check_select=check_select|check_cell;
456%     end
457
458
459%% cell for ordinary plots
460iremove=false(1,numel(ind_coord_y));
461for ilist=1:numel(ind_coord_y)% remove the y coordinates which have been used yet in scalar or vector fields
462    for icell=1:numel(CellInfo)
463        if isfield(CellInfo{icell},'YIndex')&& isequal(CellInfo{icell}.YIndex,ind_coord_y(ilist))
464            iremove(ilist)=true;
465            continue
466        end
467    end
468end
469ind_coord_y(iremove)=[];
470if ~isempty(ind_coord_x)
471    y_nbre=zeros(1,numel(ind_coord_x));
472    for icell=1:numel(ind_coord_x)
473        Cell1DPlot{icell}.VarType='1DPlot';
474        Cell1DPlot{icell}.XIndex=ind_coord_x(icell);
475        Cell1DPlot{icell}.XName=Data.ListVarName{ind_coord_x(icell)};
476        Cell1DPlot{icell}.YIndex=[];
477        Cell1DPlot{icell}.YIndex_discrete=[];
478        DimCell_x=Data.VarDimName{ind_coord_x(icell)};
479        for ivar=ind_coord_y
480            DimCell=Data.VarDimName{ivar};
481            if  numel(DimCell_x)==1 && strcmp(DimCell_x{1},DimCell{1})
482                y_nbre(icell)=y_nbre(icell)+1;
483                Cell1DPlot{icell}.YIndex(y_nbre(icell))=ivar;
484            end
485        end
486        for ivar=ind_discrete
487            DimCell=Data.VarDimName{ivar};
488            if  numel(DimCell)==1 && strcmp(DimCell_x{1},DimCell{1})
489                y_nbre(icell)=y_nbre(icell)+1;
490                Cell1DPlot{icell}.YIndex_discrete(y_nbre(icell))=ivar;
491            end
492        end
493    end
494    Cell1DPlot(y_nbre==0)=[];
495    CellInfo=[CellInfo Cell1DPlot];
496    NbDim=[NbDim ones(1,numel(Cell1DPlot))];
497end
498
499%% document roles of non-coordinate variables
500for icell=1:numel(CellInfo)
501    if isfield(CellInfo{icell},'VarIndex')
502        VarIndex=CellInfo{icell}.VarIndex;
503        for ivar=VarIndex
504            %         if isfield(CellInfo{icell},['VarIndex_' Role{ivar}])
505            %             CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar];
506            %         else
507            %             CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar;
508            %         end
509            if ~isempty(ProjModeRequest{ivar})
510                CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar};
511            end
512            if ~isempty(FieldName{ivar})
513                CellInfo{icell}.FieldName=FieldName{ivar};
514            end
515            if CheckSub(ivar)==1
516                CellInfo{icell}.CheckSub=1;
517            end
518        end
519    end
520end
521% for icell=ind_coord_tps
522%     VarIndex=CellInfo{icell}.VarIndex;
523%     for ivar=VarIndex
524%         if isfield(CellInfo{icell},['VarIndex_' Role{ivar}])
525%             CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar];
526%         else
527%             CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar;
528%         end
529%         if ~isempty(ProjModeRequest{ivar})
530%             CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar};
531%         end
532%         if ~isempty(FieldName{ivar})
533%             CellInfo{icell}.FieldName=FieldName{ivar};
534%         end
535%         if CheckSub(ivar)==1
536%             CellInfo{icell}.CheckSub=1;
537%         end
538%     end
539% end
540
541
542
543%
544% %% analyse vector fields
545% if ~isempty(ind_vector_x) && ~isempty(ind_vector_y)
546%     if numel(ind_vector_x)>1
547%         errormsg='multiply defined vector x component'
548%         return
549%     end
550%     DimCell_vec=Data.VarDimName{ind_vector_x};% cell of dimension names for ivar_coord_x(icell)
551%     if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension
552%     DimCell_y=Data.VarDimName{ind_vector_y};% cell of dimension names for ivar_coord_x(icell)
553%     if ischar(DimCell_y),DimCell_y={DimCell_y};end % transform char to cell for a single dimension
554%     if ~isequal(DimCell,DimCell_y)
555%         errormsg='inconsistent x and y vector components';
556%         return
557%     end
558%     %look for coordinates
559%     for ivar=ind_coord_y
560%         DimCell=Data.VarDimName{ivar};
561%         if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension
562%         if isequal(DimCell,DimCell_vec)
563%             CoordType='scattered';
564%             coordy=ivar;
565%         else
566%             if isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{1})
567%                 CoordType='grid';
568%                 coordy=ivar;
569%             elseif ~isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{2})
570%                 CoordType='grid';
571%                 coordy=ivar;
572%                 coordz=ind_coord_z;
573%             end
574%         end
575%         
576%         %% find scattered (unstructured) coordinates
577%         ivar_coord_x=find(strcmp('coord_x',Role));%find variables with Role='coord_x'
578%         check_select=false(1,nbvar);
579%         check_coord=false(1,nbvar);
580%         CellInfo=cell(1,numel(ivar_coord_x));
581%         NbDim=zeros(1,numel(ivar_coord_x));
582%         % loop on unstructured coordinate x -> different field cells
583%         for icell=1:numel(ivar_coord_x)
584%             DimCell=Data.VarDimName{ivar_coord_x(icell)};% cell of dimension names for ivar_coord_x(icell)
585%             if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension
586%             % look for variables sharing dimension(s) with ivar_coord_x(icell)
587%             check_cell=zeros(numel(DimCell),nbvar);
588%             for idim=1:numel(DimCell);% for each variable with role coord_x, look at which other variables contain the same dimension
589%                 for ivar=1:nbvar
590%                     check_cell(idim,ivar)=max(strcmp(DimCell{idim},Data.VarDimName{ivar}));
591%                 end
592%             end
593%             check_cell=sum(check_cell,1)==numel(DimCell);%logical array=1 for variables belonging to the current cell
594%             VarIndex=find(check_cell);% list of detected variable indices
595%             if ~(numel(VarIndex)==1 && numel(DimCell)==1)% exclude case of isolated coord_x variable (treated later)
596%                 if ~(numel(VarIndex)==1 && numel(DimCell)>1)% a variable is associated to coordinate
597%                     CellInfo{icell}.CoordIndex=ivar_coord_x(icell);
598%                     % size of coordinate var
599%                     if check_var
600%                         CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));
601%                     else
602%                         for idim=1:numel(DimCell)
603%                             check_index= strcmp(DimCell{idim},Data.ListDimName);
604%                             CellInfo{icell}.CoordSize(idim)=Data.DimValue(check_index);
605%                         end
606%                         CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize);
607%                     end
608%                     %             ind_scalar=find(strcmp('scalar',Role(VarIndex)));
609%                     %             ind_vector_x=find(strcmp('vector_x',Role(VarIndex)));
610%                     %             ind_vector_y=find(strcmp('vector_y',Role(VarIndex)));
611%                     ind_y=find(strcmp('coord_y',Role(VarIndex)));
612%                     if numel([ind_scalar ind_vector_x ind_vector_y])==0
613%                         %             if numel(VarIndex)==2||isempty(ind_y)% no variable, except possibly y
614%                         NbDim(icell)=1;
615%                     else
616%                         CellInfo{icell}.CoordType='scattered';
617%                         ind_z=find(strcmp('coord_z',Role(VarIndex)));
618%                         if numel(VarIndex)==3||isempty(ind_z)% no z variable, except possibly as a fct z(x,y)
619%                             CellInfo{icell}.CoordIndex=[VarIndex(ind_y) CellInfo{icell}.CoordIndex];
620%                             NbDim(icell)=2;
621%                         else
622%                             CellInfo{icell}.CoordIndex=[VarIndex(ind_z) CellInfo{icell}.CoordIndex];
623%                             NbDim(icell)=3;
624%                         end
625%                     end
626%                 end
627%                 CellInfo{icell}.VarIndex=VarIndex;
628%                 check_select=check_select|check_cell;
629%             end
630%         end
631%         
632%         %% look for tps coordinates
633%         ivar_remain=find(~check_select);% indices of remaining variables (not already selected)
634%         check_coord_tps= strcmp('coord_tps',Role(~check_select));
635%         ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates
636%         
637%         % loop on the tps coordinate sets
638%         for icell_tps=1:numel(ivar_tps)
639%             check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell
640%             check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected
641%             DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable
642%             icell=numel(CellInfo)+icell_tps; % new field cell index
643%             CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the  tps coordinate variable
644%             if numel(DimCell)==3
645%                 VarDimName=Data.VarDimName(~check_select);
646%                 for ivardim=1:numel(VarDimName)
647%                     if strcmp(VarDimName{ivardim},DimCell{3})
648%                         CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain
649%                         check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
650%                     elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3})
651%                         CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps
652%                         check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
653%                     elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable
654%                         check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
655%                     end
656%                 end
657%             end
658%             CellInfo{icell}.CoordType='tps';
659%             CellInfo{icell}.VarIndex=find(check_cell);
660%             if check_var
661%                 NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
662%                 CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);
663%             else
664%                 check_index_1= strcmp(DimCell{1},Data.ListDimName);
665%                 check_index_2= strcmp(DimCell{2},Data.ListDimName);
666%                 NbDim(icell)=Data.DimValue(check_index_2);
667%                 if numel(DimCell)>=3
668%                     check_index_3= strcmp(DimCell{3},Data.ListDimName);
669%                     CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3);
670%                 end
671%             end
672%             check_select=check_select|check_cell;
673%         end
674%         
675%     
676%         
677%         % determine dimension sizes
678%         CoordSize=zeros(size(ListCoordIndex));
679%         for ilist=1:numel(ListCoordIndex)
680%             if iscell(ListDimName{ilist})
681%                 ListDimName(ilist)=ListDimName{ilist};%transform cell to string
682%             end
683%             if check_var% if the list of dimensions has been directly defined, no variable data available
684%                 CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist
685%             else
686%                 check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the  index in the list of dimensions
687%                 CoordSize(ilist)=Data.DimValue(check_index);% find the  corresponding dimension value
688%             end
689%             if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only
690%                 ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name
691%             end
692%         end
693%     end
694% end
695%
696%
697%
698% %% suppress empty cells or cells with a single coordinate variable
699% check_remove=false(size(CellInfo));
700% for icell=1:numel(check_remove)
701%     if isempty(CellInfo{icell})||(numel(CellInfo{icell}.VarIndex)==1 && numel(check_coord)>=icell && check_coord(icell))
702%         check_remove(icell)=1;
703%     end
704% end
705% CellInfo(check_remove)=[];
706% NbDim(check_remove)=[];
707%
708%
Note: See TracBrowser for help on using the repository browser.