Index: /trunk/src/find_field_cells.m
===================================================================
--- /trunk/src/find_field_cells.m	(revision 1044)
+++ /trunk/src/find_field_cells.m	(revision 1045)
@@ -18,4 +18,5 @@
 %              _vector_x,_y,_z: indices of variables giving the vector components x, y, z
 %              _warnflag: index of warnflag    
+%       .DimIndex
 %      .ProjModeRequest= 'interp_lin', 'interp_tps' indicate whether lin interpolation  or derivatives (tps) is needed to calculate the requested field
 %      .FieldName = operation to be performed to finalise the field cell after projection
@@ -64,5 +65,5 @@
 
 function [CellInfo,NbDim,errormsg]=find_field_cells(Data)
-CellInfo={};
+CellInfo={};%default output
 NbDim=0;
 errormsg='';
@@ -87,5 +88,5 @@
 FieldName=cell(size(Role)); % fieldRequest set to {} by default
 CheckSub=zeros(size(Role));% =1 for fields to substract
-Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default
+%Role=regexprep(Role,' ','scalar'); % Role set to 'scalar' by default
 if isfield(Data,'VarAttribute')
     for ivar=1:numel(Data.VarAttribute)
@@ -105,223 +106,590 @@
 end
 
-%% find scattered (unstructured) coordinates
-ivar_coord_x=find(strcmp('coord_x',Role));%find variables with Role='coord_x'
-check_select=false(1,nbvar);
-check_coord=false(1,nbvar);
-CellInfo=cell(1,numel(ivar_coord_x));
-NbDim=zeros(1,numel(ivar_coord_x));
-% loop on unstructured coordinate x -> different field cells
-for icell=1:numel(ivar_coord_x)
-    DimCell=Data.VarDimName{ivar_coord_x(icell)};% cell of dimension names for ivar_coord_x(icell)
-    if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension
-    % look for variables sharing dimension(s) with ivar_coord_x(icell)
-    check_cell=zeros(numel(DimCell),nbvar);
-    for idim=1:numel(DimCell);% for each variable with role coord_x, look at which other variables contain the same dimension
-        for ivar=1:nbvar
-            check_cell(idim,ivar)=max(strcmp(DimCell{idim},Data.VarDimName{ivar}));
-        end
-    end
-    check_cell=sum(check_cell,1)==numel(DimCell);%logical array=1 for variables belonging to the current cell
-    VarIndex=find(check_cell);% list of detected variable indices
-    if ~(numel(VarIndex)==1 && numel(DimCell)==1)% exclude case of isolated coord_x variable (treated later)
-        if ~(numel(VarIndex)==1 && numel(DimCell)>1)% a variable is associated to coordinate
-            CellInfo{icell}.CoordIndex=ivar_coord_x(icell);
-            % size of coordinate var
+%% detect  fields with different roles
+ind_scalar=find(strcmp('scalar',Role));
+ind_errorflag=find(strcmp('errorflag',Role));
+ind_image=find(strcmp('image',Role));
+ind_vector_x=[find(strcmp('vector_x',Role)) find(strcmp('vector_x_tps',Role))];
+if ~isempty(ind_vector_x)
+    ind_vector_y=[find(strcmp('vector_y',Role)) find(strcmp('vector_y_tps',Role))];
+    ind_vector_z=find(strcmp('vector_z',Role));
+    ind_warnflag=find(strcmp('warnflag',Role));
+    ind_ancillary=find(strcmp('ancillary',Role));
+end
+ind_discrete=find(strcmp('discrete',Role));
+ind_coord_x=find(strcmp('coord_x',Role));
+ind_coord_y=find(strcmp('coord_y',Role));
+ind_coord_z=find(strcmp('coord_z',Role));
+ind_coord_tps=find(strcmp('coord_tps',Role));
+check_string=cellfun(@ischar,Data.VarDimName)==1;
+index_string=find(check_string);
+for ivar=index_string
+    Data.VarDimName{ivar}={Data.VarDimName{ivar}};%transform char strings into cells
+end
+check_coord_names= cellfun(@numel,Data.VarDimName)==1;
+check_coord_raster=false(size(check_coord_names));% check variables describing regular mesh (raster coordinates), from two values, min and max.
+if check_var
+    for ivar=find(check_coord_names)
+        if numel(Data.(Data.ListVarName{ivar}))==2
+            check_coord_raster(ivar)=true;
+        end
+    end
+else
+    for ivar=find(check_coord_names)
+        DimIndex=find(strcmp(Data.VarDimName{ivar},Data.ListDimName));
+        if Data.DimValue(DimIndex)==2
+            check_coord_raster(ivar)=true;
+        end
+    end
+end
+
+
+%% initate cells around each scalar field
+index_remove=[];
+cell_nbre=numel(ind_scalar)+numel(ind_vector_x);
+flag_remove=false(1,cell_nbre);
+NbDim=zeros(1,cell_nbre);
+index_coord_x=zeros(size(ind_coord_x));
+for icell=1:numel(ind_scalar)
+    CellInfo{icell}.VarType='scalar';
+    CellInfo{icell}.VarIndex_scalar=ind_scalar(icell);
+    CellInfo{icell}.VarIndex=ind_scalar(icell);
+    DimCell_var=Data.VarDimName{ind_scalar(icell)};% cell of dimension names for ivar_coord_x(icell)
+    %look for errorflag
+    for ivar=ind_errorflag
+        DimCell=Data.VarDimName{ivar};
+        if isequal(DimCell,DimCell_var)
+            CellInfo{icell}.VarIndex(2)=ivar;
+            CellInfo{icell}.VarIndex_errorflag=ivar;
+            break
+        end
+    end
+end
+
+%% initate cells around each vector field
+for icell=numel(ind_scalar)+1:cell_nbre
+    CellInfo{icell}.VarType='vector';
+    CellInfo{icell}.VarIndex(1)=ind_vector_x(icell-numel(ind_scalar));
+    CellInfo{icell}.VarIndex_vector_x=ind_vector_x(icell-numel(ind_scalar));
+    DimCell_var=Data.VarDimName{ind_vector_x(icell-numel(ind_scalar))};% cell of dimension names for ivar_coord_x(icell)
+    % look for the associated y vector component
+    nbvar=1;
+    for ivar=ind_vector_y
+        DimCell=Data.VarDimName{ivar};
+        if isequal(DimCell,DimCell_var)
+            CellInfo{icell}.VarIndex(2)=ivar;
+            nbvar=2;
+            CellInfo{icell}.VarIndex_vector_y=ivar;
+            break
+        end
+    end
+    if ~isfield(CellInfo{icell},'VarIndex_vector_y')
+        flag_remove(icell)=true;% no vector_y found , mark cell to remove
+    end
+    % look for the associated z vector component
+    for ivar=ind_vector_z
+        DimCell=Data.VarDimName{ivar};
+        if isequal(DimCell,DimCell_var)
+            CellInfo{icell}.VarIndex(3)=ivar;
+            nbvar=3;
+            break
+        end
+    end
+    %look for the vector color scalar (ancillary)
+    for ivar=ind_ancillary
+        DimCell=Data.VarDimName{ivar};
+        if isequal(DimCell,DimCell_var)
+            nbvar=nbvar+1;
+            CellInfo{icell}.VarIndex(nbvar)=ivar;
+            CellInfo{icell}.VarIndex_ancillary=ivar;
+            break
+        end
+    end
+    %look for warnflag
+    for ivar=ind_warnflag
+        DimCell=Data.VarDimName{ivar};
+        if isequal(DimCell,DimCell_var)
+            nbvar=nbvar+1;
+            CellInfo{icell}.VarIndex(nbvar)=ivar;
+            CellInfo{icell}.VarIndex_warnflag=ivar;
+            break
+        end
+    end
+    %look for errorflag
+    for ivar=ind_errorflag
+        DimCell=Data.VarDimName{ivar};
+        if isequal(DimCell,DimCell_var)
+            nbvar=nbvar+1;
+            CellInfo{icell}.VarIndex(nbvar)=ivar;
+            CellInfo{icell}.VarIndex_errorflag=ivar;
+            break
+        end
+    end
+end
+
+%% find coordinates for each cell around field variables, scalars or vectors
+for icell=1:cell_nbre
+    CellInfo{icell}.CoordType='';
+    ind_var=CellInfo{icell}.VarIndex(1);
+    DimCell_var=Data.VarDimName{ind_var};% cell of dimension names for ivar_coord_x(icell)
+    if ~check_var
+        for idim=1:numel(DimCell_var)
+            CellInfo{icell}.DimIndex(idim)=find(strcmp(DimCell_var{idim},Data.ListDimName));
+        end
+    end
+    %look for z scattered coordinates
+    if isempty(ind_coord_z)
+        NbDim(icell)=2;
+        CellInfo{icell}.CoordIndex=[0 0];
+    else
+        NbDim(icell)=3;
+        CellInfo{icell}.CoordIndex=[0 0 0];
+        for ivar=ind_coord_z
+            DimCell=Data.VarDimName{ivar};
+            if isequal(DimCell,DimCell_var)
+                CellInfo{icell}.CoordType='scattered';
+                CellInfo{icell}.CoordIndex(1)=ivar;
+                CellInfo{icell}.ZName=Data.ListVarName{ivar};
+                CellInfo{icell}.ZIndex=ivar;
+                break
+            end
+        end
+    end
+    % look for y coordinate
+    for ivar=ind_coord_y
+        % detect scattered y coordinates, variable with the same dimension(s) as the field variable considered
+        DimCell=Data.VarDimName{ivar};
+        if isequal(DimCell,DimCell_var)
+            CellInfo{icell}.CoordType='scattered';
+            CellInfo{icell}.CoordIndex(NbDim(icell)-1)=ivar;
+            CellInfo{icell}.YName=Data.ListVarName{ivar};
+            CellInfo{icell}.YIndex=ivar;
+            break
+        end
+    end
+    
+    %look for x coordinates
+    if strcmp(CellInfo{icell}.CoordType,'scattered')
+        for ivar=ind_coord_x
+            DimCell=Data.VarDimName{ivar};
+            if isequal(DimCell,DimCell_var)
+                CellInfo{icell}.CoordIndex(NbDim(icell))=ivar;
+                CellInfo{icell}.XName=Data.ListVarName{ivar};
+                CellInfo{icell}.XIndex=ivar;
+                break
+            end
+        end
+    end
+    if isfield(CellInfo{icell},'ZName')
+        if isfield(CellInfo{icell},'YName')&& isfield(CellInfo{icell},'XName')
+            continue %scattered coordinates OK
+        end
+    else
+        if isfield(CellInfo{icell},'YName')
+            if isfield(CellInfo{icell},'XName')
+                NbDim(icell)=2;
+                continue %scattered coordinates OK
+            end
+        else
+            if isfield(CellInfo{icell},'XName'); % only one coordinate x, switch vector field to 1D plot
+                for ind=1:numel(CellInfo{icell}.VarIndex)
+                    Role{CellInfo{icell}.VarIndex(ind)}='coord_y';
+                end
+                continue
+            end
+        end
+    end
+    
+    %look for grid  coordinates
+    if isempty(CellInfo{icell}.CoordType)
+        NbDim(icell)=numel(DimCell_var);
+        CellInfo{icell}.DimOrder=[];
+        if NbDim(icell)==3
+            %coord z
+            for ivar=ind_coord_z
+                if check_coord_names(ivar)
+                    DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var));
+                check_coord=~isempty(DimRank);
+            elseif check_coord_raster(ivar)
+                DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var));
+                check_coord=~isempty(DimRank);
+            end
+%                 check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{1}))||...% coord varbable
+%                     (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{1})); % rasrewr coord defined by min and max
+                if check_coord
+                    CellInfo{icell}.CoordType='grid';
+                    CellInfo{icell}.CoordIndex(1)=ivar;
+                    CellInfo{icell}.ZName=Data.ListVarName{ivar};
+                    CellInfo{icell}.ZIndex=ivar;
+                    CellInfo{icell}.DimOrder=DimRank;
+                    break
+                end
+            end
+        end
+        for ivar=ind_coord_y
+              if check_coord_names(ivar)
+                    DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var));
+                check_coord=~isempty(DimRank);
+            elseif check_coord_raster(ivar)
+                DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var));
+                check_coord=~isempty(DimRank);
+            end
+%             check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)-1}))||...% coord variable
+%                 (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)-1})); % rasrewr coord defined by min and max
+            if check_coord
+                CellInfo{icell}.CoordType='grid';
+                CellInfo{icell}.CoordIndex(NbDim(icell)-1)=ivar;
+                CellInfo{icell}.YName=Data.ListVarName{ivar};
+                CellInfo{icell}.YIndex=ivar;
+                CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank];
+                break
+            end
+        end
+        for ivar=ind_coord_x
+            if check_coord_names(ivar)
+                    DimRank=find(strcmp(Data.VarDimName{ivar},DimCell_var));
+                check_coord=~isempty(DimRank);
+            elseif check_coord_raster(ivar)
+                DimRank=find(strcmp(Data.ListVarName{ivar},DimCell_var));
+                check_coord=~isempty(DimRank);
+            end
+%             check_coord= (check_coord_names(ivar) && strcmp(Data.VarDimName{ivar},DimCell_var{NbDim(icell)}))||...% coord variable
+%                 (check_coord_raster(ivar) && strcmp(Data.ListVarName{ivar},DimCell_var{NbDim(icell)})); % raster coord defined by min and max
+            if check_coord
+                CellInfo{icell}.CoordIndex(NbDim(icell))=ivar;
+                CellInfo{icell}.XName=Data.ListVarName{ivar};
+                CellInfo{icell}.XIndex=ivar;
+                CellInfo{icell}.DimOrder=[CellInfo{icell}.DimOrder DimRank];
+                break
+            end
+        end
+    end
+    %look for tps coordinates
+    for ivar=ind_coord_tps
+        DimCell=Data.VarDimName{ivar};
+        if  numel(DimCell)==3 && strcmp(DimCell{1},DimCell_var{1})
+            CellInfo{icell}.CoordType='tps';
+            CellInfo{icell}.CoordIndex=ivar;
             if check_var
