Index: trunk/src/proj_field.m
===================================================================
--- trunk/src/proj_field.m	(revision 521)
+++ trunk/src/proj_field.m	(revision 530)
@@ -148,5 +148,6 @@
 [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
 ProjData.NbDim=0;
-[CellVarIndex,NbDimCell,VarTypeCell,errormsg]=find_field_cells(FieldData);
+[CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData);
+%[CellVarIndex,NbDimCell,VarTypeCell,errormsg]=find_field_cells(FieldData);
 if ~isempty(errormsg)
     errormsg=['error in proj_field/proj_points:' errormsg];
@@ -154,31 +155,55 @@
 end
 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
-for icell=1:length(CellVarIndex)
-    if NbDimCell(icell)==1
-        continue
-    end
-    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
-    VarType=VarTypeCell{icell};% structure defining the types of variables in the cell
-    ivar_X=VarType.coord_x;
-    ivar_Y=VarType.coord_y;
-    ivar_Z=VarType.coord_z;
-    ivar_Anc=VarType.ancillary;
-    test_anc(ivar_Anc)=ones(size(ivar_Anc));
-    ivar_F=VarType.warnflag;
-    ivar_FF=VarType.errorflag;
-    VarIndex([ivar_X ivar_Y ivar_Z ivar_Anc ivar_F ivar_FF])=[];% not projected variables removed frlom list
-    if isempty(ivar_X)
-        test_grid=1;%test for input data on regular grid (e.g. image)coordinates      
-    else
-        if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1
-                 errormsg='multiple coordinate input in proj_field.m';
-                    return
-        end
-        if length(ivar_Y)~=1
-                errormsg='y coordinate not defined in proj_field.m';
-                return
-        end
-        test_grid=0;
-    end
+for icell=1:length(CellInfo)
+    if NbDimArray(icell)<=1
+        continue %projection only for multidimensional fields
+    end
+    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
+   % VarType=CellInfo{icell}.VarType;% structure defining the types of variables in the cell
+    ivar_X=CellInfo{icell}.CoordIndex(end);
+    ivar_Y=CellInfo{icell}.CoordIndex(end-1);
+    ivar_Z=[];
+    if NbDimArray(icell)==3
+        ivar_Z=CellInfo{icell}.CoordIndex(1);
+    end
+%     ivar_rem=[];
+%     if isfield(CellInfo{icell},'VarIndex_ancillary')
+%         ivar_rem=CellInfo{icell}.VarIndex_ancillary;
+%     end
+%     if isfield(CellInfo{icell},'VarIndex_warnflag')
+%         ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_warnflag];
+%     end
+    ivar_FF=[];
+    if isfield(CellInfo{icell},'VarIndex_errorflag')
+        ivar_FF=CellInfo{icell}.VarIndex_errorflag;
+        if numel(ivar_FF)>1
+            errormsg='multiple error flag input';
+            return
+        end
+    end
+%     
+    % select types of  variables to be projected
+   ListProject={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
+   check_project=false(size(VarIndex));
+   for ilist=1:numel(ListProject)
+       if isfield(CellInfo{icell},ListProject{ilist})
+           check_project(CellInfo{icell}.(ListProject{ilist}))=1;
+       end
+   end
+   VarIndex=VarIndex(check_project);
+     
+%     if isempty(ivar_X)
+%         test_grid=1;%test for input data on regular grid (e.g. image)coordinates      
+%     else
+%         if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1
+%                  errormsg='multiple coordinate input in proj_field.m';
+%                     return
+%         end
+%         if length(ivar_Y)~=1
+%                 errormsg='y coordinate not defined in proj_field.m';
+%                 return
+%         end
+%         test_grid=0;
+%     end
     ProjData.ListVarName={'Y','X','NbVal'};
     ProjData.VarDimName={'nb_points','nb_points','nb_points'};
@@ -190,17 +215,15 @@
         ProjData.ListVarName=[ProjData.ListVarName {VarName}];% add the current variable to the list of projected variables
         ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}]; % projected VarName has a single dimension called 'nb_points' (set of projection points)
-    end
-    if ~test_grid
-        eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';'])
-        eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';'])
+
+    end
+    if strcmp( CellInfo{icell}.CoordType,'scattered')
+        coord_x=FieldData.(FieldData.ListVarName{ivar_X});
+        coord_y=FieldData.(FieldData.ListVarName{ivar_Y});
         test3D=0;% TEST 3D CASE : NOT COMPLETED ,  3D CASE : NOT COMPLETED 
         if length(ivar_Z)==1
