Home > . > proj_field.m

# proj_field

## PURPOSE

'proj_field': projects the field on a projection object

## SYNOPSIS

function [ProjData,errormsg]=proj_field(FieldData,ObjectData,IndexObj)

## DESCRIPTION

    'proj_field': projects the field on a projection object
    --------------------------------------------------------------------------
      function [ProjData,errormsg]=proj_field(FieldData,ObjectData,IndexObj)

     OUTPUT:
     ProjData structure containing the fields of the input field FieldData,
     transmitted or projected on the object, plus the additional fields
        .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
        .UMean,VMean: mean of the velocity components in a domain
        .AMin, AMax: min and max of a scalar
        .AMean: mean of a scalar in a domain
      .NbPix;
      .DimName=  names of the matrix dimensions (matlab cell)
      .DimValue= values of the matricx dimensions (matlab vector, same length as .DimName);
      .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
      .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;

    INPUT
     ObjectData: structure characterizing the projection object
        .Style : style of projection object
        .ProjMode=type of projection ;
        .CoordType: 'px' or 'phys' type of coordinates defining the object position
        .Phi  angle of rotation (=0 by default)
        .ProjAngle=angle of projection;
        .DX,.DY,.DZ=increments along each coordinate
        .Coord(nbpoints,3): set of coordinates defining the object position;

## CROSS-REFERENCE INFORMATION

This function calls:

- find_field_indices 'find_file_indices': group the variables of a nc-formated Matlab structure into 'fields' with common dimensions
- griddata_uvmat 'griddata_uvmat': function griddata_uvmat(vec2_X,vec2_Y,vec2_U,vec_X,vec_Y,'linear')
- warndlg_uvmat 'warndlg_uvmat': display warning message (error, warning, confirmation) in a given figure

This function is called by:

- series 'series': master function associated to the GUI series.m for analysis field series
- update_obj 'update_obj': update the object graph representation and its projection field, record it in the uvmat interface
- uvmat 'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization

## SUBFUNCTIONS

- function [ProjData,errormsg]=proj_points(FieldData,ObjectData)
- function [ProjData,errormsg]=proj_patch(FieldData,ObjectData)
- function [ProjData,errormsg] = proj_line(FieldData, ObjectData)
- function [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
- function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)