-                CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));
+                NbDim(icell)=size(Data.(Data.ListVarName{ivar}),2);
             else
-                for idim=1:numel(DimCell)
-                    check_index= strcmp(DimCell{idim},Data.ListDimName);
-                    CellInfo{icell}.CoordSize(idim)=Data.DimValue(check_index);
+                DimIndex=find(strcmp(Data.VarDimName{ivar},Data.ListDimName));
+                NbDim(icell)= Data.DimValue(DimIndex);
+            end
+            for ivardim=1:numel(Data.VarDimName)
+                if strcmp(Data.VarDimName{ivardim},DimCell{3})
+                    CellInfo{icell}.NbCentres_tps= ivardim;% nbre of sites for each tps subdomain
+                elseif strcmp(Data.VarDimName{ivardim}{1},DimCell{2}) && numel(Data.VarDimName{ivardim})>=3 && strcmp(Data.VarDimName{ivardim}{3},DimCell{3})
+                    CellInfo{icell}.SubRange_tps=ivardim;% subrange definiton for tps
                 end
-                CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize);
-            end
-            ind_scalar=find(strcmp('scalar',Role(VarIndex)));
-            ind_vector_x=find(strcmp('vector_x',Role(VarIndex)));
-            ind_vector_y=find(strcmp('vector_y',Role(VarIndex)));
-            ind_y=find(strcmp('coord_y',Role(VarIndex)));
-            if numel([ind_scalar ind_vector_x ind_vector_y])==0           
-%             if numel(VarIndex)==2||isempty(ind_y)% no variable, except possibly y
-                NbDim(icell)=1;
-            else
-                CellInfo{icell}.CoordType='scattered';
-                ind_z=find(strcmp('coord_z',Role(VarIndex)));
-                if numel(VarIndex)==3||isempty(ind_z)% no z variable, except possibly as a fct z(x,y)
-                    CellInfo{icell}.CoordIndex=[VarIndex(ind_y) CellInfo{icell}.CoordIndex];
-                    NbDim(icell)=2;
+            end
+        end
+        break
+    end
+end
+
+%% get number of coordinate points for each cell
+if check_var
+    for icell=1:numel(CellInfo)
+        switch CellInfo{icell}.CoordType
+            case 'scattered'
+                CellInfo{icell}.CoordSize=numel(Data.(CellInfo{icell}.XName));
+            case 'grid'
+                if NbDim(icell)==3
+                    CellInfo{icell}.CoordSize=[numel(Data.(CellInfo{icell}.XName)) numel(Data.(CellInfo{icell}.YName)) numel(Data.(CellInfo{icell}.YName))];
                 else
-                    CellInfo{icell}.CoordIndex=[VarIndex(ind_z) CellInfo{icell}.CoordIndex];
-                    NbDim(icell)=3;
+                    CellInfo{icell}.CoordSize=[numel(Data.(CellInfo{icell}.XName)) numel(Data.(CellInfo{icell}.YName))];
                 end