-            eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])
+            coord_z=FieldData.(FieldData.ListVarName{ivar_Z});
             test3D=1;
         end
-        if length(ivar_F)>1 || length(ivar_FF)>1 
-                 msgbox_uvmat('ERROR','multiple flag input in proj_field.m')
-                    return
-        end      
+   
         for ipoint=1:siz(1)
            Xpoint=ObjectData.Coord(ipoint,:);
@@ -231,21 +254,20 @@
         end
     else    %case of structured coordinates
-        if  numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
-            AYName=FieldData.ListVarName{VarType.coord(1)};
-            AXName=FieldData.ListVarName{VarType.coord(2)};
+        if  strcmp( CellInfo{icell}.CoordType,'grid')
+            AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
+            AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
             eval(['AX=FieldData.' AXName ';']);% set of x positions
             eval(['AY=FieldData.' AYName ';']);% set of y positions  
             AName=FieldData.ListVarName{VarIndex(1)};% a single variable assumed in the current cell
             eval(['A=FieldData.' AName ';']);% scalar
-            npxy=size(A);        
-            NbDim=numel(VarType.coord(VarType.coord>0));%number of space dimensions 
+            npxy=size(A);         
             %update VarDimName in case of components (non coordinate dimensions e;g. color components)
-            if numel(npxy)>NbDim
+            if numel(npxy)>NbDimArray(icell)
                 ProjData.VarDimName{end}={'nb_points','component'};
             end
-            for idim=1:NbDim %loop on space dimensions
+            for idim=1:NbDimArray(icell) %loop on space dimensions
                 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
                 test_coord(idim)=0;%test for defined coordinates, =0 by default
-                ivar=VarType.coord(idim);
+                ivar=CellInfo{icell}.CoordIndex(idim);
                 Coord{idim}=FieldData.(FieldData.ListVarName{ivar}); % position for the first index
                 if numel(Coord{idim})==2
@@ -342,5 +364,6 @@
 % DimVarIndex=0;%initilise list of indices for dimension variables
 idimvar=0;
-[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData);
+[CellInfo,NbDim,errormsg]=find_field_cells(FieldData);
+%[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData);
 if ~isempty(errormsg)
     errormsg=['error in proj_field/proj_patch:' errormsg];
@@ -350,26 +373,38 @@
 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
 dimcounter=0;
-for icell=1:length(CellVarIndex)
+for icell=1:length(CellInfo)
     testX=0;
     testY=0;
     test_Amat=0;
     testfalse=0;
-    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
-    VarType=VarTypeCell{icell};
+    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
+  %  VarType=VarTypeCell{icell};
   %  DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
     if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2
         continue
     end
-    testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);
-    testfalse=~isempty(VarType.errorflag);
+    %testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);
+    testfalse=isfield(CellInfo{icell},'VarIndex_errorflag');
     testproj(VarIndex)=zeros(size(VarIndex));%default
-    testproj(VarType.scalar)=1;
-    testproj(VarType.vector_x)=1;
-    testproj(VarType.vector_y)=1;
-    testproj(VarType.vector_z)=1;
-    testproj(VarType.image)=1;
-    testproj(VarType.color)=1;
-    VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
-    if check_unstructured%case of unstructured coordinates
+    ivar_X=CellInfo{icell}.CoordIndex(end);
+    ivar_Y=CellInfo{icell}.CoordIndex(end-1);
+    ivar_Z=[];
+    if NbDimArray(icell)==3
+        ivar_Z=CellInfo{icell}.CoordIndex(1);
+    end
+    ivar_rem=[];
+    if isfield(CellInfo{icell},'VarIndex_ancillary')
+        ivar_rem=CellInfo{icell}.VarIndex_ancillary;
+    end
+    if isfield(CellInfo{icell},'VarIndex_warnflag')
+        ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_warnflag];
+    end
+    if isfield(CellInfo{icell},'VarIndex_errorflag')
+        ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_errorflag];
+        ivar_FF=CellInfo{icell}.VarIndex_errorflag;
+    end
+    VarIndex([ivar_X ivar_Y ivar_Z ivar_rem])=[];% not projected variables removed frlom list
+
+    if strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured coordinates
          eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');'])
          for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag]
@@ -377,6 +412,6 @@
             eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);'])
          end
