source: trunk/src/proj_field.m @ 868

Last change on this file since 868 was 867, checked in by sommeria, 9 years ago

python option added in series and bug corrections

File size: 109.0 KB
Line 
1%'proj_field': projects the field on a projection object
2%--------------------------------------------------------------------------
3%  function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
4%
5% OUTPUT:
6% ProjData structure containing the fields of the input field FieldData,
7% transmitted or projected on the object, plus the additional fields
8%    .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
9%    .UMean,VMean: mean of the velocity components in a domain
10%    .AMin, AMax: min and max of a scalar
11%    .AMean: mean of a scalar in a domain 
12%  .NbPix;
13%  .DimName=  names of the matrix dimensions (matlab cell)
14%  .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
15%  .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;
16%
17%INPUT
18% ObjectData: structure characterizing the projection object
19%    .Type : type of projection object
20%    .ProjMode=mode of projection ;
21%    .CoordUnit: 'px', 'cm' units for the coordinates defining the object
22%    .Angle (  angles of rotation (=[0 0 0] by default)
23%    .ProjAngle=angle of projection;
24%    .DX,.DY,.DZ=increments along each coordinate
25%    .Coord(nbpoints,3): set of coordinates defining the object position;
26
27%FieldData: data of the field to be projected on the projection object, with optional fields
28%    .Txt: error message, transmitted to the projection
29%    .FieldList: cell array of strings representing the fields to calculate
30%    .CoordMesh: typical distance between data points (used for mouse action or display), transmitted
31%    .CoordUnit, .TimeUnit, .dt: transmitted
32% standardised description of fields, nc-formated Matlab structure with fields:
33%         .ListGlobalAttribute: cell listing the names of the global attributes
34%        .Att_1,Att_2... : values of the global attributes
35%            .ListVarName: cell listing the names of the variables
36%           .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
37%        .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
38% The variables are grouped in 'fields', made of a set of variables with common dimensions (using the function find_field_cells)
39% The variable attribute 'Role' is used to define the role for plotting:
40%       Role = 'scalar':  (default) represents a scalar field
41%            = 'coord':  represents a set of unstructured coordinates, whose
42%                     space dimension is given by the last array dimension (called 'NbDim').
43%            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
44%                        unstructured coordinate x, y  or z
45%            = 'vector': represents a vector field whose number of components
46%                is given by the last dimension (called 'NbDim')
47%            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector 
48%            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
49%            = 'errorflag': provides an error flag marking false data,
50%                   default=0, no error. Different non zero values can represent different criteria of elimination.
51%
52% Default role of variables (by name)
53%  vector field:
54%    .X,.Y: position of the velocity vectors, projected on the object
55%    .U, .V, .W: velocity components, projected on the object
56%    .C, .CName: scalar associated to the vector
57%    .F : equivalent to 'warnflag'
58%    .FF: equivalent to 'errorflag'
59%  scalar field or image:
60%    .AName: name of a scalar (to be calculated from velocity fields after projection), transmitted
61%    .A: scalar, projected on the object
62%    .AX, .AY: positions for the scalar
63%     case of a structured grid: A is a dim 2 matrix and .AX=[first last] (length 2 vector) represents the first and last abscissa of the grid
64%     case of an unstructured scalar: A is a vector, AX and AY the corresponding coordinates
65
66%=======================================================================
67% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
68%   http://www.legi.grenoble-inp.fr
69%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
70%
71%     This file is part of the toolbox UVMAT.
72%
73%     UVMAT is free software; you can redistribute it and/or modify
74%     it under the terms of the GNU General Public License as published
75%     by the Free Software Foundation; either version 2 of the license,
76%     or (at your option) any later version.
77%
78%     UVMAT is distributed in the hope that it will be useful,
79%     but WITHOUT ANY WARRANTY; without even the implied warranty of
80%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81%     GNU General Public License (see LICENSE.txt) for more details.
82%=======================================================================
83
84function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
85errormsg='';%default
86ProjData=[];
87
88%% check input projection object: type, projection mode and Coord:
89if ~isfield(ObjectData,'Type')||~isfield(ObjectData,'ProjMode')
90    return
91end
92ListProjMode={'projection','interp_lin','interp_tps','inside','outside'};%list of effective projection modes
93if isempty(find(strcmp(ObjectData.ProjMode,ListProjMode), 1))% no projection in case
94    return
95end
96if ~isfield(ObjectData,'Coord')||isempty(ObjectData.Coord)
97    if strcmp(ObjectData.Type,'plane')
98        ObjectData.Coord=[0 0];%default
99    else
100        return
101    end
102end
103
104%% apply projection depending on the object type
105switch ObjectData.Type
106    case 'points'
107        [ProjData,errormsg]=proj_points(FieldData,ObjectData);
108    case {'line','polyline'}
109        [ProjData,errormsg] = proj_line(FieldData,ObjectData);
110    case {'polygon','rectangle','ellipse'}
111        if isequal(ObjectData.ProjMode,'inside')||isequal(ObjectData.ProjMode,'outside')
112            [ProjData,errormsg] = proj_patch(FieldData,ObjectData);
113        else
114            [ProjData,errormsg] = proj_line(FieldData,ObjectData);
115        end
116    case 'plane'
117        [ProjData,errormsg] = proj_plane(FieldData,ObjectData);
118    case 'volume'
119        [ProjData,errormsg] = proj_volume(FieldData,ObjectData);
120end
121
122% %% take the difference of projected input fields if relevant
123% [CellInfo,NbDim,errormsg]=find_field_cells(ProjData);
124% ind_remove=zeros(size(ProjData.ListVarName));
125% ivar=[];
126% ivar_1=[];
127% for icell=1:numel(CellInfo)
128%     if ~isempty(CellInfo{icell})
129%         % if two scalar are in the same cell
130%         if isfield(CellInfo{icell},'VarIndex_scalar') && numel(CellInfo{icell}.VarIndex_scalar)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_scalar(2)}.CheckSub;
131%             ivar=[ivar CellInfo{icell}.VarIndex_scalar(1)];
132%             ivar_1=[ivar_1 CellInfo{icell}.VarIndex_scalar(2)];
133%         end
134%         % if two vector u components are in the same cell
135%         if isfield(CellInfo{icell},'VarIndex_vector_x') && numel(CellInfo{icell}.VarIndex_vector_x)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_vector_x(2)}.CheckSub;
136%             ivar=[ivar CellInfo{icell}.VarIndex_vector_x(1)];
137%             ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_x(2)];
138%         end
139%          % if two vector v components are in the same cell
140%         if isfield(CellInfo{icell},'VarIndex_vector_y') && numel(CellInfo{icell}.VarIndex_vector_y)==2 && ProjData.VarAttribute{CellInfo{icell}.VarIndex_vector_y(2)}.CheckSub;
141%             ivar=[ivar CellInfo{icell}.VarIndex_vector_y(1)];
142%             ivar_1=[ivar_1 CellInfo{icell}.VarIndex_vector_y(2)];
143%         end
144%     end
145% end
146% % subtract fields if relevant
147% for imod=1:numel(ivar)
148%         VarName=ProjData.ListVarName{ivar(imod)};
149%         VarName_1=ProjData.ListVarName{ivar_1(imod)};
150%         ProjData.(VarName)=double(ProjData.(VarName))-double(ProjData.(VarName_1));
151%         ind_remove(ivar_1(imod))=1;
152% end
153% ProjData.ListVarName(find(ind_remove))=[];
154% ProjData.VarDimName(find(ind_remove))=[];
155% ProjData.VarAttribute(find(ind_remove))=[];
156
157%-----------------------------------------------------------------
158%project on a set of points
159function  [ProjData,errormsg]=proj_points(FieldData,ObjectData)%%
160%-------------------------------------------------------------------
161
162siz=size(ObjectData.Coord);
163width=0;
164if isfield(ObjectData,'Range')
165    width=ObjectData.Range(1,2);
166end
167if isfield(ObjectData,'RangeX')&&~isempty(ObjectData.RangeX)
168    width=max(ObjectData.RangeX);
169end
170if isfield(ObjectData,'RangeY')&&~isempty(ObjectData.RangeY)
171    width=max(width,max(ObjectData.RangeY));
172end
173if isfield(ObjectData,'RangeZ')&&~isempty(ObjectData.RangeZ)
174    width=max(width,max(ObjectData.RangeZ));
175end
176if isequal(ObjectData.ProjMode,'projection')
177    if width==0
178        errormsg='projection range around points needed';
179        return
180    end
181elseif  ~isequal(ObjectData.ProjMode,'interp_lin')
182    errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field']);
183        return
184end
185[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
186if ~isempty(errormsg)
187    return
188end
189ProjData.NbDim=0;
190[CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData);
191if ~isempty(errormsg)
192    errormsg=['error in proj_field/proj_points:' errormsg];
193    return
194end
195%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
196for icell=1:length(CellInfo)
197    if NbDimArray(icell)<=1
198        continue %projection only for multidimensional fields
199    end
200    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
201    ivar_X=CellInfo{icell}.CoordIndex(end);
202    ivar_Y=CellInfo{icell}.CoordIndex(end-1);
203    ivar_Z=[];
204    if NbDimArray(icell)==3
205        ivar_Z=CellInfo{icell}.CoordIndex(1);
206    end
207    ivar_FF=[];
208    if isfield(CellInfo{icell},'VarIndex_errorflag')
209        ivar_FF=CellInfo{icell}.VarIndex_errorflag;
210        if numel(ivar_FF)>1
211            errormsg='multiple error flag input';
212            return
213        end
214    end   
215    % select types of  variables to be projected
216   ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
217      check_proj=false(size(FieldData.ListVarName));
218   for ilist=1:numel(ListProj)
219       if isfield(CellInfo{icell},ListProj{ilist})
220           check_proj(CellInfo{icell}.(ListProj{ilist}))=1;
221       end
222   end
223   VarIndex=find(check_proj);
224    ProjData.ListVarName={'Y','X','NbVal'};
225    ProjData.VarDimName={'nb_points','nb_points','nb_points'};
226    ProjData.VarAttribute{1}.Role='ancillary';
227    ProjData.VarAttribute{2}.Role='ancillary';
228    ProjData.VarAttribute{3}.Role='ancillary';
229    for ivar=VarIndex       
230        VarName=FieldData.ListVarName{ivar};
231        ProjData.ListVarName=[ProjData.ListVarName {VarName}];% add the current variable to the list of projected variables
232        ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}]; % projected VarName has a single dimension called 'nb_points' (set of projection points)
233
234    end
235    if strcmp( CellInfo{icell}.CoordType,'scattered')
236        coord_x=FieldData.(FieldData.ListVarName{ivar_X});
237        coord_y=FieldData.(FieldData.ListVarName{ivar_Y});
238        test3D=0;% TEST 3D CASE : NOT COMPLETED ,  3D CASE : NOT COMPLETED
239        if length(ivar_Z)==1
240            coord_z=FieldData.(FieldData.ListVarName{ivar_Z});
241            test3D=1;
242        end
243   
244        for ipoint=1:siz(1)
245           Xpoint=ObjectData.Coord(ipoint,:);
246           distX=coord_x-Xpoint(1);
247           distY=coord_y-Xpoint(2);         
248           dist=distX.*distX+distY.*distY;
249           indsel=find(dist<width*width);
250           ProjData.X(ipoint,1)=Xpoint(1);
251           ProjData.Y(ipoint,1)=Xpoint(2);
252           if isequal(length(ivar_FF),1)
253               FFName=FieldData.ListVarName{ivar_FF};
254               FF=FieldData.(FFName)(indsel);
255               indsel=indsel(~FF);
256           end
257           ProjData.NbVal(ipoint,1)=length(indsel);
258            for ivar=VarIndex
259               VarName=FieldData.ListVarName{ivar};
260               if isempty(indsel)
261                    ProjData.(VarName)(ipoint,1)=NaN;
262               else
263                    Var=FieldData.(VarName)(indsel);
264                    ProjData.(VarName)(ipoint,1)=mean(Var);
265                    if isequal(ObjectData.ProjMode,'interp_lin')
266                         ProjData.(VarName)(ipoint,1)=griddata_uvmat(coord_x(indsel),coord_y(indsel),Var,Xpoint(1),Xpoint(2));
267                    end
268               end
269            end
270        end
271    else    %case of structured coordinates
272        if  strcmp( CellInfo{icell}.CoordType,'grid')
273            AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
274            AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
275            eval(['AX=FieldData.' AXName ';']);% set of x positions
276            eval(['AY=FieldData.' AYName ';']);% set of y positions 
277            AName=FieldData.ListVarName{VarIndex(1)};% a single variable assumed in the current cell
278            eval(['A=FieldData.' AName ';']);% scalar
279            npxy=size(A);         
280            %update VarDimName in case of components (non coordinate dimensions e;g. color components)
281            if numel(npxy)>NbDimArray(icell)
282                ProjData.VarDimName{end}={'nb_points','component'};
283            end
284            for idim=1:NbDimArray(icell) %loop on space dimensions
285                test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
286                test_coord(idim)=0;%test for defined coordinates, =0 by default
287                ivar=CellInfo{icell}.CoordIndex(idim);
288                Coord{idim}=FieldData.(FieldData.ListVarName{ivar}); % position for the first index
289                if numel(Coord{idim})==2
290                    DCoord_min(idim)= (Coord{idim}(2)-Coord{idim}(1))/(npxy(idim)-1);
291                    test_direct(idim)=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
292                else
293                    DCoord=diff(Coord{idim});
294                    DCoord_min(idim)=min(DCoord);
295                    DCoord_max=max(DCoord);
296                    test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
297                    test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
298                    if ~isequal(test_direct(idim),test_direct_min)
299                        errormsg=['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'];
300                        return
301                    end
302                    test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
303                    test_coord(idim)=1;
304                end
305            end
306            DX=DCoord_min(2);
307            DY=DCoord_min(1);
308            for ipoint=1:siz(1)
309                xwidth=width/(abs(DX));
310                ywidth=width/(abs(DY));
311                i_min=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5-xwidth); %minimum index of the selected region
312                i_min=max(1,i_min);%restrict to field limit
313                i_plus=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5+xwidth);
314                i_plus=min(npxy(2),i_plus); %restrict to field limit
315                j_min=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY-ywidth+0.5);
316                j_min=max(1,j_min);
317                j_plus=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY+ywidth+0.5);
318                j_plus=min(npxy(1),j_plus);
319                ProjData.X(ipoint,1)=ObjectData.Coord(ipoint,1);
320                ProjData.Y(ipoint,1)=ObjectData.Coord(ipoint,2);
321                i_int=(i_min:i_plus);
322                j_int=(j_min:j_plus);
323                ProjData.NbVal(ipoint,1)=length(j_int)*length(i_int);
324                if isempty(i_int) || isempty(j_int)
325                   for ivar=VarIndex   
326                        eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=NaN;']);
327                   end
328                   errormsg=['no data points in the selected projection range ' num2str(width) ];
329                else
330                    %TODO: introduce circle in the selected subregion
331                    %[I,J]=meshgrid([1:j_int],[1:i_int]);
332                    for ivar=VarIndex   
333                        Avalue=FieldData.(FieldData.ListVarName{ivar})(j_int,i_int,:);
334                        ProjData.(FieldData.ListVarName{ivar})(ipoint,:)=mean(mean(Avalue));
335                    end
336                end
337            end
338        end
339   end
340end
341
342%-----------------------------------------------------------------
343%project in a patch
344function  [ProjData,errormsg]=proj_patch(FieldData,ObjectData)%%
345%-------------------------------------------------------------------
346[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
347if ~isempty(errormsg)
348    return
349end
350%objectfield=fieldnames(ObjectData);
351widthx=0;
352widthy=0;
353if isfield(ObjectData,'RangeX') && ~isempty(ObjectData.RangeX)
354    widthx=max(ObjectData.RangeX);
355end
356if isfield(ObjectData,'RangeY') && ~isempty(ObjectData.RangeY)
357    widthy=max(ObjectData.RangeY);
358end
359
360%A REVOIR, GENERALISER: UTILISER proj_line
361ProjData.NbDim=1;
362ProjData.ListVarName={};
363ProjData.VarDimName={};
364ProjData.VarAttribute={};
365
366CoordMesh=zeros(1,numel(FieldData.ListVarName));
367if isfield (FieldData,'VarAttribute')
368    for iattr=1:length(FieldData.VarAttribute)%initialization of variable attribute values
369        if isfield(FieldData.VarAttribute{iattr},'Unit')
370            unit{iattr}=FieldData.VarAttribute{iattr}.Unit;
371        end
372        if isfield(FieldData.VarAttribute{iattr},'CoordMesh')
373            CoordMesh(iattr)=FieldData.VarAttribute{iattr}.CoordMesh;
374        end
375    end
376end
377
378%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
379[CellInfo,NbDim,errormsg]=find_field_cells(FieldData);
380if ~isempty(errormsg)
381    errormsg=['error in proj_field/proj_patch:' errormsg];
382    return
383end
384
385%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
386for icell=1:length(CellInfo)
387    CoordType=CellInfo{icell}.CoordType;
388%     testY=0;
389    test_Amat=0;
390    if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2
391        continue
392    end
393    ivar_FF=[];
394    testfalse=isfield(CellInfo{icell},'VarIndex_errorflag');
395    if testfalse
396        ivar_FF=CellInfo{icell}.VarIndex_errorflag;
397        FFName=FieldData.ListVarName{ivar_FF};
398        errorflag=FieldData.(FFName);
399    end
400    % select types of  variables to be projected
401    ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
402    check_proj=false(size(FieldData.ListVarName));
403    for ilist=1:numel(ListProj)
404        if isfield(CellInfo{icell},ListProj{ilist})
405            check_proj(CellInfo{icell}.(ListProj{ilist}))=1;
406        end
407    end
408    VarIndex=find(check_proj);
409   
410    ivar_X=CellInfo{icell}.CoordIndex(end);
411    ivar_Y=CellInfo{icell}.CoordIndex(end-1);
412    ivar_Z=[];
413    if NbDim(icell)==3
414        ivar_Z=CellInfo{icell}.CoordIndex(1);
415    end
416    switch CellInfo{icell}.CoordType
417        case 'scattered' %case of unstructured coordinates
418            for ivar=[VarIndex ivar_X ivar_Y ivar_FF]
419                VarName=FieldData.ListVarName{ivar};
420                FieldData.(VarName)=reshape(FieldData.(VarName),[],1);
421            end
422            XName=FieldData.ListVarName{ivar_X};
423            YName=FieldData.ListVarName{ivar_Y};
424            coord_x=FieldData.(FieldData.ListVarName{ivar_X});
425            coord_y=FieldData.(FieldData.ListVarName{ivar_Y});
426            % image or 2D matrix
427        case 'grid' %case of structured coordinates
428            test_Amat=1;% test for image or 2D matrix
429            AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
430            AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
431            AX=FieldData.(AXName);% x coordinate
432            AY=FieldData.(AYName);% y coordinate
433            VarName=FieldData.ListVarName{VarIndex(1)};
434            DimValue=size(FieldData.(VarName));
435            if length(AX)==2
436                AX=linspace(AX(1),AX(end),DimValue(2));
437            end
438            if length(AY)==2
439                AY=linspace(AY(1),AY(end),DimValue(1));
440            end
441            if length(DimValue)==3
442                testcolor=1;
443                npxy(3)=3;
444            else
445                testcolor=0;
446                npxy(3)=1;
447            end
448            [Xi,Yi]=meshgrid(AX,AY);
449            npxy(1)=length(AY);
450            npxy(2)=length(AX);
451            Xi=reshape(Xi,npxy(1)*npxy(2),1);
452            Yi=reshape(Yi,npxy(1)*npxy(2),1);
453            for ivar=1:length(VarIndex)
454                VarName=FieldData.ListVarName{VarIndex(ivar)};
455                FieldData.(VarName)=reshape(FieldData.(VarName),npxy(1)*npxy(2),npxy(3)); % keep only non false vectors
456            end
457    end
458    %select the indices in the range of action
459    testin=[];%default
460    if isequal(ObjectData.Type,'rectangle')
461        if strcmp(CellInfo{icell}.CoordType,'scattered')
462            distX=abs(coord_x-ObjectData.Coord(1,1));
463            distY=abs(coord_y-ObjectData.Coord(1,2));
464            testin=distX<widthx & distY<widthy;
465        elseif test_Amat
466            distX=abs(Xi-ObjectData.Coord(1,1));
467            distY=abs(Yi-ObjectData.Coord(1,2));
468            testin=distX<widthx & distY<widthy;
469        end
470    elseif isequal(ObjectData.Type,'polygon')
471        if strcmp(CoordType,'scattered')
472            testin=inpolygon(coord_x,coord_y,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
473        elseif strcmp(CoordType,'grid')
474            testin=inpolygon(Xi,Yi,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
475        else%calculate the scalar
476            testin=[]; %A REVOIR
477        end
478    elseif isequal(ObjectData.Type,'ellipse')
479        X2Max=widthx*widthx;
480        Y2Max=(widthy)*(widthy);
481        if strcmp(CoordType,'scattered')
482            distX=(coord_x-ObjectData.Coord(1,1));
483            distY=(coord_y-ObjectData.Coord(1,2));
484            testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
485        elseif strcmp(CoordType,'grid') %case of usual 2x2 matrix
486            distX=(Xi-ObjectData.Coord(1,1));
487            distY=(Yi-ObjectData.Coord(1,2));
488            testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
489        end
490    end
491    %selected indices
492    if isequal(ObjectData.ProjMode,'outside')
493        testin=~testin;
494    end
495    if testfalse
496        testin=testin & (errorflag==0); % keep only non false vectors
497    end
498    indsel=find(testin);
499    for ivar=VarIndex
500        VarName=FieldData.ListVarName{ivar};
501        ProjData.([VarName 'Mean'])=mean(double(FieldData.(VarName)(indsel,:))); % take the mean in the selected region, for each color component
502        ProjData.([VarName 'Min'])=min(double(FieldData.(VarName)(indsel,:))); % take the min in the selected region , for each color component
503        ProjData.([VarName 'Max'])=max(double(FieldData.(VarName)(indsel,:))); % take the max in the selected region , for each color component
504        if isequal(CoordMesh(ivar),0)
505            [ProjData.([VarName 'Histo']),ProjData.(VarName)]=hist(double(FieldData.(VarName)(indsel,:,:)),100); % default histogram with 100 bins
506        else
507            ProjData.(VarName)=ProjData.([VarName 'Min'])+CoordMesh(ivar)/2:CoordMesh(ivar):ProjData.([VarName 'Max']); % list of bin values
508            ProjData.([VarName 'Histo'])=hist(double(FieldData.(VarName)(indsel,:)),ProjData.(VarName)); % histogram at predefined bin positions
509        end
510        ProjData.ListVarName=[ProjData.ListVarName {VarName} {[VarName 'Histo']} {[VarName 'Mean']} {[VarName 'Min']} {[VarName 'Max']}];
511        if test_Amat && testcolor
512            ProjData.VarDimName=[ProjData.VarDimName  {VarName} {{VarName,'rgb'}} {'rgb'} {'rgb'} {'rgb'}];%{{'nb_point','rgb'}};
513        else
514            ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'one'} {'one'} {'one'}];
515        end
516        if isfield(FieldData,'VarAttribute')&& numel(FieldData.VarAttribute)>=ivar
517            ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute{ivar} {[]} {[]} {[]} {[]}];
518        end
519    end
520end
521
522%-----------------------------------------------------------------
523%project on a line
524% AJOUTER flux,circul,error
525% OUTPUT:
526% ProjData: projected field
527%
528function  [ProjData,errormsg] = proj_line(FieldData, ObjectData)
529%-----------------------------------------------------------------
530[ProjData,errormsg]=proj_heading(FieldData,ObjectData);%transfer global attributes
531if ~isempty(errormsg)
532    return
533end
534ProjData.NbDim=1;
535%initialisation of the input parameters and defaultoutput
536ProjMode=ObjectData.ProjMode; %rmq: ProjMode always defined from input={'projection','interp_lin','interp_tps'}
537% ProjAngle=90; %90 degrees projection by default
538width=0;
539if isfield(ObjectData,'RangeY')
540    width=max(ObjectData.RangeY);%Rangey needed bfor mode 'projection'
541end
542% default output
543errormsg='';%default
544Xline=[];
545flux=0;
546circul=0;
547liny=ObjectData.Coord(:,2);
548NbPoints=size(ObjectData.Coord,1);
549testfalse=0;
550ListIndex={};
551
552
553%% projection line: object types selected from  proj_field='line','polyline','polygon','rectangle','ellipse':
554LineCoord=ObjectData.Coord;
555switch ObjectData.Type
556    case 'ellipse'
557        LineLength=2*pi*ObjectData.RangeX*ObjectData.RangeY;
558        NbSegment=0;
559    case 'rectangle'
560        LineCoord([1 4],1)=ObjectData.Coord(1,1)-ObjectData.RangeX;
561        LineCoord([1 2],2)=ObjectData.Coord(1,2)-ObjectData.RangeY;
562        LineCoord([2 3],1)=ObjectData.Coord(1,1)+ObjectData.RangeX;
563        LineCoord([4 1],2)=ObjectData.Coord(1,2)+ObjectData.RangeY;
564    case 'polygon'
565        LineCoord(NbPoints+1)=LineCoord(1);
566end
567if ~strcmp(ObjectData.Type,'ellipse')
568    if ~strcmp(ObjectData.Type,'rectangle') && NbPoints<2
569        return% line needs at least 2 points to be defined
570    end
571    dlinx=diff(LineCoord(:,1));
572    dliny=diff(LineCoord(:,2));
573    [theta,dlength]=cart2pol(dlinx,dliny);%angle and length of each segment
574    LineLength=sum(dlength);
575    NbSegment=numel(LineLength);
576end
577CheckClosedLine=~isempty(find(strcmp(ObjectData.Type,{'rectangle','ellipse','polygon'})));
578
579%     x = a \ \cosh \mu \ \cos \nu
580%
581%     y = a \ \sinh \mu \ \sin \nu
582
583%% angles of the polyline and boundaries of action for mode 'projection'
584
585% determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'interp_tps')
586xsup=zeros(1,NbPoints); xinf=zeros(1,NbPoints); ysup=zeros(1,NbPoints); yinf=zeros(1,NbPoints);
587if isequal(ProjMode,'projection')
588    if strcmp(ObjectData.Type,'line')
589        xsup=ObjectData.Coord(:,1)-width*sin(theta);
590        xinf=ObjectData.Coord(:,1)+width*sin(theta);
591        ysup=ObjectData.Coord(:,2)+width*cos(theta);
592        yinf=ObjectData.Coord(:,2)-width*cos(theta);
593    else
594        errormsg='mode projection only available for simple line, use interpolation otherwise';
595        return
596    end
597else % need to define the set of interpolation points
598    if isfield(ObjectData,'DX') && ~isempty(ObjectData.DX)
599        DX=abs(ObjectData.DX);%mesh of interpolation points along the line
600        if CheckClosedLine
601            NbPoint=ceil(LineLength/DX);
602            DX=LineLength/NbPoint;%adjust DX to get an integer nbre of intervals in a closed line
603            DX_edge=DX/2;
604        else
605            DX_edge=(LineLength-DX*floor(LineLength/DX))/2;%margin from the first point and first interpolation point, the same for the end point
606        end
607        XI=[];
608        YI=[];
609        ThetaI=[];
610        dlengthI=[];
611        if strcmp(ObjectData.Type,'ellipse')
612            phi=(DX_edge:DX:LineLength)*2*pi/LineLength;
613            XI=ObjectData.RangeX*cos(phi);
614            YI=ObjectData.RangeY*sin(phi);
615            dphi=2*pi*DX/LineLength;
616            [ThetaI,dlengthI]=cart2pol(-ObjectData.RangeX*sin(phi)*dphi,ObjectData.RangeY*cos(phi)*dphi);
617        else
618            for isegment=1:NbSegment
619                costheta=cos(theta(isegment));
620                sintheta=sin(theta(isegment));
621                %                 XIsegment=LineCoord(isegment,1)+DX_edge*costheta:DX*costheta:LineCoord(isegment+1,1));
622                %                 YIsegment=(LineCoord(isegment,2)+DX_edge*sintheta:DX*sintheta:LineCoord(isegment+1,2));
623                NbInterval=floor((dlength(isegment)-DX_edge)/DX);
624                LastX=DX_edge+DX*NbInterval;
625                NbPoint=NbInterval+1;
626                XIsegment=linspace(LineCoord(isegment,1)+DX_edge*costheta,LineCoord(isegment,1)+LastX*costheta,NbPoint);
627                YIsegment=linspace(LineCoord(isegment,2)+DX_edge*sintheta,LineCoord(isegment,2)+LastX*sintheta,NbPoint);
628                XI=[XI XIsegment];
629                YI=[YI YIsegment];
630                ThetaI=[ThetaI theta(isegment)*ones(1,numel(XIsegment))];
631                dlengthI=[dlengthI DX*ones(1,numel(XIsegment))];
632                DX_edge=DX-(dlength(isegment)-LastX);%edge for the next segment set to keep DX=DX_end+DX_edge between two segments
633            end
634        end
635        Xproj=cumsum(dlengthI);
636    else
637        errormsg='abscissa mesh along line DX needed for interpolation';
638        return
639    end
640end
641
642
643%% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
644[CellInfo,NbDim,errormsg]=find_field_cells(FieldData);
645if ~isempty(errormsg)
646    errormsg=['error in proj_field/proj_line:' errormsg];
647    return
648end
649CellInfo=CellInfo(NbDim==2); %keep only the 2D cells
650%%%%%% TODO: treat 1D fields: project as identity so that P o P=P for projection operation
651
652%% loop on variable cells with the same space dimension 2
653ProjData.ListVarName={};
654ProjData.VarDimName={};
655check_abscissa=0;
656for icell=1:length(CellInfo)
657    % list of variable types to be projected
658    ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
659    check_proj=false(size(FieldData.ListVarName));
660    for ilist=1:numel(ListProj)
661        if isfield(CellInfo{icell},ListProj{ilist})
662            check_proj(CellInfo{icell}.(ListProj{ilist}))=1;
663        end
664    end
665    VarIndex=find(check_proj);% indices of the variables to be projected
666   
667    %% identify vector components
668    %testU=isfield(CellInfo{icell},'VarIndex_vector_x') &&isfield(CellInfo{icell},'VarIndex_vector_y') ;% test for vectors
669    %     if testU
670    %         UName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x};
671    %         VName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y};
672    %         vector_x=FieldData.(UName);
673    %         vector_y=FieldData.(VName);
674    %     end
675    %identify error flag
676    errorflag=0; %default, no error flag
677    if isfield(CellInfo{icell},'VarIndex_errorflag');% test for error flag
678        FFName=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag};
679        errorflag=FieldData.(FFName);
680    end
681    VarName=FieldData.ListVarName(VarIndex);% cell array of the names of variables to pje
682    ivar_U=[];
683    ivar_V=[];
684    %% check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
685   
686    %         circul=0;
687    %         flux=0;
688    %%%%%%%  % A FAIRE CALCULER MEAN DES QUANTITES    %%%%%%
689    switch CellInfo{icell}.CoordType
690        %case of unstructured coordinates
691        case 'scattered'
692%             XName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
693%             YName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
694            coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});
695            coord_y=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)});
696           
697            if isequal(ProjMode,'projection')
698                if width==0
699                    errormsg='range of the projection object is missing';
700                    return
701                end
702                ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName(CellInfo{icell}.CoordIndex(end))];
703                ProjData.VarDimName=[ProjData.VarDimName FieldData.ListVarName(CellInfo{icell}.CoordIndex(end))];
704                nbvar=numel(ProjData.ListVarName);
705                ProjData.VarAttribute{nbvar}.long_name='abscissa along line';
706                % select the (non false) input data located in the band of projection
707                flagsel=(errorflag==0) & ((coord_y -yinf(1))*(xinf(2)-xinf(1))>(coord_x-xinf(1))*(yinf(2)-yinf(1))) ...
708                    & ((coord_y -ysup(1))*(xsup(2)-xsup(1))<(coord_x-xsup(1))*(ysup(2)-ysup(1))) ...
709                    & ((coord_y -yinf(2))*(xsup(2)-xinf(2))>(coord_x-xinf(2))*(ysup(2)-yinf(2))) ...
710                    & ((coord_y -yinf(1))*(xsup(1)-xinf(1))<(coord_x-xinf(1))*(ysup(1)-yinf(1)));
711                coord_x=coord_x(flagsel);
712                coord_y=coord_y(flagsel);
713                costheta=cos(theta);
714                sintheta=sin(theta);
715                Xproj=(coord_x-ObjectData.Coord(1,1))*costheta + (coord_y-ObjectData.Coord(1,2))*sintheta; %projection on the line
716                [Xproj,indsort]=sort(Xproj);% sort points by increasing absissa along the projection line
717                ProjData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)})=Xproj;
718                for ivar=1:numel(VarIndex)
719                    ProjData.(VarName{ivar})=FieldData.(VarName{ivar})(flagsel);% restrict variables to the projection band
720                    ProjData.(VarName{ivar})=ProjData.(VarName{ivar})(indsort);% sort by absissa
721                    ProjData.ListVarName=[ProjData.ListVarName VarName{ivar}];
722                    ProjData.VarDimName=[ProjData.VarDimName FieldData.ListVarName(CellInfo{icell}.CoordIndex(end))];
723                    ProjData.VarAttribute{nbvar+ivar}=FieldData.VarAttribute{VarIndex(ivar)};%reproduce var attribute
724                    if isfield(ProjData.VarAttribute{nbvar+ivar},'Role')
725                        if  strcmp(ProjData.VarAttribute{nbvar+ivar}.Role,'vector_x');
726                            ivar_U=nbvar+ivar;
727                        elseif strcmp(ProjData.VarAttribute{nbvar+ivar}.Role,'vector_y');
728                            ivar_V=nbvar+ivar;
729                        end
730                    end
731                    ProjData.VarAttribute{ivar+nbvar}.Role='discrete';% will promote plots of the profiles with continuous lines
732                end
733            elseif isequal(ProjMode,'interp_lin')  %filtering %linear interpolation:
734                if ~check_abscissa
735                    XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
736                    ProjData.ListVarName=[ProjData.ListVarName {XName}];
737                    ProjData.VarDimName=[ProjData.VarDimName {XName}];
738                    nbvar=numel(ProjData.ListVarName);
739                    ProjData.VarAttribute{nbvar}.long_name='abscissa along line';
740                    check_abscissa=1; % define abcissa only once
741                end
742                if ~isequal(errorflag,0)
743                    VarName_FF=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag};
744                    indsel=find(FieldData.(VarName_FF)==0);
745                    coord_x=coord_x(indsel);
746                    coord_y=coord_y(indsel);
747                    for ivar=1:numel(CellInfo{icell}.VarIndex)
748                        VarName=FieldData.ListVarName{CellInfo{icell}.VarIndex(ivar)};
749                        FieldData.(VarName)=FieldData.(VarName)(indsel);
750                    end
751                end
752                [ProjVar,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_x coord_y],FieldData,CellInfo{icell}.FieldName,XI,YI);
753                ProjData.X=Xproj;
754                nbvar=numel(ProjData.ListVarName);
755                ProjData.ListVarName=[ProjData.ListVarName ListFieldProj];
756                ProjData.VarAttribute=[ProjData.VarAttribute VarAttribute];
757                for ivar=1:numel(VarAttribute)
758                    ProjData.VarDimName=[ProjData.VarDimName {XName}];
759                    if isfield(VarAttribute{ivar},'Role')
760                        if  strcmp(VarAttribute{ivar}.Role,'vector_x');
761                            ivar_U=ivar+nbvar;
762                        elseif strcmp(VarAttribute{ivar}.Role,'vector_y');
763                            ivar_V=ivar+nbvar;
764                        end
765                    end
766                    ProjData.VarAttribute{ivar+nbvar}.Role='continuous';% will promote plots of the profiles with continuous lines
767                    ProjData.(ListFieldProj{ivar})=ProjVar{ivar};
768                end
769            end
770        case 'tps'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
771            if strcmp(ProjMode,'interp_tps')
772                Coord=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex});
773                NbCentres=FieldData.(FieldData.ListVarName{CellInfo{icell}.NbCentres_tps});
774                SubRange=FieldData.(FieldData.ListVarName{CellInfo{icell}.SubRange_tps});
775                if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps')
776                    FieldVar=cat(3,FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x_tps}),FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y_tps}));
777                end
778                [DataOut,VarAttribute,errormsg]=calc_field_tps(Coord,NbCentres,SubRange,FieldVar,CellInfo{icell}.FieldName,cat(3,XI,YI));
779                ProjData.ListVarName=[ProjData.ListVarName {'X'}];
780                ProjData.VarDimName=[ProjData.VarDimName {'X'}];
781                ProjData.X=Xproj;
782                nbvar=numel(ProjData.ListVarName);
783                ProjData.VarAttribute{nbvar}.long_name='abscissa along line';
784                ProjVarName=(fieldnames(DataOut))';
785                ProjData.ListVarName=[ProjData.ListVarName ProjVarName];
786                ProjData.VarAttribute=[ProjData.VarAttribute VarAttribute];
787                for ivar=1:numel(VarAttribute)
788                    ProjData.VarDimName=[ProjData.VarDimName {'X'}];
789                    if isfield(VarAttribute{ivar},'Role')
790                        if  strcmp(VarAttribute{ivar}.Role,'vector_x');
791                            ivar_U=ivar+nbvar;
792                        elseif strcmp(VarAttribute{ivar}.Role,'vector_y');
793                            ivar_V=ivar+nbvar;
794                        end
795                    end
796                    ProjData.VarAttribute{ivar+nbvar}.Role='continuous';% will promote plots of the profiles with continuous lines
797                    ProjData.(ProjVarName{ivar})=DataOut.(ProjVarName{ivar});
798                end
799            end
800            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
801           
802        case 'grid'   %case of structured coordinates
803            if ~isequal(ObjectData.Type,'line')% exclude polyline
804                errormsg=['no  projection available on ' ObjectData.Type 'for structured coordinates']; %
805            else
806                test_Amat=1;%image or 2D matrix
807                test_interp2=0;%default
808                AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
809                AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
810                eval(['AX=FieldData.' AXName ';']);% set of x positions
811                eval(['AY=FieldData.' AYName ';']);% set of y positions
812                AName=FieldData.ListVarName{VarIndex(1)};
813                eval(['A=FieldData.' AName ';']);% scalar
814                npxy=size(A);
815                npx=npxy(2);
816                npy=npxy(1);
817                if numel(AX)==2
818                    DX=(AX(2)-AX(1))/(npx-1);
819                else
820                    DX_vec=diff(AX);
821                    DX=max(DX_vec);
822                    DX_min=min(DX_vec);
823                    if (DX-DX_min)>0.0001*abs(DX)
824                        test_interp2=1;
825                        DX=DX_min;
826                    end
827                end
828                if numel(AY)==2
829                    DY=(AY(2)-AY(1))/(npy-1);
830                else
831                    DY_vec=diff(AY);
832                    DY=max(DY_vec);
833                    DY_min=min(DY_vec);
834                    if (DY-DY_min)>0.0001*abs(DY)
835                        test_interp2=1;
836                        DY=DY_min;
837                    end
838                end
839                AXI=linspace(AX(1),AX(end), npx);%set of  x  positions for the interpolated input data
840                AYI=linspace(AY(1),AY(end), npy);%set of  x  positions for the interpolated input data
841                if isfield(ObjectData,'DX')
842                    DXY_line=ObjectData.DX;%mesh on the projection line
843                else
844                    DXY_line=sqrt(abs(DX*DY));% mesh on the projection line
845                end
846                dlinx=ObjectData.Coord(2,1)-ObjectData.Coord(1,1);
847                dliny=ObjectData.Coord(2,2)-ObjectData.Coord(1,2);
848                linelength=sqrt(dlinx*dlinx+dliny*dliny);
849                theta=angle(dlinx+i*dliny);%angle of the line
850                if isfield(FieldData,'RangeX')
851                    XMin=min(FieldData.RangeX);%shift of the origin on the line
852                else
853                    XMin=0;
854                end
855                eval(['ProjData.' AXName '=linspace(XMin,XMin+linelength,linelength/DXY_line+1);'])%abscissa of the new pixels along the line
856                y=linspace(-width,width,2*width/DXY_line+1);%ordintes of the new pixels (coordinate across the line)
857                eval(['npX=length(ProjData.' AXName ');'])
858                npY=length(y); %TODO: utiliser proj_grid
859                eval(['[X,Y]=meshgrid(ProjData.' AXName ',y);'])%grid in the line coordinates
860                XIMA=ObjectData.Coord(1,1)+(X-XMin)*cos(theta)-Y*sin(theta);
861                YIMA=ObjectData.Coord(1,2)+(X-XMin)*sin(theta)+Y*cos(theta);
862                XIMA=(XIMA-AX(1))/DX+1;%  index of the original image along x
863                YIMA=(YIMA-AY(1))/DY+1;% index of the original image along y
864                XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
865                YIMA=reshape(round(YIMA),1,npX*npY);
866                flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
867                ind_in=find(flagin);
868                ind_out=find(~flagin);
869                ICOMB=(XIMA-1)*npy+YIMA;
870                ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
871                nbcolor=1; %color images
872                if numel(npxy)==2
873                    nbcolor=1;
874                elseif length(npxy)==3
875                    nbcolor=npxy(3);
876                else
877                    errormsg='multicomponent field not projected';
878                    display(errormsg)
879                    return
880                end
881                nbvar=length(ProjData.ListVarName);% number of var from previous cells
882                ProjData.ListVarName=[ProjData.ListVarName {AXName}];
883                ProjData.VarDimName=[ProjData.VarDimName {AXName}];
884                for ivar=VarIndex
885                    %VarName{ivar}=FieldData.ListVarName{ivar};
886                    if test_interp2% interpolate on new grid
887                        FieldData.(FieldData.ListVarName{ivar})=interp2(FieldData.(AXName),FieldData.(AYName),FieldData.(FieldData.ListVarName{ivar}),AXI,AYI);%TO TEST
888                    end
889                    vec_A=reshape(squeeze(FieldData.(FieldData.ListVarName{ivar})),npx*npy,nbcolor); %put the original image in colum
890                    if nbcolor==1
891                        vec_B(ind_in)=vec_A(ICOMB);
892                        vec_B(ind_out)=zeros(size(ind_out));
893                        A_out=reshape(vec_B,npY,npX);
894                        ProjData.(FieldData.ListVarName{ivar}) =sum(A_out,1)/npY;
895                    elseif nbcolor==3
896                        vec_B(ind_in,1:3)=vec_A(ICOMB,:);
897                        vec_B(ind_out,1)=zeros(size(ind_out));
898                        vec_B(ind_out,2)=zeros(size(ind_out));
899                        vec_B(ind_out,3)=zeros(size(ind_out));
900                        A_out=reshape(vec_B,npY,npX,nbcolor);
901                        ProjData.(FieldData.ListVarName{ivar})=squeeze(sum(A_out,1)/npY);
902                    end
903                    ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName{ivar}];
904                    ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate
905                    ProjData.VarAttribute{ivar}.Role='continuous';% for plot with continuous line
906                end
907                if nbcolor==3
908                    ProjData.VarDimName{end}={AXName,'rgb'};
909                end
910            end
911    end
912    if ~isempty(ivar_U) && ~isempty(ivar_V)
913        vector_x =ProjData.(ProjData.ListVarName{ivar_U});
914        ProjData.(ProjData.ListVarName{ivar_U}) =cos(theta)*vector_x+sin(theta)*ProjData.(ProjData.ListVarName{ivar_V});
915        ProjData.(ProjData.ListVarName{ivar_V}) =-sin(theta)*vector_x+cos(theta)*ProjData.(ProjData.ListVarName{ivar_V});
916    end
917end
918
919% %shotarter case for horizontal or vertical line (A FAIRE
920% %     Rangx=[0.5 npx-0.5];%image coordiantes of corners
921% %     Rangy=[npy-0.5 0.5];
922% %     if isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
923% %         Rangx=Rangx/Calib.Pxcmx;
924% %         Rangy=Rangy/Calib.Pxcmy;
925% %     else
926% %         [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[0 0]);%case of translations without rotation and quadratic deformation
927% %         [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[0 0]);
928% %     end
929%
930% %     test_scal=0;%default% 3- 'UserData':(get(handles.Tag,'UserData')
931
932
933%-----------------------------------------------------------------
934%project on a plane
935% AJOUTER flux,circul,error
936function  [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
937%-----------------------------------------------------------------
938
939%% rotation angles
940PlaneAngle=[0 0 0];
941norm_plane=[0 0 1];
942cos_om=1;
943sin_om=0;
944test90x=0;%=1 for 90 degree rotation alround x axis
945test90y=0;%=1 for 90 degree rotation alround y axis
946if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0])
947    test90y=isequal(ObjectData.Angle,[0 90 0]);
948    PlaneAngle=(pi/180)*ObjectData.Angle;
949    om=norm(PlaneAngle);%norm of rotation angle in radians
950    OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
951    cos_om=cos(om);
952    sin_om=sin(om);
953    coeff=OmAxis(3)*(1-cos_om);
954    %components of the unity vector norm_plane normal to the projection plane
955    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
956    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
957    norm_plane(3)=OmAxis(3)*coeff+cos_om;
958end
959testangle=~isequal(PlaneAngle,[0 0 0])||~isequal(ObjectData.Coord(1:2),[0 0 ]) ;% && ~test90y && ~test90x;%=1 for slanted plane
960
961%% mesh sizes DX and DY
962DX=[];
963DY=[];%default
964if isfield(ObjectData,'DX') && ~isempty(ObjectData.DX)
965    DX=abs(ObjectData.DX);%mesh of interpolation points
966elseif isfield(FieldData,'CoordMesh')
967    DX=FieldData.CoordMesh;
968end
969if isfield(ObjectData,'DY') && ~isempty(ObjectData.DY)
970    DY=abs(ObjectData.DY);%mesh of interpolation points
971elseif isfield(FieldData,'CoordMesh')
972    DY=FieldData.CoordMesh;
973end
974if  ~strcmp(ObjectData.ProjMode,'projection') && (isempty(DX)||isempty(DY))
975    errormsg='DX or DY not defined';
976    return
977end
978
979%% extrema along each axis
980testXMin=0;% test if min of X coordinates defined on the projection object, =0 by default
981testXMax=0;% test if max of X coordinates defined on the projection object, =0 by default
982testYMin=0;% test if min of Y coordinates defined on the projection object, =0 by default
983testYMax=0;% test if max of Y coordinates defined on the projection object, =0 by default
984if isfield(ObjectData,'RangeX') % rangeX defined by the projection object
985    XMin=min(ObjectData.RangeX);
986    XMax=max(ObjectData.RangeX);
987    testXMin=XMax>XMin;%=1 if XMin defined (i.e. RangeY has two distinct elements)
988    testXMax=1;% max of X coordinates defined on the projection object
989end
990if isfield(ObjectData,'RangeY') % rangeY defined by the projection object
991    YMin=min(ObjectData.RangeY);
992    YMax=max(ObjectData.RangeY);
993    testYMin=YMax>YMin;%=1 if YMin defined (i.e. RangeY has tow distinct elements)
994    testYMax=1;% max of Y coordinates defined on the projection object
995end
996width=0;%default width of the projection band
997if isfield(ObjectData,'RangeZ')
998    width=max(ObjectData.RangeZ);
999end
1000
1001%% initiate Matlab  structure for physical field
1002[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
1003if ~isempty(errormsg)
1004    return
1005end
1006
1007%% reproduce initial plane position and angle
1008if isfield(FieldData,'PlaneCoord')&&length(FieldData.PlaneCoord)==3&& isfield(ProjData,'ProjObjectCoord')
1009    if length(ProjData.ProjObjectCoord)==3% if the projection plane has a z coordinate
1010        if isfield(ProjData,'.PlaneCoord') && ~isequal(ProjData.PlaneCoord(3),ProjData.ProjObjectCoord) %check the consistency with the z coordinate of the field plane (set by calibration)
1011            errormsg='inconsistent z position for field and projection plane';
1012            return
1013        end
1014    else % the z coordinate is set only by the field plane (by calibration)
1015        ProjData.ProjObjectCoord(3)=FieldData.PlaneCoord(3);
1016    end
1017    if isfield(FieldData,'PlaneAngle')
1018        if isfield(ProjData,'ProjObjectAngle')
1019            if ~isequal(FieldData.PlaneAngle,ProjData.ProjObjectAngle) %check the consistency with the z coordinate of the field plane (set by calibration)
1020                errormsg='inconsistent plane angle for field and projection plane';
1021                return
1022            end
1023        else
1024            ProjData.ProjObjectAngle=FieldData.PlaneAngle;
1025        end
1026    end
1027end
1028ProjData.NbDim=2;
1029ProjData.ListVarName={};
1030ProjData.VarDimName={};
1031ProjData.VarAttribute={};
1032if ~isempty(DX) && ~isempty(DY)
1033    ProjData.CoordMesh=sqrt(DX*DY);%define typical data mesh, useful for mouse selection in plots
1034elseif isfield(FieldData,'CoordMesh')
1035    ProjData.CoordMesh=FieldData.CoordMesh;
1036end
1037error=0;%default
1038flux=0;
1039testfalse=0;
1040ListIndex={};
1041
1042%% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
1043[CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData);
1044
1045if ~isempty(errormsg)
1046    errormsg=['error in proj_field/proj_plane:' errormsg];
1047    return
1048end
1049check_grid=zeros(size(CellInfo));% =1 if a grid is needed , =0 otherwise, for each field cell
1050
1051ProjMode=cell(size(CellInfo));
1052for icell=1:numel(CellInfo)
1053    ProjMode{icell}=ObjectData.ProjMode;% projection mode of the plane object
1054end
1055    icell_grid=[];% field cell index which defines the grid
1056if ~strcmp(ObjectData.ProjMode,'projection')
1057    %% define the new coordinates in case of interpolation on a imposed grid
1058    if ~testYMin
1059        errormsg='min Y value not defined for the projection grid';return
1060    end
1061    if ~testYMax
1062        errormsg='max Y value not defined for the projection grid';return
1063    end
1064    if ~testXMin
1065        errormsg='min X value not defined for the projection grid';return
1066    end
1067    if ~testXMax
1068        errormsg='max X value not defined for the projection grid';return
1069    end
1070else
1071    %% case of a grid requested by the input field
1072    for icell=1:numel(CellInfo)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates
1073        if isfield(CellInfo{icell},'ProjModeRequest')
1074            switch CellInfo{icell}.ProjModeRequest
1075                case 'interp_lin'
1076                    ProjMode{icell}='interp_lin';
1077                case 'interp_tps'
1078                    ProjMode{icell}='interp_tps';
1079            end
1080        end
1081        if strcmp(ProjMode{icell},'interp_lin')||strcmp(ProjMode{icell},'interp_tps')
1082            check_grid(icell)=1;
1083        end
1084        if strcmp(CellInfo{icell}.CoordType,'grid')&&NbDimArray(icell)>=2
1085            if ~testangle && isempty(icell_grid)% if the input gridded data is not modified, choose the first one in case of multiple gridded field cells
1086                icell_grid=icell;
1087                ProjMode{icell}='projection';
1088            end
1089            check_grid(icell)=1;
1090        end
1091    end
1092    if ~isempty(find(check_grid))% if a grid is requested by the input field
1093        if isempty(icell_grid)%  if the grid is not given by cell #icell_grid
1094            if ~isfield(FieldData,'XMax')
1095                FieldData=find_field_bounds(FieldData);
1096            end
1097        end
1098    end
1099end
1100if ~isempty(find(check_grid))||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used
1101    if isempty(icell_grid)||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used
1102        AYName='coord_y';
1103        AXName='coord_x';
1104        if strcmp(ObjectData.ProjMode,'projection')
1105            ProjData.coord_y=[FieldData.YMin FieldData.YMax];%note that if projection is done on a grid, the Min and Max along each direction must have been defined
1106            ProjData.coord_x=[FieldData.XMin FieldData.XMax];
1107            coord_x_proj=FieldData.XMin:FieldData.CoordMesh:FieldData.XMax;
1108            coord_y_proj=FieldData.YMin:FieldData.CoordMesh:FieldData.YMax;
1109        else
1110            ProjData.coord_y=[ObjectData.RangeY(1) ObjectData.RangeY(2)];%note that if projection is done on a grid, the Min and Max along each direction must have been defined
1111            ProjData.coord_x=[ObjectData.RangeX(1) ObjectData.RangeX(2)];
1112            coord_x_proj=ObjectData.RangeX(1):ObjectData.DX:ObjectData.RangeX(2);
1113            coord_y_proj=ObjectData.RangeY(1):ObjectData.DY:ObjectData.RangeY(2);
1114        end
1115        [XI,YI]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
1116%         XI=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-YI*sin(PlaneAngle(3));%corresponding coordinates in the original system
1117%         YI=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+YI*cos(PlaneAngle(3));
1118    else% we use the existing grid from field cell #icell_grid
1119        NbDim=NbDimArray(icell_grid);
1120        AYName=FieldData.ListVarName{CellInfo{icell_grid}.CoordIndex(NbDim-1)};%name of input x coordinate (name preserved on projection)
1121        AXName=FieldData.ListVarName{CellInfo{icell_grid}.CoordIndex(NbDim)};%name of input y coordinate (name preserved on projection)
1122        ProjData.(AYName)=FieldData.(AYName); % new (projected ) y coordinates
1123        ProjData.(AXName)=FieldData.(AXName); % new (projected ) y coordinates
1124    end
1125    ProjData.ListVarName={AYName,AXName};
1126    ProjData.VarDimName={AYName,AXName};
1127    ProjData.VarAttribute={[],[]};
1128end
1129   
1130%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1131% LOOP ON FIELD CELLS, PROJECT VARIABLES
1132% CellVarIndex=cells of variable index arrays
1133%ivar_new=0; % index of the current variable in the projected field
1134% icoord=0;
1135nbcoord=0;%number of added coordinate variables brought by projection
1136%nbvar=0;
1137vector_x_proj=[];
1138vector_y_proj=[];
1139for icell=1:length(CellInfo)
1140    NbDim=NbDimArray(icell);
1141    if NbDim<2
1142        continue % only cells represnting 2D or 3D fields are involved
1143    end
1144    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
1145    %dimensions
1146    DimCell=FieldData.VarDimName{VarIndex(1)};
1147    if ischar(DimCell)
1148        DimCell={DimCell};%name of dimensions
1149    end
1150    coord_z=0;%default
1151    ListVarName={};% initiate list of projected variables for cell # icell
1152    VarDimName={};% initiate coresponding list of dimensions for cell # icell
1153    VarAttribute={};% initiate coresponding list of var attributes  for cell # icell
1154    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1155    switch CellInfo{icell}.CoordType
1156       
1157        case 'scattered'
1158            %% case of input fields with unstructured coordinates (applies for projMode ='projection' or 'interp_lin')
1159            if strcmp(ProjMode{icell},'interp_tps')
1160                continue %skip for next cell (needs tps field cell)
1161            end
1162            coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});% initial x coordinates
1163            coord_y=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)});% initial y coordinates
1164            check3D=(numel(CellInfo{icell}.CoordIndex)==3);
1165            if check3D
1166                coord_z=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});
1167            end
1168           
1169            % translate  initial coordinates to account for the new origin
1170            coord_x=coord_x-ObjectData.Coord(1,1);
1171            coord_y=coord_y-ObjectData.Coord(1,2);
1172            if check3D
1173                coord_z=coord_z-ObjectData.Coord(1,3);
1174            end
1175           
1176            % selection of the vectors in the projection range (3D case)
1177            if check3D &&  width > 0
1178                %components of the unitiy vector normal to the projection plane
1179                fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane
1180                indcut=find(abs(fieldZ) <= width);
1181                for ivar=VarIndex
1182                    VarName=FieldData.ListVarName{ivar};
1183                    FieldData.(VarName)=FieldData.(VarName)(indcut);
1184                end
1185                coord_x=coord_x(indcut);
1186                coord_y=coord_y(indcut);
1187                coord_z=coord_z(indcut);
1188            end
1189           
1190            %rotate coordinates if needed: coord_X,coord_Y= = coordinates in the new plane
1191            Psi=PlaneAngle(1);
1192            Theta=PlaneAngle(2);
1193            Phi=PlaneAngle(3);
1194            if testangle && ~test90y && ~test90x;%=1 for slanted plane
1195                coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
1196                coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
1197                coord_Y=coord_Y+coord_z *sin(Theta);
1198                coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
1199                coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
1200            else
1201                coord_X=coord_x;
1202                coord_Y=coord_y;
1203            end
1204           
1205            %restriction to the range of X and Y if imposed by the projection object
1206            testin=ones(size(coord_X)); %default
1207            testbound=0;
1208            if testXMin
1209                testin=testin & (coord_X >= XMin);
1210                testbound=1;
1211            end
1212            if testXMax
1213                testin=testin & (coord_X <= XMax);
1214                testbound=1;
1215            end
1216            if testYMin
1217                testin=testin & (coord_Y >= YMin);
1218                testbound=1;
1219            end
1220            if testYMin
1221                testin=testin & (coord_Y <= YMax);
1222                testbound=1;
1223            end
1224            if testbound
1225                indcut=find(testin);
1226                if isempty(indcut)
1227                    errormsg='data outside the bounds of the projection object';
1228                    return
1229                end
1230                for ivar=VarIndex
1231                    VarName=FieldData.ListVarName{ivar};
1232                    FieldData.(VarName)=FieldData.(VarName)(indcut);
1233                end
1234                coord_X=coord_X(indcut);
1235                coord_Y=coord_Y(indcut);
1236                if check3D
1237                    coord_Z=coord_Z(indcut);
1238                end
1239            end
1240           
1241            % two cases of projection for scattered coordinates
1242            switch ProjMode{icell}
1243                case 'projection'
1244                    nbvar=0;
1245                    %nbvar=numel(ProjData.ListVarName);
1246                    for ivar=VarIndex %transfer variables to the projection plane
1247                        VarName=FieldData.ListVarName{ivar};
1248                        if ivar==CellInfo{icell}.CoordIndex(end)
1249                            ProjData.(VarName)=coord_X;
1250                        elseif ivar==CellInfo{icell}.CoordIndex(end-1)  % y coordinate
1251                            ProjData.(VarName)=coord_Y;
1252                        elseif ~(check3D && ivar==CellInfo{icell}.CoordIndex(1)) % other variables (except Z coordinate wyhich is not reproduced)
1253                            ProjData.(VarName)=FieldData.(VarName);
1254                        end
1255                        if ~(check3D && ivar==CellInfo{icell}.CoordIndex(1))
1256                            ListVarName=[ListVarName VarName];
1257                            VarDimName=[VarDimName DimCell];
1258                            nbvar=nbvar+1;
1259                            if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
1260                                VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
1261                            end
1262                        end
1263                    end
1264                case 'interp_lin'%interpolate data on a regular grid
1265                    if isfield(CellInfo{icell},'VarIndex_errorflag')
1266                        VarName_FF=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag};
1267                        indsel=find(FieldData.(VarName_FF)==0);
1268                        coord_X=coord_X(indsel);
1269                        coord_Y=coord_Y(indsel);
1270                        for ivar=1:numel(CellInfo{icell}.VarIndex)
1271                            VarName=FieldData.ListVarName{CellInfo{icell}.VarIndex(ivar)};
1272                            FieldData.(VarName)=FieldData.(VarName)(indsel);
1273                        end
1274                    end
1275                    % interpolate and calculate field on the grid
1276                    [VarVal,ListVarName,VarAttribute,errormsg]=calc_field_interp([coord_X coord_Y],FieldData,CellInfo{icell}.FieldName,XI,YI);
1277                   
1278                    if isfield(CellInfo{icell},'CheckSub') && CellInfo{icell}.CheckSub && ~isempty(vector_x_proj)
1279                        ProjData.(FieldData.ListVarName{vector_x_proj})=ProjData.(FieldData.ListVarName{vector_x_proj})-VarVal{1};
1280                        ProjData.(FieldData.ListVarName{vector_y_proj})=ProjData.(FieldData.ListVarName{vector_y_proj})-VarVal{2};
1281                        ListVarName={};% no new variable
1282                        VarAttribute={};
1283                    else
1284                        VarDimName=cell(size(ListVarName));
1285                        for ilist=1:numel(ListVarName)% reshape data, excluding coordinates (ilist=1-2), TODO: rationalise
1286                            ListVarName{ilist}=regexprep(ListVarName{ilist},'(.+','');
1287                            if ~isempty(find(strcmp(ListVarName{ilist},ProjData.ListVarName)))
1288                                ListVarName{ilist}=[ListVarName{ilist} '_1'];
1289                            end
1290                            ProjData.(ListVarName{ilist})=VarVal{ilist};
1291                            VarDimName{ilist}={'coord_y','coord_x'};
1292                        end
1293                    end
1294                    vector_x_proj=CellInfo{icell}.VarIndex_vector_x; %preserve for next cell
1295                    vector_y_proj=CellInfo{icell}.VarIndex_vector_y; %preserve for next cell
1296            end
1297           
1298        case 'tps'
1299            %% case of tps data (applies only in interp_tps mode)
1300            if strcmp(ProjMode{icell},'interp_tps')
1301                Coord=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex});
1302                NbCentres=FieldData.(FieldData.ListVarName{CellInfo{icell}.NbCentres_tps});
1303                SubRange=FieldData.(FieldData.ListVarName{CellInfo{icell}.SubRange_tps});
1304                if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps')
1305                    FieldVar=cat(3,FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x_tps}),FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y_tps}));
1306                end
1307                [DataOut,VarAttribute,errormsg]=calc_field_tps(Coord,NbCentres,SubRange,FieldVar,CellInfo{icell}.FieldName,cat(3,XI,YI));
1308                ListVarName=(fieldnames(DataOut))';
1309                VarDimName=cell(size(ListVarName));
1310                for ilist=1:numel(ListVarName)% reshape data, excluding coordinates (ilist=1-2), TODO: rationalise
1311                    VarName=ListVarName{ilist};
1312                    ProjData.(VarName)=DataOut.(VarName);
1313                    VarDimName{ilist}={'coord_y','coord_x'};
1314                end
1315            end
1316           
1317        case 'grid'
1318            %% case of input fields defined on a structured  grid
1319            VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
1320            DimValue=size(FieldData.(VarName));%input matrix dimensions
1321            DimValue(DimValue==1)=[];%remove singleton dimensions
1322            NbDim=numel(DimValue);%update number of space dimensions
1323            nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
1324            if NbDim>=3
1325                if NbDim>3
1326                    errormsg='matrices with more than 3 dimensions not handled';
1327                    return
1328                else
1329                    if numel(CellInfo{icell}.CoordIndex)==2% the third matrix dimension does not correspond to a space coordinate
1330                        nbcolor=DimValue(3);
1331                        DimValue(3)=[]; %number of 'color' components updated
1332                        NbDim=2;% space dimension set to 2
1333                    end
1334                end
1335            end
1336            Coord_z=[];
1337            Coord_y=[];
1338            Coord_x=[];
1339           
1340            if testangle
1341                ProjMode{icell}='interp_lin'; %request linear interpolation for projection on a tilted plane
1342            end
1343           
1344            if isequal(ProjMode{icell},'projection')% && (~testangle || test90y || test90x)
1345                if  NbDim==2 && ~testXMin && ~testXMax && ~testYMin && ~testYMax% no range restriction
1346                    ListVarName=[ListVarName FieldData.ListVarName(VarIndex)];
1347                    VarDimName=[VarDimName FieldData.VarDimName(VarIndex)];
1348                    if isfield(FieldData,'VarAttribute')
1349                        VarAttribute=[VarAttribute FieldData.VarAttribute(VarIndex)];
1350                    end
1351                    ProjData.(AYName)=FieldData.(AYName);
1352                    ProjData.(AXName)=FieldData.(AXName);
1353                    for ivar=VarIndex
1354                        VarName=FieldData.ListVarName{ivar};
1355                        ProjData.(VarName)=FieldData.(VarName);% no change by projection
1356                    end
1357                else
1358                    Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});
1359                    Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)});
1360                    if NbDim==3
1361                        Coord{3}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(3)});
1362                    end
1363                    if numel(Coord{NbDim-1})==2
1364                        DY=(Coord{NbDim-1}(2)-Coord{NbDim-1}(1))/(DimValue(1)-1);
1365                    end
1366                    if numel(Coord{NbDim})==2
1367                        DX=(Coord{NbDim}(2)-Coord{NbDim}(1))/(DimValue(2)-1);
1368                    end
1369                    if testYMax
1370                         YIndexMax=(YMax-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the max y value for the new field
1371                        if testYMin%test_direct(indY)
1372                            YIndexMin=(YMin-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the min x value for the new field
1373                        else
1374                            YIndexMin=1;
1375                        end         
1376                    else
1377                        YIndexMax=Coord{NbDim-1}(end)/DY;
1378                        YIndexMin=1;
1379                    end
1380                    if testXMax
1381                         XIndexMax=(XMax-Coord{NbDim}(1))/DY+1;% matrix index corresponding to the max y value for the new field
1382                        if testYMin%test_direct(indY)
1383                            XIndexMin=(XMin-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the min x value for the new field
1384                        else
1385                            XIndexMin=1;
1386                        end         
1387                    else
1388                        XIndexMax=Coord{NbDim}(end)/DX;
1389                        XIndexMin=1;
1390                    end
1391                    YIndexRange(1)=ceil(min(YIndexMin,YIndexMax));%first y index to select from the previous field
1392                    YIndexRange(1)=max(YIndexRange(1),1);% avoid bound lower than the first index
1393                    YIndexRange(2)=floor(max(YIndexMin,YIndexMax));%last y index to select from the previous field
1394                    YIndexRange(2)=min(YIndexRange(2),DimValue(NbDim-1));% limit to the last available index
1395                    XIndexRange(1)=ceil(min(XIndexMin,XIndexMax));%first x index to select from the previous field
1396                    XIndexRange(1)=max(XIndexRange(1),1);% avoid bound lower than the first index
1397                    XIndexRange(2)=floor(max(XIndexMin,XIndexMax));%last x index to select from the previous field
1398                    XIndexRange(2)=min(XIndexRange(2),DimValue(NbDim));% limit to the last available index
1399                    if test90y
1400                        ind_new=[3 2 1];
1401                        DimCell={AYProjName,AXProjName};
1402                        iz=ceil((ObjectData.Coord(1,1)-Coord{3}(1))/DX)+1;
1403                        for ivar=VarIndex
1404                            VarName=FieldData.ListVarName{ivar};
1405                            ListVarName=[ListVarName VarName];
1406                            VarDimName=[VarDimName {DimCell}];
1407                            VarAttribute{length(ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
1408                            ProjData.(VarName)=permute(FieldData.(VarName),ind_new);% permute x and z indices for 90 degree rotation
1409                            ProjData.(VarName)=squeeze(ProjData.(VarName)(iz,:,:));% select the z index iz
1410                        end
1411                        ProjData.(AYName)=[Ybound(1) Ybound(2)]; %record the new (projected ) y coordinates
1412                        ProjData.(AXName)=[Coord{1}(end),Coord{1}(1)]; %record the new (projected ) x coordinates
1413                    else
1414                        if NbDim==3
1415                            DZ=(Coord{1}(end)-Coord{1}(1))/(numel(Coord{1})-1);
1416                            DimCell(1)=[]; %suppress z variable
1417                            DimValue(1)=[];
1418                            test_direct=1;%TOdo; GENERALIZE, SEE CASE OF points
1419                            if test_direct(1)
1420                                iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
1421                            else
1422                                iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
1423                            end
1424                        end
1425                        for ivar=VarIndex% loop on non coordinate variables
1426                            VarName=FieldData.ListVarName{ivar};
1427                            ListVarName=[ListVarName VarName];
1428                            VarDimName=[VarDimName {DimCell}];
1429                            if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
1430                                VarAttribute{length(ListVarName)}=FieldData.VarAttribute{ivar};
1431                            end
1432                            if NbDim==3
1433                                ProjData.(VarName)=squeeze(FieldData.(VarName)(iz,YIndexRange(1):YIndexRange(end),XIndexRange(1):XIndexRange(end)));
1434                            else
1435                                ProjData.(VarName)=FieldData.(VarName)(YIndexRange(1):YIndexRange(end),XIndexRange(1):XIndexRange(end),:);
1436                            end
1437                        end
1438                        if testXMax
1439                         ProjData.(AXName)=Coord{NbDim}(1)+DX*(XIndexRange-1); %record the new (projected ) x coordinates
1440                        else
1441                          ProjData.(AXName)=FieldData.(AXName);
1442                        end
1443                        if testYMax
1444                            ProjData.(AYName)=Coord{NbDim-1}(1)+DY*(YIndexRange-1); %record the new (projected ) x coordinates
1445                        else
1446                          ProjData.(AYName)=FieldData.(AYName);
1447                        end                           
1448                    end
1449                end
1450            else       % case with interpolation on a grid
1451                if NbDim==2 %2D case
1452                    if isequal(ProjMode{icell},'interp_tps')
1453                        npx_interp_tps=ceil(abs(DX/DAX));
1454                        npy_interp_tps=ceil(abs(DY/DAY));
1455                        Minterp_tps=ones(npy_interp_tps,npx_interp_tps)/(npx_interp_tps*npy_interp_tps);
1456                        test_interp_tps=1;
1457                    else
1458                        test_interp_tps=0;
1459                    end
1460                    Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});
1461                    Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)});
1462                    if ~(testXMin && testYMin)% % if the range of the projected coordinates is not fully defined by the projection object, find the extrema of the projected field
1463                        xcorner=[min(Coord{NbDim}) max(Coord{NbDim}) max(Coord{NbDim}) min(Coord{NbDim})]-ObjectData.Coord(1,1);% corner absissa of the original grid with respect to the new origin
1464                        ycorner=[min(Coord{NbDim-1}) min(Coord{NbDim-1}) max(Coord{NbDim-1}) max(Coord{NbDim-1})]-ObjectData.Coord(1,2);% corner ordinates of the original grid
1465                        xcor_new=xcorner*cos(PlaneAngle(3))+ycorner*sin(PlaneAngle(3));%coordinates of the corners in new frame
1466                        ycor_new=-xcorner*sin(PlaneAngle(3))+ycorner*cos(PlaneAngle(3));
1467                        if ~testXMin
1468                            XMin=min(xcor_new);
1469                        end
1470                        if ~testXMax
1471                            XMax=max(xcor_new);
1472                        end
1473                        if ~testYMin
1474                            YMin=min(ycor_new);
1475                        end
1476                        if ~testYMax
1477                            YMax=max(ycor_new);
1478                        end
1479                    end
1480                    coord_x_proj=XMin:DX:XMax;
1481                    coord_y_proj=YMin:DY:YMax;
1482                    ProjData.(AYName)=[coord_y_proj(1) coord_y_proj(end)]; %record the new (projected ) y coordinates
1483                    ProjData.(AXName)=[coord_x_proj(1) coord_x_proj(end)]; %record the new (projected ) x coordinates
1484                    [X,YI]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
1485                    XI=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-YI*sin(PlaneAngle(3));%corresponding coordinates in the original system
1486                    YI=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+YI*cos(PlaneAngle(3));
1487                    if numel(Coord{1})==2% x coordiante defiend by its bounds, get the whole set
1488                        Coord{1}=linspace(Coord{1}(1),Coord{1}(2),CellInfo{icell}.CoordSize(1));
1489                    end
1490                    if numel(Coord{2})==2% y coordiante defiend by its bounds, get the whole set
1491                        Coord{2}=linspace(Coord{2}(1),Coord{2}(2),CellInfo{icell}.CoordSize(2));
1492                    end
1493                    [X,Y]=meshgrid(Coord{2},Coord{1});%initial coordinates
1494                    %name of error flag variable
1495                    FFName='FF';%default name (if not already used)
1496                    if isfield(ProjData,'FF')
1497                        ind=1;
1498                        while isfield(ProjData,['FF_' num2str(ind)])
1499                            ind=ind+1;
1500                        end
1501                        FFName=['FF_' num2str(ind)];% append an index to the name of error flag, FF_1,FF_2...
1502                    end
1503                    % project all variables in the cell
1504                    for ivar=VarIndex
1505                        VarName=FieldData.ListVarName{ivar};
1506                        if size(FieldData.(VarName),3)==1
1507                            ProjData.(VarName)=interp2(X,Y,double(FieldData.(VarName)),XI,YI,'*linear');%interpolation fct
1508                        else
1509                            ProjData.(VarName)=interp2(X,Y,double(FieldData.(VarName)(:,:,1)),XI,YI,'*linear');
1510                            for icolor=2:size(FieldData.(VarName),3)% project 'color' components
1511                                ProjData.(VarName)=cat(3,ProjData.(VarName),interp2(X,Y,double(FieldData.(VarName)(:,:,icolor)),XI,YI,'*linear'));
1512                            end
1513                        end
1514                        if isa(FieldData.(VarName),'uint8')
1515                            ProjData.(VarName)=uint8(ProjData.(VarName));%put result to integer 8 bits if the initial field is integer (image)
1516                        elseif isa(FieldData.(VarName),'uint16')
1517                            ProjData.(VarName)=uint16(ProjData.(VarName));%put result to integer 16 bits if the initial field is integer (image)
1518                        end
1519                        ListVarName=[ListVarName VarName];
1520                        DimCell(1:2)={AYName,AXName};
1521                        VarDimName=[VarDimName {DimCell}];
1522                        if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
1523                            VarAttribute{length(ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
1524                        end;
1525                        ProjData.(FFName)=isnan(ProjData.(VarName));%detact NaN (points outside the interpolation range)
1526                        ProjData.(VarName)(ProjData.(FFName))=0; %set to 0 the NaN data
1527                    end
1528                    %update list of variables with error flag
1529                    ListVarName=[ListVarName FFName];
1530                    VarDimName=[VarDimName {DimCell}];
1531                    VarAttribute{numel(ListVarName)}.Role='errorflag';
1532                elseif ~testangle
1533                    % unstructured z coordinate
1534                    test_sup=(Coord{1}>=ObjectData.Coord(1,3));
1535                    iz_sup=find(test_sup);
1536                    iz=iz_sup(1);
1537                    if iz>=1 & iz<=npz
1538                        %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
1539                        %ProjData.DimValue=[ProjData.DimValue npY npX];
1540                        for ivar=VarIndex
1541                            VarName=FieldData.ListVarName{ivar};
1542                            ListVarName=[ListVarName VarName];
1543                            VarAttribute{length(ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
1544                            ProjData.(VarName)=squeeze(FieldData.(VarName)(iz,:,:));% select the z index iz
1545                            %TODO : do a vertical average for a thick plane
1546                            if test_interp(2) || test_interp(3)
1547                                ProjData.(VarName)=interp2(Coord{3},Coord{2},ProjData.(VarName),Coord_x,Coord_y);
1548                            end
1549                        end
1550                    end
1551                else
1552                    errormsg='projection of structured coordinates on oblique plane not yet implemented';
1553                    %TODO: use interp_lin3
1554                    return
1555                end
1556            end
1557    end
1558    % update the global list of projected variables:
1559    ProjData.ListVarName=[ProjData.ListVarName ListVarName];
1560    ProjData.VarDimName=[ProjData.VarDimName VarDimName];
1561    ProjData.VarAttribute=[ProjData.VarAttribute VarAttribute];
1562   
1563    %% projection of  velocity components in the rotated coordinates
1564    if testangle
1565        ivar_U=[];ivar_V=[];ivar_W=[];
1566        for ivar=1:numel(VarAttribute)
1567            if isfield(VarAttribute{ivar},'Role')
1568                if strcmp(VarAttribute{ivar}.Role,'vector_x')
1569                    ivar_U=ivar;
1570                elseif strcmp(VarAttribute{ivar}.Role,'vector_y')
1571                    ivar_V=ivar;
1572                elseif strcmp(VarAttribute{ivar}.Role,'vector_z')
1573                    ivar_W=ivar;
1574                end
1575            end
1576        end
1577        if ~isempty(ivar_U)
1578            if isempty(ivar_V)
1579                msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
1580                return
1581            else
1582                UName=ListVarName{ivar_U};
1583                VName=ListVarName{ivar_V};
1584                ProjData.(UName)=cos(PlaneAngle(3))*ProjData.(UName)+ sin(PlaneAngle(3))*ProjData.(VName);
1585                ProjData.(VName)=(-sin(PlaneAngle(3))*ProjData.(UName)+ cos(PlaneAngle(3))*ProjData.(VName));
1586                if ~isempty(ivar_W)
1587                    WName=FieldData.ListVarName{ivar_W};
1588                    ProjData.(VName)=ProjData.(VName)+ ProjData.(WName)*sin(Theta);%
1589                    ProjData.(WName)=NormVec_X*ProjData.(UName)+ NormVec_Y*ProjData.(VName)+ NormVec_Z* ProjData.(WName);
1590                end
1591            end
1592        end
1593    end
1594end
1595% %prepare substraction in case of two input fields
1596% SubData.ListVarName={};
1597% SubData.VarDimName={};
1598% SubData.VarAttribute={};
1599% check_remove=zeros(size(ProjData.ListVarName));
1600% for iproj=1:numel(ProjData.VarAttribute)
1601%     if isfield(ProjData.VarAttribute{iproj},'CheckSub')&&isequal(ProjData.VarAttribute{iproj}.CheckSub,1)
1602%         VarName=ProjData.ListVarName{iproj};
1603%         SubData.ListVarName=[SubData.ListVarName {VarName}];
1604%         SubData.VarDimName=[SubData.VarDimName ProjData.VarDimName{iproj}];
1605%         SubData.VarAttribute=[SubData.VarAttribute ProjData.VarAttribute{iproj}];
1606%         SubData.(VarName)=ProjData.(VarName);
1607%         check_remove(iproj)=1;
1608%     end
1609% end
1610% if ~isempty(find(check_remove))
1611%     ind_remove=find(check_remove);
1612%     ProjData.ListVarName(ind_remove)=[];
1613%     ProjData.VarDimName(ind_remove)=[];
1614%     ProjData.VarAttribute(ind_remove)=[];
1615%     ProjData=sub_field(ProjData,[],SubData);
1616% end
1617
1618%-----------------------------------------------------------------
1619%projection in a volume
1620function  [ProjData,errormsg] = proj_volume(FieldData, ObjectData)
1621
1622%-----------------------------------------------------------------
1623ProjData=FieldData;%default output
1624
1625%% axis origin
1626if isempty(ObjectData.Coord)
1627    ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
1628    ObjectData.Coord(1,2)=0;
1629    ObjectData.Coord(1,3)=0;
1630end
1631
1632%% rotation angles
1633VolumeAngle=[0 0 0];
1634norm_plane=[0 0 1];
1635if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0])
1636    PlaneAngle=ObjectData.Angle;
1637    VolumeAngle=ObjectData.Angle;
1638    om=norm(VolumeAngle);%norm of rotation angle in radians
1639    OmAxis=VolumeAngle/om; %unit vector marking the rotation axis
1640    cos_om=cos(pi*om/180);
1641    sin_om=sin(pi*om/180);
1642    coeff=OmAxis(3)*(1-cos_om);
1643    %components of the unity vector norm_plane normal to the projection plane
1644    norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
1645    norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
1646    norm_plane(3)=OmAxis(3)*coeff+cos_om;
1647end
1648testangle=~isequal(VolumeAngle,[0 0 0]);
1649
1650%% mesh sizes DX, DY, DZ
1651DX=0;
1652DY=0; %default
1653DZ=0;
1654if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
1655     DX=abs(ObjectData.DX);%mesh of interpolation points
1656end
1657if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
1658     DY=abs(ObjectData.DY);%mesh of interpolation points
1659end
1660if isfield(ObjectData,'DZ')&~isempty(ObjectData.DZ)
1661     DZ=abs(ObjectData.DZ);%mesh of interpolation points
1662end
1663if  ~strcmp(ProjMode,'projection') && (DX==0||DY==0||DZ==0)
1664        errormsg='grid mesh DX , DY or DZ is missing';
1665        return
1666end
1667
1668%% extrema along each axis
1669testXMin=0;
1670testXMax=0;
1671testYMin=0;
1672testYMax=0;
1673if isfield(ObjectData,'RangeX')
1674        XMin=min(ObjectData.RangeX);
1675        XMax=max(ObjectData.RangeX);
1676        testXMin=XMax>XMin;
1677        testXMax=1;
1678end
1679if isfield(ObjectData,'RangeY')
1680        YMin=min(ObjectData.RangeY);
1681        YMax=max(ObjectData.RangeY);
1682        testYMin=YMax>YMin;
1683        testYMax=1;
1684end
1685width=0;%default width of the projection band
1686if isfield(ObjectData,'RangeZ')
1687        ZMin=min(ObjectData.RangeZ);
1688        ZMax=max(ObjectData.RangeZ);
1689        testZMin=ZMax>ZMin;
1690        testZMax=1;
1691end
1692
1693%% initiate Matlab  structure for physical field
1694[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
1695if ~isempty(errormsg)
1696    return
1697end
1698
1699ProjData.NbDim=3;
1700ProjData.ListVarName={};
1701ProjData.VarDimName={};
1702if ~isequal(DX,0)&& ~isequal(DY,0)
1703    ProjData.CoordMesh=sqrt(DX*DY);%define typical data mesh, useful for mouse selection in plots
1704elseif isfield(FieldData,'CoordMesh')
1705    ProjData.CoordMesh=FieldData.CoordMesh;
1706end
1707
1708error=0;%default
1709flux=0;
1710testfalse=0;
1711ListIndex={};
1712
1713%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1714%% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
1715%-----------------------------------------------------------------
1716idimvar=0;
1717% LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
1718% CellVarIndex=cells of variable index arrays
1719ivar_new=0; % index of the current variable in the projected field
1720icoord=0;
1721nbcoord=0;%number of added coordinate variables brought by projection
1722nbvar=0;
1723for icell=1:length(CellVarIndex)
1724    NbDim=NbDimVec(icell);
1725    if NbDim<3
1726        continue
1727    end
1728    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
1729    VarType=VarTypeCell{icell};
1730    ivar_X=VarType.coord_x;
1731    ivar_Y=VarType.coord_y;
1732    ivar_Z=VarType.coord_z;
1733    ivar_U=VarType.vector_x;
1734    ivar_V=VarType.vector_y;
1735    ivar_W=VarType.vector_z;
1736    ivar_C=VarType.scalar ;
1737    ivar_Anc=VarType.ancillary;
1738    test_anc=zeros(size(VarIndex));
1739    test_anc(ivar_Anc)=ones(size(ivar_Anc));
1740    ivar_F=VarType.warnflag;
1741    ivar_FF=VarType.errorflag;
1742    check_unstructured_coord=~isempty(ivar_X) && ~isempty(ivar_Y);
1743    DimCell=FieldData.VarDimName{VarIndex(1)};
1744    if ischar(DimCell)
1745        DimCell={DimCell};%name of dimensions
1746    end
1747
1748%% case of input fields with unstructured coordinates
1749    if check_unstructured_coord
1750        XName=FieldData.ListVarName{ivar_X};
1751        YName=FieldData.ListVarName{ivar_Y};
1752        eval(['coord_x=FieldData.' XName ';'])
1753        eval(['coord_y=FieldData.' YName ';'])
1754        if length(ivar_Z)==1
1755            ZName=FieldData.ListVarName{ivar_Z};
1756            eval(['coord_z=FieldData.' ZName ';'])
1757        end
1758
1759        % translate  initial coordinates
1760        coord_x=coord_x-ObjectData.Coord(1,1);
1761        coord_y=coord_y-ObjectData.Coord(1,2);
1762        if ~isempty(ivar_Z)
1763            coord_z=coord_z-ObjectData.Coord(1,3);
1764        end
1765       
1766        % selection of the vectors in the projection range
1767%         if length(ivar_Z)==1 &&  width > 0
1768%             %components of the unitiy vector normal to the projection plane
1769%             fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane           
1770%             indcut=find(abs(fieldZ) <= width);
1771%             for ivar=VarIndex
1772%                 VarName=FieldData.ListVarName{ivar};
1773%                 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);']) 
1774%                     % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE             
1775%             end
1776%             coord_x=coord_x(indcut);
1777%             coord_y=coord_y(indcut);
1778%             coord_z=coord_z(indcut);
1779%         end
1780
1781       %rotate coordinates if needed: TODO modify
1782       if testangle
1783           coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
1784           coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
1785           if ~isempty(ivar_Z)
1786               coord_Y=coord_Y+coord_z *sin(Theta);
1787           end
1788           
1789           coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
1790           coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
1791           
1792       else
1793           coord_X=coord_x;
1794           coord_Y=coord_y;
1795           coord_Z=coord_z;
1796       end
1797        %restriction to the range of x and y if imposed
1798        testin=ones(size(coord_X)); %default
1799        testbound=0;
1800        if testXMin
1801            testin=testin & (coord_X >= XMin);
1802            testbound=1;
1803        end
1804        if testXMax
1805            testin=testin & (coord_X <= XMax);
1806            testbound=1;
1807        end
1808        if testYMin
1809            testin=testin & (coord_Y >= YMin);
1810            testbound=1;
1811        end
1812        if testYMax
1813            testin=testin & (coord_Y <= YMax);
1814            testbound=1;
1815        end
1816        if testbound
1817            indcut=find(testin);
1818            for ivar=VarIndex
1819                VarName=FieldData.ListVarName{ivar};
1820                eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])           
1821            end
1822            coord_X=coord_X(indcut);
1823            coord_Y=coord_Y(indcut);
1824            if length(ivar_Z)==1
1825                coord_Z=coord_Z(indcut);
1826            end
1827        end
1828        % different cases of projection
1829        if isequal(ObjectData.ProjMode,'projection')%%%%%%%   NOT USED %%%%%%%%%%
1830            for ivar=VarIndex %transfer variables to the projection plane
1831                VarName=FieldData.ListVarName{ivar};
1832                if ivar==ivar_X %x coordinate
1833                    eval(['ProjData.' VarName '=coord_X;'])
1834                elseif ivar==ivar_Y % y coordinate
1835                    eval(['ProjData.' VarName '=coord_Y;'])
1836                elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
1837                    eval(['ProjData.' VarName '=FieldData.' VarName ';'])
1838                end
1839                if isempty(ivar_Z) || ivar~=ivar_Z
1840                    ProjData.ListVarName=[ProjData.ListVarName VarName];
1841                    ProjData.VarDimName=[ProjData.VarDimName DimCell];
1842                    nbvar=nbvar+1;
1843                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
1844                        ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
1845                    end
1846                end
1847            end 
1848        elseif isequal(ObjectData.ProjMode,'interp_lin')||isequal(ObjectData.ProjMode,'interp_tps')%interpolate data on a regular grid
1849            coord_x_proj=XMin:DX:XMax;
1850            coord_y_proj=YMin:DY:YMax;
1851            coord_z_proj=ZMin:DZ:ZMax;
1852            DimCell={'coord_z','coord_y','coord_x'};
1853            ProjData.ListVarName={'coord_z','coord_y','coord_x'};
1854            ProjData.VarDimName={'coord_z','coord_y','coord_x'};   
1855            nbcoord=2; 
1856            ProjData.coord_z=[ZMin ZMax];
1857            ProjData.coord_y=[YMin YMax];
1858            ProjData.coord_x=[XMin XMax];
1859            if isempty(ivar_X), ivar_X=0; end;
1860            if isempty(ivar_Y), ivar_Y=0; end;
1861            if isempty(ivar_Z), ivar_Z=0; end;
1862            if isempty(ivar_U), ivar_U=0; end;
1863            if isempty(ivar_V), ivar_V=0; end;
1864            if isempty(ivar_W), ivar_W=0; end;
1865            if isempty(ivar_F), ivar_F=0; end;
1866            if isempty(ivar_FF), ivar_FF=0; end;
1867            if ~isequal(ivar_FF,0)
1868                VarName_FF=FieldData.ListVarName{ivar_FF};
1869                eval(['indsel=find(FieldData.' VarName_FF '==0);'])
1870                coord_X=coord_X(indsel);
1871                coord_Y=coord_Y(indsel);
1872            end
1873            FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
1874            testFF=0;
1875            [X,Y,Z]=meshgrid(coord_y_proj,coord_z_proj,coord_x_proj);%grid in the new coordinates
1876            for ivar=VarIndex
1877                VarName=FieldData.ListVarName{ivar};
1878                if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)                 
1879                    ivar_new=ivar_new+1;
1880                    ProjData.ListVarName=[ProjData.ListVarName {VarName}];
1881                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
1882                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
1883                        ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
1884                    end
1885                    if  ~isequal(ivar_FF,0)
1886                        eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
1887                    end
1888                    % linear interpolation
1889                    InterpFct=TriScatteredInterp(double(coord_X),double(coord_Y),double(coord_Z),double(FieldData.(VarName)));
1890                    ProjData.(VarName)=InterpFct(X,Y,Z);
1891%                     eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
1892%                     FFlag= isnan(varline); %detect undefined values NaN
1893%                     indnan=find(FFlag);
1894%                     if ~isempty(indnan)
1895%                         varline(indnan)=zeros(size(indnan));
1896%                         eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
1897%                         FF(indnan)=ones(size(indnan));
1898%                         testFF=1;
1899%                     end
1900                    if ivar==ivar_U
1901                        ivar_U=ivar_new;
1902                    end
1903                    if ivar==ivar_V
1904                        ivar_V=ivar_new;
1905                    end
1906                    if ivar==ivar_W
1907                        ivar_W=ivar_new;
1908                    end
1909                end
1910            end
1911            if testFF
1912                ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
1913                ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
1914               ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
1915                ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
1916            end
1917        end
1918       
1919%% case of input fields defined on a structured  grid
1920    else
1921        VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
1922        eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
1923        DimValue(DimValue==1)=[];%remove singleton dimensions       
1924        NbDim=numel(DimValue);%update number of space dimensions
1925        nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
1926        if NbDim>=3
1927            if NbDim>3
1928                errormsg='matrices with more than 3 dimensions not handled';
1929                return
1930            else
1931                if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate
1932                    nbcolor=DimValue(3);
1933                    DimValue(3)=[]; %number of 'color' components updated
1934                    NbDim=2;% space dimension set to 2
1935                end
1936            end
1937        end
1938        AYName=FieldData.ListVarName{VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection)
1939        AXName=FieldData.ListVarName{VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection)   
1940        eval(['AX=FieldData.' AXName ';'])
1941        eval(['AY=FieldData.' AYName ';'])
1942        ListDimName=FieldData.VarDimName{VarIndex(1)};
1943        ProjData.ListVarName=[ProjData.ListVarName {AYName} {AXName}]; %TODO: check if it already exists in Projdata (several cells)
1944        ProjData.VarDimName=[ProjData.VarDimName {AYName} {AXName}];
1945
1946%         for idim=1:length(ListDimName)
1947%             DimName=ListDimName{idim};
1948%             if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i')
1949%                nbcolor=DimValue(idim);
1950%                DimValue(idim)=[];
1951%             end
1952%             if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
1953%                 DimValue(idim)=[];
1954%             end
1955%         end 
1956        Coord_z=[];
1957        Coord_y=[];
1958        Coord_x=[];   
1959
1960        for idim=1:NbDim %loop on space dimensions
1961            test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
1962            ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
1963            if ~isequal(ivar,0)%  a variable corresponds to the dimension #idim
1964                eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
1965                if numel(Coord{idim})==2 %input array defined on a regular grid
1966                   DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
1967                else
1968                    DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
1969                    DCoord_min(idim)=min(DCoord);
1970                    DCoord_max=max(DCoord);
1971                %    test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
1972                    if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
1973                        msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'])
1974                                return
1975                    end               
1976                    test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
1977                end
1978                test_direct(idim)=(DCoord_min(idim)>0);
1979            else  % no variable associated with the  dimension #idim, the coordinate value is set equal to the matrix index by default
1980                Coord_i_str=['Coord_' num2str(idim)];
1981                DCoord_min(idim)=1;%default
1982                Coord{idim}=[0.5 DimValue(idim)-0.5];
1983                test_direct(idim)=1;
1984            end
1985        end
1986        if DY==0
1987            DY=abs(DCoord_min(NbDim-1));
1988        end
1989        npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol
1990        if DX==0
1991            DX=abs(DCoord_min(NbDim));
1992        end
1993        npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol
1994        for idim=1:NbDim
1995            if test_interp(idim)
1996                DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri
1997            end
1998        end       
1999        Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
2000        test_direct_y=test_direct(NbDim-1);
2001        Coord_x=linspace(Coord{NbDim}(1),Coord{NbDim}(end),npX);
2002        test_direct_x=test_direct(NbDim);
2003        DAX=DCoord_min(NbDim);
2004        DAY=DCoord_min(NbDim-1); 
2005        minAX=min(Coord_x);
2006        maxAX=max(Coord_x);
2007        minAY=min(Coord_y);
2008        maxAY=max(Coord_y);
2009        xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
2010        ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
2011        xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
2012        ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
2013        if ~testXMax
2014            XMax=max(xcor_new);
2015        end
2016        if ~testXMin
2017            XMin=min(xcor_new);
2018        end
2019        if ~testYMax
2020            YMax=max(ycor_new);
2021        end
2022        if ~testYMin
2023            YMin=min(ycor_new);
2024        end
2025        DXinit=(maxAX-minAX)/(DimValue(NbDim)-1);
2026        DYinit=(maxAY-minAY)/(DimValue(NbDim-1)-1);
2027        if DX==0
2028            DX=DXinit;
2029        end
2030        if DY==0
2031            DY=DYinit;
2032        end
2033        if NbDim==3
2034            DZ=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
2035            if ~test_direct(1)
2036                DZ=-DZ;
2037            end
2038            Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
2039            test_direct_z=test_direct(1);
2040        end
2041        npX=floor((XMax-XMin)/DX+1);
2042        npY=floor((YMax-YMin)/DY+1);   
2043        if test_direct_y
2044            coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
2045        else
2046            coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
2047        end
2048        if test_direct_x
2049            coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
2050        else
2051            coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
2052        end
2053       
2054        % case with no rotation and interpolation
2055        if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
2056            if ~testXMin && ~testXMax && ~testYMin && ~testYMax && NbDim==2
2057                ProjData=FieldData;
2058            else
2059                indY=NbDim-1;
2060                if test_direct(indY)
2061                    min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1;
2062                    YIndexFirst=floor((YMax-Coord{indY}(1))/DYinit)+1;
2063                    Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1);
2064                    Ybound(2)=Coord{indY}(1)+DYinit*(YIndexFirst-1);
2065                else
2066                    min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;
2067                    max_indy=floor((Coord{indY}(1)-YMin)/DYinit)+1;
2068                    Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1);
2069                    Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1);
2070                end   
2071                if test_direct(NbDim)==1
2072                    min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;
2073                    max_indx=floor((XMax-Coord{NbDim}(1))/DXinit)+1;
2074                    Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
2075                    Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
2076                else
2077                    min_indx=ceil((Coord{NbDim}(1)-XMax)/DXinit)+1;
2078                    max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1;
2079                    Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
2080                    Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
2081                end
2082                if NbDim==3
2083                    DimCell(1)=[]; %suppress z variable
2084                    DimValue(1)=[];
2085                                        %structured coordinates
2086                    if test_direct(1)
2087                        iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
2088                    else
2089                        iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
2090                    end
2091                end
2092                min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
2093                min_indx=max(min_indx,1);
2094                max_indy=min(max_indy,DimValue(1));
2095                max_indx=min(max_indx,DimValue(2));
2096                for ivar=VarIndex% loop on non coordinate variables
2097                    VarName=FieldData.ListVarName{ivar};
2098                    ProjData.ListVarName=[ProjData.ListVarName VarName];
2099                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
2100                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
2101                        ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
2102                    end
2103                    if NbDim==3
2104                        eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']);
2105                    else
2106                        eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']);
2107                    end
2108                end 
2109                eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
2110                eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
2111            end
2112        elseif isfield(FieldData,'A') %TO GENERALISE       % case with rotation and/or interpolation
2113            if NbDim==2 %2D case
2114                [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
2115                XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
2116                YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
2117                XIMA=(XIMA-minAX)/DXinit+1;% image index along x
2118                YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
2119                XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
2120                YIMA=reshape(round(YIMA),1,npX*npY);
2121                flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
2122                if isequal(ObjectData.ProjMode,'interp_tps')
2123                    npx_interp_tps=ceil(abs(DX/DAX));
2124                    npy_interp_tps=ceil(abs(DY/DAY));
2125                    Minterp_tps=ones(npy_interp_tps,npx_interp_tps)/(npx_interp_tps*npy_interp_tps);
2126                    test_interp_tps=1;
2127                else
2128                    test_interp_tps=0;
2129                end
2130                eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
2131                eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
2132                for ivar=VarIndex
2133                    VarName=FieldData.ListVarName{ivar};
2134                    if test_interp(1) || test_interp(2)%interpolate on a regular grid       
2135                          eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
2136                    end
2137                    %filter the field (image) if option 'interp_tps' is used
2138                    if test_interp_tps 
2139                         Aclass=class(FieldData.A);
2140                         ProjData.(VarName)=interp_tps2(Minterp_tps,FieldData.(VarName),'valid');
2141                         if ~isequal(Aclass,'double')
2142                             ProjData.(VarName)=Aclass(FieldData.(VarName));%revert to integer values
2143                         end
2144                    end
2145                    eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line             
2146                    %ind_in=find(flagin);
2147                    ind_out=find(~flagin);
2148                    ICOMB=(XIMA-1)*DimValue(1)+YIMA;
2149                    ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
2150                    vec_B(flagin,1:nbcolor)=vec_A(ICOMB,:);
2151                    for icolor=1:nbcolor
2152                        vec_B(ind_out,icolor)=zeros(size(ind_out));
2153                    end
2154                    ProjData.ListVarName=[ProjData.ListVarName VarName];
2155                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
2156                    if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
2157                        ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
2158                    end     
2159                    eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
2160                end
2161                ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antï¿œrieur 
2162                ProjData.ListVarName=[ProjData.ListVarName 'FF'];
2163                ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
2164                ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
2165            else %3D case
2166                if ~testangle     
2167                    % unstructured z coordinate
2168                    test_sup=(Coord{1}>=ObjectData.Coord(1,3));
2169                    iz_sup=find(test_sup);
2170                    iz=iz_sup(1);
2171                    if iz>=1 & iz<=npz
2172                        %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
2173                        %ProjData.DimValue=[ProjData.DimValue npY npX];
2174                        for ivar=VarIndex
2175                            VarName=FieldData.ListVarName{ivar};
2176                            ProjData.ListVarName=[ProjData.ListVarName VarName];
2177                            ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes 
2178                            eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
2179                            %TODO : do a vertical average for a thick plane
2180                            if test_interp(2) || test_interp(3)
2181                                eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
2182                            end
2183                        end
2184                    end
2185                else
2186                    errormsg='projection of structured coordinates on oblique plane not yet implemented';
2187                    %TODO: use interp3
2188                    return
2189                end
2190            end
2191        end
2192    end
2193
2194    %% projection of  velocity components in the rotated coordinates
2195    if testangle
2196        if isempty(ivar_V)
2197            msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
2198            return
2199        end
2200        UName=FieldData.ListVarName{ivar_U};
2201        VName=FieldData.ListVarName{ivar_V};   
2202        eval(['ProjData.' UName  '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
2203        eval(['ProjData.' VName  '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
2204        if ~isempty(ivar_W)
2205            WName=FieldData.ListVarName{ivar_W};
2206            eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
2207            eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
2208        end
2209        if ~isequal(Psi,0)
2210            eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
2211            eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
2212        end
2213    end
2214end
2215
2216%------------------------------------------------------------------------
2217%--- transfer the global attributes
2218function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
2219%------------------------------------------------------------------------
2220ProjData=[];%default
2221errormsg='';%default
2222
2223%% transfer error
2224if isfield(FieldData,'Txt')
2225    errormsg=FieldData.Txt; %transmit erreur message
2226    return;
2227end
2228
2229%% transfer global attributes
2230if ~isfield(FieldData,'ListGlobalAttribute')
2231    ProjData.ListGlobalAttribute={};
2232else
2233    ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
2234end
2235for iattr=1:length(ProjData.ListGlobalAttribute)
2236    AttrName=ProjData.ListGlobalAttribute{iattr};
2237    if isfield(FieldData,AttrName)
2238        ProjData.(AttrName)=FieldData.(AttrName);
2239    end
2240end
2241
2242%% transfer coordinate unit
2243if isfield(ProjData,'CoordUnit')
2244    ProjData=rmfield(ProjData,'CoordUnit');% do not transfer by default (to avoid x/y=1 for profiles)
2245end
2246if isfield(FieldData,'CoordUnit')
2247    if isfield(ObjectData,'CoordUnit') && ~strcmp(FieldData.CoordUnit,ObjectData.CoordUnit)
2248        errormsg=[ObjectData.Type ' in ' ObjectData.CoordUnit ' coordinates, while field in ' FieldData.CoordUnit ];
2249        return
2250    elseif strcmp(ObjectData.Type,'plane')|| strcmp(ObjectData.Type,'volume')
2251         ProjData.CoordUnit=FieldData.CoordUnit;
2252    end
2253end
2254
2255%% store the properties of the projection object
2256ListObject={'Name','Type','ProjMode','angle','RangeX','RangeY','RangeZ','DX','DY','DZ','Coord'};
2257for ilist=1:length(ListObject)
2258    if isfield(ObjectData,ListObject{ilist})
2259        val=ObjectData.(ListObject{ilist});
2260        if ~isempty(val)
2261            ProjData.(['ProjObject' ListObject{ilist}])=val;
2262            ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['ProjObject' ListObject{ilist}]}];
2263        end
2264    end   
2265end
2266
Note: See TracBrowser for help on using the repository browser.