-            end
-        end
-        CellInfo{icell}.VarIndex=VarIndex;
-        check_select=check_select|check_cell;
-    end
-end
-
-%% look for tps coordinates
-ivar_remain=find(~check_select);% indices of remaining variables (not already selected)
-check_coord_tps= strcmp('coord_tps',Role(~check_select));
-ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates
-
-% loop on the tps coordinate sets
-for icell_tps=1:numel(ivar_tps)
-    check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell
-    check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected
-    DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable
-    icell=numel(CellInfo)+icell_tps; % new field cell index
-    CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the  tps coordinate variable
-    if numel(DimCell)==3
-        VarDimName=Data.VarDimName(~check_select);
-        for ivardim=1:numel(VarDimName)
-            if strcmp(VarDimName{ivardim},DimCell{3})
-                CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain
-                check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
-            elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3})
-                CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps
-                check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
-            elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable
-                check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
-            end
-        end
-    end
-    CellInfo{icell}.CoordType='tps';
-    CellInfo{icell}.VarIndex=find(check_cell);
-    if check_var
-        NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
-        CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);
-    else
-        check_index_1= strcmp(DimCell{1},Data.ListDimName);
-        check_index_2= strcmp(DimCell{2},Data.ListDimName);
-        NbDim(icell)=Data.DimValue(check_index_2);
-        if numel(DimCell)>=3
-        check_index_3= strcmp(DimCell{3},Data.ListDimName);  
-        CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3);
-        end
-    end
-    check_select=check_select|check_cell;
-end
-
-%% look for coordinate variables and corresponding gridded data:
-% coordinate variables are variables associated with a single dimension, defining the coordinate values
-% two cases: 1)the coordiante variable represents the set of coordiante values
-%            2)the coordinate variable contains only two elements, representing the coordinate bounds for the dimension with the same name as the cordinate
-ivar_remain=find(~check_select);% indices of remaining variables, not already taken into account
-ListVarName=Data.ListVarName(~check_select);%list of names of remaining variables
-VarDimName=Data.VarDimName(~check_select);%dimensions of remaining variables
-check_coord_select= cellfun(@numel,VarDimName)==1|cellfun(@ischar,VarDimName)==1;% find remaining variables with a single dimension
-check_coord_select=check_coord_select & ~strcmp('ancillary',Role(~check_select));% do not select ancillary variables as coordinates
-ListCoordIndex=ivar_remain(check_coord_select);% indices of remaining variables with a single dimension
-ListCoordName=ListVarName(check_coord_select);% corresponding names of remaining variables with a single dimension
-ListDimName=VarDimName(check_coord_select);% dimension names of remaining variables with a single dimension
-
-%remove redondant variables -> keep only one variable per dimension
-check_keep=true(size(ListDimName));
-for idim=1:numel(ListDimName)
-    prev_ind=find(strcmp(ListDimName{idim},ListDimName(1:idim-1)));% check whether the dimension is already taken into account
-    if ~isempty(prev_ind)% in case of multiple coord variable
-        if strcmp(ListCoordName{idim},ListDimName{idim}) %variable with the same name as the coordinate taken in priority
-            check_keep(prev_ind)=0;% choose a variable with the same name as coordinate in priority
-        else
-           check_keep(idim)=0; %keep the first coordiante variable found
-        end
-    end
-end
-ListCoordIndex=ListCoordIndex(check_keep);% list of coordinate variable indices
-ListCoordName=ListCoordName(check_keep);% list of coordinate variable names
-ListDimName=ListDimName(check_keep);% list of coordinate dimension names
-
-% determine dimension sizes
-CoordSize=zeros(size(ListCoordIndex));
-for ilist=1:numel(ListCoordIndex)
-    if iscell(ListDimName{ilist})
-        ListDimName(ilist)=ListDimName{ilist};%transform cell to string
-    end
-    if check_var% if the list of dimensions has been directly defined, no variable data available
-        CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist
-    else
-        check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the  index in the list of dimensions
-        CoordSize(ilist)=Data.DimValue(check_index);% find the  corresponding dimension value
-    end
-    if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only
-        ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name 
-    end
-end
-
-%% group the remaining variables in cells sharing the same coordinate variables
-NewCellInfo={};
-NewCellDimIndex={};
-NewNbDim=[];
-for ivardim=1:numel(VarDimName) % loop at the list of dimensions for the remaining variables
-    DimCell=VarDimName{ivardim};% dimension names of the current variable 
-    if ischar(DimCell), DimCell={DimCell}; end %transform char to cell if needed
-    DimIndices=[];
-    for idim=1:numel(DimCell)
-        ind_dim=find(strcmp(DimCell{idim},ListDimName));%find the dim index in the list of dimensions ListDimName
-        if ~isempty(ind_dim)
-            DimIndices=[DimIndices ind_dim]; %update the list of dim indices included in DimCell
-            if check_var & CoordSize(ind_dim)==2 % determine the size of the coordinate in case of coordinate definition limited to lower and upper bounds
-                if isvector(Data.(ListVarName{ivardim})) 
-                    if numel(Data.(ListVarName{ivardim}))>2
-                        CoordSize(ind_dim)=numel(Data.(ListVarName{ivardim}));
-                    end
-                else
-                    CoordSize(ind_dim)=size(Data.(ListVarName{ivardim}),idim);
-                end
-            end
-        end
-    end
-    % look for cells of variables with the same coordinate variables
-    check_previous=0;
-    for iprev=1:numel(NewCellInfo)
-        if isequal(DimIndices,NewCellDimIndex{iprev})
-            check_previous=1;
-            NewCellInfo{iprev}.VarIndex=[NewCellInfo{iprev}.VarIndex ivar_remain(ivardim)];%append the current variable index to the found field cell
-            break
-        end
-    end
-    % create a new cell if no previous one contains the coordinate variables
-    if ~check_previous
-        nbcell=numel(NewCellInfo)+1;
-        NewCellDimIndex{nbcell}=DimIndices;
-        NewCellInfo{nbcell}.VarIndex=ivar_remain(ivardim);% create a new field cell with the current variable index
-        NewNbDim(nbcell)=numel(DimIndices);
-        NewCellInfo{nbcell}.CoordType='grid';
-        NewCellInfo{nbcell}.CoordSize=CoordSize(DimIndices);
-        NewCellInfo{nbcell}.CoordIndex=ListCoordIndex(DimIndices);
-    end
-end
-NbDim=[NbDim NewNbDim];
-CellInfo=[CellInfo NewCellInfo];
-
-%% suppress empty cells or cells with a single coordinate variable 
-check_remove=false(size(CellInfo));
-for icell=1:numel(check_remove)
-    if isempty(CellInfo{icell})||(numel(CellInfo{icell}.VarIndex)==1 && numel(check_coord)>=icell && check_coord(icell))
-        check_remove(icell)=1;
-    end
-end
-CellInfo(check_remove)=[];
-NbDim(check_remove)=[];
+            case 'tps'
+                NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
+                CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1);
+        end
+    end
+else
+    for icell=1:numel(CellInfo)
+        CellInfo{icell}.CoordSize=size(Data.DimValue(CellInfo{icell}.DimIndex));
+    end
+end
+%
+% %% loop on the tps coordinate sets
+%
+%     for icell_tps=1:numel(ind_coord_tps)
+%         check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell
+%         check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected
+%         DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable
+%         icell=numel(CellInfo)+icell_tps; % new field cell index
+%         CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the  tps coordinate variable
+%         if numel(DimCell)==3
+%             VarDimName=Data.VarDimName(~check_select);
+%             for ivardim=1:numel(VarDimName)
+%                 if strcmp(VarDimName{ivardim},DimCell{3})
+%                     CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain
+%                     check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
+%                 elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3})
+%                     CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps
+%                     check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
+%                 elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable
+%                     check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
+%                 end
+%             end
+%         end
+%         CellInfo{icell}.CoordType='tps';
+%         CellInfo{icell}.VarIndex=find(check_cell);
+%         if check_var
+%             NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
+%             CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);
+%         else
+%             check_index_1= strcmp(DimCell{1},Data.ListDimName);
+%             check_index_2= strcmp(DimCell{2},Data.ListDimName);
+%             NbDim(icell)=Data.DimValue(check_index_2);
+%             if numel(DimCell)>=3
+%                 check_index_3= strcmp(DimCell{3},Data.ListDimName);
+%                 CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3);
+%             end
+%         end
+%         check_select=check_select|check_cell;
+%     end
+
+
+%% cell for ordinary plots
+iremove=false(1,numel(ind_coord_y));
+for ilist=1:numel(ind_coord_y)% remove the y coordinates which have been used yet in scalar or vector fields
+    for icell=1:numel(CellInfo)
+        if isfield(CellInfo{icell},'YIndex')&& isequal(CellInfo{icell}.YIndex,ind_coord_y(ilist))
+            iremove(ilist)=true;
+            continue
+        end
+    end
+end
+ind_coord_y(iremove)=[];
+if ~isempty(ind_coord_x)
+    y_nbre=zeros(1,numel(ind_coord_x));
+    for icell=1:numel(ind_coord_x)
+        Cell1DPlot{icell}.VarType='1DPlot';
+        Cell1DPlot{icell}.XIndex=ind_coord_x(icell);
+        Cell1DPlot{icell}.XName=Data.ListVarName{ind_coord_x(icell)};
+        DimCell_x=Data.VarDimName{ind_coord_x(icell)};
+        for ivar=[ind_coord_y ind_discrete]
+            DimCell=Data.VarDimName{ivar};
+            if  numel(DimCell)==1 && strcmp(DimCell_x{1},DimCell{1})
+                y_nbre(icell)=y_nbre(icell)+1;
+                Cell1DPlot{icell}.YIndex(y_nbre(icell))=ivar;
+                break
+            end
+        end
+    end
+    Cell1DPlot(find(y_nbre==0))=[];
+    CellInfo=[CellInfo Cell1DPlot];
+    NbDim=[NbDim ones(1,numel(Cell1DPlot))];
+end
 
 %% document roles of non-coordinate variables
 for icell=1:numel(CellInfo)