-         XName=FieldData.ListVarName{VarType.coord_x};
-         YName=FieldData.ListVarName{VarType.coord_y};
+         XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
+         YName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
          eval(['coord_x=FieldData.' XName ';'])
          eval(['coord_y=FieldData.' YName ';'])
@@ -387,8 +422,8 @@
     end
     % image or 2D matrix
-    if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
+    if  strcmp(CellInfo{icell}.CoordType,'grid')%case of structured coordinates
         test_Amat=1;% test for image or 2D matrix
-        AYName=FieldData.ListVarName{VarType.coord(1)};
-        AXName=FieldData.ListVarName{VarType.coord(2)};
+        AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
+        AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
         eval(['AX=FieldData.' AXName ';'])% x coordinate
         eval(['AY=FieldData.' AYName ';'])% y coordinate
@@ -562,5 +597,6 @@
 
 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
-[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData);
+%[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData);
+[CellInfo,NbDim,errormsg]=find_field_cells(FieldData);
 if ~isempty(errormsg)
     errormsg=['error in proj_field/proj_line:' errormsg];
@@ -571,34 +607,37 @@
 ProjData.ListVarName={};
 ProjData.VarDimName={};
-testproj=zeros(size(FieldData.ListVarName));
-for icell=1:length(CellVarIndex)
-    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
-    VarType=VarTypeCell{icell}; %types of variables
+for icell=1:length(CellInfo)
+    %VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
+   % VarType=VarTypeCell{icell}; %types of variables
     if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case
         continue
     end
-    check_unstructured=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates
-    test_tps=~isempty(VarType.coord_tps);
-    testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors
-    testfalse=~isempty(VarType.errorflag);% test for error flag
-    testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0
-                                             %=0 for vector components, treated separately
-    testproj([VarType.scalar VarType.image VarType.color VarType.vector_x VarType.vector_y])=1;
-    VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
+
+    % select types of  variables to be projected
+   ListProject={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};
+   check_project=false(size(FieldData.ListVarName));
+   for ilist=1:numel(ListProject)
+       if isfield(CellInfo{icell},ListProject{ilist})
+           check_project(CellInfo{icell}.(ListProject{ilist}))=1;
+       end
+   end
+   VarIndex=find(check_project);
 
     %identify vector components   
+    testU=isfield(CellInfo{icell},'VarIndex_vector_x') &&isfield(CellInfo{icell},'VarIndex_vector_y') ;% test for vectors
     if testU
-        UName=FieldData.ListVarName{VarType.vector_x};
-        VName=FieldData.ListVarName{VarType.vector_y};
+        UName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x};
+        VName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y};
         vector_x=FieldData.(UName);
         vector_y=FieldData.(VName);
     end  
     %identify error flag
+    testfalse=isfield(CellInfo{icell},'VarIndex_errorflag');% test for error flag
     if testfalse
-        FFName=FieldData.ListVarName{VarType.errorflag};
+        FFName=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag};
         errorflag=FieldData.(FFName);
     end   
     % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
-    if check_unstructured
+    if strcmp(CellInfo{icell}.CoordType,'scattered')
         if  ~isequal(ProjMode,'interp')
             if width==0
@@ -617,6 +656,6 @@
             end
         end
-        XName= FieldData.ListVarName{VarType.coord_x};
-        YName= FieldData.ListVarName{VarType.coord_y};
+        XName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
+        YName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
         coord_x=FieldData.(XName);    
         coord_y=FieldData.(YName);
@@ -633,5 +672,5 @@
   %%%%%%%  % A FAIRE CALCULER MEAN DES QUANTITES    %%%%%%
    %case of unstructured coordinates
-    if check_unstructured   
+    if strcmp(CellInfo{icell}.CoordType,'scattered')  
         for ip=1:siz_line(1)-1     %Loop on the segments of the polyline
             linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip));  
@@ -725,5 +764,5 @@
     
     %case of structured coordinates
-    elseif  numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
+    elseif strcmp(CellInfo{icell}.CoordType,'grid')
         if ~isequal(ObjectData.Type,'line')% exclude polyline
             errormsg=['no  projection available on ' ObjectData.Type 'for structured coordinates']; % 
@@ -732,6 +771,6 @@
             test_interp2=0;%default
 %             if ~isempty(VarType.coord_y)  
-            AYName=FieldData.ListVarName{VarType.coord(1)};
-            AXName=FieldData.ListVarName{VarType.coord(2)};
+            AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
+            AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)};
             eval(['AX=FieldData.' AXName ';']);% set of x positions
             eval(['AY=FieldData.' AYName ';']);% set of y positions  