## SOURCE CODE

    0001 %'proj_field': projects the field on a projection object
    0002 %--------------------------------------------------------------------------
    0003 %  function [ProjData,errormsg]=proj_field(FieldData,ObjectData,IndexObj)
    0004 %
    0005 % OUTPUT:
    0006 % ProjData structure containing the fields of the input field FieldData,
    0007 % transmitted or projected on the object, plus the additional fields
    0008 %    .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
    0009 %    .UMean,VMean: mean of the velocity components in a domain
    0010 %    .AMin, AMax: min and max of a scalar
    0011 %    .AMean: mean of a scalar in a domain
    0012 %  .NbPix;
    0013 %  .DimName=  names of the matrix dimensions (matlab cell)
    0014 %  .DimValue= values of the matricx dimensions (matlab vector, same length as .DimName);
    0015 %  .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
    0016 %  .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;
    0017 %
    0018 %INPUT
    0019 % ObjectData: structure characterizing the projection object
    0020 %    .Style : style of projection object
    0021 %    .ProjMode=type of projection ;
    0022 %    .CoordType: 'px' or 'phys' type of coordinates defining the object position
    0023 %    .Phi  angle of rotation (=0 by default)
    0024 %    .ProjAngle=angle of projection;
    0025 %    .DX,.DY,.DZ=increments along each coordinate
    0026 %    .Coord(nbpoints,3): set of coordinates defining the object position;
    0027
    0028 %FieldData: data of the field to be projected on the projection object, with optional fields
    0029 %    .Txt: error message, transmitted to the projection
    0030 %    .CoordType: 'px' or 'phys' type of coordinates of the field, must be the same as for the projection object, transmitted
    0031 %    .Mesh: typical distance between data points (used for mouse action or display), transmitted
    0032 %    .CoordUnit, .TimeUnit, .dt: transmitted
    0033 % standardised description of fields, nc-formated Matlab structure with fields:
    0034 %         .ListGlobalAttribute: cell listing the names of the global attributes
    0035 %        .Att_1,Att_2... : values of the global attributes
    0036 %            .ListDimName: cell listing the names of the array dimensions
    0037 %               .DimValue: array dimension values (Matlab vector with the same length as .ListDimName
    0038 %            .ListVarName: cell listing the names of the variables
    0039 %            .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName
    0040 %           .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
    0041 %        .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
    0042 % The variables are grouped in 'fields', made of a set of variables with common dimensions (using the function find_field_indices)
    0043 % The variable attribute 'Role' is used to define the role for plotting:
    0044 %       Role = 'scalar':  (default) represents a scalar field
    0045 %            = 'coord':  represents a set of unstructured coordinates, whose
    0046 %                     space dimension is given by the last array dimension (called 'nb_dim').
    0047 %            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
    0048 %                        unstructured coordinate x, y  or z
    0049 %            = 'vector': represents a vector field whose number of components
    0050 %                is given by the last dimension (called 'nb_dim')
    0051 %            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector
    0052 %            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
    0053 %            = 'errorflag': provides an error flag marking false data,
    0054 %                   default=0, no error. Different non zero values can represent different criteria of elimination.
    0055 %
    0056 % Default role of variables (by name)
    0057 %  vector field:
    0058 %    .X,.Y: position of the velocity vectors, projected on the object
    0059 %    .U, .V, .W: velocity components, projected on the object
    0060 %    .C, .CName: scalar associated to the vector
    0061 %    .F : equivalent to 'warnflag'
    0062 %    .FF: equivalent to 'errorflag'
    0063 %  scalar field or image:
    0064 %    .AName: name of a scalar (to be calculated from velocity fields after projection), transmitted
    0065 %    .A: scalar, projected on the object
    0066 %    .AX, .AY: positions for the scalar
    0067 %     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
    0068 %     case of an unstructured scalar: A is a vector, AX and AY the corresponding coordinates
    0069 %
    0070 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0071 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
    0072 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0073 %     This file is part of the toolbox UVMAT.
    0074 %
    0075 %     UVMAT is free software; you can redistribute it and/or modify
    0076 %     it under the terms of the GNU General Public License as published by
    0077 %     the Free Software Foundation; either version 2 of the License, or
    0078 %     (at your option) any later version.
    0079 %
    0080 %     UVMAT is distributed in the hope that it will be useful,
    0081 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
    0082 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0083 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
    0084 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    0085
    0086 function [ProjData,errormsg]=proj_field(FieldData,ObjectData,IndexObj)
    0087
    0088 if isfield(ObjectData,'ProjMode') && (isequal(ObjectData.ProjMode,'none')||isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'))
    0089     ProjData=[];
    0090     return
    0091 end
    0092 %introduce default field properties (reading old standards)
    0093 if ~isfield(ObjectData,'Style')||~isfield(ObjectData,'Coord')||~isfield(ObjectData,'ProjMode')
    0094     ProjData=FieldData;
    0095     return
    0096 end
    0097
    0098 % OBSOLETE
    0099 if isfield(ObjectData,'XMax') && ~isempty(ObjectData.XMax)
    0100     ObjectData.RangeX(1)=ObjectData.XMax;
    0101 end
    0102 if isfield(ObjectData,'XMin') && ~isempty(ObjectData.XMin)
    0103     ObjectData.RangeX(2)=ObjectData.XMin;
    0104 end
    0105 if isfield(ObjectData,'YMax') && ~isempty(ObjectData.YMax)
    0106     ObjectData.RangeY(1)=ObjectData.YMax;
    0107 end
    0108 if isfield(ObjectData,'YMin') && ~isempty(ObjectData.YMin)
    0109     ObjectData.RangeY(2)=ObjectData.YMin;
    0110 end
    0111 if isfield(ObjectData,'ZMax') && ~isempty(ObjectData.ZMax)
    0112     ObjectData.RangeZ(1)=ObjectData.ZMax;
    0113 end
    0114 if isfield(ObjectData,'ZMin') && ~isempty(ObjectData.ZMin)
    0115     ObjectData.RangeZ(2)=ObjectData.ZMin;
    0116 end
    0117 %%%%%%%%%%
    0118
    0119 % FieldData=document_field(FieldData);%transform FieldData to the standard format
    0120 % if ~isfield(FieldData,'VarAttribute')
    0121 %     FieldData.VarAttribute={};
    0122 % end
    0123
    0124 if isequal(ObjectData.Style,'points')
    0125     [ProjData,errormsg]=proj_points(FieldData,ObjectData);
    0126 elseif isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')
    0127      [ProjData,errormsg] = proj_line(FieldData,ObjectData);
    0128 elseif isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')
    0129     if isequal(ObjectData.ProjMode,'inside')|isequal(ObjectData.ProjMode,'outside')
    0130         [ProjData,errormsg] = proj_patch(FieldData,ObjectData);
    0131     else
    0132         [ProjData,errormsg] = proj_line(FieldData,ObjectData);
    0133     end
    0134      %A FAIRE : GERER MASK
    0135 elseif isequal(ObjectData.Style,'plane')
    0136 %         if isfield(FieldData,'NbDim') & isequal(FieldData.NbDim,3)
    0137 %             ProjData= proj_plane3D(FieldData,ObjectData);%
    0138 %         else
    0139             [ProjData,errormsg] = proj_plane(FieldData,ObjectData);
    0140 %         end
    0141 end
    0142 if exist('IndexObj','var')
    0143     ProjData.IndexObj=IndexObj;%transfer object index
    0144 end
    0145
    0146 %-----------------------------------------------------------------
    0147 %project on a set of points
    0148 function  [ProjData,errormsg]=proj_points(FieldData,ObjectData)%%
    0149 %-------------------------------------------------------------------
    0150
    0151 siz=size(ObjectData.Coord);
    0152 width=0;
    0153 if isfield(ObjectData,'Range')
    0154     width=ObjectData.Range(1,2);
    0155 end
    0156 if isfield(ObjectData,'RangeX')&~isempty(ObjectData.RangeX)
    0157     width=max(ObjectData.RangeX);
    0158 end
    0159 if isfield(ObjectData,'RangeY')&~isempty(ObjectData.RangeY)
    0160     width=max(width,max(ObjectData.RangeY));
    0161 end
    0162 if isfield(ObjectData,'RangeZ')&~isempty(ObjectData.RangeZ)
    0163     width=max(width,max(ObjectData.RangeZ));
    0164 end
    0165 if isequal(ObjectData.ProjMode,'projection')
    0166     if width==0
    0167         errormsg='projection range around points needed';
    0168         return
    0169     end
    0170 elseif  ~isequal(ObjectData.ProjMode,'interp')
    0171     errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field']);
    0172         return
    0173 end
    0174 ProjData=proj_heading(FieldData,ObjectData);
    0175 ProjData.NbDim=0;
    0176 ProjData.ListDimName= {'nb_points'};
    0177 ProjData.DimValue=siz(1);  %nbre of projection points
    0178
    0179
    0180 % idimvar=0;
    0181 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
    0182 if ~isempty(errormsg)
    0183     errormsg=['error in proj_field/proj_points:' errormsg];
    0184     return
    0185 end
    0186 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
    0187 % CellVarIndex=cells of variable index arrays
    0188 % ivar_new=0; % index of the current variable in the projected field
    0189 % icoord=0;
    0190 for icell=1:length(CellVarIndex)
    0191     if NbDim(icell)==1
    0192         continue
    0193     end
    0194     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
    0195     VarType=VarTypeCell{icell};
    0196     ivar_X=VarType.coord_x;
    0197     ivar_Y=VarType.coord_y;
    0198     ivar_Z=VarType.coord_z;
    0199 %     ivar_U=VarType.vector_x;
    0200 %     ivar_V=VarType.vector_y;
    0201 %     ivar_W=VarType.vector_z;
    0202 %     ivar_C=VarType.scalar ;
    0203     ivar_Anc=VarType.ancillary;
    0204 %     test_anc=zeros(size(VarIndex));
    0205     test_anc(ivar_Anc)=ones(size(ivar_Anc));
    0206     ivar_F=VarType.warnflag;
    0207     ivar_FF=VarType.errorflag;
    0208     VarIndex([ivar_X ivar_Y ivar_Z ivar_Anc ivar_F ivar_FF])=[];% not projected variables removed frlom list
    0209     if isempty(ivar_X)
    0210         test_grid=1;%test for input data on regular grid (e.g. image)coordinates
    0211
    0212     else
    0213         if length(ivar_X)>1 | length(ivar_Y)>1 | length(ivar_Z)>1
    0214                  warndlg_uvmat('multiple coordinate input in proj_field.m','ERROR')
    0215                     return
    0216         end
    0217         if length(ivar_Y)~=1
    0218                 warndlg_uvmat('y coordinate not defined in proj_field.m','ERROR')
    0219                 return
    0220         end
    0221         test_grid=0;
    0222     end
    0223     ProjData.ListVarName={'Y','X','NbVal'};
    0224     ProjData.VarDimIndex={[1],[1],[1]};
    0225     ProjData.VarAttribute{1}.Role='ancillary';
    0226     ProjData.VarAttribute{2}.Role='ancillary';
    0227     ProjData.VarAttribute{3}.Role='ancillary';
    0228     for ivar=VarIndex
    0229         VarName=FieldData.ListVarName{ivar};
    0230         ProjData.ListVarName=[ProjData.ListVarName {VarName}];
    0231         ProjData.VarDimIndex=[ProjData.VarDimIndex {[1]}];
    0232     end
    0233     if ~test_grid
    0234         eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';'])
    0235         eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';'])
    0236         test3D=0;% TEST 3D CASE : NOT COMPLETED ,  3D CASE : NOT COMPLETED
    0237         if length(ivar_Z)==1
    0238             eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])
    0239             test3D=1;
    0240         end
    0241 %         if length(ivar_U)>1 | length(ivar_V)>1 | length(ivar_W)>1
    0242 %                  warndlg_uvmat('multiple vector input in proj_field.m','ERROR')
    0243 %                     return
    0244 %         end
    0245         if length(ivar_F)>1 | length(ivar_FF)>1
    0246                  warndlg_uvmat('multiple flag input in proj_field.m','ERROR')
    0247                     return
    0248         end
    0249
    0250         for ipoint=1:siz(1)
    0251            Xpoint=ObjectData.Coord(ipoint,:);
    0252            distX=coord_x-Xpoint(1);
    0253            distY=coord_y-Xpoint(2);
    0254            dist=distX.*distX+distY.*distY;
    0255            indsel=find(dist<width*width);
    0256            ProjData.X(ipoint,1)=Xpoint(1);
    0257            ProjData.Y(ipoint,1)=Xpoint(2);
    0258            if isequal(length(ivar_FF),1)
    0259                FFName=FieldData.ListVarName{ivar_FF};
    0260                eval(['FF=FieldData.' FFName '(indsel);'])
    0261                ind_indsel=find(~FF);
    0262                indsel=indsel(ind_indsel);
    0263            end
    0264            ProjData.NbVal(ipoint,1)=length(indsel);
    0265             for ivar=VarIndex
    0266                VarName=FieldData.ListVarName{ivar};
    0267                if isempty(indsel)
    0268                     eval(['ProjData.' VarName '(ipoint,1)=NaN;'])
    0269                else
    0270                     eval(['Var=FieldData.' VarName '(indsel);'])
    0271                     eval(['ProjData.' VarName '(ipoint,1)=mean(Var);'])
    0272                     if isequal(ObjectData.ProjMode,'interp')
    0273                          eval(['ProjData.' VarName '(ipoint,1)=griddata_uvmat(coord_x(indsel),coord_y(indsel),Var,Xpoint(1),Xpoint(2)))';])
    0274                     end
    0275                end
    0276             end
    0277         end
    0278     else
    0279         DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
    0280      %input field on a structured  grid  A REVOIR  A REVOIR  A REVOIR
    0281         if ~isempty(find(DimIndices))
    0282             DimValue=FieldData.DimValue(DimIndices);%set of dimension values
    0283             ListDimName=FieldData.ListDimName(DimIndices);
    0284 %             nbcolor=1; %default
    0285             for idim=1:length(ListDimName)
    0286                 DimName=ListDimName{idim};
    0287                 if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
    0288                    nbcolor=DimValue(idim);
    0289                    DimIndices(idim)=[];
    0290                    DimValue(idim)=[];
    0291                 end
    0292                 if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
    0293                     DimIndices(idim)=[];
    0294                     DimValue(idim)=[];
    0295                 end
    0296             end
    0297             ind_1=find(DimValue==1);
    0298             DimIndices(ind_1)=[]; %suppress singleton dimensions
    0299             indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
    0300             nb_dim=length(DimIndices);%number of space dimensions
    0301             Coord_z=[];
    0302             Coord_y=[];
    0303             Coord_x=[];
    0304             for idim=1:nb_dim %loop on space dimensions
    0305                 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
    0306                 test_coord(idim)=0;%test for defined coordinates, =0 by default
    0307                 ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
    0308                 if ~isequal(ivar,0)%  a variable corresponds to the current dimension
    0309                     eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
    0310                     DCoord=diff(Coord{idim});
    0311                     DCoord_min(idim)=min(DCoord);
    0312                     DCoord_max=max(DCoord);
    0313                     test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
    0314                     test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
    0315                     if ~isequal(test_direct(idim),test_direct_min)
    0316                          warndlg_uvmat(['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'],'ERROR')
    0317                                     return
    0318                     end
    0319                     test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
    0320                     test_coord(idim)=1;
    0321
    0322                 else  % no variable associated with the first dimension, look fo variable  attributes Coord_1, _2 or _3
    0323                     Coord_i_str=['Coord_' num2str(idim)];
    0324                     DCoord_min(idim)=1;%default
    0325                     Coord{idim}=[0.5 DimValue(idim)];
    0326                     test_direct(idim)=1;
    0327 %                     for ivar=VarIndex
    0328 %                         if  length(FieldData.VarAttribute)>=ivar && isfield(FieldData.VarAttribute{ivar},Coord_i_str)% if there is a variable  attribute named Coord_1, _2 or _3
    0329 %                             eval(['Coord_i=FieldData.VarAttribute{ivar}.' Coord_i_str ';']);%'range x
    0330 %                             if isnumeric(Coord_i)
    0331 %                                  if length(Coord_i)>=2
    0332 %                                     Coord{idim}=[Coord_i(1) Coord_i(end)];
    0333 %                                     %test_direct(idim)=(Coord{idim}(2)>Coord{idim}(1));
    0334 %                                  else
    0335 %                                     warndlg_uvmat(['two values needed for ' Coord_i_str 'in proj_field.m'],'ERROR')
    0336 %                                     return
    0337 %                                  end
    0338 %                              else
    0339 %                                 warndlg_uvmat(['non numerical coordinate attributes' Coord_i_str 'in proj_field.m'],'ERROR')
    0340 %                                 return
    0341 %                              end
    0342 %                              %test_coord(idim)=1;
    0343 %                              DCoord_min(idim)=(Coord{idim}(end)-Coord{idim}(1))/(DimValue(idim)-1);
    0344 %                         end
    0345 %                     end
    0346                 end
    0347             end
    0348             DX=DCoord_min(2);
    0349             DY=DCoord_min(1);
    0350             for ipoint=1:siz(1)
    0351                 xwidth=width/(abs(DX));
    0352                 ywidth=width/(abs(DY));
    0353                 i_min=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5-xwidth); %minimum index of the selected region
    0354                 i_min=max(1,i_min);%restrict to field limit
    0355                 i_plus=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5+xwidth);
    0356                 i_plus=min(DimValue(2),i_plus); %restrict to field limit
    0357                 j_min=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY-ywidth+0.5);
    0358                 j_min=max(1,j_min);
    0359                 j_plus=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY+ywidth+0.5);
    0360                 j_plus=min(DimValue(1),j_plus);
    0361                 ProjData.X(ipoint,1)=ObjectData.Coord(ipoint,1);
    0362                 ProjData.Y(ipoint,1)=ObjectData.Coord(ipoint,2);
    0363                 i_int=[i_min:i_plus];
    0364                 j_int=[j_min:j_plus];
    0365                 ProjData.NbVal(ipoint,1)=length(j_int)*length(i_int);
    0366                 if isempty(i_int) | isempty(j_int)
    0367                    for ivar=VarIndex
    0368                         eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=NaN;']);
    0369                    end
    0370                    errormsg=['no data points in the selected projection range ' num2str(width) ];
    0371                 else
    0372                     %TODO: introduce circle in the selected subregion
    0373                     %[I,J]=meshgrid([1:j_int],[1:i_int]);
    0374                     for ivar=VarIndex
    0375                         eval(['Avalue=FieldData.' FieldData.ListVarName{ivar} '(j_int,i_int,:);']);
    0376                         eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=mean(mean(Avalue));']);
    0377                     end
    0378                 end
    0379             end
    0380         end
    0381    end
    0382 end
    0383 % if isfield(FieldData,'U')& isfield(FieldData,'V')& ~isempty(FieldData.U)& ~isempty(FieldData.V)
    0384 %     ProjData.ListVarName={'Y','X','U','V','NbVec'};
    0385 %     ProjData.VarDimIndex={[1],[1],[1],[1],[1]};
    0386 %     Role={'coord_y','coord_x','vector_x','vector_y','ancillary'};
    0387 %     for ivar=1:5
    0388 %         ProjData.VarAttribute{ivar}.Role=Role{ivar};
    0389 %     end
    0390 %     if isfield(FieldData,'FF')
    0391 %         indsel=find(FieldData.FF==0);
    0392 %         if isempty(indsel)
    0393 %             FieldData.U=[];
    0394 %             FieldData.V=[];
    0395 %             FieldData.X=[];
    0396 %             FieldData.Y=[];
    0397 %         else
    0398 %             FieldData.U=FieldData.U(indsel);
    0399 %             FieldData.V=FieldData.V(indsel);
    0400 %             FieldData.X=FieldData.X(indsel);
    0401 %             FieldData.Y=FieldData.Y(indsel);
    0402 %         end
    0403 %     end
    0404 %     if isequal(ObjectData.ProjMode,'projection')
    0405 %         if ~isfield(ObjectData,'Range') & ~isfield(ObjectData,'RangeX')& ~isfield(ObjectData,'RangeY')
    0406 %             errormsg='projection range needed';
    0407 %             return
    0408 %         end
    0409 %
    0410 %        for ipoint=1:siz(1)
    0411 %            Xpoint=ObjectData.Coord(ipoint,:);
    0412 % %            Ypoint=ObjectData.YObject(ipoint);
    0413 %            distX=FieldData.X-Xpoint(1);
    0414 %            distY=FieldData.Y-Xpoint(2);
    0415 %            dist=distX.*distX+distY.*distY;
    0416 % %            indsel=find(dist<ObjectData.YMax*ObjectData.YMax);
    0417 %            indsel=find(dist<width*width);
    0418 %            ProjData.X(ipoint,1)=Xpoint(1);
    0419 %            ProjData.Y(ipoint,1)=Xpoint(2);
    0420 %            ProjData.U(ipoint,1)=NaN;
    0421 %            ProjData.V(ipoint,1)=NaN;
    0422 %            ProjData.NbVec(ipoint,1)=length(indsel);
    0423 %            if ~isempty(indsel)
    0424 %               vector_x=FieldData.U(indsel);
    0425 %               vector_y=FieldData.V(indsel);
    0426 %               ProjData.U(ipoint,1)=sum(vector_x)/ProjData.NbVec(ipoint,1);
    0427 %               ProjData.V(ipoint,1)=sum(vector_y)/ProjData.NbVec(ipoint,1);
    0428 % %               ProjData.UMax(ipoint)=max(vector_x);
    0429 % %               ProjData.UMin(ipoint)=min(vector_x);
    0430 % %               ProjData.VMax(ipoint)=max(vector_y);
    0431 % %               ProjData.VMin(ipoint)=min(vector_y);
    0432 %            end
    0433 %        end
    0434 %     elseif isequal(ObjectData.ProjMode,'interp')
    0435 %        ProjData.U=(griddata_uvmat(FieldData.X,FieldData.Y,FieldData.U,ProjData.Coord(:,1),ProjData.Coord(:,2)))';
    0436 %        ProjData.V=(griddata_uvmat(FieldData.X,FieldData.Y,FieldData.V,ProjData.Coord(:,1),ProjData.Coord(:,2)))';
    0437 %     else
    0438 %         errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field'])
    0439 %         return
    0440 %     end
    0441 % end
    0442 % if isfield(FieldData,'AName')
    0443 %     ProjData.ListVarName={'AY','AX','A'};
    0444 %     ProjData.VarDimIndex={[1],[1],[1]};
    0445 % %     ProjData.ListVarAttribute={'Role'};
    0446 % %     ProjData.Role={'coord_y','coord_x',[]};
    0447 % %     ProjData.VarAttribute{1}.Role='coord_y';
    0448 % %     ProjData.VarAttribute{2}.Role='coord_x';
    0449 %
    0450 % %     if ~isfield(FieldData,'A')
    0451 % %         ProjData.A=calc_scal(FieldData.AName,ProjData);
    0452 % %         ProjData.AName=FieldData.AName;
    0453 % %     else
    0454 %     siz=size(ObjectData.Coord);
    0455 %     if isequal(size(FieldData.A),size(FieldData.AX))%case of unstructured field at points (AX,AY)
    0456 %         for ipoint=1:siz(1)
    0457 %            Xpoint=ObjectData.Coord(ipoint,1);
    0458 %            Ypoint=ObjectData.Coord(ipoint,2);
    0459 %            distX=FieldData.AX-Xpoint;
    0460 %            distY=FieldData.AY-Ypoint;
    0461 %            dist=distX.*distX+distY.*distY;
    0462 % %                indsel=find(dist<ObjectData.YMax*ObjectData.YMax);
    0463 %            indsel=find(dist<width*width);
    0464 %            ProjData.NbScal=length(indsel);
    0465 %            A=FieldData.A(indsel);
    0466 %            ProjData.A(ipoint)=sum(A)/ProjData.NbScal;
    0467 %         end
    0468 %     elseif length(size(FieldData.A))>=2% A is already a matrix
    0469 %         siz_A=size(FieldData.A);
    0470 %         npx=siz_A(2);
    0471 %         npy=siz_A(1);
    0472 %         if length(siz_A)==3
    0473 %             npcolor=siz_A(3);
    0474 %             ProjData.ListDimName=[ProjData.ListDimName {'rgb'} ];
    0475 %             ProjData.VarDimIndex{3}=[1 2];
    0476 %             ProjData.DimValue=[siz(1) 3];
    0477 %         else
    0478 %             npcolor=1;
    0479 %         end
    0480 %         DX=abs(FieldData.AX(end)-FieldData.AX(1))/(npx-1);
    0481 %         DY=abs(FieldData.AY(end)-FieldData.AY(1))/(npy-1);
    0482 %         for ipoint=1:siz(1)
    0483 %             i_min=round((ObjectData.Coord(ipoint,1)-FieldData.AX(1)-width)/DX+0.5);
    0484 %             i_min=max(1,i_min);
    0485 %             i_plus=round((ObjectData.Coord(ipoint,1)-FieldData.AX(1)+width)/DX+0.5);
    0486 %             i_plus=min(npx,i_plus);
    0487 %             j_min=-round((ObjectData.Coord(ipoint,2)-FieldData.AY(1)+width)/DY+0.5);
    0488 %             j_min=max(1,j_min);
    0489 %             j_plus=-round((ObjectData.Coord(ipoint,2)-FieldData.AY(1)-width)/DY+0.5);
    0490 %             j_plus=min(npy,j_plus);
    0491 %             ProjData.AX(ipoint,1)=ObjectData.Coord(ipoint,1);
    0492 %             ProjData.AY(ipoint,1)=ObjectData.Coord(ipoint,2);
    0493 %             i_int=[i_min:i_plus];
    0494 %             j_int=[j_min:j_plus];
    0495 %             if ~isempty(i_int) & ~isempty(j_int)
    0496 %                 Avalue=FieldData.A(j_int,i_int,:);
    0497 %                 ProjData.A(ipoint,:)=mean(mean(Avalue));
    0498 %             else
    0499 %                ProjData.A(ipoint,:)=NaN;
    0500 %             end
    0501 %         end
    0502 %     end
    0503 % end
    0504
    0505 %-----------------------------------------------------------------
    0506 %project in a patch
    0507 function  [ProjData,errormsg]=proj_patch(FieldData,ObjectData)%%
    0508 %-------------------------------------------------------------------
    0509 ProjData=proj_heading(FieldData,ObjectData);
    0510
    0511 objectfield=fieldnames(ObjectData);
    0512 widthx=0;
    0513 widthy=0;
    0514 if isfield(ObjectData,'RangeX')&~isempty(ObjectData.RangeX)
    0515     widthx=max(ObjectData.RangeX);
    0516 end
    0517 if isfield(ObjectData,'RangeY')&~isempty(ObjectData.RangeY)
    0518     widthy=max(ObjectData.RangeY);
    0519 end
    0520
    0521 %A REVOIR, GENERALISER: UTILISER proj_line
    0522 ProjData.NbDim=0;
    0523 ProjData.ListDimName={};%name of dimension
    0524 ProjData.DimValue=[];%values of dimension (nbre of vectors)
    0525 ProjData.ListVarName={};
    0526 %ProjData.VarDimIndex={};
    0527 ProjData.VarDimName={};
    0528 if isfield (FieldData,'ListVarAttribute')
    0529     ProjData.ListVarAttribute=FieldData.ListVarAttribute;%list of variable attribute names
    0530     for iattr=1:length(ProjData.ListVarAttribute)%initialization of variable attribute values
    0531         AttrName=ProjData.ListVarAttribute{iattr};
    0532         eval(['ProjData.' AttrName '={};'])
    0533     end;
    0534 end
    0535
    0536 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
    0537 testfalse=0;
    0538 ListIndex={};
    0539 % DimVarIndex=0;%initilise list of indices for dimension variables
    0540 idimvar=0;
    0541 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
    0542 if ~isempty(errormsg)
    0543     errormsg=['error in proj_field/proj_patch:' errormsg];
    0544     return
    0545 end
    0546
    0547 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
    0548 dimcounter=0;
    0549 for icell=1:length(CellVarIndex)
    0550     testX=0;
    0551     testY=0;
    0552     test_Amat=0;
    0553     testfalse=0;
    0554     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
    0555     VarType=VarTypeCell{icell};
    0556     DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
    0557     if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2
    0558         continue
    0559     end
    0560     testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);
    0561     testfalse=~isempty(VarType.errorflag);
    0562     testproj(VarIndex)=zeros(size(VarIndex));%default
    0563     testproj(VarType.scalar)=1;
    0564     testproj(VarType.vector_x)=1;
    0565     testproj(VarType.vector_y)=1;
    0566     testproj(VarType.vector_z)=1;
    0567     testproj(VarType.image)=1;
    0568     testproj(VarType.color)=1;
    0569     VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
    0570     if testX %case of unstructured coordinates
    0571          eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');'])
    0572          for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag]
    0573                VarName=FieldData.ListVarName{ivar};
    0574             eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);'])
    0575          end
    0576          XName=FieldData.ListVarName{VarType.coord_x};
    0577          YName=FieldData.ListVarName{VarType.coord_y};
    0578          eval(['coord_x=FieldData.' XName ';'])
    0579          eval(['coord_y=FieldData.' YName ';'])
    0580     end
    0581     if testfalse
    0582         FFName=FieldData.ListVarName{VarType.errorflag};
    0583         eval(['errorflag=FieldData.' FFName ';'])
    0584     end
    0585     % image or 2D matrix
    0586     if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
    0587         test_Amat=1;%image or 2D matrix
    0588         AYName=FieldData.ListVarName{VarType.coord(1)};
    0589         AXName=FieldData.ListVarName{VarType.coord(2)};
    0590         eval(['AX=FieldData.' AXName ';'])
    0591         eval(['AY=FieldData.' AYName ';'])
    0592         VarName=FieldData.ListVarName{VarIndex(1)};
    0593         eval(['DimValue=size(FieldData.' VarName ');'])
    0594         testcolor=find(numel(DimValue)==3);
    0595 %                     errormsg='multicomponent field not projected';
    0596
    0597         for idim=1:length(DimIndices)
    0598             Coord_i_str=['Coord_' num2str(idim)];
    0599             DCoord_min(idim)=1;%default
    0600             Coord{idim}=[0.5 DimValue(idim)];
    0601             test_direct(idim)=1;
    0602             if isfield(FieldData,'VarAttribute')
    0603                 for ivar=VarIndex
    0604                     if length(FieldData.VarAttribute)>=ivar & isfield(FieldData.VarAttribute{ivar},Coord_i_str)% if there is a variable  attribute named Coord_1, _2 or _3
    0605                         eval(['Coord_i=FieldData.VarAttribute{ivar}.' Coord_i_str ';']);%'range x
    0606                         if isnumeric(Coord_i)
    0607                              if length(Coord_i)>=2
    0608                                 Coord{idim}=[Coord_i(1) Coord_i(end)];
    0609                                 %test_direct(idim)=(Coord{idim}(2)>Coord{idim}(1));
    0610                              else
    0611                                 warndlg_uvmat(['two values needed for ' Coord_i_str 'in proj_field.m'],'ERROR')
    0612                                 return
    0613                              end
    0614                          else
    0615                             warndlg_uvmat(['non numerical coordinate attributes' Coord_i_str 'in proj_field.m'],'ERROR')
    0616                             return
    0617                          end
    0618                          %test_coord(idim)=1;
    0619                          DCoord_min(idim)=(Coord{idim}(end)-Coord{idim}(1))/(DimValue(idim)-1);
    0620                     end
    0621                 end
    0622             end
    0623         end
    0624         AX=linspace(Coord{2}(1),Coord{2}(2),DimValue(2));
    0625         AY=linspace(Coord{1}(1),Coord{1}(2),DimValue(1));  %TODO : 3D case
    0626         if length(DimValue)==3
    0627             testcolor=1;
    0628             npxy(3)=3;
    0629         else
    0630             testcolor=0;
    0631         end
    0632         [Xi,Yi]=meshgrid(AX,AY);
    0633         npxy(1)=length(AY);
    0634         npxy(2)=length(AX);
    0635         Xi=reshape(Xi,npxy(1)*npxy(2),1);
    0636         Yi=reshape(Yi,npxy(1)*npxy(2),1);
    0637         for ivar=1:length(VarIndex)
    0638             VarName=FieldData.ListVarName{VarIndex(ivar)};
    0639             eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',npxy(1)*npxy(2),npxy(3));']); % keep only non false vectors
    0640         end
    0641     end
    0642 %select the indices in the range of action
    0643     testin=[];%default
    0644     if isequal(ObjectData.Style,'rectangle')
    0645 %            if ~isfield(ObjectData,'RangeX')|~isfield(ObjectData,'RangeY')
    0646 %                 errormsg='rectangle half sides RangeX and RangeY needed'
    0647 %                 return
    0648 %            end
    0649        if testX
    0650             distX=abs(coord_x-ObjectData.Coord(1,1));
    0651             distY=abs(coord_y-ObjectData.Coord(1,2));
    0652             testin=distX<widthx & distY<widthy;
    0653        elseif test_Amat
    0654            distX=abs(Xi-ObjectData.Coord(1,1));
    0655            distY=abs(Yi-ObjectData.Coord(1,2));
    0656            testin=distX<widthx & distY<widthy;
    0657        end
    0658     elseif isequal(ObjectData.Style,'polygon')
    0659         if testX
    0660             testin=inpolygon(coord_x,coord_y,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
    0661         elseif test_Amat
    0662            testin=inpolygon(Xi,Yi,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
    0663        else%calculate the scalar
    0664            testin=[]; %A REVOIR
    0665        end
    0666     elseif isequal(ObjectData.Style,'ellipse')
    0667        X2Max=widthx*widthx;
    0668        Y2Max=(widthy)*(widthy);
    0669        if testX
    0670             distX=(coord_x-ObjectData.Coord(1,1));
    0671             distY=(coord_y-ObjectData.Coord(1,2));
    0672             testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
    0673        elseif test_Amat %case of usual 2x2 matrix
    0674            distX=(Xi-ObjectData.Coord(1,1));
    0675            distY=(Yi-ObjectData.Coord(1,2));
    0676            testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
    0677        end
    0678     end
    0679     %selected indices
    0680     if isequal(ObjectData.ProjMode,'outside')
    0681             testin=~testin;
    0682     end
    0683     if testfalse
    0684         testin=testin & (errorflag==0); % keep only non false vectors
    0685     end
    0686     indsel=find(testin);
    0687     if length(DimIndices)==1
    0688         ProjDimName=FieldData.ListDimName(DimIndices);% reproduce the previous dim name
    0689     elseif dimcounter==0
    0690         ProjDimName={'nb_point'};
    0691         dimcounter=dimcounter+1;
    0692     else
    0693         ProjDimName={['nb_point_' num2str(dimcounter)]};
    0694     end
    0695    % ProjData.ListDimName=[ProjData.ListDimName ProjDimName];
    0696     %ProjData.DimValue=[ProjData.DimValue length(indsel)];
    0697     for ivar=VarIndex
    0698         if testproj(ivar)
    0699             VarName=FieldData.ListVarName{ivar};
    0700             eval(['ProjData.' VarName '=FieldData.' VarName '(indsel,:);']); % keep only non false vectors
    0701             ProjData.ListVarName=[ProjData.ListVarName {VarName}];
    0702            % ProjData.VarDimIndex=[ProjData.VarDimIndex {length(ProjData.DimValue)}];
    0703            ProjData.VarDimName=[ProjData.VarDimName ProjDimName];
    0704         end
    0705     end
    0706     if test_Amat & testcolor
    0707        %ProjData.ListDimName=[ProjData.ListDimName {'rgb'}];
    0708       % ProjData.DimValue=[ProjData.DimValue 3];
    0709       % ProjData.VarDimIndex={[1 2]};
    0710        ProjData.VarDimName={{'nb_point','rgb'}};
    0711     end
    0712 end
    0713
    0714
    0715
    0716 %-----------------------------------------------------------------
    0717 %project on a line
    0718 % AJOUTER flux,circul,error
    0719 function  [ProjData,errormsg] = proj_line(FieldData, ObjectData)
    0720 %-----------------------------------------------------------------
    0721 ProjData=proj_heading(FieldData,ObjectData);%transfer global attributes
    0722 ProjData.NbDim=1;
    0723
    0724 %initialisation of the input parameters
    0725 ProjMode='projection';%direct projection on the line by default
    0726 if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
    0727 ProjAngle=90; %90 degrees projection by default
    0728 if isfield(FieldData,'ProjAngle'),ProjAngle=ObjectData.ProjAngle; end;
    0729 width=0;%default width of the projection band
    0730
    0731 if isfield(ObjectData,'Range')&size(ObjectData.Range,2)>=2
    0732     width=abs(ObjectData.Range(1,2));
    0733 end
    0734 if isfield(ObjectData,'RangeY')
    0735     width=max(ObjectData.RangeY);
    0736 end
    0737 error=0;%default
    0738 Xline=[];
    0739
    0740 flux=0;
    0741 circul=0;
    0742 liny=ObjectData.Coord(:,2);
    0743 siz_line=size(ObjectData.Coord);
    0744 if siz_line(1)<2
    0745     return% line needs at least 2 points to be defined
    0746 end
    0747 testfalse=0;
    0748 ListIndex={};
    0749
    0750 %angles of the polyline and boundaries of action
    0751 dlinx=diff(ObjectData.Coord(:,1));
    0752 dliny=diff(ObjectData.Coord(:,2));
    0753 theta=angle(dlinx+i*dliny);%angle of each segment
    0754 theta(siz_line(1))=theta(siz_line(1)-1);
    0755 % determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
    0756 if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
    0757     xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
    0758     xinf(1)=ObjectData.Coord(1,1)+width*sin(theta(1));
    0759     ysup(1)=ObjectData.Coord(1,2)+width*cos(theta(1));
    0760     yinf(1)=ObjectData.Coord(1,2)-width*cos(theta(1));
    0761     for ip=2:siz_line(1)
    0762         xsup(ip)=ObjectData.Coord(ip,1)-width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
    0763         xinf(ip)=ObjectData.Coord(ip,1)+width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
    0764         ysup(ip)=ObjectData.Coord(ip,2)+width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
    0765         yinf(ip)=ObjectData.Coord(ip,2)-width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
    0766     end
    0767 end
    0768
    0769 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
    0770 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
    0771 if ~isempty(errormsg)
    0772     errormsg=['error in proj_field/proj_line:' errormsg];
    0773     return
    0774 end
    0775
    0776 ProjData.ListVarName={};
    0777 ProjData.VarDimName={};
    0778 for icell=1:length(CellVarIndex)
    0779     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
    0780     VarType=VarTypeCell{icell};
    0781     %DimCell=FieldData.VarDimName{VarIndex(1)}; % list of dimension names fore the cell
    0782     if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case
    0783         continue
    0784     end
    0785     testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);
    0786     testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);
    0787     testfalse=~isempty(VarType.errorflag);
    0788     testproj(VarIndex)=zeros(size(VarIndex));%default
    0789     testproj(VarType.scalar)=1;
    0790 %     testproj(VarType.vector_x)=1;
    0791 %     testproj(VarType.vector_y)=1;
    0792     testproj(VarType.vector_z)=1;
    0793     testproj(VarType.image)=1;
    0794     testproj(VarType.color)=1;
    0795     VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
    0796     if testU
    0797          VarIndex=[VarIndex VarType.vector_x VarType.vector_y];%put u and v at the end of the list of variables
    0798     end
    0799     %identify vector components
    0800     if testU
    0801         UName=FieldData.ListVarName{VarType.vector_x};
    0802         VName=FieldData.ListVarName{VarType.vector_y};
    0803         eval(['vector_x=FieldData.' UName ';'])
    0804         eval(['vector_y=FieldData.' VName ';'])
    0805     end
    0806
    0807     %identify error flag
    0808     if testfalse
    0809         FFName=FieldData.ListVarName{VarType.errorflag};
    0810         eval(['errorflag=FieldData.' FFName ';'])
    0811     end
    0812
    0813     %identify coordinates
    0814 %     ivar_x=VarType.coord_x % .ccord_x and .coord_y exist if NbDim(icell)>=2
    0815 %     DimCell_x=FieldData.VarDimName{ivar_x};
    0816 %     if ischar(DimCell_x)
    0817 %         DimCell_x={DimCell_x};
    0818 %     end
    0819
    0820     % case of unstructured positions (position given by the variables with role coord_x, coord_y
    0821     if testX
    0822         if  ~isequal(ProjMode,'interp')
    0823             if width==0
    0824                 errormsg='range of the projection object is missing';
    0825                 return
    0826             else
    0827                 lambda=2/(width*width); %smoothing factor used for filter: weight exp(-2) at distance width from the line
    0828             end
    0829         end
    0830         if ~isequal(ProjMode,'projection')
    0831             if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
    0832                 DX=abs(ObjectData.DX);%mesh of interpolation points along the line
    0833             else
    0834                 errormsg='DX missing';
    0835                 return
    0836             end
    0837         end
    0838         XName= FieldData.ListVarName{VarType.coord_x};
    0839         YName= FieldData.ListVarName{VarType.coord_y};
    0840         eval(['coord_x=FieldData.' XName ';'])
    0841         eval(['coord_y=FieldData.' YName ';'])
    0842     end
    0843
    0844     %initiate projection
    0845     for ivar=1:length(VarIndex)
    0846         ProjLine{ivar}=[];
    0847     end
    0848     XLine=[];
    0849     linelengthtot=0;
    0850
    0851 %         circul=0;
    0852 %         flux=0;
    0853   %%%%%%%  % A FAIRE CALCULER MEAN DES QUANTITES    %%%%%%
    0854    %case of unstructured coordinates
    0855     if testX
    0856         for ip=1:siz_line(1)-1     %Loop on the segments of the polyline
    0857             linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip));
    0858             %select the vector indices in the range of action
    0859             if testfalse
    0860                 flagsel=(errorflag==0); % keep only non false vectors
    0861             else
    0862                 flagsel=ones(size(coord_x));
    0863             end
    0864             if isequal(ProjMode,'projection') | isequal(ProjMode,'filter')
    0865                 flagsel=flagsel & ((coord_y -yinf(ip))*(xinf(ip+1)-xinf(ip))>(coord_x-xinf(ip))*(yinf(ip+1)-yinf(ip))) ...
    0866                 & ((coord_y -ysup(ip))*(xsup(ip+1)-xsup(ip))<(coord_x-xsup(ip))*(ysup(ip+1)-ysup(ip))) ...
    0867                 & ((coord_y -yinf(ip+1))*(xsup(ip+1)-xinf(ip+1))>(coord_x-xinf(ip+1))*(ysup(ip+1)-yinf(ip+1))) ...
    0868                 & ((coord_y -yinf(ip))*(xsup(ip)-xinf(ip))<(coord_x-xinf(ip))*(ysup(ip)-yinf(ip)));
    0869             end
    0870             indsel=find(flagsel);%indsel =indices of good vectors
    0871             X_sel=coord_x(indsel);
    0872             Y_sel=coord_y(indsel);
    0873             nbvar=0;
    0874             for iselect=1:numel(VarIndex)-2*testU
    0875                 VarName=FieldData.ListVarName{VarIndex(iselect)};
    0876                 eval(['ProjVar{iselect}=FieldData.' VarName '(indsel);']);%scalar value
    0877             end
    0878             if testU
    0879                 ProjVar{numel(VarIndex)-1}=cos(theta(ip))*vector_x(indsel)+sin(theta(ip))*vector_y(indsel);% longitudinal component
    0880                 ProjVar{numel(VarIndex)}=-sin(theta(ip))*vector_x(indsel)+cos(theta(ip))*vector_y(indsel);%transverse component
    0881             end
    0882             if isequal(ProjMode,'projection')
    0883                 sintheta=sin(theta(ip));
    0884                 costheta=cos(theta(ip));
    0885                 Xproj=(X_sel-ObjectData.Coord(ip,1))*costheta + (Y_sel-ObjectData.Coord(ip,2))*sintheta; %projection on the line
    0886                 [Xproj,indsort]=sort(Xproj);
    0887                 for ivar=1:numel(ProjVar)
    0888                     if ~isempty(ProjVar{ivar})
    0889                         ProjVar{ivar}=ProjVar{ivar}(indsort);
    0890                      end
    0891                 end
    0892             elseif isequal(ProjMode,'interp') %linear interpolation:
    0893                 npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
    0894                 Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
    0895                 xreg=cos(theta(ip))*Xproj+ObjectData.Coord(ip,1);
    0896                 yreg=sin(theta(ip))*Xproj+ObjectData.Coord(ip,2);
    0897                 for ivar=1:numel(ProjVar)
    0898                      if ~isempty(ProjVar{ivar})
    0899                         ProjVar{ivar}=griddata_uvmat(X_sel,Y_sel,ProjVar{ivar},xreg,yreg);
    0900                      end
    0901                 end
    0902             elseif isequal(ProjMode,'filter') %filtering
    0903                 npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
    0904                 Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
    0905                 siz=size(X_sel);
    0906                 xregij=cos(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,1);
    0907                 yregij=sin(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,2);
    0908                 xij=ones(npoint,1)*X_sel;
    0909                 yij=ones(npoint,1)*Y_sel;
    0910                 Aij=exp(-lambda*((xij-xregij).*(xij-xregij)+(yij-yregij).*(yij-yregij)));
    0911                 norm=ones(1,siz(2))*Aij';
    0912                 for ivar=1:numel(ProjVar)
    0913                      if ~isempty(ProjVar{ivar})
    0914                         ProjVar{ivar}=ProjVar{ivar}*Aij'./norm;
    0915                      end
    0916                 end
    0917             end
    0918             %prolongate the total record
    0919             for ivar=1:numel(ProjVar)
    0920                   if ~isempty(ProjVar{ivar})
    0921                      ProjLine{ivar}=[ProjLine{ivar}; ProjVar{ivar}];
    0922                   end
    0923             end
    0924             XLine=[XLine ;(Xproj+linelengthtot)];%along line abscissa
    0925             linelengthtot=linelengthtot+linelength;
    0926             %     circul=circul+(sum(U_sel))*linelength/npoint;
    0927             %     flux=flux+(sum(V_sel))*linelength/npoint;
    0928         end
    0929         ProjData.X=XLine';
    0930 %         eval(['ProjData.' XName '=XLine'';']); % x coordinate
    0931         %ProjData.ListDimName={XName};
    0932         %ProjData.DimValue=[length(XLine)];%values of dimension (nbre of vectors)
    0933         cur_index=1;
    0934         ProjData.ListVarName=[ProjData.ListVarName {XName}];
    0935         ProjData.VarDimName=[ProjData.VarDimName {XName}];
    0936         %ProjData.VarDimIndex{1}=[1];
    0937         ProjData.VarAttribute{1}.long_name='abscissa along line';
    0938
    0939         %ProjData.VarAttribute{1}.Role='coord_x';
    0940         for iselect=1:numel(VarIndex)
    0941             VarName=FieldData.ListVarName{VarIndex(iselect)};
    0942             eval(['ProjData.' VarName '=ProjLine{iselect};'])
    0943             ProjData.ListVarName=[ProjData.ListVarName {VarName}];
    0944             ProjData.VarDimName=[ProjData.VarDimName {XName}];
    0945             %ProjData.VarDimIndex=[ProjData.VarDimIndex {[1]}];
    0946             ProjData.VarAttribute{iselect}=FieldData.VarAttribute{VarIndex(iselect)};
    0947         end
    0948
    0949     %case of structured coordinates
    0950     elseif  numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
    0951         if ~isequal(ObjectData.Style,'line')% exclude polyline
    0952             errormsg=['no  projection available on ' ObjectData.Style 'for structured coordinates']; %
    0953         else
    0954             test_Amat=1;%image or 2D matrix
    0955             test_interp2=0;%default
    0956 %             if ~isempty(VarType.coord_y)
    0957             AYName=FieldData.ListVarName{VarType.coord(1)};
    0958             AXName=FieldData.ListVarName{VarType.coord(2)};
    0959             eval(['AX=FieldData.' AXName ';']);% set of x positions
    0960             eval(['AY=FieldData.' AYName ';']);% set of y positions
    0961             AName=FieldData.ListVarName{VarType.scalar};
    0962             eval(['A=FieldData.' AName ';']);% scalar
    0963             npxy=size(A);
    0964             npx=npxy(2);
    0965             npy=npxy(1);
    0966             if numel(AX)==2
    0967                 DX=(AX(2)-AX(1))/(npx-1);
    0968             else
    0969                 DX_vec=diff(AX);
    0970                 DX=max(DX_vec);
    0971                 DX_min=min(DX_vec);
    0972                 if (DX-DX_min)>0.0001*abs(DX)
    0973                     test_interp2=1;
    0974                     DX=DX_min;
    0975                 end
    0976             end
    0977             if numel(AY)==2
    0978                 DY=(AY(2)-AY(1))/(npy-1);
    0979             else
    0980                 DY_vec=diff(AY);
    0981                 DY=max(DY_vec);
    0982                 DY_min=min(DY_vec);
    0983                 if (DY-DY_min)>0.0001*abs(DY)
    0984                    test_interp2=1;
    0985                     DY=DY_min;
    0986                 end
    0987             end
    0988             AXI=linspace(AX(1),AX(end), npx);%set of  x  positions for the interpolated input data
    0989             AYI=linspace(AY(1),AY(end), npy);%set of  x  positions for the interpolated input data
    0990 %             else   % coordinates defined by first and last values (regular grids)
    0991 %                 if isempty(Coord_x)
    0992 %                     Coord_x=[0.5 npx-0.5];% default coordinate equal to index
    0993 %                 end
    0994 %                 if isempty(Coord_y)
    0995 %                     Coord_y=[npy-0.5 0.5];% default coordinate equal to reversed index (image convention)
    0996 %                 end
    0997 %                 AXI=linspace(Coord_x(1),Coord_x(2), npx);%set of  y positions in the input data
    0998 %                 DX=(Coord_x(2)-Coord_x(1))/(npx-1);%grid mesh
    0999 %                 AYI=linspace(Coord_y(1),Coord_y(2), npy);%set of  y positions in the input data
    1000 %                 DY=(Coord_y(2)-Coord_y(1))/(npy-1);%grid mesh
    1001 %                % indcolor([1 2])=[]; %indices of non-coordinate dimensions (e.g; color component)
    1002 %             end
    1003             if isfield(ObjectData,'DX')
    1004                 DXY_line=ObjectData.DX;%mesh on the projection line
    1005             else
    1006                 DXY_line=sqrt(abs(DX*DY));% mesh on the projection line
    1007             end
    1008             dlinx=ObjectData.Coord(2,1)-ObjectData.Coord(1,1);
    1009             dliny=ObjectData.Coord(2,2)-ObjectData.Coord(1,2);
    1010             linelength=sqrt(dlinx*dlinx+dliny*dliny);
    1011             theta=angle(dlinx+i*dliny);%angle of the line
    1012             if isfield(FieldData,'RangeX')
    1013                 XMin=min(FieldData.RangeX);%shift of the origin on the line
    1014             else
    1015                 XMin=0;
    1016             end
    1017             ProjData.AX=linspace(XMin,XMin+linelength,linelength/DXY_line+1);%abscissa of the new pixels along the line
    1018             y=linspace(-width,width,2*width/DXY_line+1);%ordintes of the new pixels (coordinate across the line)
    1019             npX=length(ProjData.AX);
    1020             npY=length(y); %TODO: utiliser proj_grid
    1021             [X,Y]=meshgrid(ProjData.AX,y);%grid in the line coordinates
    1022             XIMA=ObjectData.Coord(1,1)+(X-XMin)*cos(theta)-Y*sin(theta);
    1023             YIMA=ObjectData.Coord(1,2)+(X-XMin)*sin(theta)+Y*cos(theta);
    1024             XIMA=(XIMA-AX(1))/DX+1;%  index of the original image along x
    1025             YIMA=(YIMA-AY(1))/DY+1;% index of the original image along y
    1026             XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
    1027             YIMA=reshape(round(YIMA),1,npX*npY);
    1028             flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
    1029             ind_in=find(flagin);
    1030             ind_out=find(~flagin);
    1031             ICOMB=(XIMA-1)*npy+YIMA;
    1032             ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
    1033             nbcolor=1; %color images
    1034             if numel(npxy)==2
    1035                 nbcolor=1;
    1036             elseif length(npxy)==3
    1037                 nbcolor=npxy(3);
    1038             else
    1039                 errormsg='multicomponent field not projected';
    1040                 display(errormsg)
    1041                 return
    1042             end
    1043             nbvar=length(ProjData.ListVarName);% number of var from previous cells
    1044           %  nbdim=length(ProjData.ListDimName);%number of dim from previous cells
    1045             ProjData.ListVarName=[ProjData.ListVarName {AXName}];
    1046             ProjData.VarDimName=[ProjData.VarDimName {AXName}];
    1047             for ivar=VarIndex
    1048                 VarName{ivar}=FieldData.ListVarName{ivar};
    1049                 if test_interp2% interpolate on new grid
    1050                     eval(['FieldData.' VarName{ivar} '=interp2(FieldData.' AXName ',FieldData.' AYName ',FieldData.' VarName{ivar} ',AXI,AYI'');']) %TO TEST
    1051                 end
    1052                 eval(['vec_A=reshape(squeeze(FieldData.' VarName{ivar} '),npx*npy,nbcolor);']) %put the original image in colum
    1053                 if nbcolor==1
    1054                     vec_B(ind_in)=vec_A(ICOMB);
    1055                     vec_B(ind_out)=zeros(size(ind_out));
    1056                     A_out=reshape(vec_B,npY,npX);
    1057                     eval(['ProjData.' VarName{ivar} '=((sum(A_out,1)/npY))'';']);
    1058                 elseif nbcolor==3
    1059                     vec_B(ind_in,[1:3])=vec_A(ICOMB,:);
    1060                     vec_B(ind_out,1)=zeros(size(ind_out));
    1061                     vec_B(ind_out,2)=zeros(size(ind_out));
    1062                     vec_B(ind_out,3)=zeros(size(ind_out));
    1063                     A_out=reshape(vec_B,npY,npX,nbcolor);
    1064                     eval(['ProjData.' VarName{ivar} '=squeeze(sum(A_out,1)/npY);']);
    1065                 end
    1066                 ProjData.ListVarName=[ProjData.ListVarName VarName{ivar} ];
    1067                 ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate
    1068                 %ProjData.VarDimIndex=[ProjData.VarDimIndex nbdim+1];
    1069             end
    1070             if testU
    1071                  eval(['vector_x =ProjData.' VarName{ivar_u} ';'])
    1072                  eval(['vector_y =ProjData.' VarName{ivar_v} ';'])
    1073                  eval(['ProjData.' VarName{ivar_u} '=cos(theta)*vector_x+sin(theta)*vector_y;'])
    1074                  eval(['ProjData.' VarName{ivar_v} '=-sin(theta)*vector_x+cos(theta)*vector_y;'])
    1075             end
    1076            % ProjData.AX=(AXI)';
    1077             %ProjData.ListDimName=[ProjData.ListDimName 'AX'];
    1078             %ProjData.DimValue=[ProjData.DimValue length(ProjData.AX)];%values of dimension (nbre of vectors)
    1079             %ProjData.VarDimIndex=[ProjData.VarDimIndex length(ProjData.ListDimName)];
    1080             ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line';
    1081             %ProjData.VarAttribute{nbvar+1}.Role='coord_x';
    1082             if nbcolor==3
    1083                 %ProjData.ListDimName=[ProjData.ListDimName 'rgb'];%GENERALIZE TO OTHER COMPONENT DIMENSIONS
    1084                 %ProjData.DimValue=[ProjData.DimValue 3];%values of dimension
    1085                 %ProjData.VarDimIndex{end}=[length(ProjData.ListDimName)-1 length(ProjData.ListDimName)];
    1086                 ProjData.VarDimName{end}={XName,'rgb'};
    1087             end
    1088         end
    1089     end
    1090 end
    1091
    1092 % %shorter case for horizontal or vertical line (A FAIRE
    1093 % %     Rangx=[0.5 npx-0.5];%image coordiantes of corners
    1094 % %     Rangy=[npy-0.5 0.5];
    1095 % %     if isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
    1096 % %         Rangx=Rangx/Calib.Pxcmx;
    1097 % %         Rangy=Rangy/Calib.Pxcmy;
    1098 % %     else
    1099 % %         [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[0 0]);%case of translations without rotation and quadratic deformation
    1100 % %         [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[0 0]);
    1101 % %     end
    1102 %
    1103 % %     test_scal=0;%default% 3- 'UserData':(get(handles.Tag,'UserData')
    1104
    1105
    1106 %-----------------------------------------------------------------
    1107 %project on a plane
    1108 % AJOUTER flux,circul,error
    1109  function  [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
    1110 %-----------------------------------------------------------------
    1111
    1112 %initialisation of the input parameters of the projection plane
    1113 %-----------------------------------------------------------------
    1114 ProjMode='projection';%direct projection by default
    1115 if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
    1116
    1117 %axis origin
    1118 if isempty(ObjectData.Coord)
    1119     ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
    1120     ObjectData.Coord(1,2)=0;
    1121     ObjectData.Coord(1,3)=0;
    1122 end
    1123
    1124 %rotation angles
    1125 Phi=0;%default
    1126 Theta=0;
    1127 Psi=0;
    1128 if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
    1129     Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
    1130 end
    1131 if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
    1132     Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
    1133 end
    1134 if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
    1135     Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
    1136 end
    1137
    1138 %components of the unity vector normal to the projection plane
    1139 NormVec_X=-sin(Phi)*sin(Theta);
    1140 NormVec_Y=cos(Phi)*sin(Theta);
    1141 NormVec_Z=cos(Theta);
    1142
    1143 % test for 3D fields
    1144 test3D=0;
    1145 if isfield(FieldData,'NbDim')
    1146     test3D=isequal(FieldData.NbDim,3);
    1147 end
    1148 test3C=test3D; %default 3 vel components
    1149
    1150 %mesh sizes DX and DY
    1151 DX=0;
    1152 DY=0; %default
    1153 if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
    1154      DX=abs(ObjectData.DX);%mesh of interpolation points
    1155 end
    1156 if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
    1157      DY=abs(ObjectData.DY);%mesh of interpolation points
    1158 end
    1159 if  ~isequal(ProjMode,'projection') & (DX==0|DY==0)
    1160         errormsg='DX or DY missing';
    1161         display(errormsg)
    1162         return
    1163 end
    1164
    1165 %extrema along each axis
    1166 testXMin=0;
    1167 testXMax=0;
    1168 testYMin=0;
    1169 testYMax=0;
    1170 if isfield(ObjectData,'RangeX')
    1171         XMin=min(ObjectData.RangeX);
    1172         XMax=max(ObjectData.RangeX);
    1173         testXMin=XMax>XMin;
    1174         testXMax=1;
    1175 end
    1176 if isfield(ObjectData,'RangeY')
    1177         YMin=min(ObjectData.RangeY);
    1178         YMax=max(ObjectData.RangeY);
    1179         testYMin=YMax>YMin;
    1180         testYMax=1;
    1181 end
    1182 width=0;%default width of the projection band
    1183 if isfield(ObjectData,'RangeZ')
    1184         width=max(ObjectData.RangeZ);
    1185 end
    1186
    1187 % initiate Matlab  structure for physical field
    1188 ProjData=proj_heading(FieldData,ObjectData);
    1189 ProjData.NbDim=2;
    1190 ProjData.ListDimName={};%name of dimension
    1191 ProjData.DimValue=[];%values of dimension (nbre of vectors)
    1192 ProjData.ListVarName={};
    1193 ProjData.VarDimIndex={};
    1194
    1195 error=0;%default
    1196 flux=0;
    1197 testfalse=0;
    1198 ListIndex={};
    1199
    1200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1201 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
    1202 %-----------------------------------------------------------------
    1203 idimvar=0;
    1204 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
    1205 if ~isempty(errormsg)
    1206     errormsg=['error in proj_field/proj_plane:' errormsg];
    1207     return
    1208 end
    1209 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
    1210 % CellVarIndex=cells of variable index arrays
    1211 ivar_new=0; % index of the current variable in the projected field
    1212 icoord=0;
    1213 for icell=1:length(CellVarIndex)
    1214     if NbDim(icell)==1
    1215         continue
    1216     end
    1217     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
    1218     VarType=VarTypeCell{icell};
    1219     ivar_X=VarType.coord_x;
    1220     ivar_Y=VarType.coord_y;
    1221     ivar_Z=VarType.coord_z;
    1222     ivar_U=VarType.vector_x;
    1223     ivar_V=VarType.vector_y;
    1224     ivar_W=VarType.vector_z;
    1225     ivar_C=VarType.scalar ;
    1226     ivar_Anc=VarType.ancillary;
    1227     test_anc=zeros(size(VarIndex));
    1228     test_anc(ivar_Anc)=ones(size(ivar_Anc));
    1229     ivar_F=VarType.warnflag;
    1230     ivar_FF=VarType.errorflag;
    1231     if isempty(ivar_X)
    1232         test_grid=1;%test for input data on regular grid (e.g. image)coordinates
    1233     else
    1234         if length(ivar_Y)~=1
    1235                 warndlg_uvmat('y coordinate missing in proj_field.m','ERROR')
    1236                 return
    1237         end
    1238         test_grid=0;
    1239     end
    1240     DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
    1241
    1242 %case of input fields with unstructured coordinates
    1243     if ~test_grid
    1244         if length(ivar_X)==1
    1245             eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';'])
    1246         end
    1247         if length(ivar_Y)==1
    1248             eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';'])
    1249         end
    1250         if length(ivar_Z)==1
    1251             eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])
    1252         end
    1253         if length(ivar_U)>1 | length(ivar_V)>1 | length(ivar_W)>1
    1254                  warndlg_uvmat('multiple vector input in proj_field.m','ERROR')
    1255                     return
    1256         end
    1257         if length(ivar_X)>1 | length(ivar_Y)>1 | length(ivar_Z)>1
    1258                  warndlg_uvmat('multiple coordinate input in proj_field.m','ERROR')
    1259                     return
    1260         end
    1261         if length(ivar_F)>1 | length(ivar_FF)>1
    1262                  warndlg_uvmat('multiple flag input in proj_field.m','ERROR')
    1263                     return
    1264         end
    1265         if length(ivar_Y)~=1
    1266             warndlg_uvmat('y coordinate missing in proj_field.m','ERROR')
    1267             return
    1268         end
    1269         % translate  initial coordinates
    1270         coord_x=coord_x-ObjectData.Coord(1,1);
    1271         coord_y=coord_y-ObjectData.Coord(1,2);
    1272         if ~isempty(ivar_Z)
    1273             coord_z=coord_z-ObjectData.Coord(1,3);
    1274         end
    1275         % selection of the vectors in the projection range (3D case)
    1276         if length(ivar_Z)==1 &  width > 0
    1277             %components of the unitiy vector normal to the projection plane
    1278             fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
    1279             indcut=find(abs(fieldZ) <= width);
    1280             for ivar=VarIndex
    1281                 VarName=FieldData.ListVarName{ivar};
    1282                 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
    1283 %                 end
    1284                     % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
    1285             end
    1286             coord_x=coord_x(indcut);
    1287             coord_y=coord_y(indcut);
    1288             coord_z=coord_z(indcut);
    1289         end
    1290
    1291        %rotate coordinates if needed
    1292         if isequal(Phi,0)
    1293             coord_X=coord_x;
    1294             coord_Y=coord_y;
    1295             if ~isequal(Theta,0)
    1296                 coord_Y=coord_Y *cos(Theta);
    1297             end
    1298         else
    1299             coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
    1300             coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
    1301         end
    1302         if ~isempty(ivar_Z)
    1303             coord_Y=coord_Y+coord_z *sin(Theta);
    1304         end
    1305         if ~isequal(Psi,0)
    1306                 coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
    1307                 coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
    1308         end
    1309
    1310         %restriction to the range of x and y if imposed
    1311         testin=ones(size(coord_X)); %default
    1312         testbound=0;
    1313         if testXMin
    1314             testin=testin & (coord_X >= XMin);
    1315             testbound=1;
    1316         end
    1317         if testXMax
    1318             testin=testin & (coord_X <= XMax);
    1319             testbound=1;
    1320         end
    1321         if testYMin
    1322             testin=testin & (coord_Y >= YMin);
    1323             testbound=1;
    1324         end
    1325         if testYMin
    1326             testin=testin & (coord_Y <= YMax);
    1327             testbound=1;
    1328         end
    1329         if testbound
    1330             indcut=find(testin);
    1331             for ivar=VarIndex
    1332                 VarName=FieldData.ListVarName{ivar};
    1333                 eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
    1334             end
    1335             coord_X=coord_X(indcut);
    1336             coord_Y=coord_Y(indcut);
    1337             if length(ivar_Z)==1
    1338                 coord_Z=coord_Z(indcut);
    1339             end
    1340         end
    1341         % different cases of projection
    1342         if isequal(ObjectData.ProjMode,'projection')
    1343             ProjData.ListDimName=[ProjData.ListDimName FieldData.ListDimName(DimIndices(1))];%add the point index to the list of dimensions
    1344             ProjData.DimValue=[ProjData.DimValue length(coord_X)];
    1345             nbvar=0;
    1346             for ivar=VarIndex %transfer variables to the projection plane
    1347                 VarName=FieldData.ListVarName{ivar};
    1348                 if ivar==ivar_X %x coordinate
    1349                     eval(['ProjData.' VarName '=coord_X;'])
    1350                 elseif ivar==ivar_Y % y coordinate
    1351                     eval(['ProjData.' VarName '=coord_Y;'])
    1352                 elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
    1353                     eval(['ProjData.' VarName '=FieldData.' VarName ';'])
    1354                 end
    1355                 if isempty(ivar_Z) || ivar~=ivar_Z
    1356                     ProjData.ListVarName=[ProjData.ListVarName VarName];
    1357                     ProjData.VarDimIndex=[ProjData.VarDimIndex DimIndices(1)];
    1358                     nbvar=nbvar+1;
    1359                     if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
    1360                         ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
    1361                     end
    1362                 end
    1363             end
    1364         elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
    1365             coord_x_proj=[XMin:DX:XMax];
    1366             coord_y_proj=[YMin:DY:YMax];
    1367             ProjData.ListDimName={'coord_y','coord_x'};
    1368             ProjData.DimValue=[length(coord_y_proj) length(coord_x_proj)];
    1369             ProjData.ListVarName={};
    1370             ProjData.VarDimIndex={};
    1371             if isempty(ivar_X), ivar_X=0; end;
    1372             if isempty(ivar_Y), ivar_Y=0; end;
    1373             if isempty(ivar_Z), ivar_Z=0; end;
    1374             if isempty(ivar_U), ivar_U=0; end;
    1375             if isempty(ivar_V), ivar_V=0; end;
    1376             if isempty(ivar_W), ivar_W=0; end;
    1377             if isempty(ivar_F), ivar_F=0; end;
    1378             if isempty(ivar_FF), ivar_FF=0; end;
    1379             if ~isequal(ivar_FF,0)
    1380                 VarName_FF=FieldData.ListVarName{ivar_FF};
    1381                 eval(['indsel=find(FieldData.' VarName_FF '==0);'])
    1382                 coord_X=coord_X(indsel);
    1383                 coord_Y=coord_Y(indsel);
    1384             end
    1385             FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
    1386             testFF=0;
    1387             for ivar=VarIndex
    1388                 VarName=FieldData.ListVarName{ivar};
    1389                 if ~( ivar==ivar_X | ivar==ivar_Y | ivar==ivar_Z | ivar==ivar_F | ivar==ivar_FF | test_anc(ivar)==1)
    1390                     ivar_new=ivar_new+1;
    1391                     ProjData.ListVarName=[ProjData.ListVarName {VarName}];
    1392                     ProjData.VarDimIndex=[ProjData.VarDimIndex {[1 2]}];
    1393                     if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
    1394                         ProjData.VarAttribute{ivar_new}=FieldData.VarAttribute{ivar};
    1395                     end
    1396                     ProjData.VarAttribute{ivar_new}.Coord_2=[XMin XMax];
    1397                     ProjData.VarAttribute{ivar_new}.Coord_1=[YMin YMax];
    1398                     if  ~isequal(ivar_FF,0)
    1399                         eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
    1400                     end
    1401                     eval(['ProjData.' VarName '=griddata_uvmat(coord_X,coord_Y,FieldData.' VarName ',coord_x_proj,coord_y_proj'');'])
    1402                     eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
    1403                     FFlag= isnan(varline); %detect undefined values NaN
    1404                     indnan=find(FFlag);
    1405                     if~isempty(indnan)
    1406                         varline(indnan)=zeros(size(indnan));
    1407                         eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
    1408                         FF(indnan)=ones(size(indnan));
    1409 %                         eval(['ProjData.' VarName '(indnan)=zeros(size(indnan));'])%put NaN to 0
    1410 %                         FF=FF|FFlag;
    1411                         testFF=1;
    1412                     end
    1413                     if ivar==ivar_U
    1414                         ivar_U=ivar_new;
    1415                     end
    1416                     if ivar==ivar_V
    1417                         ivar_V=ivar_new;
    1418                     end
    1419                     if ivar==ivar_W
    1420                         ivar_W=ivar_new;
    1421                     end
    1422                 end
    1423             end
    1424             if testFF
    1425                 ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
    1426                 ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
    1427                 ProjData.VarDimIndex=[ProjData.VarDimIndex {[1 2]}];
    1428                 ProjData.VarAttribute{ivar_new+1}.Role='errorflag';
    1429             end
    1430         end
    1431 %case of fields defined on a structured  grid
    1432     else
    1433         DimValue=FieldData.DimValue(DimIndices);%set of dimension values
    1434         ListDimName=FieldData.ListDimName(DimIndices);
    1435         nbcolor=1; %default
    1436         for idim=1:length(ListDimName)
    1437             DimName=ListDimName{idim};
    1438             if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
    1439                nbcolor=DimValue(idim);
    1440                DimIndices(idim)=[];
    1441                DimValue(idim)=[];
    1442             end
    1443             if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
    1444                 DimIndices(idim)=[];
    1445                 DimValue(idim)=[];
    1446             end
    1447         end
    1448         ind_1=find(DimValue==1);
    1449         DimIndices(ind_1)=[]; %suppress singleton dimensions
    1450         indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
    1451         nb_dim=length(DimIndices);%number of space dimensions
    1452         Coord_z=[];
    1453         Coord_y=[];
    1454         Coord_x=[];
    1455
    1456         for idim=1:nb_dim %loop on space dimensions
    1457             test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
    1458             test_coord(idim)=0;%test for defined coordinates, =0 by default
    1459             ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
    1460             if ~isequal(ivar,0)%  a variable corresponds to the current dimension
    1461                 eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
    1462                 DCoord=diff(Coord{idim});
    1463                 DCoord_min(idim)=min(DCoord);
    1464                 DCoord_max=max(DCoord);
    1465                 test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
    1466                 test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
    1467                 if ~isequal(test_direct(idim),test_direct_min)
    1468                      warndlg_uvmat(['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'],'ERROR')
    1469                                 return
    1470                 end
    1471                 test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
    1472                 test_coord(idim)=1;
    1473
    1474             else  % no variable associated with the first dimension, look for variable  attributes Coord_1, _2 or _3
    1475                 Coord_i_str=['Coord_' num2str(idim)];
    1476                 DCoord_min(idim)=1;%default
    1477                 Coord{idim}=[0.5 DimValue(idim)-0.5];
    1478                 test_direct(idim)=1;
    1479                 for ivar=VarIndex
    1480                     if  isfield(FieldData.VarAttribute{ivar},Coord_i_str)% if there is a variable  attribute named Coord_1, _2 or _3
    1481                          eval(['Coord{idim}=FieldData.VarAttribute{ivar}.' Coord_i_str ';']);%'range x
    1482                          if isnumeric(Coord{idim})
    1483                              if length(Coord{idim})>=2
    1484                                 test_direct(idim)=(Coord{idim}(2)>Coord{idim}(1));
    1485                              else
    1486                                 warndlg_uvmat(['two values needed for ' Coord_i_str 'in proj_field.m'],'ERROR')
    1487                                 return
    1488                              end
    1489                          else
    1490                             warndlg_uvmat(['non numerical coordinate attributes' Coord_i_str 'in proj_field.m'],'ERROR')
    1491                             return
    1492                          end
    1493                          DCoord_min(idim)=(Coord{idim}(end)-Coord{idim}(1))/(DimValue(idim)-1);
    1494                     end
    1495                 end
    1496             end
    1497         end
    1498         if nb_dim==2
    1499             if DY==0
    1500                 DY=abs(DCoord_min(1));
    1501             end
    1502             npY=1+round(abs(Coord{1}(end)-Coord{1}(1))/DY);%nbre of points after interpolation
    1503             npy=1+round(abs(Coord{1}(end)-Coord{1}(1))/abs(DCoord_min(1)));%nbre of points after possible interpolation on a regular grid
    1504             if DX==0
    1505                 DX=abs(DCoord_min(2));
    1506             end
    1507             npX=1+round(abs(Coord{2}(end)-Coord{2}(1))/DX);%nbre of points after interpol
    1508             npx=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points after possible interpolation on a regular grid
    1509             Coord_y=linspace(Coord{1}(1),Coord{1}(end),npY);
    1510             test_direct_y=test_direct(1);
    1511             Coord_x=linspace(Coord{2}(1),Coord{2}(end),npX);
    1512             test_direct_x=test_direct(2);
    1513             DAX=DCoord_min(2);
    1514             DAY=DCoord_min(1);
    1515         elseif nb_dim==3
    1516             DZ=abs(DCoord_min(1));
    1517             npz=1+round(abs(Coord{1}(end)-Coord{1}(1))/DZ);%nbre of points after interpolation
    1518             if DY==0
    1519                 DY=abs(DCoord_min(2));
    1520             end
    1521             npY=1+round(abs(Coord{2}(end)-Coord{2}(1))/DY);%nbre of points after interpol
    1522             npy=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol
    1523             if DX==0
    1524                 DX=abs(DCoord_min(3));
    1525             end
    1526             npX=1+round(abs(Coord{3}(end)-Coord{3}(1))/DX);%nbre of points after interpol
    1527             npx=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol
    1528             Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz);
    1529             test_direct_z=test_direct(1);
    1530             Coord_y=linspace(Coord{2}(1),Coord{2}(end),npY);
    1531             test_direct_y=test_direct(2);
    1532             Coord_x=linspace(Coord{3}(1),Coord{3}(end),npX);
    1533             test_direct_x=test_direct(3);
    1534         end
    1535         minAX=min(Coord_x);
    1536         maxAX=max(Coord_x);
    1537         minAY=min(Coord_y);
    1538         maxAY=max(Coord_y);
    1539         xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
    1540         ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
    1541         xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
    1542         ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
    1543         if ~testXMax
    1544             XMax=max(xcor_new);
    1545         end
    1546         if ~testXMin
    1547             XMin=min(xcor_new);
    1548         end
    1549         if ~testYMax
    1550             YMax=max(ycor_new);
    1551         end
    1552         if ~testYMin
    1553             YMin=min(ycor_new);
    1554         end
    1555         DXinit=(maxAX-minAX)/(npx-1);
    1556         DYinit=(maxAY-minAY)/(npy-1);
    1557         if DX==0
    1558             DX=DXinit;
    1559         end
    1560         if DY==0
    1561             DY=DYinit;
    1562         end
    1563         npX=floor((XMax-XMin)/DX+1);
    1564         npY=floor((YMax-YMin)/DY+1);
    1565         if test_direct_y
    1566             coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
    1567         else
    1568             coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
    1569         end
    1570         if test_direct_x
    1571             coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
    1572         else
    1573             coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
    1574         end
    1575
    1576         % case with no rotation and interpolation
    1577         if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
    1578             if test_direct(1)
    1579                 min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
    1580                 max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
    1581                 Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
    1582                 Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
    1583             else
    1584                 min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
    1585                 max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
    1586                 Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
    1587                 Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
    1588             end
    1589             if test_direct(2)==1
    1590                 min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
    1591                 max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
    1592                 Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
    1593                 Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
    1594             else
    1595                 min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
    1596                 max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
    1597                 Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
    1598                 Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
    1599             end
    1600             min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
    1601             min_ind2=max(min_ind2,1);
    1602             max_ind1=min(max_ind1,npy);
    1603             max_ind2=min(max_ind2,npx);
    1604             for ivar=VarIndex
    1605                 VarName=FieldData.ListVarName{ivar};
    1606                 if isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')% coordinates common to all fields
    1607                     ProjData.ListDimName={'coord_y','coord_x'};
    1608                     ProjData.DimValue=[length(coord_y_proj) length(coord_x_proj)];
    1609                 else
    1610                     icoord=icoord+1;
    1611                     ProjData.ListDimName=[ProjData.ListDimName {['coord_y_' num2str(icoord)],['coord_x_' num2str(icoord)]}];
    1612                     ProjData.DimValue=[ProjData.DimValue length(coord_y_proj) length(coord_x_proj)];
    1613                 end
    1614                 ProjData.ListVarName=[ProjData.ListVarName VarName];
    1615                 ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
    1616                 if length(FieldData.VarAttribute)>=ivar
    1617                     ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
    1618                 end
    1619                 ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=Xbound;
    1620                 ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=Ybound;
    1621                 eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2) ;']);
    1622             end
    1623         else
    1624         % case with rotation and/or interpolation
    1625             if isempty(Coord_z) %2D case
    1626                 [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
    1627                 XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
    1628                 YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
    1629                 XIMA=(XIMA-minAX)/DXinit+1;% image index along x
    1630                 YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
    1631                 XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
    1632                 YIMA=reshape(round(YIMA),1,npX*npY);
    1633                 flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
    1634                 if isequal(ObjectData.ProjMode,'filter')
    1635                     npx_filter=ceil(abs(DX/DAX));
    1636                     npy_filter=ceil(abs(DY/DAY));
    1637                     Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
    1638                     test_filter=1;
    1639                 else
    1640                     test_filter=0;
    1641                 end
    1642                 for ivar=VarIndex
    1643                     VarName=FieldData.ListVarName{ivar} ;
    1644                     if test_interp(1) | test_interp(2)%interpolate on a regular grid
    1645                           eval(['FieldData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
    1646                     end
    1647                     %filter the field (image) if option 'filter' is used
    1648                     if test_filter
    1649                          Aclass=class(FieldData.A);
    1650                          eval(['FieldData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
    1651                          if ~isequal(Aclass,'double')
    1652                              eval(['FieldData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
    1653                          end
    1654                     end
    1655                     eval(['vec_A=reshape(FieldData.' VarName ',npx*npy,nbcolor);'])%put the original image in line
    1656                     ind_in=find(flagin);
    1657                     ind_out=find(~flagin);
    1658                     ICOMB=(XIMA-1)*npy+YIMA;
    1659                     ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
    1660                     vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:);
    1661                     for icolor=1:nbcolor
    1662                         vec_B(ind_out,icolor)=zeros(size(ind_out));
    1663                     end
    1664                     if isequal(ObjectData.ProjMode,'interp') || isequal(ObjectData.ProjMode,'filter')% coordinates common to all fields
    1665                         ProjData.ListDimName={'coord_y','coord_x'};
    1666                         ProjData.DimValue=[length(coord_y_proj) length(coord_x_proj)];
    1667                     else
    1668                         icoord=icoord+1;
    1669                         ProjData.ListDimName=[ProjData.ListDimName {['coord_y_' num2str(icoord)],['coord_x_' num2str(icoord)]}];
    1670                         ProjData.DimValue=[ProjData.DimValue length(coord_y_proj) length(coord_x_proj)];
    1671                     end
    1672                     ProjData.ListVarName=[ProjData.ListVarName VarName];
    1673                     ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
    1674                     if length(FieldData.VarAttribute)>=ivar
    1675                         ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
    1676                     end
    1677                     if test_direct(2)==1
    1678                         ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMin XMax];
    1679                     else
    1680                         ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMax XMin];
    1681                     end
    1682                     if test_direct(1)==1
    1683                         ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMin YMax];
    1684                     else
    1685                         ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMax YMin];
    1686                     end
    1687                     eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
    1688                 end
    1689                 ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
    1690                 ProjData.ListVarName=[ProjData.ListVarName 'FF'];
    1691                 ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
    1692                 ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
    1693             else %3D case
    1694                 if isequal(Theta,0) & isequal(Phi,0)
    1695                     test_sup=(Coord{1}>=ObjectData.Coord(1,3));
    1696                     iz_sup=find(test_sup);
    1697                     iz=iz_sup(1);
    1698                     if iz>=1 & iz<=npz
    1699                         ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
    1700                         ProjData.DimValue=[ProjData.DimValue npY npX];
    1701                         for ivar=VarIndex
    1702                             VarName=FieldData.ListVarName{ivar};
    1703                             ProjData.ListVarName=[ProjData.ListVarName VarName];
    1704                             ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-2 nb_dim-1]];
    1705                             ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
    1706                             if test_direct_x==1
    1707                                 ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMin XMax];
    1708                             else
    1709                                 ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_2=[XMax XMin];
    1710                             end
    1711                             if test_direct_y==1
    1712                                 ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMin YMax];
    1713                             else
    1714                                 ProjData.VarAttribute{length(ProjData.ListVarName)}.Coord_1=[YMax YMin];
    1715                             end
    1716                             eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
    1717                             %TODO : do a vertical average for a thick plane
    1718                             if test_interp(2) | test_interp(3)
    1719                                 eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
    1720                             end
    1721                         end
    1722                     end
    1723                 else
    1724                     warndlg_uvmat('projection of structured coordinates on oblique plane not yet implemented','ERROR')
    1725                     %TODO: use interp3
    1726                     return
    1727                 end
    1728             end
    1729         end
    1730     end
    1731     %projection of  velocity components in the rotated coordinates
    1732     if ~isequal(Phi,0) & length(ivar_U)==1
    1733         if isempty(ivar_V)
    1734             warndlg_uvmat('v velocity component missing in proj_field.m','ERROR')
    1735             return
    1736         end
    1737         UName=FieldData.ListVarName{ivar_U};
    1738         VName=FieldData.ListVarName{ivar_V};
    1739         eval(['ProjData.' UName  '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
    1740         eval(['ProjData.' VName  '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
    1741         if ~isempty(ivar_W)
    1742             WName=FieldData.ListVarName{ivar_W};
    1743             eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
    1744             eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
    1745         end
    1746         if ~isequal(Psi,0)
    1747             eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
    1748             eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
    1749         end
    1750     end
    1751 end
    1752
    1753 %-----------------------------------------------------------------
    1754 %transmit the global attributes
    1755 function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
    1756 %-----------------------------------------------------------------
    1757 % ProjData=FieldData;
    1758 ProjData=[];%default
    1759 if ~isfield(FieldData,'ListGlobalAttribute')
    1760     ProjData.ListGlobalAttribute={};
    1761 else
    1762     ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
    1763 end
    1764 if isfield(FieldData,'Txt')
    1765     errormsg=FieldData.Txt; %transmit erreur message
    1766     return;
    1767 end
    1768 for iattr=1:length(ProjData.ListGlobalAttribute)
    1769     AttrName=ProjData.ListGlobalAttribute{iattr};
    1770     if isfield(FieldData,AttrName)
    1771         eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
    1772     end
    1773 end
    1774 if isfield(FieldData,'CoordType')
    1775     if isfield(ObjectData,'CoordType')&~isequal(FieldData.CoordType,ObjectData.CoordType)
    1776         errormsg=[ObjectData.Style ' in ' ObjectData.CoordType ' coordinates, while field in ' FieldData.CoordType ' coordinates'];
    1777         return
    1778     else
    1779          ProjData.CoordType=FieldData.CoordType;
    1780     end
    1781 end
    1782
    1783 ListObject={'Style','ProjMode','RangeX','RangeY','RangeZ','Phi','Theta','Psi','Coord'};
    1784 for ilist=1:length(ListObject)
    1785     if isfield(ObjectData,ListObject{ilist})
    1786         eval(['val=ObjectData.' ListObject{ilist} ';'])
    1787         if ~isempty(val)
    1788             eval(['ProjData.Object' ListObject{ilist} '=val;']);
    1789             ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
    1790         end
    1791     end
    1792 end