-    VarIndex=CellInfo{icell}.VarIndex;
-    for ivar=VarIndex
-        if isfield(CellInfo{icell},['VarIndex_' Role{ivar}])
-            CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar];
-        else
-            CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar;
-        end
-        if ~isempty(ProjModeRequest{ivar})
-            CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar};
-        end
-        if ~isempty(FieldName{ivar})
-            CellInfo{icell}.FieldName=FieldName{ivar};
-        end
-        if CheckSub(ivar)==1
-            CellInfo{icell}.CheckSub=1;
-        end
-    end
-end
+    if isfield(CellInfo{icell},'VarIndex')
+        VarIndex=CellInfo{icell}.VarIndex;
+        for ivar=VarIndex
+            %         if isfield(CellInfo{icell},['VarIndex_' Role{ivar}])
+            %             CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar];
+            %         else
+            %             CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar;
+            %         end
+            if ~isempty(ProjModeRequest{ivar})
+                CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar};
+            end
+            if ~isempty(FieldName{ivar})
+                CellInfo{icell}.FieldName=FieldName{ivar};
+            end
+            if CheckSub(ivar)==1
+                CellInfo{icell}.CheckSub=1;
+            end
+        end
+    end
+end
+% for icell=ind_coord_tps
+%     VarIndex=CellInfo{icell}.VarIndex;
+%     for ivar=VarIndex
+%         if isfield(CellInfo{icell},['VarIndex_' Role{ivar}])
+%             CellInfo{icell}.(['VarIndex_' Role{ivar}])=[CellInfo{icell}.(['VarIndex_' Role{ivar}]) ivar];
+%         else
+%             CellInfo{icell}.(['VarIndex_' Role{ivar}])= ivar;
+%         end
+%         if ~isempty(ProjModeRequest{ivar})
+%             CellInfo{icell}.ProjModeRequest=ProjModeRequest{ivar};
+%         end
+%         if ~isempty(FieldName{ivar})
+%             CellInfo{icell}.FieldName=FieldName{ivar};
+%         end
+%         if CheckSub(ivar)==1
+%             CellInfo{icell}.CheckSub=1;
+%         end
+%     end
+% end
+
+
+
+% 
+% %% analyse vector fields
+% if ~isempty(ind_vector_x) && ~isempty(ind_vector_y)
+%     if numel(ind_vector_x)>1
+%         errormsg='multiply defined vector x component'
+%         return
+%     end
+%     DimCell_vec=Data.VarDimName{ind_vector_x};% cell of dimension names for ivar_coord_x(icell)
+%     if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension
+%     DimCell_y=Data.VarDimName{ind_vector_y};% cell of dimension names for ivar_coord_x(icell)
+%     if ischar(DimCell_y),DimCell_y={DimCell_y};end % transform char to cell for a single dimension
+%     if ~isequal(DimCell,DimCell_y)
+%         errormsg='inconsistent x and y vector components';
+%         return
+%     end
+%     %look for coordinates
+%     for ivar=ind_coord_y
+%         DimCell=Data.VarDimName{ivar};
+%         if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension
+%         if isequal(DimCell,DimCell_vec)
+%             CoordType='scattered';
+%             coordy=ivar;
+%         else
+%             if isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{1})
+%                 CoordType='grid';
+%                 coordy=ivar;
+%             elseif ~isempty(ind_coord_z) && strcmp(DimCell{1},DimCell_vec{2})
+%                 CoordType='grid';
+%                 coordy=ivar;
+%                 coordz=ind_coord_z;
+%             end
+%         end
+%         
+%         %% find scattered (unstructured) coordinates
+%         ivar_coord_x=find(strcmp('coord_x',Role));%find variables with Role='coord_x'
+%         check_select=false(1,nbvar);
+%         check_coord=false(1,nbvar);
+%         CellInfo=cell(1,numel(ivar_coord_x));
+%         NbDim=zeros(1,numel(ivar_coord_x));
+%         % loop on unstructured coordinate x -> different field cells
+%         for icell=1:numel(ivar_coord_x)
+%             DimCell=Data.VarDimName{ivar_coord_x(icell)};% cell of dimension names for ivar_coord_x(icell)
+%             if ischar(DimCell),DimCell={DimCell};end % transform char to cell for a single dimension
+%             % look for variables sharing dimension(s) with ivar_coord_x(icell)
+%             check_cell=zeros(numel(DimCell),nbvar);
+%             for idim=1:numel(DimCell);% for each variable with role coord_x, look at which other variables contain the same dimension
+%                 for ivar=1:nbvar
+%                     check_cell(idim,ivar)=max(strcmp(DimCell{idim},Data.VarDimName{ivar}));
+%                 end
+%             end
+%             check_cell=sum(check_cell,1)==numel(DimCell);%logical array=1 for variables belonging to the current cell
+%             VarIndex=find(check_cell);% list of detected variable indices
+%             if ~(numel(VarIndex)==1 && numel(DimCell)==1)% exclude case of isolated coord_x variable (treated later)
+%                 if ~(numel(VarIndex)==1 && numel(DimCell)>1)% a variable is associated to coordinate
+%                     CellInfo{icell}.CoordIndex=ivar_coord_x(icell);
+%                     % size of coordinate var
+%                     if check_var
+%                         CellInfo{icell}.CoordSize=numel(Data.(Data.ListVarName{ivar_coord_x(icell)}));
+%                     else
+%                         for idim=1:numel(DimCell)
+%                             check_index= strcmp(DimCell{idim},Data.ListDimName);
+%                             CellInfo{icell}.CoordSize(idim)=Data.DimValue(check_index);
+%                         end
+%                         CellInfo{icell}.CoordSize=prod(CellInfo{icell}.CoordSize);
+%                     end
+%                     %             ind_scalar=find(strcmp('scalar',Role(VarIndex)));
+%                     %             ind_vector_x=find(strcmp('vector_x',Role(VarIndex)));
+%                     %             ind_vector_y=find(strcmp('vector_y',Role(VarIndex)));
+%                     ind_y=find(strcmp('coord_y',Role(VarIndex)));
+%                     if numel([ind_scalar ind_vector_x ind_vector_y])==0
+%                         %             if numel(VarIndex)==2||isempty(ind_y)% no variable, except possibly y
+%                         NbDim(icell)=1;
+%                     else
+%                         CellInfo{icell}.CoordType='scattered';
+%                         ind_z=find(strcmp('coord_z',Role(VarIndex)));
+%                         if numel(VarIndex)==3||isempty(ind_z)% no z variable, except possibly as a fct z(x,y)
+%                             CellInfo{icell}.CoordIndex=[VarIndex(ind_y) CellInfo{icell}.CoordIndex];
+%                             NbDim(icell)=2;
+%                         else
+%                             CellInfo{icell}.CoordIndex=[VarIndex(ind_z) CellInfo{icell}.CoordIndex];
+%                             NbDim(icell)=3;
+%                         end
+%                     end
+%                 end
+%                 CellInfo{icell}.VarIndex=VarIndex;
+%                 check_select=check_select|check_cell;
+%             end
+%         end
+%         
+%         %% look for tps coordinates
+%         ivar_remain=find(~check_select);% indices of remaining variables (not already selected)
+%         check_coord_tps= strcmp('coord_tps',Role(~check_select));
+%         ivar_tps=ivar_remain(check_coord_tps);% variable indices corresponding to tps coordinates
+%         
+%         % loop on the tps coordinate sets
+%         for icell_tps=1:numel(ivar_tps)
+%             check_cell=zeros(1,nbvar);% =1 for the variables selected in the current cell
+%             check_cell(ivar_tps(icell_tps))=1;% mark the coordinate variable as selected
+%             DimCell=Data.VarDimName{ivar_tps(icell_tps)};% dimension names for the current tps coordinate variable
+%             icell=numel(CellInfo)+icell_tps; % new field cell index
+%             CellInfo{icell}.CoordIndex=ivar_tps(icell_tps);% index of the  tps coordinate variable
+%             if numel(DimCell)==3
+%                 VarDimName=Data.VarDimName(~check_select);
+%                 for ivardim=1:numel(VarDimName)
+%                     if strcmp(VarDimName{ivardim},DimCell{3})
+%                         CellInfo{icell}.NbCentres_tps= ivar_remain(ivardim);% nbre of sites for each tps subdomain
+%                         check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
+%                     elseif strcmp(VarDimName{ivardim}{1},DimCell{2}) && numel(VarDimName{ivardim})>=3 && strcmp(VarDimName{ivardim}{3},DimCell{3})
+%                         CellInfo{icell}.SubRange_tps=ivar_remain(ivardim);% subrange definiton for tps
+%                         check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
+%                     elseif strcmp(VarDimName{ivardim}{1},DimCell{1}) && strcmp(VarDimName{ivardim}{2},DimCell{3})% variable
+%                         check_cell(ivar_remain(ivardim))=1;% mark the variable as selected
+%                     end
+%                 end
+%             end
+%             CellInfo{icell}.CoordType='tps';
+%             CellInfo{icell}.VarIndex=find(check_cell);
+%             if check_var
+%                 NbDim(icell)=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),2);
+%                 CellInfo{icell}.CoordSize=size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),1)*size(Data.(Data.ListVarName{CellInfo{icell}.CoordIndex}),3);
+%             else
+%                 check_index_1= strcmp(DimCell{1},Data.ListDimName);
+%                 check_index_2= strcmp(DimCell{2},Data.ListDimName);
+%                 NbDim(icell)=Data.DimValue(check_index_2);
+%                 if numel(DimCell)>=3
+%                     check_index_3= strcmp(DimCell{3},Data.ListDimName);
+%                     CellInfo{icell}.CoordSize=Data.DimValue(check_index_1)*Data.DimValue(check_index_3);
+%                 end
+%             end
+%             check_select=check_select|check_cell;
+%         end
+%         
+%      
+%         
+%         % determine dimension sizes
+%         CoordSize=zeros(size(ListCoordIndex));
+%         for ilist=1:numel(ListCoordIndex)
+%             if iscell(ListDimName{ilist})
+%                 ListDimName(ilist)=ListDimName{ilist};%transform cell to string
+%             end
+%             if check_var% if the list of dimensions has been directly defined, no variable data available
+%                 CoordSize(ilist)=numel(Data.(ListCoordName{ilist}));% number of elements in the variable corresponding to the dimension #ilist
+%             else
+%                 check_index= strcmp(ListDimName{ilist},Data.ListDimName);% find the  index in the list of dimensions
+%                 CoordSize(ilist)=Data.DimValue(check_index);% find the  corresponding dimension value
+%             end
+%             if CoordSize(ilist)==2% case of uniform grid coordinate defined by lower and upper bounds only
+%                 ListDimName{ilist}=ListCoordName{ilist};% replace the dimension name by the coordinate variable name
+%             end
+%         end
+%     end
+% end
+% 
+% 
+% 
+% %% suppress empty cells or cells with a single coordinate variable 
+% check_remove=false(size(CellInfo));
+% for icell=1:numel(check_remove)
+%     if isempty(CellInfo{icell})||(numel(CellInfo{icell}.VarIndex)==1 && numel(check_coord)>=icell && check_coord(icell))
+%         check_remove(icell)=1;
+%     end
+% end
+% CellInfo(check_remove)=[];
+% NbDim(check_remove)=[];
+% 
+% 
Index: /trunk/src/get_field.m
===================================================================
--- /trunk/src/get_field.m	(revision 1044)
+++ /trunk/src/get_field.m	(revision 1045)
@@ -135,5 +135,11 @@
     return
 end
-[Field.MaxDim,imax]=max(NbDim);
+if isempty(CellInfo)
+    Field.MaxDim=max(cellfun(@numel,Field.Display.VarDimName));
+    check_cellinfo=false;
+else
+    [Field.MaxDim,imax]=max(NbDim);
+    check_cellinfo=true;
+end
 
 %% set time mode
@@ -210,9 +216,10 @@
 %% set default field options
 checknbdim=cellfun('size',Field.Display.VarDimName,2);
-if max(checknbdim)<=1
-    Field.MaxDim=1;% only 1D fields, considered as a time series by default
-end
+% if max(checknbdim)<=1
+%     Field.MaxDim=1;% only 1D fields, considered as a time series by default
+% end
 if Field.MaxDim>=2 && ~checkseries% case of 2D (or 3D) fields
     check_vec_input=0;
+    % case of vector initially selected from uvmat input
     if isfield(ParamIn,'vector_x')&& isfield(ParamIn,'vector_y')
         ichoice_x=find(strcmp(ParamIn.vector_x,Field.Display.ListVarName),1);
@@ -224,5 +231,6 @@
         end
     end
-    if ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
+    % otherwise select vectors marked as attributes in the input field
+    if check_cellinfo && ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') &&  isfield(CellInfo{imax},'VarIndex_vector_y')
         set(handles.vector_x,'UserData',CellInfo{imax}.VarIndex_vector_x(1))
         set(handles.vector_y,'UserData',CellInfo{imax}.VarIndex_vector_y(1))
@@ -252,25 +260,45 @@
 
 %% Make choices of coordinates from input
-if isfield(CellInfo{imax},'CoordIndex')
-    CoordIndex=CellInfo{imax}.CoordIndex;
-    if numel(CoordIndex)==2
-        if isfield(ParamIn,'Coord_x')&& isfield(ParamIn,'Coord_y')
-            YName=ParamIn.Coord_y;
-            XName=ParamIn.Coord_x;
-        else
-        YName=Field.ListVarName{CoordIndex(1)};
-        XName=Field.ListVarName{CoordIndex(2)};
-        end
-        ListCoord=get(handles.Coord_x,'String');
-        XIndex=find(strcmp(XName,ListCoord));
-        if ~isempty(XIndex)
-            set(handles.Coord_x,'Value',XIndex)
-        end
-        YIndex=find(strcmp(YName,ListCoord));
-        if ~isempty(YIndex)
-            set(handles.Coord_y,'Value',YIndex)
-        end
-    end
-end
+%     check_menu=false(1,numel(Data.ListVarName));
+%     ListCoordMenu=1:numel(Data.ListVarName);
+%     CoordIndex=CellInfo{icell}.CoordIndex(CellInfo{icell}.CoordIndex~=0);
+% 
+%             for ivar=find(check_coord_names)
+%                 check_dim=strcmp(Data.VarDimName{ivar},DimCell_var);
+%                 if ~isempty(find(check_dim))
+%                     check_menu(ivar)=true;
+%                 end
+%             end
+%             CellInfo{icell}.CoordMenu=[CoordIndex find(check_menu)];
+%             ListCoordMenu(CoordIndex)=[];
+%             for ivar=ListCoordMenu
+%                 DimCell=Data.VarDimName{ivar};
+%                 if isequal(DimCell,DimCell_var)
+%                     check_menu(ivar)=true;
+%                 end
+%             end
+%             CellInfo{icell}.CoordMenu=[CellInfo{icell}.CoordMenu find(check_menu)];
+% 
+% if isfield(CellInfo{imax},'CoordIndex')
+%     CoordIndex=CellInfo{imax}.CoordIndex;
+%     if numel(CoordIndex)==2
+%         if isfield(ParamIn,'Coord_x')&& isfield(ParamIn,'Coord_y')
+%             YName=ParamIn.Coord_y;
+%             XName=ParamIn.Coord_x;
+%         else
+%         YName=Field.ListVarName{CoordIndex(1)};
+%         XName=Field.ListVarName{CoordIndex(2)};
+%         end
+%         ListCoord=get(handles.Coord_x,'String');
+%         XIndex=find(strcmp(XName,ListCoord));
+%         if ~isempty(XIndex)
+%             set(handles.Coord_x,'Value',XIndex)
+%         end
+%         YIndex=find(strcmp(YName,ListCoord));
+%         if ~isempty(YIndex)
+%             set(handles.Coord_y,'Value',YIndex)
+%         end
+%     end
+% end
 
 %% put the GUI on the lower right of the sceen