@@ -832,8 +871,8 @@
             end
             if testU
-                 vector_x =ProjData.(FieldData.ListVarName{VarType.vector_x});
-                 vector_y =ProjData.(FieldData.ListVarName{VarType.vector_y});
-                 ProjData.(FieldData.ListVarName{VarType.vector_x}) =cos(theta)*vector_x+sin(theta)*vector_y;
-                 ProjData.(FieldData.ListVarName{VarType.vector_y}) =-sin(theta)*vector_x+cos(theta)*vector_y;
+                 vector_x =ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x});
+                 vector_y =ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y});
+                 ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}) =cos(theta)*vector_x+sin(theta)*vector_y;
+                 ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}) =-sin(theta)*vector_x+cos(theta)*vector_y;
             end
             ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line';
@@ -842,5 +881,5 @@
             end
         end
-    elseif test_tps
+    elseif strcmp(CellInfo{icell}.CoordType,'tps')
          if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
                 DX=abs(ObjectData.DX);%mesh of interpolation points along the line
@@ -972,5 +1011,6 @@
 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
 % CellVarIndex=cells of variable index arrays
-[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData);
+%[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData);
+[CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData);
 if ~isempty(errormsg)
     errormsg=['error in proj_field/proj_plane:' errormsg];
@@ -980,9 +1020,9 @@
 %% projection modes
 check_grid=0;
-ProjMode=cell(size(VarTypeCell));
-for icell=1:numel(VarTypeCell)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates
+ProjMode=cell(size(CellInfo));
+for icell=1:numel(CellInfo)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates
     ProjMode{icell}=ObjectData.ProjMode;
-    if isfield(VarTypeCell{icell},'FieldRequest')
-        switch VarTypeCell{icell}.FieldRequest
+    if isfield(CellInfo{icell},'FieldRequest')
+        switch CellInfo{icell}.FieldRequest
             case 'interp_lin'
                 ProjMode{icell}='interp';
@@ -1014,28 +1054,34 @@
 vector_x_proj=[];
 vector_y_proj=[];
-for icell=1:length(CellVarIndex)
-    NbDim=NbDimVec(icell);
+for icell=1:length(CellInfo)
+    NbDim=NbDimArray(icell);
     if NbDim<2
         continue % only cells represnting 2D or 3D fields are involved
     end
-    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
-    VarType=VarTypeCell{icell};
-    ivar_U=VarType.vector_x;
-    ivar_V=VarType.vector_y;
-    if ~isempty(VarType.vector_x_tps)&&~isempty(VarType.vector_y_tps)
-        ivar_U=VarType.vector_x_tps;
-        ivar_V=VarType.vector_y_tps;
-    end
-    ivar_W=VarType.vector_z;
-
-    %type of coordinates
-    if ~isempty(VarType.coord_x) && ~isempty(VarType.coord_y)
-        CoordType='unstructured';
-    elseif ~isempty(VarType.coord_tps)
-        CoordType='tps';
-    else
-        CoordType='structured';
-    end
-    
+    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
+    ivar_U=[];ivar_V=[];ivar_W=[];
+    if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps')
+        ivar_U=CellInfo{icell}.VarIndex_vector_x_tps;
+        ivar_V=CellInfo{icell}.VarIndex_vector_y_tps;
+    elseif isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y')
+        ivar_U=CellInfo{icell}.VarIndex_vector_x;
+        ivar_V=CellInfo{icell}.VarIndex_vector_y;
+    end
+%     if ~isempty(VarType.vector_x_tps)&&~isempty(VarType.vector_y_tps)
+%         ivar_U=VarType.vector_x_tps;
+%         ivar_V=VarType.vector_y_tps;
+%     end
+    if isfield(CellInfo{icell},'VarIndex_vector_z')
+    ivar_W=CellInfo{icell}.VarIndex_vector_z;
+    end
+%     %type of coordinates
+%     if ~isempty(VarType.coord_x) && ~isempty(VarType.coord_y)
+%         CoordType='unstructured';
+%     elseif ~isempty(VarType.coord_tps)
+%         CoordType='tps';
+%     else
+%         CoordType='structured';
+%     end
+%     
     %dimensions
     DimCell=FieldData.VarDimName{VarIndex(1)};
@@ -1046,15 +1092,16 @@
 
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-    switch CoordType
+    switch CellInfo{icell}.CoordType
         
         %% case of input fields with unstructured coordinates