@@ -304,5 +332,5 @@
 % --- Activated by selection in the list of variables
 % ----------------------------------------------------------------------
-function variables_Callback(hObject, eventdata, handles)
+function variables_Callback(hObject, VarName, handles)
 
 Tabchar={''};%default
@@ -388,6 +416,6 @@
 end
 
-%% propose a plot by default if a variable has been selected
-if ~isequal(index,1)
+%% propose a plot by default if variables_Callback has not been already called by FieldOption_Callback (VarName is not a char string)
+if ~ischar(VarName) && ~isequal(index,1)
     if numel(DimCell)==1
         set(handles.FieldOption,'Value',1)%propose 1D plot
@@ -412,5 +440,4 @@
 FieldOption=FieldList{get(handles.FieldOption,'Value')};
 switch FieldOption
-    
     case '1D plot'
         set(handles.Coordinates,'Visible','on')
@@ -423,10 +450,9 @@
         set(handles.PanelScalar,'Visible','off')
         set(handles.PanelVectors,'Visible','off')
-        set(handles.Coord_y,'Visible','off')
-        set(handles.Y_title,'Visible','off')
+        set(handles.Coord_y,'Visible','on')
+        set(handles.Y_title,'Visible','on')
         set(handles.Coord_z,'Visible','off')
         set(handles.Z_title,'Visible','off')
-        ordinate_Callback(hObject, VarName, handles)
-        
+        %ordinate_Callback(hObject, VarName, handles)       
     case {'scalar'}
         set(handles.Coordinates,'Visible','on')
@@ -440,32 +466,28 @@
         set(handles.PanelScalar,'Position',pos)
         set(handles.Coord_y,'Visible','on')
-        set(handles.Y_title,'Visible','on')
-        
-        if ~ischar(VarName)
-            
-        %default scalar selection
-        test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
-        for ilist=1:numel(Field.Display.VarDimName)
-            if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
-                Role=Field.Display.VarAttribute{ilist}.Role;
-                if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
+        set(handles.Y_title,'Visible','on')     
+        if ~ischar(VarName)      
+            %default scalar selection
+            test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
+            for ilist=1:numel(Field.Display.VarDimName)
+                if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role')
+                    Role=Field.Display.VarAttribute{ilist}.Role;
+                    if strcmp(Role,'coord_x')||strcmp(Role,'coord_y')
+                        test_coord(ilist)=1;
+                    end
+                end
+                dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
+                if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
                     test_coord(ilist)=1;
                 end
             end
-            dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist
-            if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable
-                test_coord(ilist)=1;
-            end
-        end
-        scalar_index=find(~test_coord,1);%get the first variable not a coordinate
-        if isempty(scalar_index)
-            set(handles.scalar,'Value',1)
-        else
-            set(handles.scalar,'Value',scalar_index)
-        end      
-        end
-        scalar_Callback(hObject,VarName, handles)
-        
-             
+            scalar_index=find(~test_coord,1);%get the first variable not a coordinate
+            if isempty(scalar_index)
+                set(handles.scalar,'Value',1)
+            else
+                set(handles.scalar,'Value',scalar_index)
+            end
+        end
+        scalar_Callback(hObject,VarName, handles)        
     case 'vectors'
         set(handles.PanelVectors,'Visible','on')
@@ -509,6 +531,5 @@
             end
         end
-        vector_Callback(handles)
-        
+        vector_Callback(handles)      
     case 'civdata...'
         set(handles.PanelOrdinate,'Visible','off')
@@ -576,7 +597,7 @@
         end
     end
-    set(handles.Coord_x,'Value',coord_val)
-end
-set(handles.Coord_x,'String',ListCoord)
+    set(handles.Coord_x,'Value',coord_val+1)
+end
+set(handles.Coord_x,'String',[{''}; ListCoord])
 
 
@@ -611,11 +632,11 @@
 function scalar_Callback(hObject, VarName, handles)
 
-Field=get(handles.get_field,'UserData');
-scalar_menu=get(handles.scalar,'String');
-if ischar(VarName)
+Field=get(handles.get_field,'UserData');% get the input field info stored in UserData of the GUI
+scalar_menu=get(handles.scalar,'String');% read the menu for scalar selection
+if ischar(VarName)% case of a call with input variable
     ScalarName=VarName;
     scalar_index=find(strcmp(VarName,scalar_menu));
-    set(handles.scalar,'Value',scalar_index)
-else
+    set(handles.scalar,'Value',scalar_index)% select the input variable field in the menu
+else % no input variable, the variable ScalarName is selected from the menu
     scalar_index=get(handles.scalar,'Value');
 	ScalarName=scalar_menu{scalar_index};
@@ -626,5 +647,5 @@
 test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante
 dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable
-if ~get(handles.CheckDimensionX,'Value')  
+%if ~get(handles.CheckDimensionX,'Value')  
     %look for coordinate variables among the other variables
     for ilist=1:numel(Field.Display.VarDimName)
@@ -636,7 +657,7 @@
         end
     end
-end
+%end
 var_component=find(test_component);% list of variable indices elligible as unstructured coordinates
-var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates
+var_coord=find(test_coord);% % list of variable indices elligible as gridded coordinates
 var_coord(var_coord==scalar_index)=[];
 var_component(var_component==scalar_index)=[];
@@ -664,6 +685,7 @@
         elseif strcmp(Role,'coord_y')
             coord_val(2)=ilist;
-            elseif strcmp(Role,'coord_z')
+        elseif strcmp(Role,'coord_z')
             coord_val(3)=ilist;
+            Check3D=1;
         end
     end
@@ -679,24 +701,27 @@
     end
 end
-if  get(handles.CheckDimensionX,'Value')
-    set(handles.Coord_x,'Value',2)
-    set(handles.Coord_x,'String',dim_var')
-else
+% if  get(handles.CheckDimensionX,'Value')
+%     set(handles.Coord_x,'Value',2)
+%     set(handles.Coord_x,'String',dim_var')
+% else
     set(handles.Coord_x,'Value',coord_val(1))
     set(handles.Coord_x,'String',ListCoord)
-end
-if  get(handles.CheckDimensionX,'Value')
-    set(handles.Coord_y,'Value',1)
-    set(handles.Coord_y,'String',dim_var')
-else
+% end
+% if  get(handles.CheckDimensionX,'Value')
+%     set(handles.Coord_y,'Value',1)
+%     set(handles.Coord_y,'String',dim_var')
+% else
     set(handles.Coord_y,'Value',coord_val(2))
     set(handles.Coord_y,'String',ListCoord)
-end
-if  get(handles.CheckDimensionX,'Value')
-    set(handles.Coord_z,'Value',1)
-    set(handles.Coord_z,'String',dim_var')
-else
+% end
+% if  get(handles.CheckDimensionX,'Value')
+%     set(handles.Coord_z,'Value',1)
+%     set(handles.Coord_z,'String',dim_var')
+% else
+if numel(test_coord)>=3
     set(handles.Coord_z,'Value',coord_val(2))
     set(handles.Coord_z,'String',ListCoord)
+    set(handles.Coord_z,'Visible','on')
+    set(handles.Check3D,'Value', 1)
 end
 
@@ -911,4 +936,5 @@
 string=get(handles.Coord_y,'String');
 VarName=string{index};
+
 if ~ischar(DimCell)
 update_field(handles,VarName)
@@ -992,5 +1018,5 @@
 if ~isempty(index)
     set(handles.variables,'Value',index+1)
-    variables_Callback(handles.variables, [], handles)
+    variables_Callback(handles.variables, VarName, handles)
 end
 
@@ -1022,11 +1048,11 @@
 
 % --- Executes on button press in CheckDimensionY.
-function CheckDimensionX_Callback(hObject, eventdata, handles)
-CheckDimensionX=get(handles.CheckDimensionX,'value')
-if CheckDimensionX
-    set(handles.Coordinates,'visible','off')
-else
-    set(handles.Coordinates,'visible','on')
-end
+% function CheckDimensionX_Callback(hObject, eventdata, handles)
+% CheckDimensionX=get(handles.CheckDimensionX,'value')
+% if CheckDimensionX
+%     set(handles.Coordinates,'visible','off')
+% else
+%     set(handles.Coordinates,'visible','on')
+% end
 % FieldList=get(handles.FieldOption,'String');
 % FieldOption=FieldList{get(handles.FieldOption,'Value')};
Index: /trunk/src/plot_field.m
===================================================================
--- /trunk/src/plot_field.m	(revision 1044)
+++ /trunk/src/plot_field.m	(revision 1045)
@@ -115,18 +115,25 @@
 %% check input structure
 % check the cells of fields :
-[CellInfo,NbDimArray,errormsg]=find_field_cells(Data);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]);
-    return
-end
-
-index_3D=find(NbDimArray>2,1);
-if ~isempty(index_3D)
-    msgbox_uvmat('ERROR','volume plot not implemented yet');
-    return
-end
-index_2D=find(NbDimArray==2);%find 2D fields
-index_1D=find(NbDimArray==1);
-index_0D=find(NbDimArray==0);
+
+% if ~isfield(PlotParam,'FieldName')
+%     index_0D=[];
+%     index_1D=1;
+%     index_2D=[];%find 2D fields
+%     index_3D=[];
+% else
+    [CellInfo,NbDimArray,errormsg]=find_field_cells(Data);
+    if ~isempty(errormsg)
+        msgbox_uvmat('ERROR',['input of plot_field/find_field_cells: ' errormsg]);
+        return
+    end
+    index_0D=find(NbDimArray==0);
+    index_1D=find(NbDimArray==1);
+    index_2D=find(NbDimArray==2);%find 2D fields
+    index_3D=find(NbDimArray>2,1);
+    if ~isempty(index_3D)
+        msgbox_uvmat('ERROR','volume plot not implemented yet');
+        return
+    end
+% end
 
 %% test axes and figure
@@ -228,13 +235,7 @@
     if ~isempty(htext)%&&~isempty(hchecktable)
         if isempty(index_0D)
-            %         set(htext,'Data',{})
-            %         set(htext,'visible','off')
-            %         set(hchecktable,'visible','off')
-            %         set(hchecktable,'Value',0)
         else
             errormsg=plot_text(Data,CellInfo(index_0D),htext);
             set(htext,'visible','on')
-%             set(hchecktable,'visible','on')
-%             set(hchecktable,'Value',1)
         end
         set(hfig,'Unit','pixels');
@@ -409,6 +410,6 @@
 %loop on input  fields
 for icell=1:numel(CellInfo)
-    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list data.ListVarName
-    coord_x_index=CellInfo{icell}.CoordIndex;
+    VarIndex=CellInfo{icell}.YIndex;%  indices of the selected variables in the list data.ListVarName
+    coord_x_index=CellInfo{icell}.XIndex;
     coord_x_name{icell}=data.ListVarName{coord_x_index};
     coord_x{icell}=data.(data.ListVarName{coord_x_index});%coordinate variable set as coord_x
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 1044)
+++ /trunk/src/proj_field.m	(revision 1045)
@@ -554,13 +554,12 @@
     return
 end
-CellInfo=CellInfo(NbDim>=2); %keep only the 2D cells
-%%%%%% TODO: treat 1D fields: project as identity so that P o P=P for projection operation
+CellInfo=CellInfo(NbDim>=2); %keep only the 2D or 3D cells
 cell_select=true(size(CellInfo));
 
 for icell=1:length(CellInfo)
     if isfield(CellInfo{icell},'ProjModeRequest')
-        if ~strcmp(CellInfo{icell}.ProjModeRequest, ProjMode)
-            cell_select(icell)=0;
-        end
+%         if ~strcmp(CellInfo{icell}.ProjModeRequest, ProjMode)
+%             cell_select(icell)=0;
+%         end
         if strcmp(ProjMode,'interp_tps')&& ~strcmp(CellInfo{icell}.CoordType,'tps')
             cell_select(icell)=0;
@@ -851,8 +850,4 @@
                 end
                 
-                
-                
-                
-                
             else
                 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)};
@@ -929,4 +924,6 @@
                 ProjData.ListVarName=[ProjData.ListVarName {AXName}];
                 ProjData.VarDimName=[ProjData.VarDimName {AXName}];
+                nbvar=numel(ProjData.VarDimName);
+                ProjData.VarAttribute{nbvar}.Role='coord_x';
                 for ivar=VarIndex
                     %VarName{ivar}=FieldData.ListVarName{ivar};
@@ -950,5 +947,6 @@
                     ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName{ivar}];
                     ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate
-                    ProjData.VarAttribute{ivar}.Role='continuous';% for plot with continuous line
+                    nbvar=nbvar+1;
+                    ProjData.VarAttribute{nbvar}.Role='coord_y';% for plot with continuous line
                 end
                 if nbcolor==3
@@ -1122,8 +1120,10 @@
 
 check_grid=zeros(size(CellInfo));% =1 if a grid is needed , =0 otherwise, for each field cell
-ProjMode=cell(size(CellInfo));
-for icell=1:numel(CellInfo)
-    ProjMode{icell}=ObjectData.ProjMode;% projection mode of the plane object
-end
+ProjMode=num2cell(blanks(numel(CellInfo)));
+ProjMode=regexprep(ProjMode,' ',ObjectData.ProjMode);
+%ProjMode=cell(size(CellInfo));
+% for icell=1:numel(CellInfo)
+%     ProjMode{icell}=ObjectData.ProjMode;% projection mode of the plane object
+% end
 icell_grid=[];% field cell index which defines the grid
 if ~strcmp(ObjectData.ProjMode,'projection')&& ~strcmp(ObjectData.Type,'plane_z')% TODO:rationalize
@@ -1202,5 +1202,6 @@
     ProjData.ListVarName={AYName,AXName};
     
-    ProjData.VarAttribute={[],[]};
+    ProjData.VarAttribute{1}.Role='coord_y';
+    ProjData.VarAttribute{2}.Role='coord_x';
 end
     
@@ -1219,5 +1220,5 @@
         continue % only cells represnting 2D or 3D fields are involved
     end
-    VarIndex=CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
+    VarIndex= CellInfo{icell}.VarIndex;%  indices of the selected variables in the list FieldData.ListVarName
     %dimensions
     DimCell=FieldData.VarDimName{VarIndex(1)};
@@ -1237,9 +1238,9 @@
                 continue %skip for next cell (needs tps field cell)
             end
-            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
+            coord_x=FieldData.(CellInfo{icell}.XName);% initial x coordinates
+            coord_y=FieldData.(CellInfo{icell}.YName);% initial y coordinates
             check3D=(numel(CellInfo{icell}.CoordIndex)==3);
             if check3D
-                coord_z=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});
+                coord_z=FieldData.(CellInfo{icell}.ZName);
             end
             
@@ -1256,5 +1257,5 @@
                 fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane
                 indcut=find(abs(fieldZ) <= width);
-                for ivar=VarIndex
+                for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex]
                     VarName=FieldData.ListVarName{ivar};
                     FieldData.(VarName)=FieldData.(VarName)(indcut);
@@ -1305,5 +1306,5 @@
                     return
                 end
-                for ivar=VarIndex
+                for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex]
                     VarName=FieldData.ListVarName{ivar};
                     FieldData.(VarName)=FieldData.(VarName)(indcut);
@@ -1321,5 +1322,5 @@
                     nbvar=0;
                     %nbvar=numel(ProjData.ListVarName);
-                    for ivar=VarIndex %transfer variables to the projection plane
+                    for ivar=[CellInfo{icell}.CoordIndex CellInfo{icell}.VarIndex] %transfer variables to the projection plane
                         VarName=FieldData.ListVarName{ivar};
                         if ivar==CellInfo{icell}.CoordIndex(end)
@@ -1401,6 +1402,6 @@
                 SubRange=FieldData.(FieldData.ListVarName{CellInfo{icell}.SubRange_tps});
                 checkUV=0;
-                if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps')
-                    FieldVar=cat(3,FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x_tps}),FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y_tps}));
+                if strcmp(CellInfo{icell}.VarType,'vector')
+                    FieldVar=cat(3,FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}),FieldData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}));
                     checkUV=1;
                 end
Index: /trunk/src/read_field.m
===================================================================
--- /trunk/src/read_field.m	(revision 1044)
+++ /trunk/src/read_field.m	(revision 1045)
@@ -8,5 +8,5 @@
 %        .FieldName; field name
 %        .VelType
-%        .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2  (fix1)....     
+%        .CivStage: stage of civx processing (=0, not Civx, =1 (civ1), =2  (fix1)....
 %        .Npx,.Npy: for images, nbre of pixels in x and y
 % errormsg: error message, ='' by default
@@ -20,5 +20,5 @@
 %     .ColorVar: variable used for vector color
 %     .Npx, .Npy: nbre of pixels along x and y (used for .vol input files)
-%     .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num'   
+%     .TimeDimName: name of the dimension considered as 'time', selected index value then set by input 'num'
 % num: frame number for movies
 %
@@ -94,58 +94,51 @@
         ParamOut.CivStage=Field.CivStage;
     case 'netcdf'% general netcdf file (not recognized as civ)
-        ListVar={};
+        ListVarName={};
         Role={};
         ProjModeRequest={};
-        ListInputField={};
-        ListOperator={};
-        checkU=0;
-        checkV=0;
+        %ListInputField={};
+        %checkU=0;
+        %checkV=0;
         % scan the list InputField
+        Operator=cell(1,numel(InputField));
+        InputVar=cell(1,numel(InputField));
         for ilist=1:numel(InputField)
             % look for input variables to read
             r=regexp(InputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
             if isempty(r)%  no operator used
-                if isempty(find(strcmp(InputField{ilist},ListVar),1))
-                    ListVar=[ListVar InputField(ilist)];%append the variable name if not already in the list
-                    ListInputField=[ListInputField InputField(ilist)];
-                    ListOperator=[ListOperator {''}];
-                end
-                if check_colorvar(ilist)
-                    if isempty(find(strcmp(InputField{ilist},ListVar),1))
-                    Role{numel(ListVar)}='ancillary';% not projected with interpolation
-                    ProjModeRequest{numel(ListVar)}='';
+                ListVarName=[ListVarName InputField(ilist)];%append the variable name
+                %InputVar{ilist}=InputField(ilist);
+                %ListInputField=[ListInputField InputField(ilist)];
+                if check_colorvar(ilist)% case of field used for vector color
+                    Role{numel(ListVarName)}='ancillary';% not projected with interpolation
+                    ProjModeRequest{numel(ListVarName)}='';
+                else
+                    Role{numel(ListVarName)}='scalar';
+                    ProjModeRequest{numel(ListVarName)}='interp_lin';%scalar field (requires interpolation for plot)
+                end
+                Operator{numel(ListVarName)}='';
+            else  % an operator 'vec' or 'norm' is used
+                ListVarName=[ListVarName {r.UName}]; % append the variable in the list if not previously listed
+                if  strcmp(r.Operator,'norm')
+                    if check_colorvar(ilist) 
+                    Role=[Role {'ancillary'}];
+                    else
+                       Role=[Role {'scalar'}]; 
                     end
                 else
-                    Role{numel(ListVar)}='scalar';
-                    ProjModeRequest{numel(ListVar)}='interp_lin';%scalar field (requires interpolation for plot)
-                end
-                if isfield(ParamIn,'Coord_y')
-                    if ~isempty(strcmp(InputField{ilist},ParamIn.Coord_y))
-                        Role{numel(ListVar)}='coord_y';
-                    end
-                end
-            else  % an operator 'vec' or 'norm' is used
+                     Role=[Role {'vector_x'}];
+                end
+                %ListInputField=[ListInputField InputField(ilist)];
+                ListVarName=[ListVarName {r.VName}];% append the variable in the list if not previously listed
+                Role=[Role {'vector_y'}];
+                %ListInputField=[ListInputField InputField(ilist)];
+                Operator{numel(ListVarName)-1}=r.Operator;
+                Operator{numel(ListVarName)}='';           
                 if ~check_colorvar(ilist) && strcmp(r.Operator,'norm')
-                    ProjModeRequestVar='interp_lin';%scalar field (requires interpolation for plot)
+                    ProjModeRequest{numel(ListVarName)}='interp_lin';%scalar field (requires interpolation for plot)
+                    ProjModeRequest{numel(ListVarName)-1}='interp_lin';%scalar field (requires interpolation for plot)
                 else
-                    ProjModeRequestVar='';
-                end
-                ind_var_U=find(strcmp(r.UName,ListVar));%check previous listing of variable r.UName
-                ind_var_V=find(strcmp(r.VName,ListVar));%check previous listing of variable r.VName
-                if isempty(ind_var_U)
-                    ListVar=[ListVar {r.UName}]; % append the variable in the list if not previously listed
-                    Role=[Role {'vector_x'}];
-                    ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}];
-                    ListInputField=[ListInputField InputField(ilist)];
-                else
-                    checkU=1;
-                end
-                if isempty(ind_var_V)
-                    ListVar=[ListVar {r.VName}];% append the variable in the list if not previously listed
-                    Role=[Role {'vector_y'}];
-                    ProjModeRequest=[ProjModeRequest {ProjModeRequestVar}];
-                    ListInputField=[ListInputField InputField(ilist)];                
-                else
-                    checkV=1;
+                    ProjModeRequest{numel(ListVarName)}='';
+                    ProjModeRequest{numel(ListVarName)-1}='';
                 end
             end
@@ -156,12 +149,12 @@
         NbCoord=~isempty(ParamIn.Coord_x)+~isempty(ParamIn.Coord_y)+~isempty(ParamIn.Coord_z);
         if isfield(ParamIn,'TimeDimName')% case of reading of a single time index in a multidimensional array
-            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar]);
+            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeDimName',ParamIn.TimeDimName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);
         elseif isfield(ParamIn,'TimeVarName')% case of reading of a single time  in a multidimensional array
-            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar]);
+            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,'TimeVarName',ParamIn.TimeVarName,num,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);
             if numel(num)~=1
                 NbCoord=NbCoord+1;% adds time coordinate, except if a single time has been selected
             end
         else
-            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVar]);
+            [Field,var_detect,ichoice,errormsg]=nc2struct(FileName,[ParamIn.Coord_x ParamIn.Coord_y ParamIn.Coord_z ListVarName]);
         end
         if ~isempty(errormsg)
@@ -169,87 +162,82 @@
         end
         CheckStructured=1;
-        %scan all the variables beyond the two first NbCoord ones describing the coordinates.
-        for ilist=NbCoord+1:numel(Field.VarDimName)
-            if isequal(Field.VarDimName{1},Field.VarDimName{ilist}) % if a variable has the same dimension as the coordinate, it denotes a field with unstructured coordinates
-                Field.VarAttribute{1}.Role='coord_x';%unstructured coordinates
-                Field.VarAttribute{2}.Role='coord_y';
-                if NbCoord>=3
-                    Field.VarAttribute{3}.Role='coord_z';
-                end
-                CheckUnstructured=0;
-                break
-            end
-        end
-        if CheckStructured
-            for ilist=NbCoord+1:numel(Field.VarDimName)
-                if numel(Field.VarDimName{ilist})==NbCoord
-                    rank(1)=find(strcmp(ParamIn.Coord_x,Field.VarDimName{ilist}));
-                    rank(2)=find(strcmp(ParamIn.Coord_y,Field.VarDimName{ilist}));
-                    if NbCoord==3
-                        rank(3)=find(strcmp(ParamIn.Coord_z,Field.VarDimName{ilist}));
-                    end
-                    rank=rank(end:-1:1);
-                    VarName=Field.ListVarName{ilist};
-                    Field.(VarName)=permute(Field.(VarName),rank);
-                    Field.VarDimName{ilist}=Field.VarDimName{ilist}(rank);% permute the order of dimensions
-                end
-            end
+        %scan all the variables
+        NbCoord=0;
+        if ~isempty(ParamIn.Coord_x)
+            index_Coord_x=find(strcmp(ParamIn.Coord_x,Field.ListVarName));
+            Field.VarAttribute{index_Coord_x}.Role='coord_x';%
+            NbCoord=NbCoord+1;
+        end
+        if ~isempty(ParamIn.Coord_y)
+            if ischar(ParamIn.Coord_y)
+                index_Coord_y=find(strcmp(ParamIn.Coord_y,Field.ListVarName));
+                Field.VarAttribute{index_Coord_y}.Role='coord_y';%
+                NbCoord=NbCoord+1;
+            else
+                for icoord_y=1:numel(ParamIn.Coord_y)
+                    index_Coord_y=find(strcmp(ParamIn.Coord_y{icoord_y},Field.ListVarName));
+                    Field.VarAttribute{index_Coord_y}.Role='coord_y';%
+                    NbCoord=NbCoord+1;
+                end
+            end
+        end
+        NbDim=1;
+        if ~isempty(ParamIn.Coord_z)
+            index_Coord_z=find(strcmp(ParamIn.Coord_z,Field.ListVarName));
+            Field.VarAttribute{index_Coord_z}.Role='coord_z';%
+            NbCoord=NbCoord+1;
+            NbDim=3;
+        elseif ~isempty(ParamIn.FieldName)
+            NbDim=2;
         end
         NormName='';
         UName='';
         VName='';
-        if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (1 D plots)
-            for ilist=1:numel(ListVar)
-                Field.VarAttribute{ilist+NbCoord}.Role=Role{ilist};
-                Field.VarAttribute{ilist+NbCoord}.ProjModeRequest=ProjModeRequest{ilist};
+        if numel(Field.ListVarName)>NbCoord % if there are variables beyond coord (exclude 1 D plots)
+            VarAttribute=cell(1,numel(ListVarName));
+            for ilist=1:numel(ListVarName)
+                index_var=find(strcmp(ListVarName{ilist},Field.ListVarName),1);
+                VarDimName{ilist}=Field.VarDimName{index_var};
+                DimOrder=[];
+                if NbDim ==2
+                    DimOrder=[find(strcmp(ParamIn.Coord_y,VarDimName{ilist})) find(strcmp(ParamIn.Coord_x,VarDimName{ilist}))];
+                elseif NbDim ==3
+                    DimOrder=[find(strcmp(ParamIn.Coord_z,VarDimName{ilist}))...
+                        find(strcmp(ParamIn.Coord_y,VarDimName{ilist}))...
+                        find(strcmp(ParamIn.Coord_x,VarDimName{ilist}))];
+                end
+                if ~isempty(DimOrder)
+                    Field.(ListVarName{ilist})=permute(Field.(ListVarName{ilist}),DimOrder);
+                    VarDimName{ilist}=VarDimName{ilist}(DimOrder);
+                end
+                if numel(Field.VarAttribute)>=index_var
+                VarAttribute{ilist}=Field.VarAttribute{index_var};% read var attributes from input if exist
+                end
+            end
+            check_remove=false(1,numel(Field.ListVarName));
+            for ilist=1:numel(ListVarName)
+                VarAttribute{ilist}.Role=Role{ilist};
+                VarAttribute{ilist}.ProjModeRequest=ProjModeRequest{ilist};
                 if isfield(ParamIn,'FieldName')
-                    Field.VarAttribute{ilist+NbCoord}.FieldName=ListInputField{ilist};
-                end
-                r=regexp(ListInputField{ilist},'(?<Operator>(^vec|^norm))\((?<UName>.+),(?<VName>.+)\)$','names');
-                if ~isempty(r)&& strcmp(r.Operator,'norm')
-                    NormName='norm';
-                    if ~isempty(find(strcmp(ListVar,'norm')))
-                        NormName='norm_1';
-                    end
-                    Field.ListVarName=[Field.ListVarName {NormName}];
-                    ilistmax=numel(Field.ListVarName);
-                    Field.VarDimName{ilistmax}=Field.VarDimName{ilist+2};
-                    Field.VarAttribute{ilistmax}.Role='scalar';
-                    Field.(NormName)=Field.(r.UName).*Field.(r.UName)+Field.(r.VName).*Field.(r.VName);
-                    Field.(NormName)=sqrt(Field.(NormName));
-                    UName=r.UName;
-                    VName=r.VName;
-                end
-            end
-            
-            if ~isempty(NormName)% remove U and V if norm has been calculated and U and V are not needed as variables
-                ind_var_U=find(strcmp(UName,ListVar));%check previous listing of variable r.UName
-                ind_var_V=find(strcmp(VName,ListVar));%check previous listing of variable r.VName
-                if ~checkU && ~checkV
-                    Field.ListVarName([ind_var_U+2 ind_var_V+2])=[];
-                    Field.VarDimName([ind_var_U+2 ind_var_V+2])=[];
-                    Field.VarAttribute([ind_var_U+2 ind_var_V+2])=[];
-                elseif ~checkU
-                    Field.ListVarName(ind_var_U+2)=[];
-                    Field.VarDimName(ind_var_U+2)=[];
-                    Field.VarAttribute(ind_var_U+2 )=[];
-                elseif ~checkV
-                    Field.ListVarName(ind_var_V+2)=[];
-                    Field.VarDimName(ind_var_V+2)=[];
-                    Field.VarAttribute(ind_var_V+2 )=[];
-                end
-            end
-            % insert coordinates as indices in case of plots vs matrix index
-            if isfield(ParamIn,'CheckCoordIndex') && ParamIn.CheckCoordIndex
-                Field.ListVarName=[Field.ListDimName Field.ListVarName];
-                Field.VarDimName=[Field.ListDimName Field.VarDimName];
-                for idim=1:numel(Field.ListDimName)
-                    CoordName=Field.ListDimName{idim};
-                    Field.(CoordName)=1:Field.DimValue(idim);
-                end
-                Field.VarAttribute=[cell(1,numel(Field.ListDimName)) Field.VarAttribute];
-            end
-            
-        end
+                    VarAttribute{ilist}.Operator=Operator{ilist};
+                end
+                if strcmp(Operator{ilist},'norm')
+                    UName=ListVarName{ilist};
+                    VName=ListVarName{ilist+1};
+                    ListVarName{ilist}='norm';
+                    Field.norm=Field.(UName).*Field.(UName)+Field.(VName).*Field.(VName);
+                    Field.norm=sqrt(Field.norm);
+                    check_remove(ilist+1)=true;
+                    VarAttribute{ilist}.Operator='';
+                end
+            end
+            ListVarName(check_remove)=[];
+            VarDimName(check_remove)=[];
+            VarAttribute(check_remove)=[];
+            Field.ListVarName=[Field.ListVarName(1:NbCoord) ListVarName];% complement the list of vqriables, which may be listed twice
+            Field.VarDimName=[Field.VarDimName(1:NbCoord) VarDimName];
+            Field.VarAttribute=[Field.VarAttribute(1:NbCoord) VarAttribute];
+        end
+        
     case 'video'
         if strcmp(class(ParamIn),'VideoReader')