-        case 'unstructured'
+        case 'scattered'
             if strcmp(ProjMode{icell},'filter')
                 continue %skip for filter (needs tps field cell)
             end
-            coord_x=FieldData.(FieldData.ListVarName{VarType.coord_x});% initial x coordinates 
-            coord_y=FieldData.(FieldData.ListVarName{VarType.coord_y});% initial y coordinates
-            if ~isempty(VarType.coord_z)
-                coord_z=FieldData.(FieldData.ListVarName{VarType.coord_z});% initial z coordinates
+            coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});% initial x coordinates 
+            coord_y=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)});% initial y coordinates
+            check3D=(numel(CellInfo{icell}.CoordIndex)==3);
+            if check3D
+                coord_z=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});
             end
             
@@ -1062,10 +1109,10 @@
             coord_x=coord_x-ObjectData.Coord(1,1);
             coord_y=coord_y-ObjectData.Coord(1,2);
-            if ~isempty(VarType.coord_z)
+            if check3D
                 coord_z=coord_z-ObjectData.Coord(1,3);
             end
             
             % selection of the vectors in the projection range (3D case)
-            if ~isempty(VarType.coord_z) &&  width > 0
+            if check3D&&  width > 0
                 %components of the unitiy vector normal to the projection plane
                 fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane
@@ -1127,5 +1174,5 @@
                 coord_X=coord_X(indcut);
                 coord_Y=coord_Y(indcut);
-                if ~isempty(VarType.coord_z)
+                if check3D
                     coord_Z=coord_Z(indcut);
                 end
@@ -1138,12 +1185,12 @@
                     for ivar=VarIndex %transfer variables to the projection plane
                         VarName=FieldData.ListVarName{ivar};
-                        if ivar==VarType.coord_x %x coordinate
+                        if ivar==CellInfo{icell}.CoordIndex(end)
                             ProjData.(VarName)=coord_X;
-                        elseif ivar==VarType.coord_y  % y coordinate
+                        elseif ivar==CellInfo{icell}.CoordIndex(end-1)  % y coordinate
                             ProjData.(VarName)=coord_Y;
-                        elseif isempty(VarType.coord_z) || ivar~=VarType.coord_z % other variables (except Z coordinate wyhich is not reproduced)
+                        elseif ~(check3D && ivar==CellInfo{icell}.CoordIndex(1)) % other variables (except Z coordinate wyhich is not reproduced)
                             ProjData.(VarName)=FieldData.(VarName);
                         end
-                        if isempty(VarType.coord_z) || ivar~=VarType.coord_z
+                        if ~(check3D && ivar==CellInfo{icell}.CoordIndex(1))
                             ProjData.ListVarName=[ProjData.ListVarName VarName];
                             ProjData.VarDimName=[ProjData.VarDimName DimCell];
@@ -1158,6 +1205,6 @@
                     coord_y_proj=YMin:DY:YMax;
                     [XI,YI]=meshgrid(coord_x_proj,coord_y_proj);
-                    if ~isempty(VarType.errorflag)
-                        VarName_FF=FieldData.ListVarName{VarType.errorflag};
+                    if isfield(CellInfo{icell},'VarIndex_errorflag')
+                        VarName_FF=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag};
                         indsel=find(FieldData.(VarName_FF)==0);
                         coord_X=coord_X(indsel);
@@ -1166,32 +1213,31 @@
 %                     testFF=0;
 %                     nbvar=numel(ProjData.ListVarName);
-                    if isfield(VarType,'vector_x')&&isfield(VarType,'vector_y')&&~isempty(VarType.vector_x)
-                        VarName_x=FieldData.ListVarName{VarType.vector_x};
-                        VarName_y=FieldData.ListVarName{VarType.vector_y};
-                        if ~isempty(VarType.errorflag)
+                    if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y')
+                        VarName_x=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x};
+                        VarName_y=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y};
+                        if isfield(CellInfo{icell},'VarIndex_errorflag')
                             FieldData.(VarName_x)=FieldData.(VarName_x)(indsel);
                             FieldData.(VarName_y)=FieldData.(VarName_y)(indsel);
                         end
                         %FieldVar=cat(2,FieldData.(VarName_x),FieldData.(VarName_y));
-                        if ~isfield(VarType,'CheckSub') || ~VarType.CheckSub
+                        if ~isfield(CellInfo{icell},'CheckSub') || ~CellInfo{icell}.CheckSub
                             vector_x_proj=numel(ProjData.ListVarName)+1;
                             vector_y_proj=numel(ProjData.ListVarName)+2;
                         end
                     end