@@ -286,6 +274,6 @@
         for ilist=1:numel(Input.Frames{1}.Attributes)
             if strcmp(Input.Frames{1}.Attributes{ilist}.Name,'AcqTimeSeries')
-        timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end-3))/1000000;
-        break
+                timestamps=str2num(Input.Frames{1}.Attributes{ilist}.Value(1:end-3))/1000000;
+                break
             end
         end
@@ -294,4 +282,5 @@
     otherwise
         errormsg=[ FileType ': invalid input file type for uvmat'];
+        
 end
 
@@ -311,4 +300,6 @@
     Field.VarAttribute{1}.Unit='pixel';
     Field.VarAttribute{2}.Unit='pixel';
+    Field.VarAttribute{1}.Role='coord_y';
+    Field.VarAttribute{2}.Role='coord_x';
     Field.VarAttribute{3}.Role='scalar';
     if ndims(A)==3
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 1044)
+++ /trunk/src/uvmat.m	(revision 1045)
@@ -1748,5 +1748,5 @@
 set(handles.uvmat,'Pointer','watch') % set the mouse pointer to 'watch'
 drawnow
-% read the current input file name:
+% get the current input file name:
 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
@@ -2002,5 +2002,5 @@
 UvData.NewSeries=1; %flag for REFRESH: begin a new series
 UvData.FileName_1='';% name of the current second field (used to detect a  constant field during file scanning)
-UvData.FileType{index}=FileInfo.FileType;
+%UvData.FileType{index}=FileInfo.FileType;
 UvData.FileInfo{index}=FileInfo;
 UvData.MovieObject{index}=VideoObject;
@@ -2196,4 +2196,5 @@
 UvData.XmlData{index}=XmlData;
 UvData.NewSeries=1;
+set(handles.uvmat,'UserData',UvData)
 
 %display warning message
@@ -2233,5 +2234,5 @@
     set(handles.Coord_y,'String','Coord_y');
 end
-set(handles.uvmat,'UserData',UvData)
+
 
 %% set index navigation options
@@ -3157,10 +3158,6 @@
 if isempty(i2), set(handles.i2,'String',''); end % suppress the second i index display if not used
 if isempty(j2), set(handles.j2,'String',''); end % suppress the second j index display if not used
-% if strcmp(get(handles.NomType,'String'),'level')
-%     jindex=str2num(get(handles.j1,'String'));
-%     filename=[fullfile(RootPath,SubDir,['level' num2str(jindex)],RootFile) FileIndex FileExt];% build the input file name (first line)
-% else
 if isempty(regexp(RootPath,'^http://'))
-filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
+    filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
 else
     filename=[RootPath '/' SubDir '/' RootFile FileIndex FileExt];%
@@ -3250,5 +3247,5 @@
     for iobj=1:numel(UvData.ProjObject)
         if isfield(UvData.ProjObject{iobj},'ProjMode')&& strcmp(UvData.ProjObject{iobj}.ProjMode,'interp_tps')
-            check_proj_tps=1;
+            check_proj_tps=1;% tps projection proposed
             break
         end
@@ -3285,6 +3282,6 @@
     end
 end
-switch UvData.FileInfo{1}.FileType
-    case {'civx','civdata','netcdf','pivdata_fluidimage'};
+switch UvData.FileInfo{1}.FieldType
+    case {'civdata','netcdf'};
         list_fields=get(handles.FieldName,'String');% list menu fields
         FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field
@@ -3775,10 +3772,11 @@
         set(handles.ListObject_1,'String',{'plane'})
         if UvData.Field.NbDim==3 %3D case
-%             ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
-%             ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
             UvData.ProjObject{1}.NbDim=3;%test for 3D objects
             UvData.ProjObject{1}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
             UvData.ProjObject{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
             UvData.ProjObject{1}.Angle=[0 0];
+            if isfield(UvData.Field,'CoordUnit')
+                UvData.ProjObject{1}.CoordUnit=CoordUnit;
+            end
         elseif isfield(UvData,'Z')
             %multilevel case (single menuplane in a 3D space)
@@ -3846,8 +3844,8 @@
             UvData.ProjObject{iobj}.NbDim=3;%test for 3D objects
             if ~isfield(UvData.ProjObject{iobj},'RangeZ')
-            UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
+                UvData.ProjObject{iobj}.RangeZ=UvData.Field.CoordMesh;%main plotting plane
             end
             if iobj==1 && ~(isfield(UvData.ProjObject{iobj},'Coord') && size(UvData.ProjObject{iobj}.Coord,2)>=3 && UvData.ProjObject{iobj}.Coord(1,3)<UvData.Field.ZMax && UvData.ProjObject{iobj}.Coord(1,3)>UvData.Field.ZMin)
-                 UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
+                UvData.ProjObject{iobj}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
             end
         end
@@ -3979,19 +3977,20 @@
     % display menus and plot histograms
     test_v=0;
-    if ~isempty(menu_histo)
-        set(handles.HistoMenu,'Value',1)
-        set(handles.HistoMenu,'String',menu_histo)
-        set(handles.Histogram,'Visible','on')
-        set(handles.HistoMenu,'Visible','on')
-        set(handles.HistoAxes,'Visible','on')
-        HistoMenu_Callback(handles.HistoMenu, [], handles)% plot first histogram
-    end
-end
-
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% A REMETTRE
+%     if ~isempty(menu_histo)
+%         set(handles.HistoMenu,'Value',1)
+%         set(handles.HistoMenu,'String',menu_histo)
+%         set(handles.Histogram,'Visible','on')
+%         set(handles.HistoMenu,'Visible','on')
+%         set(handles.HistoAxes,'Visible','on')
+%         HistoMenu_Callback(handles.HistoMenu, [], handles)% plot first histogram
+%     end
+end
+% open the set_object for interactive plane projection in 3D case
 if UvData.Field.NbDim==3
     set(handles.CheckEditObject,'Value',1)
     CheckEditObject_Callback(handles.uvmat, [], handles)
 end
-%ResizeFcn(handles.uvmat,[],handles)
+
 set(handles.uvmat,'Pointer',pointer)
 
@@ -4359,5 +4358,5 @@
 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
 if isempty(regexp(RootPath,'^http://'))
-FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
+    FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
 else
     FileName=[RootPath '/' SubDir '/' RootFile FileIndices FileExt];
@@ -4452,5 +4451,5 @@
                 set(handles.Coord_y,'Max',2)
                 %set(huvmat,
-            case 'civdata...'%reinitiate input, return to automatic civ data reading
+            case 'civdata...'%reinitiate input, return to automatic civ data readingget_field
                 display_file_name(handles,FileName,1)
         end
@@ -4459,7 +4458,4 @@
             if isfield(GetFieldData,'Coordinates')
                 XName=GetFieldData.Coordinates.Coord_x;
-%                set(handles.SwitchCoordIndex,'String','var'); % variable used as coordinate
-%             else
-%                 set(handles.SwitchCoordIndex,'String','dim'); % matrix index used a coordinate
             end
             TimeNameStr=GetFieldData.Time.SwitchVarIndexTime;
@@ -4477,5 +4473,4 @@
                     MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
                     set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
-                    UvData=get(handles.uvmat,'UserData');
                     UvData.TimeUnit=GetFieldData.Time.TimeUnit;
                     set(handles.uvmat,'UserData',UvData);
@@ -4490,5 +4485,4 @@
                     MaxIndex_i{1}=num2str(GetFieldData.Time.TimeDimension);
                     set(handles.MaxIndex_i,'String',MaxIndex_i)%TODO: record time unit
-                    UvData=get(handles.uvmat,'UserData');
                     UvData.TimeUnit=GetFieldData.Time.TimeUnit;
                     set(handles.uvmat,'UserData',UvData);
@@ -4497,7 +4491,4 @@
             end
             set(handles.Coord_x,'String',XName)
-%             if ischar(YName)
-%                 YName={YName};
-%             end
             set(handles.Coord_y,'String',YName)
             set(handles.Coord_z,'String',ZName)
@@ -4506,5 +4497,5 @@
             set(handles.ColorScalar,'Value',1)
             set(handles.ColorScalar,'String',VecColorList);
-            UvData.FileInfo{1}.FileType='netcdf';
+           % UvData.FileInfo{1}.FileType='netcdf';
             set(handles.uvmat,'UserData',UvData)
             REFRESH_Callback(hObject, eventdata, handles)
@@ -4672,5 +4663,5 @@
             set(handles.FieldName_1,'String',[FieldList; {'get_field...'}]);
            
-            UvData.FileType{2}='netcdf';
+            UvData.FileInfo{2}.FileType='netcdf';
             set(handles.uvmat,'UserData',UvData)
             REFRESH_Callback(hObject, eventdata, handles)
@@ -4804,5 +4795,5 @@
 else% we introduce the same file (with a different field) for the second series
      FileName_1=FileName;% we compare two fields in the same file
-     UvData.FileType{2}=UvData.FileInfo{1}.FileType;
+     UvData.FileInfo{2}.FileType=UvData.FileInfo{1}.FileType;
      UvData.XmlData{2}= UvData.XmlData{1};
      set(handles.SubField,'Value',1)
@@ -5721,8 +5712,8 @@
 %------------------------------------------------------------------------
 check_view=get(handles.CheckViewObject,'Value');
-    hset_object=findobj(allchild(0),'tag','set_object');
-    if ~isempty(hset_object)
-        delete(hset_object)% delete existing version of set_object
-    end
+hset_object=findobj(allchild(0),'tag','set_object');
+if ~isempty(hset_object)
+    delete(hset_object)% delete existing version of set_object
+end
 if check_view %activate set_object
     IndexObj=get(handles.ListObject,'Value');
@@ -5747,5 +5738,5 @@
         data.Type='plane';
     end
-
+    
     %% initiate the new projection object
     hset_object=set_object(data,[],ZBounds);
@@ -5758,9 +5749,4 @@
         set(hhset_object.SAVE,'Enable','on')
     end
-else
-%     hset_object=findobj(allchild(0),'tag','set_object');
-%     if ~isempty(hset_object)
-%         delete(hset_object)% delete existing version of set_object
-%     end
 end
 