-                    if ~isempty(VarType.scalar)
-                        VarName_scalar=FieldData.ListVarName{VarType.scalar};
+                    if isfield(CellInfo{icell},'VarIndex_scalar')
+                        VarName_scalar=FieldData.ListVarName{CellInfo{icell}.VarIndex_scalar};
                         if ~isempty(VarType.errorflag)
                             FieldData.(VarName_scalar)=FieldData.(VarName_scalar)(indsel);
                         end
-                       % FieldVar=FieldData.(VarName_scalar);
-                    end
-                    if ~isempty(VarType.ancillary)% do not project ancillary data with interp
-                        FieldData=rmfield(FieldData,FieldData.ListVarName{VarType.ancillary});
-                    end
-                    if ~isempty(VarType.warnflag)% do not project ancillary data with interp
-                        FieldData=rmfield(FieldData,FieldData.ListVarName{VarType.warnflag});
-                    end
-                    [VarVal,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_X coord_Y],FieldData,VarType.Operation,XI,YI);
-                    if isfield(VarType,'CheckSub') && VarType.CheckSub && ~isempty(vector_x_proj)
+                    end
+                    if isfield(CellInfo{icell},'VarIndex_ancillary')% do not project ancillary data with interp
+                        FieldData=rmfield(FieldData,FieldData.ListVarName{CellInfo{icell}.VarIndex_ancillary});
+                    end
+                    if isfield(CellInfo{icell},'VarIndex_warnflag')% do not project ancillary data with interp
+                        FieldData=rmfield(FieldData,FieldData.ListVarName{CellInfo{icell}.VarIndex_warnflag});
+                    end
+                    [VarVal,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_X coord_Y],FieldData,CellInfo{icell}.Operation,XI,YI);
+                    if isfield(CellInfo{icell},'CheckSub') && CellInfo{icell}.CheckSub && ~isempty(vector_x_proj)
                         ProjData.(ProjData.ListVarName{vector_x_proj})=ProjData.(ProjData.ListVarName{vector_x_proj})-VarVal{1};
                         ProjData.(ProjData.ListVarName{vector_y_proj})=ProjData.(ProjData.ListVarName{vector_y_proj})-VarVal{2};
@@ -1242,5 +1288,5 @@
             
             %% case of input fields defined on a structured  grid
-        case 'structured'
+        case 'grid'
             
             VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
@@ -1261,6 +1307,6 @@
                 end
             end
-            AYName=FieldData.ListVarName{VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection)
-            AXName=FieldData.ListVarName{VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection)
+            AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(NbDim-1)};%name of input x coordinate (name preserved on projection)
+            AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(NbDim)};%name of input y coordinate (name preserved on projection)
             if testangle% TODO modify name also in case of origin shift in x or y
                 AYProjName='Y';
@@ -1287,7 +1333,7 @@
             for idim=1:NbDim %loop on space dimensions
                 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
-                ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
+                ivar=CellInfo{icell}.CoordIndex(idim);% index of the variable corresponding to the current dimension
                 if ~isequal(ivar,0)%  a variable corresponds to the dimension #idim
-                    eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
+                    Coord{idim}=FieldData.(FieldData.ListVarName{ivar});% coord values for the input field
                     if numel(Coord{idim})==2 %input array defined on a regular grid
                         DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
@@ -1296,5 +1342,4 @@
                         DCoord_min(idim)=min(DCoord);
                         DCoord_max=max(DCoord);
-                        %    test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
                         if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
                             msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'])
@@ -1383,5 +1428,7 @@
                     ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName(VarIndex)];
                     ProjData.VarDimName=[ProjData.VarDimName FieldData.VarDimName(VarIndex)];  
+                    if isfield(FieldData,'VarAttribute')
                     ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute(VarIndex)];
+                    end
                     ProjData.(AYProjName)=FieldData.(AYName);
                     ProjData.(AXProjName)=FieldData.(AXName);
@@ -1680,9 +1727,9 @@
 %-----------------------------------------------------------------
 idimvar=0;
-[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData);
-if ~isempty(errormsg)
-    errormsg=['error in proj_field/proj_plane:' errormsg];
-    return
-end
+% [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData);
+% if ~isempty(errormsg)
+%     errormsg=['error in proj_field/proj_plane:' errormsg];
+%     return
+% end
 
 % LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
