Index: /trunk/src/check_functions.m
===================================================================
--- /trunk/src/check_functions.m	(revision 204)
+++ /trunk/src/check_functions.m	(revision 204)
@@ -0,0 +1,121 @@
+%'check_functions': check the path and modification date for all the
+%  function in the toolbox UVMAT. Called at the opening of uvmat
+%----------------------------------------------------------------------
+% function [errormsg,date_str]=check_functions
+%
+% OUTPUT:
+% errormsg: error message listing functions whose paths are not in the directory of uvmat.m
+% date_str: date of the most recent modification of a file in the toolbox
+
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%     This file is part of the toolbox UVMAT.
+% 
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published by
+%     the Free Software Foundation; either version 2 of the License, or
+%     (at your option) any later version.
+% 
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [errormsg,date_str]=check_functions
+errormsg={};%default
+list_fct={'calc_field';...% defines fields (velocity, vort, div...) from civx data and calculate them  
+          'cell2tab';... %transform a Matlab cell in a character array suitable for display in a table
+          'check_field_structure';...% check the validity of the field struture representation consistant with the netcdf format
+          'check_functions';...  
+          'civ';...   %function associated with the interface 'civ.fig' for PIV and spline interpolation
+          'civ.fig';...
+          'civ_3D';... function associated with the interface 'civ_3D.fig' for PIV in volume (in progress) 
+          'civ_3D.fig';...
+          'close_fig';...% function  activated when a figure is closed
+          'copyfields';...% copy fields between two matlab structures
+          'create_grid';...% called by the GUI geometry_calib to create a physical grid
+          'create_grid.fig';...% GUI corresponding to create_grid.m
+          'dataview';...% function for scanning directories in a campaign
+          'delete_object';...%delete a projection object, defined by its index in the Uvmat list or by its graphic handle  
+          'editxml';...%display and edit xml files using a xls schema
+          'editxml.fig';...%interface for editxml
+          'find_field_indices';...% group the variables of a nc-formated Matlab structure into 'fields' with common dimensions
+          'geometry_calib';...%performs geometric calibration from a set of reference points
+          'geometry_calib.fig';...%interface for geometry_calib
+          'get_field';...% choose and plot a field from a Netcdf file
+          'get_field.fig';...%interface for get_field
+          'griddata_uvmat';...%make 2D linear interpolation using griddata, with input appropriate for both Matlab 6.5 and 7
+          'hist_update';...%  update of a current global histogram by inclusion of a new field  
+          'imadoc2struct';...%convert the image documentation file ImaDoc into a Matlab structure
+          'keyboard_callback';... % function activated when a key is pressed on the keyboard 
+          'ListDir';... scan the structure of the directory tree (for dataview.m)
+          'mouse_down';% function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn')
+          'mouse_motion';...% permanently called by mouse motion over a figure (callback for 'WindowButtonMotionFcn')
+          'mouse_up';... % function to be activated when the mouse button is released (callback for 'WindowButtonUpFcn')
+          'msgbox_uvmat';... associated with GUI msgbox_uvmat.fig to display message boxes, for error, warning or input calls
+          'msgbox_uvmat.fig';...
+          'name2display';...% extracts the root name and field numbers from an input filename 
+          'name_generator';...%creates a file name from a root name and indices. 
+          'nc2struct';...% transform a netcdf file in a corresponding matlab structure
+          'peaklock';...%
+          'plot_field';...%displays a vector field and/or scalar or images
+          'plot_object';...%draws a projection object (points, line, plane...)
+          'proj_field';...%project a field on a projection object (plane, line,...)
+          'read_civxdata';...reads civx data from netcdf files
+          'read_imatext';...%read .civ files (obsolete, but can be adapted to other text documentation files)
+           'read_plot_param';... %read the plotting option parameters on the uvmat interface
+           'read_set_object';...%read the data on the set_object interface
+           'read_xls';...%read excel files containing the list of the experiments
+           'reinit';...% suppress the personal parameter file 'uvmat_perso.mat' 
+           'RUN_FIX';...% fix velocity fields
+           'RUN_STLIN';...% combine 2 displacement fields for stereo PIV
+           'series';...% master function for analysis field series, with interface 'series.fig'
+           'series.fig';...% interface for 'series'
+           'set_col_vec';...
+           'set_grid';...% creates a grid for PIV
+           'set_grid.fig';...% interface for set_grid
+           'set_object.m';...%  edit a projection object
+           'set_object.fig';...% interface for set_object
+           'sub_field';...% combine the two input fields, 
+           'struct2nc';...% %write fields in netcdf files
+           'uvmat';...% master function for file scanning and visualisation of 2D fields
+           'uvmat.fig';...  %interface for uvmat  
+           'update_imadoc';...  %update the ImaDoc xml file 
+           'update_obj';... update the object representation graph and its projection field, record it in the uvmat interface
+           'update_waitbar';... update the waitbar display, used for ACTION functions in the GUI 'series'
+           'view_field.m';...% function for visualisation of projected fields'
+           'view_field.fig';...%GUI for view_field
+            'write_plot_param'};%update plotting parameters after plot 
+ dir_fct=which('uvmat');% path to uvmat
+[pathuvmat,name,ext]=fileparts(dir_fct);
+icount=0;
+% loop on the list of functions in the uvmat package
+datnum=zeros(1,length(list_fct));
+ for i=1:length(list_fct)
+    dir_fct=which(list_fct{i});% path to fct
+    if isempty(dir_fct)
+        icount=icount+1;
+        errormsg{icount}=[list_fct{i} ' not found'];% test for function not found
+    else
+       [pth,name,ext]=fileparts(dir_fct);
+       if ~isequal(pathuvmat,pth)&~isequal(fullfile(pathuvmat,'private'),pth)
+           icount=icount+1;
+           errormsg{icount}=[dir_fct ' overrides the package UVMAT'];% bad path for the function
+       end
+       datfile=dir(dir_fct);
+       if isfield(datfile,'datenum')
+          datnum(i)= datfile.datenum;
+       end
+%        date_str=datfile.date;%string of the date of last modification
+%        datnum(i)=0;%default
+%        try 
+%            datnum(i)=datenum(date_str);
+%        catch
+%            datnum(i)=0;%in case of error with datenum (e.g. date in french)
+%        end
+   end
+end
+errormsg=errormsg';
+date_str=datestr(max(datnum));
Index: /trunk/src/get_field.m
===================================================================
--- /trunk/src/get_field.m	(revision 204)
+++ /trunk/src/get_field.m	(revision 204)
@@ -0,0 +1,1508 @@
+%'get_field': display variables and attributes from a Netcdf file, and RUN selected fields
+%------------------------------------------------------------------------
+%function varargout = get_field(varargin)
+% associated with the GUI get_field.fig
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%     This file is part of the toolbox UVMAT.
+% 
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published by
+%     the Free Software Foundation; either version 2 of the License, or
+%     (at your option) any later version.
+% 
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = get_field(varargin)
+
+% Last Modified by GUIDE v2.5 06-Feb-2010 09:58:13
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 0;
+gui_State = struct('gui_Name',       mfilename, ...
+                   'gui_Singleton',  gui_Singleton, ...
+                   'gui_OpeningFcn', @get_field_OpeningFcn, ...
+                   'gui_OutputFcn',  @get_field_OutputFcn, ...
+                   'gui_LayoutFcn',  [] , ...
+                   'gui_Callback',   []);
+if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
+    gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+    gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+%------------------------------------------------------------------------
+% --- Executes just before get_field is made visible.
+function get_field_OpeningFcn(hObject, eventdata, handles,filename,multiple)
+%------------------------------------------------------------------------
+global nb_builtin % nbre of functions to include by default in the menu of  functions called by RUN
+
+%% look at the existing figures in the work space
+browse_fig(handles.list_fig)
+
+%% Choose default command line output for get_field
+handles.output = hObject;
+
+%% Update handles structure
+guidata(hObject, handles);
+
+%% activate the mouse action function: visualise the current field on work space by right click action
+set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles})
+
+%% prepare the list of RUN fcts and set their paths
+% functions included by default in 'get_field.m
+menu_str={'PLOT';'FFT';'filter_band';'histogram'}; 
+nb_builtin=numel(menu_str);
+path_uvmat=fileparts(which('uvmat'));%path of the function 'uvmat'
+addpath(fullfile(path_uvmat,'get_field'))
+testexist=zeros(size(menu_str'));%default
+for ilist=1:length(menu_str)
+    if exist(menu_str{ilist},'file')
+        fct_handle{ilist,1}=str2func(menu_str{ilist});
+        testexist(ilist)=1;
+    else
+        fct_handle{ilist,1}=[];
+        testexist(ilist)=0;
+    end
+end
+rmpath(fullfile(path_uvmat,'get_field'))
+dir_perso=prefdir;
+
+% look for functions previously used (names and paths saved in the personal file uvmat_perso.mat):
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+if exist(profil_perso,'file')
+      h=load (profil_perso);
+     if isfield(h,'get_field_fct') && iscell(h.get_field_fct)
+         for ilist=1:length(h.get_field_fct)
+            [path,file]=fileparts(h.get_field_fct{ilist});
+            addpath(path)        
+            if exist(file,'file')
+                h_func=str2func(file);
+                testexist=[testexist 1]; 
+             else
+                h_func=[];
+                testexist=[testexist 0]; 
+             end
+             fct_handle=[fct_handle; {h_func}]; %concatene the list of paths
+             rmpath(path)
+             menu_str=[menu_str; {file}]; 
+         end
+     end
+end
+
+menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
+fct_handle=fct_handle(testexist==1);
+menu_str=[menu_str;{'more...'}];
+set(handles.ACTION,'String',menu_str)
+set(handles.ACTION,'UserData',fct_handle)% store the list of path in UserData of ACTION
+set(handles.path_action,'String',fullfile(path_uvmat,'get_field'))
+set(handles.ACTION,'Value',1)% PLOT option selected
+
+%% settings for 'slave' mode, called by uvamt, or 'master' mode
+if exist('filename','var') && ischar(filename) %transfer input file name in slave mode
+    set(handles.inputfile,'String',filename)% prefill the input file name 
+    Field=nc2struct(filename);% reads the whole field
+    if isfield(Field,'Txt')
+        msgbox_uvmat('ERROR',Field.Txt)
+    else
+        set(handles.figure1,'UserData',Field);
+        Field_input(eventdata,handles,Field);
+    end
+else  %master mode
+    set(handles.inputfile,'String','')   
+%     set(handles.RUN,'String','RUN')%
+    % load the list of previously browsed files for the upper bar menu Open 
+    dir_perso=prefdir;
+    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');%
+    if exist(profil_perso,'file')
+        h=load (profil_perso);
+        if isfield(h,'MenuFile_1')
+            set(handles.MenuFile_1,'Label',h.MenuFile_1);
+        end
+        if isfield(h,'MenuFile_1')
+            set(handles.MenuFile_2,'Label',h.MenuFile_2);
+        end
+        if isfield(h,'MenuFile_1')
+            set(handles.MenuFile_3,'Label',h.MenuFile_3);
+        end
+        if isfield(h,'MenuFile_1')
+            set(handles.MenuFile_4,'Label',h.MenuFile_4);
+        end
+        if isfield(h,'MenuFile_1')
+            set(handles.MenuFile_5,'Label',h.MenuFile_5);
+        end
+    end
+end
+
+%% remove already opened get_field GUI with name get_field
+if ~(exist('multiple','var') && isequal(multiple,1)) %set single occurrence
+    hget_field=findobj(allchild(0),'Name','get_field'); %hget_field(1)= new GUI
+    if length(hget_field)>1
+        delete(hget_field(2))
+    end
+else
+    set(hObject,'name','get_field_1')
+end
+
+
+%------------------------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+function varargout = get_field_OutputFcn(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+varargout{1} = handles.output;
+
+%------------------------------------------------------------------------
+% --- Executes when a new input file name is introduced.
+function inputfile_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+inputfile=get(handles.inputfile,'String');
+Field=nc2struct(inputfile);% reads the whole field
+if isfield(Field,'Txt')
+    msgbox_uvmat('ERROR',Field.Txt)
+else
+set(handles.figure1,'UserData',Field);
+Field_input(eventdata,handles,Field);
+end
+huvmat=findobj(allchild(0),'tag','uvmat');
+if ~isempty(huvmat)
+    delete(huvmat)%delete uvmat for plot reinitialisation 
+end
+
+%------------------------------------------------------------------------
+% --- update the display when a new field is introduced.
+function Field_input(eventdata,handles,Field)
+%------------------------------------------------------------------------
+if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName)
+    Tabcell(:,1)=Field.ListDimName;
+    for iline=1:length(Field.ListDimName)
+        Tabcell{iline,2}=num2str(Field.DimValue(iline));
+    end
+    Tabchar=cell2tab(Tabcell,'=');
+    set(handles.dimensions,'String',Tabchar)
+end
+if ~isfield(Field,'ListVarName')
+    return
+end
+Txt=Field.ListVarName;
+set(handles.variables,'Value',1)
+set(handles.variables,'String',[{'*'} Txt])
+variables_Callback(handles.variables,[], handles)
+set(handles.abscissa,'String',[{''} Txt ])
+set(handles.ordinate,'String',Txt)
+set(handles.vector_x,'String',[Txt ])
+set(handles.vector_y,'String',[Txt ])
+set(handles.vector_z,'String',[{''} Txt ])
+set(handles.vec_color,'String',[{''} Txt ])
+set(handles.coord_x_scalar,'String',[{''} Txt ])
+set(handles.coord_y_scalar,'String',[{''} Txt ])
+set(handles.coord_x_vectors,'String',[{''} Txt ])
+set(handles.coord_y_vectors,'String',[{''} Txt ])
+set(handles.coord_z_scalar,'String',[{''} Txt ])
+set(handles.coord_z_vectors,'String',[{''} Txt ])
+set(handles.scalar,'Value',1)
+set(handles.scalar,'String', Txt )
+[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
+if ~isempty(errormsg)  
+    msgbox_uvmat('ERROR',['error in get_field/Field_input/find_field_indices: ' errormsg])
+    return
+end  
+[maxdim,imax]=max(NbDim);
+   
+if maxdim>=3
+    set(handles.vector_z,'Visible','on')
+    set(handles.vector_z,'String',[{''} Txt ])
+    set(handles.coord_z_vectors,'Visible','on')
+    set(handles.coord_z_vectors,'String',[{''} Txt ])
+    set(handles.coord_z_scalar,'Visible','on')
+    set(handles.coord_z_scalar,'String',[{''} Txt ])
+else
+    set(handles.vector_z,'Visible','off')
+    set(handles.coord_z_vectors,'Visible','off')
+    set(handles.coord_z_scalar,'Visible','off')
+end
+if maxdim>=2 
+    set(handles.check_1Dplot,'Value',0)
+    if ~isempty(VarType{imax}.vector_x) && ~isempty(VarType{imax}.vector_y)      
+        set(handles.check_vector,'Value',1)
+        set(handles.check_scalar,'Value',0)
+        set(handles.vector_x,'Value',VarType{imax}.vector_x)
+        set(handles.vector_y,'Value',VarType{imax}.vector_y)
+        if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y)
+            set(handles.coord_x_vectors,'Value',VarType{imax}.coord_x+1)
+            set(handles.coord_y_vectors,'Value',VarType{imax}.coord_y+1)
+        end
+        if ~isempty(VarType{imax}.coord) 
+            set(handles.coord_y_vectors,'Value',VarType{imax}.coord(1)+1)
+            if numel(VarType{imax}.coord)>=2
+                set(handles.coord_x_vectors,'Value',VarType{imax}.coord(2)+1)
+            end
+        end
+    else
+        set(handles.check_scalar,'Value',1)
+        set(handles.check_vector,'Value',0)
+        if isfield(VarType{imax},'scalar') && length(VarType{imax}.scalar)>=1
+            set(handles.scalar,'Value',VarType{imax}.scalar(1))
+            if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y)
+                set(handles.coord_x_scalar,'Value',VarType{imax}.coord_x+1)
+                set(handles.coord_y_scalar,'Value',VarType{imax}.coord_y+1)
+            end
+            if ~isempty(VarType{imax}.coord_z) 
+                set(handles.coord_z_scalar,'Value',VarType{imax}.coord_z+1)
+            end
+            if ~isempty(VarType{imax}.coord)
+                if numel(VarType{imax}.coord)>=maxdim-2 && maxdim>=3
+                    set(handles.coord_z_scalar,'Value',VarType{imax}.coord(maxdim-2)+1)
+                end
+                if numel(VarType{imax}.coord)>=maxdim-1
+                    set(handles.coord_y_scalar,'Value',VarType{imax}.coord(maxdim-1)+1)
+                end
+                if numel(VarType{imax}.coord)>=maxdim
+                    set(handles.coord_x_scalar,'Value',VarType{imax}.coord(maxdim)+1)
+                end     
+            end
+        end
+    end
+    check_1Dplot_Callback(handles.check_1Dplot, eventdata, handles)
+    check_scalar_Callback(handles.check_scalar, eventdata, handles)
+    check_vector_Callback(handles.check_vector, eventdata, handles)
+end
+
+%------------------------------------------------------------------------
+function ordinate_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+hselect_field=get(handles.inputfile,'parent');
+Field=get(hselect_field,'UserData');
+list=get(handles.ordinate,'String');
+yindex=get(handles.ordinate,'Value');
+yindex=name2index(list{yindex(1)},Field.ListVarName);
+if ~isempty(yindex)
+    set(handles.variables,'Value',yindex+1)
+    variables_Callback(hObject, eventdata, handles)
+end
+[CellVarIndex,NbDim,VarType,errormsg]=find_field_indices(Field);
+for icell=1:numel(CellVarIndex)
+    VarIndex=CellVarIndex{icell};
+    if ~isempty(find(VarIndex==yindex,1)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex))
+        cell_select=icell;
+        break
+    end
+end
+
+val=get(handles.abscissa,'Value');
+set(handles.abscissa,'Value',min(val,2));
+coord_x_index=VarType{cell_select}.coord;
+coord_x_index=coord_x_index(coord_x_index~=0);
+set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))'])
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in abscissa.
+function abscissa_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+ hselect_field=get(handles.inputfile,'parent');
+ Field=get(hselect_field,'UserData');%current input field
+ xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa
+% test_2D=get(handles.check_vector,'Value');% =1 for vector fields
+% test_scalar=get(handles.check_scalar,'Value');% =1 for scalar fields
+%if isequal(xdispindex,1)% blank selection, no selected variable for abscissa
+%     Txt=Field.ListVarName;
+%     set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates
+%     xindex=[];
+% else
+     xlist=get(handles.abscissa,'String');%list of abscissa
+     VarName=xlist{xdispindex}; %selected variable name
+     update_field(hObject, eventdata, handles,VarName)
+%      xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables
+%      if ~isempty(xindex)
+%         set(handles.variables,'Value',xindex+1)
+%         variables_Callback(hObject, eventdata, handles)
+%      end
+%     set(handles.variables,'Value',xindex+1)%outline  in the list of variables 
+%     variables_Callback(hObject, eventdata, handles)  %display properties of the variable (dim, attributes)
+%     if  ~test_2D &  ~test_scalar% look for possible varaibles to RUN in ordinate    
+%         index=Field.VarDimIndex{xindex};%dimension indices of the variable selected for abscissa
+%         VarIndex=[];
+%         for ilist=1:length(Field.VarDimIndex)%detect 
+%             index_i=Field.VarDimIndex{ilist};
+%             if ~isempty(index_i)
+%                 if isequal(index_i(1),index(1))%if the first dimension of the variable coincide with the selected one, RUN is possible
+%                     VarIndex=[VarIndex ilist];
+%                 end
+%             end
+%         end
+% %         set(handles.ordinate,'Value',1)
+%         set(handles.ordinate,'String',Field.ListVarName(VarIndex))
+%     end
+% end
+% 
+% update_UserData(handles)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in scalar menu.
+function scalar_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+Aindex=get(handles.scalar,'Value');
+Astring=get(handles.scalar,'String');
+VarName=Astring{Aindex};
+update_field(hObject, eventdata, handles,VarName)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in coord_x_scalar.
+function coord_x_scalar_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+index=get(handles.coord_x_scalar,'Value');
+string=get(handles.coord_x_scalar,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in coord_y_scalar.
+function coord_y_scalar_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+index=get(handles.coord_y_scalar,'Value');
+string=get(handles.coord_y_scalar,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in coord_z_scalar.
+function coord_z_scalar_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+index=get(handles.coord_z_scalar,'Value');
+string=get(handles.coord_z_scalar,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in vector_x.
+function vector_x_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+index=get(handles.vector_x,'Value');
+string=get(handles.vector_x,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in vector_y.
+function vector_y_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+index=get(handles.vector_y,'Value');
+string=get(handles.vector_y,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in vector_z.
+function vector_z_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+index=get(handles.vector_z,'Value');
+string=get(handles.vector_z,'String');
+VarName=Astring{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in coord_x_vectors.
+function coord_x_vectors_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+index=get(handles.coord_x_vectors,'Value');
+string=get(handles.coord_x_vectors,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_y_vectors.
+%-------------------------------------------------------
+function coord_y_vectors_Callback(hObject, eventdata, handles)
+index=get(handles.coord_y_vectors,'Value');
+string=get(handles.coord_y_vectors,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in coord_z_scalar.
+function coord_z_vectors_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.coord_z_vectors,'Value');
+string=get(handles.coord_z_vectors,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%-------------------------------------------------------
+% --- Executes on selection change in vec_color.
+function vec_color_Callback(hObject, eventdata, handles)
+%-------------------------------------------------------
+index=get(handles.vec_color,'Value');
+string=get(handles.vec_color,'String');
+VarName=string{index};
+update_field(hObject, eventdata, handles,VarName)
+
+%---------------------------------
+function update_field(hObject, eventdata, handles,VarName)
+% VarName= input variable name for scalar or vector plots
+hselect_field=get(handles.inputfile,'parent');
+Field=get(hselect_field,'UserData');
+index=name2index(VarName,Field.ListVarName);
+if ~isempty(index)
+    set(handles.variables,'Value',index+1)
+    variables_Callback(hObject, eventdata, handles)
+end
+% 
+% 
+% hselect_field=get(handles.inputfile,'parent');
+% Field=get(hselect_field,'UserData');
+% ivar_sel=[];%default
+% for ivar=1:length(Field.ListVarName)%detect 
+%     if isequal(Field.ListVarName{ivar},VarName)
+%         ivar_sel=ivar; %ivar_sel = index of the input variable in the list ListVarName
+%         break
+%     end
+% end
+% if isempty(ivar_sel)
+%     return
+% end
+% set(handles.variables,'Value',ivar_sel+1)%select the corresponding item in the displayed  list 'variables'
+% variables_Callback(hObject, eventdata, handles)%show the dimensions and attributes of the input variable
+% 
+% index=Field.VarDimIndex{ivar_sel};%dimension indices of the input variable
+% DimValue=Field.DimValue(index);%dimension values of the input variable
+% ind_1=find(DimValue==1);
+% index(ind_1)=[];%Mremove singletons
+% 
+% 
+% % detect possible variables for abscissa and ordinate
+% VarIndex=[];%initiate list of selected variable indices
+% ind_coordvar=[]; %initiate list of coordinate variables
+% for ilist=1:length(Field.VarDimIndex)
+%     if ~isequal(ilist,ivar_sel)        
+%         index_i=Field.VarDimIndex{ilist};%indices of dimensions associated with variable #ilist
+%         if length(index_i)>1
+%             DimValue=Field.DimValue(index_i);
+%             ind_1=find(DimValue==1);
+%             index_i(ind_1)=[];%Mremove singletons
+%             if isequal(index,index_i)
+%                 VarIndex=[VarIndex ilist]; %selected variable withb the same dimensions of the input variable
+%             end
+%         else
+%             idim=find(index==index_i(1));
+%             if ~isempty(idim)
+%                  VarIndex=[VarIndex ilist]; %possible dimension variable
+%                  if isequal(Field.ListDimName{index_i(1)},Field.ListVarName{ilist})
+%                      ind_coordvar=[ind_coordvar length(VarIndex)];
+%                  end
+%             end
+%         end
+%     end
+% end
+% % val=get(handles.abscissa,'Value');
+% % if val>length(Field.ListVarName(VarIndex))+1
+% %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
+% % end
+% % val=get(handles.ordinate,'Value');
+% % if val>length(Field.ListVarName(VarIndex))+1
+% %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
+% % end
+% % val=get(handles.coord_z_vectors_scalar,'Value');
+% % if val>length(Field.ListVarName(VarIndex))+1
+% %     set(handles.abscissa,'Value',length(Field.ListVarName(VarIndex))+1)
+% % end
+% set(handles.abscissa,'Value',1)%default
+% set(handles.ordinate,'Value',1)%default
+% set(handles.coord_z_scalar,'Value',1)%default
+% set(handles.abscissa,'String',[{''} Field.ListVarName(VarIndex) ])
+% set(handles.ordinate,'String',[{''} Field.ListVarName(VarIndex) ])
+% set(handles.coord_z_scalar,'String',[{''} Field.ListVarName(VarIndex) ])
+% if length(ind_coordvar)>=1
+%     set(handles.abscissa,'Value',ind_coordvar(1)+1)
+% elseif length(index)==1 && length(VarIndex)>=1
+%     set(handles.abscissa,'Value',2)
+% end
+% if length(ind_coordvar)>=2
+%     set(handles.ordinate,'Value',ind_coordvar(2)+1)
+% elseif length(index)==1 && length(VarIndex)>=2
+%     set(handles.ordinate,'Value',3)
+% end
+% if length(ind_coordvar)>=3
+%     set(handles.coord_z_scalar,'Value',ind_coordvar(3)+1)
+% elseif length(index)==1 && length(VarIndex)>=3
+%     set(handles.coord_z_scalar,'Value',4)
+% end
+
+%---------------------------------------------------------
+% update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback)
+function update_UserData(handles)
+%---------------------------------------------------------
+return
+% global SubField
+hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface
+Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface
+if isfield(Field,'VarAttribute')
+    VarAttribute=Field.VarAttribute;
+else
+    VarAttribute={};
+end
+
+
+% select the indices of field variables for 2D plots
+test_check_1Dplot=get(handles.check_1Dplot,'Value');
+test_scalar=get(handles.check_scalar,'Value');
+test_vector=get(handles.check_vector,'Value');
+
+%transform if needed (calibration)
+list=get(handles.menu_coord,'String');
+index=get(handles.menu_coord,'Value');
+transform=list{index};
+if ~isequal(transform,'')
+    Field=feval(transform,Field);
+end
+VarIndex.u=[];
+VarIndex.v=[];
+VarIndex.w=[];
+VarIndex.A=[];
+VarIndex_tot=[];
+iuA=[];
+if test_scalar
+    Astring=get(handles.scalar,'String');
+    Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox
+    list_var=Astring(Aindex);
+    VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName
+    VarIndex_tot= [VarIndex_tot VarIndex.A];
+    DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable
+    DimValue=Field.DimValue(DimIndex);
+    ind=find(DimValue==1);
+    DimIndex(ind)=[];%Mremove singleton
+end
+if test_vector
+    Ustring=get(handles.vector_x,'String');
+    Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox
+    list_var=Ustring{Uindex};%name of the selected scalar
+    VarIndex.u=name2index(list_var,Field.ListVarName);
+    Vstring=get(handles.vector_y,'String');
+    Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox
+    list_var=Ustring{Vindex};%name of the selected scalar
+    VarIndex.v=name2index(list_var,Field.ListVarName);
+    if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A)
+        iuA=VarIndex.A; %same variable used for vector and scalar
+        VarIndex_tot(iuA)=[];
+    end
+    VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v];
+    %dimensions
+    DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable
+    DimValue=Field.DimValue(DimIndex_u);
+    ind=find(DimValue==1);
+    DimIndex_u(ind)=[];%Mremove singleton
+    DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable
+    DimValue=Field.DimValue(DimIndex_v);
+    ind=find(DimValue==1);
+    DimIndex_v(ind)=[];%Mremove singleton
+    if ~isequal(DimIndex_u,DimIndex_v)
+        msgbox_uvmat('ERROR','inconsistent dimensions for u and v')
+        set(handles.vector_y,'Value',1); 
+        return
+    elseif  test_scalar & ~isequal(DimIndex_u,DimIndex)
+         msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color')
+         set(handles.scalar,'Value',1); 
+         return
+    end
+    DimIndex=DimIndex_u;
+    %TODO possibility of selecting 3 times the same variable for u, v, w components
+end
+
+
+% select the variable  index (or indices) for z coordinates
+test_grid=0;
+if test_scalar | test_vector
+    nbdim=length(DimIndex);
+    if nbdim > 3
+        msgbox_uvmat('ERROR','array with more than three dimensions, not supported')
+        return
+    else
+        perm_ind=[1:nbdim];
+    end
+    if nbdim==3
+        zstring=get(handles.coord_z_vectors_scalar,'String');
+        zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox
+        list_var=zstring(zindex);
+        VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable 
+        if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z)
+            if zindex ~= 1
+                set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components
+                return
+            end
+        else 
+            VarIndex_tot=[VarIndex_tot VarIndex_z];
+            DimIndex_z=Field.VarDimIndex{VarIndex_z};
+            DimValue=Field.DimValue(DimIndex_z);
+            ind=find(DimValue==1);          
+            DimIndex_z(ind)=[];%Mremove singleton
+            if isequal(DimIndex_z,DimIndex)
+                VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates
+            elseif length(DimIndex_z)==1
+                VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};  %dimension variable
+                ind_z=find(DimIndex==DimIndex_z(1));
+                perm_ind(ind_z)=1;
+                test_grid=1;
+            else
+                msgbox_uvmat('ERROR','multiple dimensions for the z coordinate')
+                return
+            end
+        end
+%         if ~isempty(VarIndex_z)
+%             DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the variable    
+%             if length(DimIndex_z)==1 & nbdim==3 %dimension variable
+%                 VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z};
+%                 ind_z=find(DimIndex==DimIndex_z(1));
+%                 perm_ind(ind_z)=1;
+%                 test_grid=1;
+%             end
+%         end
+    end
+end
+
+% select the variable  index (or indices) for ordinate
+ystring=get(handles.ordinate,'String');
+yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox
+list_var=ystring(yindex);
+VarIndex.y=name2index(list_var,Field.ListVarName);
+if isequal(VarIndex.A,VarIndex.y)
+    set(handles.coord_y_scalar,'Value',1)
+elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y)
+   set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components
+else
+    for ivar=1:length(VarIndex.y)
+        VarAttribute{VarIndex.y(ivar)}.Role='coord_y';
+    end
+    VarIndex_tot=[VarIndex_tot VarIndex.y];
+end
+if (test_scalar | test_vector) &  ~isempty(VarIndex.y)
+    DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable
+    if length(DimIndex_y)==1 
+        ind_y=find(DimIndex==DimIndex_y(1));
+        test_grid=1;
+        if nbdim==3
+            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
+            perm_ind(ind_y)=2;
+        elseif nbdim==2
+            VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y};
+             perm_ind(ind_y)=1;
+        end
+    elseif test_grid
+        msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1')   
+    end
+end
+
+%select the variable index for the abscissa
+xstring=get(handles.abscissa,'String');
+xindex=get(handles.abscissa,'Value');
+list_var=xstring(xindex);
+VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var
+if length(VarIndex.x)==1    
+    DimIndex_x=Field.VarDimIndex{VarIndex.x};
+    DimValue=Field.DimValue(DimIndex_x);
+    ind=find(DimValue==1);          
+    DimIndex_x(ind)=[];%Mremove singleton                      
+    VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};  %dimension variable           
+%     VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified)
+    index_detect=find(VarIndex_tot==VarIndex.x);
+else
+    index_detect=[];%coord x variable not already used
+end
+if isempty(index_detect)
+    VarIndex_tot=[VarIndex_tot VarIndex.x]; 
+elseif ~test_check_1Dplot
+    VarIndex.x=[];
+    set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa
+end
+
+if (test_scalar | test_vector) &  ~isempty(VarIndex.x)
+    DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable
+    if length(DimIndex_x)==1 
+        ind_x=find(DimIndex==DimIndex_x(1)); 
+        if nbdim==3
+            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
+            perm_ind(ind_x)=3;
+        elseif nbdim==2
+            %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x};
+             perm_ind(ind_x)=2;
+        end
+        if isequal(perm_ind,1:nbdim)
+            test_grid=0;
+        end
+        DimIndex=DimIndex(perm_ind);
+    elseif test_grid
+        msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1')   
+    end
+    if isequal(DimIndex_x,DimIndex)
+                VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates
+    end
+end
+
+%defined the selected sub-field SubField
+SubField.ListGlobalAttribute{1}='InputFile';
+SubField.InputFile=get(handles.inputfile,'String');
+SubField.ListDimName=Field.ListDimName;
+SubField.DimValue=Field.DimValue;
+SubField.ListVarName=Field.ListVarName(VarIndex_tot);
+SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot);
+
+testperm=0;
+testattr=0;
+for ivar=VarIndex.u
+    VarAttribute{ivar}.Role='vector_x';
+    testattr=1;
+    if test_grid
+        VarDimIndex{ivar}=DimIndex; %permute dimensions
+        testperm=1;
+    end
+end
+for ivar=VarIndex.v
+    VarAttribute{ivar}.Role='vector_y';
+    testattr=1;
+     if test_grid
+        VarDimIndex{ivar}=DimIndex;%permute dimensions
+        testperm=1;
+    end
+end
+for ivar=VarIndex.A
+    if test_grid
+        VarDimIndex{ivar}=DimIndex;%permute dimensions
+        testperm=1;
+    end
+    if isempty(iuA)
+        VarAttribute{ivar}.Role='scalar';%Role =scalar
+        testattr=1;
+    else
+       VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable
+       nbattr=length(VarAttribute);
+       VarAttribute{nbattr}.Role='scalar';
+       testattr=1;
+    end
+end
+if testperm
+    SubField.VarDimIndex=VarDimIndex(VarIndex_tot);
+end
+if testattr
+    SubField.VarAttribute=VarAttribute(VarIndex_tot);
+end
+set(hselect_field,'UserData',Field)
+
+%---------------------------------------------------------
+% --- Executes on button press in RUN.
+
+function RUN_Callback(hObject, eventdata, handles)
+%---------------------------------------------------------
+figcell=get(handles.list_fig,'String');
+index=get(handles.list_fig,'value');
+figstring=figcell{index};
+
+% plot requested in uvmat
+if isequal(figstring,'uvmat')
+    inputfile=get(handles.inputfile,'String');
+    huvmat=findobj(allchild(0),'tag','uvmat');
+    if isempty(huvmat)
+        uvmat(inputfile)
+    else
+        set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases)
+        hhuvmat=guidata(huvmat);
+        uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat
+    end
+   
+% other kind of plot
+else
+    index=get(handles.ACTION,'Value');
+    list_func=get(handles.ACTION,'UserData');
+    h_fun=list_func{index};
+    set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
+    drawnow
+    SubField=h_fun(handles.figure1);%handles.figure1 =handles of the GUI get_field
+    if ~isempty(SubField)
+        plot_get_field(SubField,handles)
+    end
+    browse_fig(handles.list_fig); %update the list of new existing figures
+end
+set(handles.RUN,'BackgroundColor',[1 0 0])
+
+%------------------------------------------------------------------------
+% --- Function for plotting the current subfield
+function plot_get_field(SubField,handles)
+%------------------------------------------------------------------------
+list_fig=get(handles.list_fig,'String')
+val=get(handles.list_fig,'Value');
+if strcmp(list_fig{val},'uvmat')
+    set(handles.inputfile,'Enable','off')% desactivate the input file edit box   
+    set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt)
+    set(handles.MenuOpen,'Visible','off')
+    set(handles.MenuExport,'Visible','off')
+    uvmat(get(handles.inputfile,'String'))
+elseif strcmp(list_fig{val},'view_field')
+    view_field(SubField)
+else
+    hfig=str2double(list_fig{val});% chosen figure number from tyhe GUI
+    if isnan(hfig)
+        hfig=figure;
+        list_fig=[list_fig;num2str(hfig)];
+        set(handles.list_fig,'String',list_fig);
+        haxes=axes;
+    else
+        figure(hfig);
+    end
+    haxes=findobj(hfig,'Type','axes');
+    plot_field(SubField,haxes) 
+end
+
+% %------------------------------------------------
+% % --- Executes on button press in Plot_histo.
+% %RUN global histograms
+% %-------------------------------------------------
+% function RUN_histo_Callback(hObject, eventdata, handles)
+% % hObject    handle to RUN (see GCBO)
+% % eventdata  reserved - to be defined in a future version of MATLAB
+% % handles    structure with handles and user data (see GUIDATA)
+% 
+% %time plots
+% leg={};
+% n=0;
+% if (get(handles.cm_switch,'Value')==1)
+%     Uval_p=Uval_cm;
+%     Vval_p=Vval_cm;
+%     Uhist_p=Uhist_cm;
+%     Vhist_p=Vhist_cm;
+%     xlab='velocity (cm/s)';
+% else
+%     Uval_p=Uval;
+%     Vval_p=Vval;
+%     Uhist_p=Uhist;
+%     Vhist_p=Vhist;
+%     xlab='velocity (pixels)';
+% end
+% if (get(handles.vector_y,'Value') == 1)
+%    hhh=figure(2);
+%    hold on
+%    title([filebase ', ' strindex ', ' fieldtitle])
+%    plot(Uval_p,Uhist_p,'b-')
+%    n=n+1;
+%    leg{n}='Uhist';
+%    xlabel(xlab)
+% end
+% if (get(handles.Vhist_input,'Value') == 1)
+%    hhh=figure(2);
+%    hold on
+%    title([filebase ', ' strindex ', ' fieldtitle])
+%    plot(Vval_p,Vhist_p,'r-')
+%    n=n+1;
+%    leg{n}='Vhist';
+%    xlabel(xlab);
+% end
+% if (get(handles.Chist_input,'Value') == 1)
+%    hhhh=figure(3);
+%    hold on
+%    title([filebase ', ' strindex ', ' fieldtitle])
+%    plot(Cval,Chist,'k-')
+%    leg{1}='Chist';
+% end
+% % hold off
+% grid on
+% legend(leg);
+
+% %-------------------------------------------------------------
+% % --- Executes on button press in Save_input.
+% function Save_input_Callback(hObject, eventdata, handles)
+% list_str=get(handles.abscissa,'String');
+% val=get(handles.abscissa,'Value');
+% var=list_str{val};
+% hselect_field=get(handles.Save_input,'parent')
+% set(hselect_field,'UserData',var);
+% set(hselect_field,'Tag','idle')
+
+%     
+% %-------------------------------------------------------------
+% % --- Executes on button press in save_histo.
+% function save_histo_Callback(hObject, eventdata, handles)
+% global filebase
+% 
+% pathstr = fileparts(filebase)
+% if (get(handles.Chist_input,'Value') == 1)
+%     def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']};
+%     else
+
+%     def = {[pathstr pathstr(1) 'vel_histo.fig']};
+% end
+% prompt={'save figure(2) as'}
+% dlg_title = 'save figure';
+% num_lines= 1;
+% answer = inputdlg(prompt,dlg_title,num_lines,def)
+% saveas(2,answer{1})
+ 
+
+%%-------------------------------------------------------
+% --- Executes on button press in peaklocking.
+%-------------------------------------------------
+function peaklocking(handles)
+%evaluation of peacklocking errors
+%use splinhist: give spline coeff cc for a smooth histo (call spline4)
+%use histsmooth(x,cc): calculate the smooth histo for any value x
+%use histder(x,cc): calculate the derivative of the smooth histo
+global hfig1 hfig2 hfig3
+global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval
+global xval xerror yval yerror
+
+set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface
+set(handles.Vhist_input,'Value',1)
+set(handles.cm_switch,'Value',0) % put the switch to 'pixel'
+
+%adjust the extremal values of the histogram in U with respect to integer
+%values
+minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins 
+maximU=round(max(Uval)-0.5)+0.5;
+minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval
+maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value
+nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below
+nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above
+Uval=[minim_fin:(1/nbb):maxim_fin];
+histu_min=zeros(nb_bin_min,1);
+histu_max=zeros(nb_bin_max,1);
+Uhist=[histu_min; Uhist ;histu_max]; % column vector
+
+%adjust the extremal values of the histogram in V
+minimV=round(min(Vval-0.5)+0.5);
+maximV=round(max(Vval-0.5)+0.5);
+minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval
+maxim_fin=maximV+0.5-1/(2*nbb); % last integer value
+nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below
+nb_bin_max=round((maxim_fin -max(Vval))*nbb);
+Vval=[minim_fin:(1/nbb):maxim_fin];
+histu_min=zeros(nb_bin_min,1);
+histu_max=zeros(nb_bin_max,1);
+Vhist=[histu_min; Vhist ;histu_max]; % column vector
+
+% RUN_histo_Callback(hObject, eventdata, handles)
+% %adjust the histogram to integer values:
+
+%histoU and V
+[Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist);
+[Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist);
+
+% selection of value ranges such that histo>=10 (enough statistics)
+Uval_ind=find(Uhist>=10);
+ind_min=min(Uval_ind);
+ind_max=max(Uval_ind);
+U_min=Uval(ind_min);% minimum allowed value 
+U_max=Uval(ind_max);%maximum allowed value
+
+% selection of value ranges such that histo>=10 (enough statistics)
+Vval_ind=find(Vhist>=10);
+ind_min=min(Vval_ind);
+ind_max=max(Vval_ind);
+V_min=Vval(ind_min);% minimum allowed value 
+V_max=Vval(ind_max);%maximum allowed value
+
+figure(4)% plot U histogram with smoothed one
+plot(Uval,Uhist,'b')
+grid on
+hold on
+plot(Uval,Uhistinter,'r');
+hold off
+
+figure(5)% plot V histogram with smoothed one
+plot(Vval,Vhist,'b')
+grid on
+hold on
+plot(Vval,Vhistinter,'r');
+hold off
+
+figure(6)% plot pixel error in two subplots
+hfig4=subplot(2,1,1);
+hfig5=subplot(2,1,2);
+axes(hfig4)
+plot(xval,xerror)
+axis([U_min U_max -0.4 0.4])
+xlabel('velocity u (pix)')
+ylabel('peaklocking error (pix)')
+grid on
+axes(hfig5)
+plot(yval,yerror)
+axis([V_min V_max -0.4 0.4]);
+xlabel('velocity v (pix)')
+ylabel('peaklocking error (pix)')
+grid on
+
+
+% ------------------------------------------------------------------
+function variables_Callback(hObject, eventdata, handles)
+Tabchar={''};%default
+Tabcell=[];
+hselect_field=get(handles.variables,'parent');
+Field=get(hselect_field,'UserData');
+index=get(handles.variables,'Value');%index in the list 'variables'
+if isequal(index,1) 
+    set(handles.attributes_txt,'String','global attributes')
+% list global attribute names and values if index=1 (blank variable display) is selected
+    if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute)
+        for iline=1:length(Field.ListGlobalAttribute)
+            Tabcell{iline,1}=Field.ListGlobalAttribute{iline};   
+            if isfield(Field, Field.ListGlobalAttribute{iline})
+                eval(['val=Field.' Field.ListGlobalAttribute{iline} ';'])
+                if ischar(val);% attribute value is char string
+                    Tabcell{iline,2}=val;
+                elseif size(val,1)==1 %attribute value is a number or matlab vector
+                    Tabcell{iline,2}=num2str(val);
+                end
+            end
+        end
+        Tabchar=cell2tab(Tabcell,'=');
+    end
+else
+%list attribute names and values associated to the variable # injdex-1   
+    list_var=get(handles.variables,'String');
+    var_select=list_var{index};
+    set(handles.attributes_txt,'String', ['attributes of ' var_select])
+    if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1
+%         nbline=0;
+        VarAttr=Field.VarAttribute{index-1};
+        if isstruct(VarAttr)
+            attr_list=fieldnames(VarAttr);
+            for iline=1:length(attr_list)
+                Tabcell{iline,1}=attr_list{iline};
+                eval(['val=VarAttr.' attr_list{iline} ';']) 
+                if ischar(val);
+                    Tabcell{iline,2}=val;
+                else
+                     Tabcell{iline,2}=num2str(val);
+                end
+            end
+        end
+    end
+
+end
+if ~isempty(Tabcell)
+    Tabchar=cell2tab(Tabcell,'=');
+    Tabchar=[{''};Tabchar];
+end
+set(handles.attributes,'Value',1);% select the first item
+set(handles.attributes,'String',Tabchar);
+
+% update dimensions;
+if isfield(Field,'ListDimName')
+    Tabdim={};%default
+    if isequal(index,1)%list all dimensions
+        dim_indices=1:length(Field.ListDimName);
+        set(handles.dimensions_txt,'String', 'dimensions')
+    else
+        DimCell=Field.VarDimName{index-1};
+        if ischar(DimCell)
+            DimCell={DimCell};
+        end   
+        dim_indices=[];
+        for idim=1:length(DimCell)
+            dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0 
+            dim_index=find(dim_index,1);
+            dim_indices=[dim_indices dim_index];
+        end
+        %dim_indices=find(dim_list) %removes 0 values
+        set(handles.dimensions_txt,'String', ['dimensions of ' var_select])
+    end
+    for iline=1:length(dim_indices)
+        Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)};
+        Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline)));
+    end
+    Tabchar=cell2tab(Tabdim,'=');
+    Tabchar=[{''} ;Tabchar];
+    set(handles.dimensions,'String',Tabchar)  
+end  
+
+%------------------------------------------------------------------------
+% --- Executes on button press in check_1Dplot.
+function check_1Dplot_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+val=get(handles.check_1Dplot,'Value');
+if isequal(val,0)
+    set(handles.Panel1Dplot,'Visible','off')
+else
+    set(handles.Panel1Dplot,'Visible','on')
+end
+
+%------------------------------------------------------------------------
+% --- Executes on button press in check_scalar.
+function check_scalar_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+val=get(handles.check_scalar,'Value');
+if isequal(val,0)
+    set(handles.PanelScalar,'Visible','off')
+else
+    set(handles.PanelScalar,'Visible','on')
+end
+
+%------------------------------------------------------------------------
+% --- Executes on button press in check_vector.
+function check_vector_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+val=get(handles.check_vector,'Value');
+if isequal(val,0)
+    set(handles.PanelVectors,'Visible','off')
+else
+    set(handles.PanelVectors,'Visible','on')
+end
+
+%------------------------------------------------------------------------
+function mouse_up_gui(ggg,eventdata,handles)
+%------------------------------------------------------------------------
+if isequal(get(ggg,'SelectionType'),'alt') 
+    message='';  
+    global CurData
+    inputfield=get(handles.inputfile,'String');
+    if exist(inputfield,'file')
+        CurData=nc2struct(inputfield);
+    else
+        CurData=get(ggg,'UserData');% get_field opened from a input field, not a file
+    end
+  %%%% TODO: put the matalb command window in front
+    evalin('base','global CurData')%make CurData global in the workspace
+    evalin('base','CurData') %display CurData in the workspace
+end
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in ACTION.
+%------------------------------------------------------------------------
+function ACTION_Callback(hObject, eventdata, handles)
+global nb_builtin
+list_ACTION=get(handles.ACTION,'String');% list menu fields
+index_ACTION=get(handles.ACTION,'Value');% selected string index
+ACTION= list_ACTION{index_ACTION}; % selected string
+list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path)
+ff=functions(list_func_handles{end});
+% add a new function to the menu
+if isequal(ACTION,'more...')
+    [FileName, PathName] = uigetfile( ...
+       {'*.m', ' (*.m)';
+        '*.m',  '.m files '; ...
+        '*.*', 'All Files (*.*)'}, ...
+        'Pick a file',ff.file);
+    if length(FileName)<2
+        return
+    end
+    [pp,ACTION,ext_fct]=fileparts(FileName);
+    if ~isequal(ext_fct,'.m')
+        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
+        return
+    end
+
+    % insert the choice in the action menu
+   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
+   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
+   addpath(PathName)
+   list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function
+   set(handles.ACTION,'UserData',list_func_handles)
+   set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off')
+   %list_path{index_ACTION}=PathName;
+   if length(menu_str)>nb_builtin+5;
+       nbremove=length(menu_str)-nb_builtin-5;
+       menu_str(nb_builtin+1:end-5)=[];
+       list_func_handles(nb_builtin+1:end-4)=[];
+       index_ACTION=index_ACTION-nbremove;
+       set(handles.ACTION,'Value',index_ACTION)
+       set(handles.ACTION,'String',menu_str)
+   end   
+   %record the current menu in personal file profil_perso
+   dir_perso=prefdir;
+   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+   get_field_fct={};
+   for ilist=nb_builtin+1:length(menu_str)-1
+       ff=functions(list_func_handles{ilist});
+       get_field_fct{ilist-nb_builtin}=ff.file;
+   end
+   if exist(profil_perso,'file')
+        save(profil_perso,'get_field_fct','-append')
+   else
+     txt=ver('MATLAB');
+    Release=txt.Release;
+       relnumb=str2num(Release(3:4));
+        if relnumb >= 14
+            save(profil_perso,'get_field_fct','-V6')
+        else
+            save(profil_perso, 'get_field_fct')
+        end
+   end
+end
+
+%check the current path to the selected function
+h_fun=list_func_handles{index_ACTION};
+if isa(h_fun,'function_handle')
+    func=functions(h_fun);
+    set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function
+    GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field
+else
+    set(handles.path_action,'String','')
+    msgbox_uvmat('ERROR','unknown path to ACTION function, reload it')
+    return
+end
+
+%prepare the GUI options for the selected ACTION
+test_1Dplot=0;
+test_scalar=0;
+test_vector=0;
+if iscell(GUI_input)
+    for ilist=1:length(GUI_input)
+        switch GUI_input{ilist}
+                           %RootFile always visible
+            case 'check_1Dplot'   
+                 test_1Dplot=1;
+            case 'check_scalar'
+                 test_scalar=1;   
+            case 'check_vector'   
+                 test_vector=1; 
+        end
+    end
+end
+set(handles.check_1Dplot,'Value',test_1Dplot);
+set(handles.check_scalar,'Value',test_scalar); 
+set(handles.check_vector,'Value',test_vector);
+check_1Dplot_Callback(hObject, eventdata, handles)
+check_scalar_Callback(hObject, eventdata, handles)
+check_vector_Callback(hObject, eventdata, handles)
+
+
+%-----------------------------------------------------
+% --- browse existing figures
+%-----------------------------------------------------
+function browse_fig(menu_handle)
+hh=findobj(allchild(0),'Type','figure');
+ilist=0;
+list={};
+for ifig=1:length(hh)  %look for all existing figures
+    name=get(hh(ifig),'Name');
+     if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI
+        hchild=get(hh(ifig),'children');% look for axes contained in each figure
+        nbaxe=0;
+        for ichild=1:length(hchild)           
+            Type=get(hchild(ichild),'Type');
+            Tag=get(hchild(ichild),'Tag');
+            if isequal(Type,'axes')
+                if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting
+                     nbaxe=nbaxe+1;%count the existing axis
+                end 
+            end
+        end    
+        if nbaxe==1
+             ilist=ilist+1;%add a line in the list of axis
+            list{ilist,1}=num2str(hh(ifig));
+        elseif nbaxe>1
+            for iaxe=1:nbaxe
+               ilist=ilist+1;%add a line in the list of axis
+               list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)];
+            end
+        end
+     end
+end
+list=['uvmat';list];
+set(menu_handle,'Value',1)
+set(menu_handle,'String',list)
+
+
+%-----------------------------------------------------
+function list_fig_Callback(hObject, eventdata, handles)
+%-----------------------------------------------------
+list_fig=get(handles.list_fig,'String');
+fig_val=get(handles.list_fig,'Value');
+plot_fig=list_fig{fig_val};
+if strcmp(plot_fig,'view_field')
+%     huvmat=findobj(allchild(0),'name','uvmat');
+%     if ~isempty(huvmat)
+%         uistack(huvmat,'top')
+%     end    
+else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat')
+    sep=regexp(plot_fig,'_');
+    if ~isempty(sep)
+        plot_fig=plot_fig([1:sep-1]);
+    end
+    if ishandle(str2num(plot_fig))
+        figure(str2num(plot_fig))% display existing figure
+    else
+        browse_fig(handles.list_fig); %reset the current list of figures
+    end
+end
+
+
+%-------------------------------------------------
+% give index numbers of the strings str in the list ListvarName
+function VarIndex_y=name2index(cell_str,ListVarName)
+VarIndex_y=[];
+if ischar(cell_str)
+    for ivar=1:length(ListVarName)
+        varlist=ListVarName{ivar};
+        if isequal(varlist,cell_str)
+            VarIndex_y= ivar;
+            break
+        end
+    end
+elseif iscell(cell_str)
+    for isel=1:length(cell_str)
+        varsel=cell_str{isel};
+        for ivar=1:length(ListVarName)
+            varlist=ListVarName{ivar};
+            if isequal(varlist,varsel)
+                VarIndex_y=[VarIndex_y ivar];
+            end
+        end
+    end
+end
+
+% --------------------------------------------------------------------
+function MenuOpen_Callback(hObject, eventdata, handles)
+% hObject    handle to MenuOpen (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuExport_Callback(hObject, eventdata, handles)
+% hObject    handle to MenuExport (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+
+
+% --------------------------------------------------------------------
+function MenuBrowse_Callback(hObject, eventdata, handles)
+
+oldfile=get(handles.inputfile,'String');
+testrootfile=0;
+testsubdir=0;
+if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
+        oldfile=''; 
+        dir_perso=prefdir;
+         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+         if exist(profil_perso,'file')
+              h=load (profil_perso);
+             if isfield(h,'RootPath')
+                  RootPath=h.RootPath;
+             end
+             if isfield(h,'SubDir')
+                  SubDir=h.SubDir;
+                  if ~isempty(SubDir)
+                    testsubdir=1;
+                  end
+             end
+             if isfield(h,'RootFile')
+                  RootFile=h.RootFile;
+                  if ~isempty(RootFile)
+                    testrootfile=1;
+                  end
+             end
+         end
+end
+if testrootfile
+    if ~testsubdir
+        oldfile=fullfile(RootPath,RootFile);
+    else
+        oldfile=fullfile(RootPath,SubDir,RootFile);
+    end
+end
+[FileName, PathName] = uigetfile( ...
+       {'*.nc', ' *.nc';...
+       '*.cdf', ' *.cdf';...
+        '*.*',  'All Files (*.*)'}, ...
+        'Pick a file',oldfile);
+
+%global inputfile
+fileinput=[PathName FileName];%complete file name 
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+    msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
+    return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
+set(handles.inputfile,'String',fileinput)
+inputfile_Callback(hObject, eventdata, handles)
+
+
+%update list of recent files in the menubar
+MenuFile_1=fileinput;
+MenuFile_2=get(handles.MenuFile_1,'Label');
+MenuFile_3=get(handles.MenuFile_2,'Label');
+MenuFile_4=get(handles.MenuFile_3,'Label');
+MenuFile_5=get(handles.MenuFile_4,'Label');
+set(handles.MenuFile_1,'Label',MenuFile_1)
+set(handles.MenuFile_2,'Label',MenuFile_2)
+set(handles.MenuFile_3,'Label',MenuFile_3)
+set(handles.MenuFile_4,'Label',MenuFile_4)
+set(handles.MenuFile_5,'Label',MenuFile_5)
+dir_perso=prefdir;
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+display(profil_perso)
+if exist(profil_perso,'file')
+    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
+else
+    txt=ver('MATLAB');
+    Release=txt.Release;
+    relnumb=str2double(Release(3:4));
+    if relnumb >= 14
+        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
+    else
+        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
+    end
+end
+
+% --------------------------------------------------------------------
+function MenuFile_1_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_1,'Label');
+set(handles.inputfile,'String',fileinput)
+inputfile_Callback(hObject, eventdata, handles)
+
+% --------------------------------------------------------------------
+function MenuFile_2_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_2,'Label');
+set(handles.inputfile,'String',fileinput)
+inputfile_Callback(hObject, eventdata, handles)
+
+% --------------------------------------------------------------------
+function MenuFile_3_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_3,'Label');
+set(handles.inputfile,'String',fileinput)
+inputfile_Callback(hObject, eventdata, handles)
+
+% --------------------------------------------------------------------
+function MenuFile_4_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_4,'Label');
+set(handles.inputfile,'String',fileinput)
+inputfile_Callback(hObject, eventdata, handles)
+
+% --------------------------------------------------------------------
+function MenuFile_5_Callback(hObject, eventdata, handles)
+fileinput=get(handles.MenuFile_5,'Label');
+set(handles.inputfile,'String',fileinput)
+inputfile_Callback(hObject, eventdata, handles)
+
+% --------------------------------------------------------------------
+function MenuExportField_Callback(hObject, eventdata, handles)
+global Data_get_field
+% huvmat=findobj(allchild(0),'Name','uvmat');
+inputfile=get(handles.inputfile,'String');
+Data_get_field=nc2struct(inputfile);
+% Data_view_field=UvData.ProjField_2;
+evalin('base','global Data_get_field')%make CurData global in the workspace
+display(['content of ' inputfile ':'])
+evalin('base','Data_get_field') %display CurData in the workspace
+commandwindow;
+
+% --------------------------------------------------------------------
+function MenuHelp_Callback(hObject, eventdata, handles)
+% hObject    handle to MenuHelp (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
+if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
+else
+web([helpfile '#get_field'])    
+end
+
Index: /trunk/src/mouse_up.m
===================================================================
--- /trunk/src/mouse_up.m	(revision 204)
+++ /trunk/src/mouse_up.m	(revision 204)
@@ -0,0 +1,408 @@
+%'mouse_up': function  activated when the mouse button is released
+%------------------------------------------------------------------------
+% function mouse_up(hObject,eventdata,handles)
+% activated by the command:
+% set(hObject,'WindowButtonUpFcn',{'mouse_up'}), 
+% where hObject is the handle of the figure
+
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%     This file is part of the toolbox UVMAT.
+% 
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published by
+%     the Free Software Foundation; either version 2 of the License, or
+%     (at your option) any later version.
+% 
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function mouse_up(hObject,eventdata,handles)
+%MouseAction='none'; %default
+test_zoom=0;%default
+test_ruler=0;%default
+currentfig=hObject;
+tagfig=get(currentfig,'tag');
+currentaxes=gca; %store the current axes handle
+AxeData=get(currentaxes,'UserData');
+if isfield(AxeData,'CurrentOrigin')
+    CurrentOrigin=AxeData.CurrentOrigin;
+end
+if isfield(AxeData,'ParentRect')% case of a zoom plot as current axis
+    parentaxes=get(AxeData.ParentRect,'parent');
+    AxeData=get(parentaxes,'UserData');
+    controlGUI=get(parentaxes,'parent');%handles of the GUI parent of the zoom plot
+    hhcurrentfig=guidata(controlGUI);
+    testsubplot=1;
+else
+    hhcurrentfig=guidata(currentfig);%the current figure is a GUI (uvmat or view_field)
+    testsubplot=0;
+end
+test_zoom=get(hhcurrentfig.zoom,'Value');
+
+huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle
+if ~isempty(huvmat)
+    hhuvmat=guidata(huvmat);
+    UvData=get(huvmat,'UserData');
+   test_ruler=~test_zoom && isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler  action, second priority
+end
+test_drawing=0;%default
+
+%% finalize the fabrication or the translation/deformation of an object and plot the corresponding projected field
+if ~isempty(huvmat) && isfield(AxeData,'Drawing') && ~isequal(AxeData.Drawing,'off') && isfield(AxeData,'CurrentObject')...
+           && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject)
+    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+    PlotData=get(AxeData.CurrentObject,'UserData');%get data attached to the current projection object  
+    IndexObj=PlotData.IndexObj;
+    ObjectData=UvData.Object{IndexObj};    
+    ObjectData.enable_plot=1;
+    
+    % ending translation
+    if isequal(AxeData.Drawing,'translate')
+        XYData=AxeData.CurrentOrigin;
+        DX=xy(1,1)-XYData(1);%translation from initial position
+        DY=xy(1,2)-XYData(2);
+        ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
+        ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
+        
+    %ending object deformation
+    elseif isequal(AxeData.Drawing,'deform')
+        ind_move=AxeData.CurrentIndex;
+        ObjectData.Coord(ind_move,1)=xy(1,1);
+        ObjectData.Coord(ind_move,2)=xy(1,2);
+        
+    %creating object   
+    else   
+        if strcmp(ObjectData.Style,'line')||strcmp(ObjectData.Style,'polyline')||...
+                strcmp(ObjectData.Style,'polygon')||strcmp(ObjectData.Style,'points')
+            if isfield(AxeData,'ObjectCoord') && size(AxeData.ObjectCoord,2)==3
+              xy(1,3)=AxeData.ObjectCoord(1,3); % z coordinate of the mouse: to generalise ...
+            else
+                 xy(1,3)=0; % z coordinate set to 0 by default
+            end
+            if ~isequal(ObjectData.Coord,xy(1,:))
+                ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];% append the coordiantes marked by the mouse to the eobject
+            end
+        elseif isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')||isequal(ObjectData.Style,'volume')
+            XYData=AxeData.CurrentOrigin;
+            ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
+            ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
+            ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
+            ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
+        elseif isequal(ObjectData.Style,'plane') %case of 'plane'
+            DX=(xy(1,1)-ObjectData.Coord(1,1));
+            DY=(xy(1,2)-ObjectData.Coord(1,2));
+            ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle width
+            if isfield(ObjectData,'RangeX')
+                XMax=sqrt(DX*DX+DY*DY);
+                if XMax>max(ObjectData.RangeX)
+                    ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
+                end
+            end
+        end
+    end
+    if strcmp(ObjectData.Style,'rectangle')||strcmp(ObjectData.Style,'ellipse')
+        NbDefPoint=1;  
+    elseif strcmp(ObjectData.Style,'line')|| strcmp(ObjectData.Style,'plane');
+        NbDefPoint=2; 
+    else
+         NbDefPoint=3;
+    end
+    
+    %show object coordinates in the GUI set_object
+    h_set_object=findobj(allchild(0),'Tag','set_object');
+    hh_set_object=guidata(h_set_object);
+    set(hh_set_object.XObject,'String',num2str(ObjectData.Coord(:,1),4)); 
+    set(hh_set_object.YObject,'String',num2str(ObjectData.Coord(:,2),4)); 
+    set(hh_set_object.ZObject,'String',num2str(ObjectData.Coord(:,3),4));
+    if strcmp(ObjectData.Style,'rectangle')||strcmp(ObjectData.Style,'ellipse')
+        set(hh_set_object.XMax,'String',num2str(ObjectData.RangeX,4));
+        set(hh_set_object.YMax,'String',num2str(ObjectData.RangeY,4));
+    end
+    if NbDefPoint<=2 || isequal(get(currentfig,'SelectionType'),'alt') ||...
+              strcmp(AxeData.Drawing,'translate') || strcmp(AxeData.Drawing,'deform');%stop drawing
+        AxeData.CurrentOrigin=[]; %suppress the current origin
+       if isequal(ObjectData.Style,'line') && size(ObjectData.Coord,1)<=1
+           AxeData.Drawing='off';
+           set(currentaxes,'UserData',AxeData);
+            return % line needs at leqst two points
+       end
+       if  ~isempty(ObjectData)
+%              testmask=0;
+%              hmask=findobj(huvmat,'Tag','makemask');
+%              if ~isempty(hmask)
+%                 testmask=get(hmask,'Value');
+%              end
+
+            %% update the object representation
+            ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj}.DisplayHandle_uvmat;
+            ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj}.DisplayHandle_view_field;
+            UvData.Object{IndexObj}=ObjectData;%update the current object properties
+            hhuvmat=guidata(huvmat);
+            IndexObj_1=get(hhuvmat.list_object_1,'Value');
+            IndexObj_2=get(hhuvmat.list_object_2,'Value');
+            UvData.Object=update_obj(UvData,IndexObj_1,IndexObj_2);
+
+            %% plot the field projected on the object 
+            ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
+            if ~isempty(ProjData)
+                if strcmp(tagfig,'uvmat')% uvmat plot selected, projection plot seen on view_field
+                    hview_field=findobj(allchild(0),'tag','view_field');
+                    if isempty(hview_field)
+                        hview_field=view_field;
+                    end
+                    ViewFieldData=get(hview_field,'UserData');
+                    ViewFieldData.axes3=ProjData;
+                    set(hview_field,'UserData',ViewFieldData)
+                    hh_plotfield=guidata(hview_field);
+                else
+                    UvData.axes3=ProjData;
+                    hh_plotfield=hhuvmat;
+                end
+                [PlotType,PlotParam]=plot_field(ProjData,hh_plotfield.axes3,read_plot_param(hh_plotfield));%update an existing field plot
+                write_plot_param(hh_plotfield,PlotParam); %update the display of plotting parameters for the current object
+            end
+            set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
+            set(hhuvmat.edit_object,'Value',1);%
+            set(hhuvmat.edit_object,'Enable','on');%
+            set(hhuvmat.MenuEditObject,'Enable','on');%
+            set(hhuvmat.MenuEdit,'Enable','on');%
+        end
+    else
+       AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the new current origin
+       test_drawing=1;%allow continuation of drawing object
+       UvData.Object{IndexObj}=ObjectData;
+    end
+    hother=findobj('Tag','deformpoint');%find all the deformpoints
+    set(hother,'Color','b');%reset all the deformpoints in 'blue' 
+else
+    test_drawing=0;
+end
+
+%% creation of a new zoom plot
+if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
+    hparentfig=currentfig;
+    %open or update a new zoom figure if a rectangle has been drawn
+    if ishandle(currentaxes);
+        if isfield(AxeData,'CurrentRectZoom') && ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom)
+            PosRect=get(AxeData.CurrentRectZoom,'Position');
+            if isfield(AxeData,'CurrentVec') && ~isempty(AxeData.CurrentVec) && ishandle(AxeData.CurrentVec)
+                delete(AxeData.CurrentVec)
+            end
+            if ~testsubplot
+                hfig2=figure;%create new figure
+                set(hfig2,'name','zoom')
+                set(hfig2,'Units','normalized')
+                set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
+                map=colormap(currentaxes);
+                colormap(map);%transmit the current colormap to the zoom fig
+                set(hfig2,'Position',[0.2 0.33 0.6 0.6]);          
+                set(hfig2,'Unit','normalized')
+                set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
+                set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
+                set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
+                set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles})
+                set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
+                set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
+                AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
+                ChildAxeData=get(AxeData.ZoomAxes,'UserData');
+                if isfield(ChildAxeData,'ParentGUI')
+                    ChildAxeData=rmfield(ChildAxeData,'ParentGUI');%no parent GUI, e.g. uvmat,  for the new plot
+                end
+                %figure(hfig2)
+                %set(0,'CurrentFigure',hfig2)% the zoom figure becomes the current figure
+                set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
+                hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
+                if ~isempty(hcol)
+                    hcol_new=colorbar;
+                    YTick=get(hcol,'YTick');
+                    YTicklabel=get(hcol,'Yticklabel');
+                    colbarlim=get(hcol,'YLim');
+                    newcolbarlim=get(hcol_new,'YLim');
+                    scale_bar=(newcolbarlim(2)-newcolbarlim(1))/(colbarlim(2)-colbarlim(1));
+                    YTick_rescaled=newcolbarlim(1)+scale_bar*(YTick-colbarlim(1));
+                    set(hcol_new,'YTick',YTick_rescaled);
+                    set(hcol_new,'Yticklabel',YTicklabel);
+                end
+            end
+    %             if ishandle(AxeData.ZoomAxes)
+%             hnew_rect=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');
+%             if ~isempty(hnew_rect)
+%                 delete(hnew_rect);
+
+                ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
+                ChildAxeData.Drawing='off';
+                ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axe
+                PosRect=CurrentOrigin;
+                xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+                set(AxeData.ZoomAxes,'Xlim',[PosRect(1) xy(1,1)])
+                set(AxeData.ZoomAxes,'Ylim',[PosRect(2) xy(1,2)])
+%             end
+            set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
+        end
+    end
+end
+
+%% zoom in by a factor 2 if no new figure is created
+if test_zoom
+    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+    xlim=get(currentaxes,'XLim');
+    ylim=get(currentaxes,'YLim');
+    if  isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
+        xlim(1)=0.5*xy(1,1)+0.5*xlim(1);
+        xlim(2)=0.5*xy(1,1)+0.5*xlim(2);
+        set(currentaxes,'XLim',xlim)
+        ylim(2)=0.5*xy(1,2)+0.5*ylim(2);
+        ylim(1)=0.5*xy(1,2)+0.5*ylim(1);
+        set(currentaxes,'YLim',ylim)
+        %zoom out by a factor of 2 out when the right mouse button has been used
+    else%if isequal(get(currentfig,'SelectionType'),'alt'); %if right button has been pressed
+        xlim(1)=2*xlim(1)-xy(1,1);
+        xlim(2)=2*xlim(2)-xy(1,1);
+        ylim(1)=2*ylim(1)-xy(1,2);
+        ylim(2)=2*ylim(2)-xy(1,2);
+        %             ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
+        %             ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
+        if isfield(AxeData,'RangeX') && isfield(AxeData,'RangeY')
+            xlim(1)=max(AxeData.RangeX(1),xlim(1));
+            xlim(2)=min(AxeData.RangeX(2),xlim(2));
+            ylim(1)=max(AxeData.RangeY(1),ylim(1));
+            ylim(2)=min(AxeData.RangeY(2),ylim(2));
+            if isequal(xlim,AxeData.RangeX) && isequal(ylim,AxeData.RangeY)
+                set(hhuvmat.zoom,'Value',0)
+                set(hhuvmat.zoom,'BackgroundColor',[0.7 0.7 0.7])
+                set(hhuvmat.FixedLimits,'Value',0)
+                set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
+            end
+        end
+        set(currentaxes,'XLim',xlim)
+        set(currentaxes,'YLim',ylim)
+        %test whther zoom out is operating (to inactivate AxedAta
+        if ~isfield(AxeData,'CurrentXLim')|| ~isequal(xlim,AxeData.CurrentXLim)
+            AxeData.CurrentXLim=xlim;%
+        end
+    end
+%     if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
+%         hparentrect=AxeData.ParentRect;
+%         xlim=get(currentaxes,'XLim');
+%         ylim=get(currentaxes,'YLim');
+%         rect([1 2])=[xlim(1) ylim(1)];
+%         rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
+%         set(hparentrect,'Position',rect)
+    if isfield(AxeData,'LimEditBox')&& AxeData.LimEditBox% update display of the GUI containing the axis (uvmat or view_field)
+        set(hhcurrentfig.MinX,'String',num2str(xlim(1)))
+        set(hhcurrentfig.MaxX,'String',num2str(xlim(2)))
+        set(hhcurrentfig.MinY,'String',num2str(ylim(1)))
+        set(hhcurrentfig.MaxY,'String',num2str(ylim(2)))
+    end
+end
+
+%% editing calibration point
+if ~test_zoom && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'calibration')
+    h_geometry_calib=findobj(allchild(0),'tag','geometry_calib'); %find the geomterty_calib GUI
+    if ~isempty(h_geometry_calib)
+        hh_geometry_calib=guidata(h_geometry_calib);
+        edit_test=get(hh_geometry_calib.edit_append,'Value');
+        hh=findobj(currentaxes,'tag','calib_points');%look for handle of calibration points
+        if ~isempty(hh) && edit_test
+            index_point=get(hh,'UserData');
+            set(hh,'UserData',[])%remove edit mode
+            h_ListCoord=hh_geometry_calib.ListCoord; %handles of the coordinate list
+            Coord=get(h_ListCoord,'String');
+            data=read_geometry_calib(Coord);
+            %         val=get(h_ListCoord,'Value');
+            xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+            data.Coord(index_point,4)=xy(1,1);
+            data.Coord(index_point,5)=xy(1,2);
+            for ipoint=1:size(data.Coord,1)
+                for jcoord=1:5
+                    Coord_cell{ipoint,jcoord}=num2str(data.Coord(ipoint,jcoord),4);%display coordiantes with 4 digits
+                end
+            end
+            Tabchar=cell2tab(Coord_cell,' | ');
+            Tabchar=[Tabchar ;{'......'}];
+            set(h_ListCoord,'String',Tabchar)
+            %         coord_str=Coord{index_point}; %current line (string)
+            %         k=findstr('|',coord_str);%find separator indices on the string
+            %         blanks=blank
+            %         xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+            %         if numel(k)>=3
+            %             coord_str=[coord_str(1:k(3)-1) ' | ' num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4)]; %update the pixel information while preserving phys coord
+            %         else
+            %             coord_str=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
+            %         end
+            %         Coord{index_point}=coord_str;
+            %         set(h_ListCoord,'String',Coord)
+            %         data=read_geometry_calib(Coord);%transform char cell to numbers
+            set(hh,'XData',data.Coord(:,4))
+            set(hh,'YData',data.Coord(:,5))
+        end
+    end
+end
+
+
+%% finalising ruler
+if test_ruler
+    set(hhuvmat.MenuRuler,'checked','off')%desable the ruler option in uvmat  
+    xy=get(currentaxes,'CurrentPoint');% get the current mouse coordinates 
+    RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)];% append the recorded ruler origin to the current mouse coordinates 
+    RulerCoord=diff(RulerCoord,1);% coordiante difference between segment end and beginning
+    RulerCoord=RulerCoord(1)+i*RulerCoord(2);
+    distance=abs(RulerCoord);
+    azimuth=(180/pi)*angle(RulerCoord);
+    msgbox_uvmat('RULER','',['length: ' num2str(distance,3) ',  angle(degrees): ' num2str(azimuth,3)])
+    delete(AxeData.RulerHandle)%delete the ruler graphic object
+    AxeData=rmfield(AxeData,'RulerHandle');%remove the ruler handle in AxeData
+    AxeData.Drawing='off';%exit the ruler drawing mode
+end
+
+%% display the data of the current object selected with the mouse right click
+if isequal(get(currentfig,'SelectionType'),'alt') && ~test_zoom && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
+    hother=findobj('Tag','proj_object');%find all the proj objects
+    nbselect=0;
+    %test the existence of selected objects:
+    for iproj=1:length(hother);
+        iselect=isequal(get(hother(iproj),'Selected'),'on');%reset all the proj objects in 'blue' by default
+        nbselect=nbselect+iselect;
+    end
+    hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
+    set(hother,'Color','b');%reset all the proj objects in 'blue' by default
+    set(hother,'Selected','off')
+    hother=findobj('Tag','proj_object','Type','rectangle');
+    set(hother,'EdgeColor','b');
+    set(hother,'Selected','off')
+    hother=findobj('Tag','proj_object','Type','patch');
+    set(hother,'FaceColor','b');   
+    if isequal(get(gco,'Type'),'image')
+        currentobj=get(gco,'parent');%parent axes of the image
+    else 
+        currentobj=gco;%default
+    end
+    if ((nbselect==0) && isequal(get(currentobj,'Type'),'axes')) || isequal(currentobj,huvmat)
+        currentfig=get(currentobj,'parent');
+        figname=get(currentfig,'name');
+        eval(['global Data_' figname])
+        eval(['Data_' figname '=get(currentobj,''UserData'')']);
+        evalin('base',['global Data_' figname])%make CurData global in the workspace
+        objtype=get(currentobj,'Type');
+        display(['UserData of ' objtype ':'])
+        evalin('base',['Data_' figname]) %display CurData in the workspace
+        commandwindow %brings the Matlab command window to the front
+    end
+end
+
+%% update 
+if test_drawing==0
+        AxeData.Drawing='off';%stop current drawing action
+end
+set(currentaxes,'UserData',AxeData);
+if ~isempty(huvmat)
+    set(huvmat,'UserData',UvData);
+end
+
+    
+
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 204)
+++ /trunk/src/proj_field.m	(revision 204)
@@ -0,0 +1,2154 @@
+%'proj_field': projects the field on a projection object
+%--------------------------------------------------------------------------
+%  function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
+%
+% OUTPUT:
+% ProjData structure containing the fields of the input field FieldData,
+% transmitted or projected on the object, plus the additional fields
+%    .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
+%    .UMean,VMean: mean of the velocity components in a domain
+%    .AMin, AMax: min and max of a scalar
+%    .AMean: mean of a scalar in a domain  
+%  .NbPix;
+%  .DimName=  names of the matrix dimensions (matlab cell)
+%  .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
+%  .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;
+%
+%INPUT
+% ObjectData: structure characterizing the projection object
+%    .Style : style of projection object
+%    .ProjMode=type of projection ;
+%    .CoordType: 'px' or 'phys' type of coordinates defining the object position
+%    .Phi  angle of rotation (=0 by default)
+%    .ProjAngle=angle of projection;
+%    .DX,.DY,.DZ=increments along each coordinate
+%    .Coord(nbpoints,3): set of coordinates defining the object position;
+
+%FieldData: data of the field to be projected on the projection object, with optional fields
+%    .Txt: error message, transmitted to the projection
+%    .CoordType: 'px' or 'phys' type of coordinates of the field, must be the same as for the projection object, transmitted
+%    .Mesh: typical distance between data points (used for mouse action or display), transmitted
+%    .CoordUnit, .TimeUnit, .dt: transmitted
+% standardised description of fields, nc-formated Matlab structure with fields:
+%         .ListGlobalAttribute: cell listing the names of the global attributes
+%        .Att_1,Att_2... : values of the global attributes
+%            .ListVarName: cell listing the names of the variables
+%           .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
+%        .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
+% The variables are grouped in 'fields', made of a set of variables with common dimensions (using the function find_field_indices)
+% The variable attribute 'Role' is used to define the role for plotting:
+%       Role = 'scalar':  (default) represents a scalar field
+%            = 'coord':  represents a set of unstructured coordinates, whose
+%                     space dimension is given by the last array dimension (called 'NbDim').
+%            = 'coord_x', 'coord_y',  'coord_z': represents a separate set of
+%                        unstructured coordinate x, y  or z
+%            = 'vector': represents a vector field whose number of components
+%                is given by the last dimension (called 'NbDim')
+%            = 'vector_x', 'vector_y', 'vector_z'  :represents the x, y or z  component of a vector  
+%            = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
+%            = 'errorflag': provides an error flag marking false data,
+%                   default=0, no error. Different non zero values can represent different criteria of elimination.
+%
+% Default role of variables (by name)
+%  vector field:
+%    .X,.Y: position of the velocity vectors, projected on the object
+%    .U, .V, .W: velocity components, projected on the object
+%    .C, .CName: scalar associated to the vector
+%    .F : equivalent to 'warnflag'
+%    .FF: equivalent to 'errorflag'
+%  scalar field or image:
+%    .AName: name of a scalar (to be calculated from velocity fields after projection), transmitted 
+%    .A: scalar, projected on the object
+%    .AX, .AY: positions for the scalar
+%     case of a structured grid: A is a dim 2 matrix and .AX=[first last] (length 2 vector) represents the first and last abscissa of the grid
+%     case of an unstructured scalar: A is a vector, AX and AY the corresponding coordinates 
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%     This file is part of the toolbox UVMAT.
+% 
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published by
+%     the Free Software Foundation; either version 2 of the License, or
+%     (at your option) any later version.
+% 
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
+errormsg=[];%default
+if isfield(ObjectData,'ProjMode') && (isequal(ObjectData.ProjMode,'none')||isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'))
+    ProjData=[];
+    return
+end
+%introduce default field properties (reading old standards)
+if ~isfield(ObjectData,'Style')||~isfield(ObjectData,'ProjMode')
+    ProjData=FieldData;
+    return
+end
+if ~isfield(ObjectData,'Coord')
+    if strcmp(ObjectData.Style,'plane')
+        ObjectData.Coord=[0 0 0];%default
+    else
+        ProjData=FieldData;
+        return
+    end
+end
+        
+%% OBSOLETE
+if isfield(ObjectData,'XMax') && ~isempty(ObjectData.XMax)
+    ObjectData.RangeX(1)=ObjectData.XMax;
+end
+if isfield(ObjectData,'XMin') && ~isempty(ObjectData.XMin)
+    ObjectData.RangeX(2)=ObjectData.XMin;
+end
+if isfield(ObjectData,'YMax') && ~isempty(ObjectData.YMax)
+    ObjectData.RangeY(1)=ObjectData.YMax;
+end
+if isfield(ObjectData,'YMin') && ~isempty(ObjectData.YMin)
+    ObjectData.RangeY(2)=ObjectData.YMin;
+end
+if isfield(ObjectData,'ZMax') && ~isempty(ObjectData.ZMax)
+    ObjectData.RangeZ(1)=ObjectData.ZMax;
+end
+if isfield(ObjectData,'ZMin') && ~isempty(ObjectData.ZMin)
+    ObjectData.RangeZ(2)=ObjectData.ZMin;
+end
+%%%%%%%%%%
+
+%% apply projection depending on the object style
+switch ObjectData.Style
+    case 'points'
+    [ProjData,errormsg]=proj_points(FieldData,ObjectData);
+    case {'line','polyline'}
+     [ProjData,errormsg] = proj_line(FieldData,ObjectData);
+    case {'polygon','rectangle','ellipse'}
+        if isequal(ObjectData.ProjMode,'inside')||isequal(ObjectData.ProjMode,'outside')
+            [ProjData,errormsg] = proj_patch(FieldData,ObjectData);
+        else
+            [ProjData,errormsg] = proj_line(FieldData,ObjectData);
+        end
+    case 'plane'
+            [ProjData,errormsg] = proj_plane(FieldData,ObjectData);
+    case 'volume'
+        [ProjData,errormsg] = proj_volume(FieldData,ObjectData);
+end
+
+%-----------------------------------------------------------------
+%project on a set of points
+function  [ProjData,errormsg]=proj_points(FieldData,ObjectData)%%
+%-------------------------------------------------------------------
+
+siz=size(ObjectData.Coord);
+width=0;
+if isfield(ObjectData,'Range')
+    width=ObjectData.Range(1,2);
+end
+if isfield(ObjectData,'RangeX')&&~isempty(ObjectData.RangeX)
+    width=max(ObjectData.RangeX);
+end
+if isfield(ObjectData,'RangeY')&&~isempty(ObjectData.RangeY)
+    width=max(width,max(ObjectData.RangeY));
+end
+if isfield(ObjectData,'RangeZ')&&~isempty(ObjectData.RangeZ)
+    width=max(width,max(ObjectData.RangeZ));
+end
+if isequal(ObjectData.ProjMode,'projection') 
+    if width==0
+        errormsg='projection range around points needed';
+        return
+    end
+elseif  ~isequal(ObjectData.ProjMode,'interp')
+    errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field']);
+        return
+end
+[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
+ProjData.NbDim=0;
+%ProjData.ListDimName= {'nb_points'};
+%ProjData.DimValue=siz(1);  %nbre of projection points  
+
+
+% idimvar=0;
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+    errormsg=['error in proj_field/proj_points:' errormsg];
+    return
+end
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% CellVarIndex=cells of variable index arrays
+% ivar_new=0; % index of the current variable in the projected field
+% icoord=0;
+for icell=1:length(CellVarIndex)
+    if NbDim(icell)==1
+        continue
+    end
+    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
+    VarType=VarTypeCell{icell};
+    ivar_X=VarType.coord_x;
+    ivar_Y=VarType.coord_y;
+    ivar_Z=VarType.coord_z;
+%     ivar_U=VarType.vector_x;
+%     ivar_V=VarType.vector_y;
+%     ivar_W=VarType.vector_z;
+%     ivar_C=VarType.scalar ;
+    ivar_Anc=VarType.ancillary;
+%     test_anc=zeros(size(VarIndex));
+    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
+    ProjData.ListVarName={'Y','X','NbVal'};
+    ProjData.VarDimName={'nb_points','nb_points','nb_points'};
+    %ProjData.VarDimIndex={[1],[1],[1]}; 
+    ProjData.VarAttribute{1}.Role='ancillary';
+    ProjData.VarAttribute{2}.Role='ancillary';
+    ProjData.VarAttribute{3}.Role='ancillary';
+    for ivar=VarIndex        
+        VarName=FieldData.ListVarName{ivar};
+        ProjData.ListVarName=[ProjData.ListVarName {VarName}];
+        %ProjData.VarDimIndex=[ProjData.VarDimIndex {[1]}];
+        ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}];
+    end
+    if ~test_grid
+        eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';'])
+        eval(['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} ';'])
+            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,:);
+           distX=coord_x-Xpoint(1);
+           distY=coord_y-Xpoint(2);          
+           dist=distX.*distX+distY.*distY;
+           indsel=find(dist<width*width);
+           ProjData.X(ipoint,1)=Xpoint(1);
+           ProjData.Y(ipoint,1)=Xpoint(2);
+           if isequal(length(ivar_FF),1)
+               FFName=FieldData.ListVarName{ivar_FF};
+               eval(['FF=FieldData.' FFName '(indsel);'])
+               ind_indsel=find(~FF);
+               indsel=indsel(ind_indsel);
+           end
+           ProjData.NbVal(ipoint,1)=length(indsel);
+            for ivar=VarIndex 
+               VarName=FieldData.ListVarName{ivar};
+               if isempty(indsel)
+                    eval(['ProjData.' VarName '(ipoint,1)=NaN;'])
+               else
+                    eval(['Var=FieldData.' VarName '(indsel);'])
+                    eval(['ProjData.' VarName '(ipoint,1)=mean(Var);'])
+                    if isequal(ObjectData.ProjMode,'interp')
+                         eval(['ProjData.' VarName '(ipoint,1)=griddata_uvmat(coord_x(indsel),coord_y(indsel),Var,Xpoint(1),Xpoint(2)))';])
+                    end
+               end
+            end
+        end
+    else 
+        %DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
+        %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)};
+            eval(['AX=FieldData.' AXName ';']);% set of x positions
+            eval(['AY=FieldData.' AYName ';']);% set of y positions  
+            AName=FieldData.ListVarName{VarIndex(1)};
+            eval(['A=FieldData.' AName ';']);% scalar
+            npxy=size(A);
+
+% %             nbcolor=1; %default
+%             for idim=1:length(ListDimName)
+%                 DimName=ListDimName{idim};
+%                 if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
+%                    nbcolor=npxy(idim);
+%                    DimIndices(idim)=[];
+%                    npxy(idim)=[];
+%                 end
+%                 if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
+%                     DimIndices(idim)=[];
+%                     npxy(idim)=[];
+%                 end
+%             end  
+            ind_1=find(npxy==1);
+            %DimIndices(ind_1)=[]; %suppress singleton dimensions 
+%             indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
+            %NbDim=length(DimIndices)%number of space dimensions
+            NbDim=numel(VarType.coord);
+            Coord_z=[];
+            Coord_y=[];
+            Coord_x=[];   
+            for idim=1:NbDim %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=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
+                ivar=VarType.coord(idim);
+%                 if ~isequal(ivar,0)%  a variable corresponds to the current dimension
+                    eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
+                    if numel(Coord{idim})==2
+                       DCoord_min(idim)= (Coord{idim}(2)-Coord{idim}(1))/(npxy(idim)-1);
+                    else
+                        DCoord=diff(Coord{idim});
+                        DCoord_min(idim)=min(DCoord);
+                        DCoord_max=max(DCoord);
+                        test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
+                        test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
+                        if ~isequal(test_direct(idim),test_direct_min)
+                            errormsg=['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'];
+                                    return
+                        end               
+                        test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
+                        test_coord(idim)=1;
+                    end
+%                 else  % no variable associated with the first dimension, look fo variable  attributes Coord_1, _2 or _3
+%                     Coord_i_str=['Coord_' num2str(idim)];
+%                     DCoord_min(idim)=1;%default
+%                     Coord{idim}=[0.5 npxy(idim)];
+%                     test_direct(idim)=1;
+%                 end
+            end
+            DX=DCoord_min(2);
+            DY=DCoord_min(1);
+            for ipoint=1:siz(1)
+                xwidth=width/(abs(DX));
+                ywidth=width/(abs(DY));
+                i_min=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5-xwidth); %minimum index of the selected region
+                i_min=max(1,i_min);%restrict to field limit
+                i_plus=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5+xwidth);
+                i_plus=min(npxy(2),i_plus); %restrict to field limit
+                j_min=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY-ywidth+0.5);
+                j_min=max(1,j_min);
+                j_plus=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY+ywidth+0.5);
+                j_plus=min(npxy(1),j_plus);
+                ProjData.X(ipoint,1)=ObjectData.Coord(ipoint,1);
+                ProjData.Y(ipoint,1)=ObjectData.Coord(ipoint,2);
+                i_int=(i_min:i_plus);
+                j_int=(j_min:j_plus);
+                ProjData.NbVal(ipoint,1)=length(j_int)*length(i_int);
+                if isempty(i_int) || isempty(j_int)
+                   for ivar=VarIndex   
+                        eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=NaN;']);
+                   end
+                   errormsg=['no data points in the selected projection range ' num2str(width) ];
+                else
+                    %TODO: introduce circle in the selected subregion
+                    %[I,J]=meshgrid([1:j_int],[1:i_int]);
+                    for ivar=VarIndex   
+                        eval(['Avalue=FieldData.' FieldData.ListVarName{ivar} '(j_int,i_int,:);']);
+                        eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=mean(mean(Avalue));']);
+                    end
+                end
+            end
+        end
+   end
+end
+
+%-----------------------------------------------------------------
+%project in a patch
+function  [ProjData,errormsg]=proj_patch(FieldData,ObjectData)%%
+%-------------------------------------------------------------------
+[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
+
+objectfield=fieldnames(ObjectData);
+widthx=0;
+widthy=0;
+if isfield(ObjectData,'RangeX')&~isempty(ObjectData.RangeX)
+    widthx=max(ObjectData.RangeX);
+end
+if isfield(ObjectData,'RangeY')&~isempty(ObjectData.RangeY)
+    widthy=max(ObjectData.RangeY);
+end
+
+%A REVOIR, GENERALISER: UTILISER proj_line
+ProjData.NbDim=1;
+ProjData.ListVarName={};
+ProjData.VarDimName={};
+ProjData.VarAttribute={};
+
+Mesh=zeros(1,numel(FieldData.ListVarName));
+if isfield (FieldData,'VarAttribute')
+    %ProjData.VarAttribute=FieldData.VarAttribute;%list of variable attribute names
+    for iattr=1:length(FieldData.VarAttribute)%initialization of variable attribute values
+%         ProjData.VarAttribute{iattr}={};
+        if isfield(FieldData.VarAttribute{iattr},'Unit')
+            unit{iattr}=FieldData.VarAttribute{iattr}.Unit;
+        end
+        if isfield(FieldData.VarAttribute{iattr},'Mesh')
+            Mesh(iattr)=FieldData.VarAttribute{iattr}.Mesh;
+        end
+    end
+end
+
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+testfalse=0;
+ListIndex={};
+% DimVarIndex=0;%initilise list of indices for dimension variables
+idimvar=0;
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+    errormsg=['error in proj_field/proj_patch:' errormsg];
+    return
+end
+
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+dimcounter=0;
+for icell=1:length(CellVarIndex)
+    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};
+  %  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);
+    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 testX %case of unstructured coordinates
+         eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');'])
+         for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag]
+               VarName=FieldData.ListVarName{ivar};
+            eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);'])
+         end
+         XName=FieldData.ListVarName{VarType.coord_x};
+         YName=FieldData.ListVarName{VarType.coord_y};
+         eval(['coord_x=FieldData.' XName ';'])
+         eval(['coord_y=FieldData.' YName ';'])
+    end
+    if testfalse
+        FFName=FieldData.ListVarName{VarType.errorflag};
+        eval(['errorflag=FieldData.' FFName ';'])
+    end
+    % image or 2D matrix
+    if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
+        test_Amat=1;% test for image or 2D matrix
+        AYName=FieldData.ListVarName{VarType.coord(1)};
+        AXName=FieldData.ListVarName{VarType.coord(2)};
+        eval(['AX=FieldData.' AXName ';'])% x coordinate
+        eval(['AY=FieldData.' AYName ';'])% y coordinate
+        VarName=FieldData.ListVarName{VarIndex(1)};
+        eval(['DimValue=size(FieldData.' VarName ');'])
+       if length(AX)==2
+           AX=linspace(AX(1),AX(end),DimValue(2));
+       end
+       if length(AY)==2
+           AY=linspace(AY(1),AY(end),DimValue(1));
+       end
+%         for idim=1:length(DimValue)        
+%             Coord_i_str=['Coord_' num2str(idim)];
+%             DCoord_min(idim)=1;%default
+%             Coord{idim}=[0.5 DimValue(idim)];
+%             test_direct(idim)=1;
+%         end
+%         AX=linspace(Coord{2}(1),Coord{2}(2),DimValue(2));
+%         AY=linspace(Coord{1}(1),Coord{1}(2),DimValue(1));  %TODO : 3D case 
+        testcolor=find(numel(DimValue)==3);
+        if length(DimValue)==3
+            testcolor=1;
+            npxy(3)=3;
+        else
+            testcolor=0;
+            npxy(3)=1;
+        end
+        [Xi,Yi]=meshgrid(AX,AY);
+        npxy(1)=length(AY);
+        npxy(2)=length(AX);
+        Xi=reshape(Xi,npxy(1)*npxy(2),1);
+        Yi=reshape(Yi,npxy(1)*npxy(2),1);
+        for ivar=1:length(VarIndex)
+            VarName=FieldData.ListVarName{VarIndex(ivar)};
+            eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',npxy(1)*npxy(2),npxy(3));']); % keep only non false vectors 
+        end
+    end
+%select the indices in the range of action
+    testin=[];%default
+    if isequal(ObjectData.Style,'rectangle')
+%            if ~isfield(ObjectData,'RangeX')|~isfield(ObjectData,'RangeY')
+%                 errormsg='rectangle half sides RangeX and RangeY needed'
+%                 return
+%            end
+       if testX
+            distX=abs(coord_x-ObjectData.Coord(1,1));
+            distY=abs(coord_y-ObjectData.Coord(1,2));
+            testin=distX<widthx & distY<widthy;
+       elseif test_Amat
+           distX=abs(Xi-ObjectData.Coord(1,1));
+           distY=abs(Yi-ObjectData.Coord(1,2));
+           testin=distX<widthx & distY<widthy;
+       end
+    elseif isequal(ObjectData.Style,'polygon')
+        if testX
+            testin=inpolygon(coord_x,coord_y,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
+        elseif test_Amat
+           testin=inpolygon(Xi,Yi,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
+       else%calculate the scalar
+           testin=[]; %A REVOIR
+       end
+    elseif isequal(ObjectData.Style,'ellipse')
+       X2Max=widthx*widthx;
+       Y2Max=(widthy)*(widthy);
+       if testX
+            distX=(coord_x-ObjectData.Coord(1,1));
+            distY=(coord_y-ObjectData.Coord(1,2));
+            testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
+       elseif test_Amat %case of usual 2x2 matrix
+           distX=(Xi-ObjectData.Coord(1,1));
+           distY=(Yi-ObjectData.Coord(1,2));
+           testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
+       end
+    end
+    %selected indices
+    if isequal(ObjectData.ProjMode,'outside')
+            testin=~testin;
+    end
+    if testfalse
+        testin=testin & (errorflag==0); % keep only non false vectors         
+    end
+    indsel=find(testin);
+    for ivar=VarIndex
+        if testproj(ivar)
+            VarName=FieldData.ListVarName{ivar};
+            eval(['ProjData.' VarName 'Mean=mean(mean(double(FieldData.' VarName '(indsel,:))));']); % keep only non false vectors
+            eval(['ProjData.' VarName 'Min=min(min(double(FieldData.' VarName '(indsel,:))));']); % keep only non false vectors
+            eval(['ProjData.' VarName 'Max=max(max(double(FieldData.' VarName '(indsel,:))));']); % keep only non false vectors
+            if isequal(Mesh(ivar),0)
+                eval(['[ProjData.' VarName 'Histo,ProjData.' VarName ']=hist(double(FieldData.' VarName '(indsel,:)),100);']); % default histogram with 100 bins
+            else
+                eval(['ProjData.' VarName '=(ProjData.' VarName 'Min+Mesh(ivar)/2:Mesh(ivar):ProjData.' VarName 'Max);']); % list of bin values
+                eval(['ProjData.' VarName 'Histo=hist(double(FieldData.' VarName '(indsel,:)),ProjData.' VarName ');']); % histogram at predefined bin positions
+            end
+            ProjData.ListVarName=[ProjData.ListVarName {VarName} {[VarName 'Histo']} {[VarName 'Mean']} {[VarName 'Min']} {[VarName 'Max']}];
+            if test_Amat && testcolor
+                 ProjData.VarDimName=[ProjData.VarDimName  {VarName} {{VarName,'rgb'}} {'rgb'}];%{{'nb_point','rgb'}};
+            else
+               ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'nbpoint'} {'nbpoint'} {'nbpoint'}];
+            end
+            ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute{ivar} {[]} {[]} {[]} {[]}];
+        end
+    end 
+%     if test_Amat & testcolor
+%        %ProjData.ListDimName=[ProjData.ListDimName {'rgb'}];
+%       % ProjData.DimValue=[ProjData.DimValue 3];
+%       % ProjData.VarDimIndex={[1 2]};
+%        ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName,'rgb'}];%{{'nb_point','rgb'}};
+%        ProjData.VarDimName
+%     end
+end
+
+
+%-----------------------------------------------------------------
+%project on a line
+% AJOUTER flux,circul,error
+function  [ProjData,errormsg] = proj_line(FieldData, ObjectData)
+%-----------------------------------------------------------------
+[ProjData,errormsg]=proj_heading(FieldData,ObjectData);%transfer global attributes
+if ~isempty(errormsg)
+    return
+end
+ProjData.NbDim=1;
+%initialisation of the input parameters and defaultoutput
+ProjMode='projection';%direct projection on the line by default
+if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end; 
+ProjAngle=90; %90 degrees projection by default
+if isfield(FieldData,'ProjAngle'),ProjAngle=ObjectData.ProjAngle; end; 
+width=0;%default width of the projection band
+if isfield(ObjectData,'Range')&size(ObjectData.Range,2)>=2
+    width=abs(ObjectData.Range(1,2));
+end
+if isfield(ObjectData,'RangeY')
+    width=max(ObjectData.RangeY);
+end
+
+% default output
+errormsg=[];%default
+Xline=[];
+flux=0;
+circul=0;
+liny=ObjectData.Coord(:,2);
+siz_line=size(ObjectData.Coord);
+if siz_line(1)<2
+    return% line needs at least 2 points to be defined
+end
+testfalse=0;
+ListIndex={};
+
+%angles of the polyline and boundaries of action
+dlinx=diff(ObjectData.Coord(:,1));
+dliny=diff(ObjectData.Coord(:,2));
+theta=angle(dlinx+i*dliny);%angle of each segment
+theta(siz_line(1))=theta(siz_line(1)-1);
+% determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
+if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
+    xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
+    xinf(1)=ObjectData.Coord(1,1)+width*sin(theta(1));
+    ysup(1)=ObjectData.Coord(1,2)+width*cos(theta(1));
+    yinf(1)=ObjectData.Coord(1,2)-width*cos(theta(1));
+    for ip=2:siz_line(1)
+        xsup(ip)=ObjectData.Coord(ip,1)-width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+        xinf(ip)=ObjectData.Coord(ip,1)+width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+        ysup(ip)=ObjectData.Coord(ip,2)+width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+        yinf(ip)=ObjectData.Coord(ip,2)-width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
+    end
+end
+
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+    errormsg=['error in proj_field/proj_line:' errormsg];
+    return
+end
+
+% loop on variable cells with the same space dimension
+ProjData.ListVarName={};
+ProjData.VarDimName={};
+for icell=1:length(CellVarIndex)
+    VarIndex=CellVarIndex{icell};%  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
+    testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates
+    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)=1;
+    testproj(VarType.image)=1;
+    testproj(VarType.color)=1;
+    VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
+    if testU
+         VarIndex=[VarIndex VarType.vector_x VarType.vector_y];%append u and v at the end of the list of variables
+    end
+    %identify vector components   
+    if testU
+        UName=FieldData.ListVarName{VarType.vector_x};
+        VName=FieldData.ListVarName{VarType.vector_y};
+        eval(['vector_x=FieldData.' UName ';'])
+        eval(['vector_y=FieldData.' VName ';'])
+    end  
+    %identify error flag
+    if testfalse
+        FFName=FieldData.ListVarName{VarType.errorflag};
+        eval(['errorflag=FieldData.' FFName ';'])
+    end   
+    % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
+    if testX
+        if  ~isequal(ProjMode,'interp')
+            if width==0
+                errormsg='range of the projection object is missing';
+                return      
+            else
+                lambda=2/(width*width); %smoothing factor used for filter: weight exp(-2) at distance width from the line
+            end
+        end
+        if ~isequal(ProjMode,'projection')
+            if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
+                DX=abs(ObjectData.DX);%mesh of interpolation points along the line
+            else
+                errormsg='DX missing';
+                return
+            end
+        end
+        XName= FieldData.ListVarName{VarType.coord_x};
+        YName= FieldData.ListVarName{VarType.coord_y};
+        eval(['coord_x=FieldData.' XName ';'])    
+        eval(['coord_y=FieldData.' YName ';'])
+    end   
+    %initiate projection
+    for ivar=1:length(VarIndex)
+        ProjLine{ivar}=[];
+    end
+    XLine=[];
+    linelengthtot=0;
+
+%         circul=0;
+%         flux=0;
+  %%%%%%%  % A FAIRE CALCULER MEAN DES QUANTITES    %%%%%%
+   %case of unstructured coordinates
+    if testX   
+        for ip=1:siz_line(1)-1     %Loop on the segments of the polyline
+            linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip));  
+            %select the vector indices in the range of action
+            if testfalse
+                flagsel=(errorflag==0); % keep only non false vectors
+            else
+                flagsel=ones(size(coord_x));
+            end
+            if isequal(ProjMode,'projection') | isequal(ProjMode,'filter')
+                flagsel=flagsel & ((coord_y -yinf(ip))*(xinf(ip+1)-xinf(ip))>(coord_x-xinf(ip))*(yinf(ip+1)-yinf(ip))) ...
+                & ((coord_y -ysup(ip))*(xsup(ip+1)-xsup(ip))<(coord_x-xsup(ip))*(ysup(ip+1)-ysup(ip))) ...
+                & ((coord_y -yinf(ip+1))*(xsup(ip+1)-xinf(ip+1))>(coord_x-xinf(ip+1))*(ysup(ip+1)-yinf(ip+1))) ...
+                & ((coord_y -yinf(ip))*(xsup(ip)-xinf(ip))<(coord_x-xinf(ip))*(ysup(ip)-yinf(ip)));
+            end
+            indsel=find(flagsel);%indsel =indices of good vectors 
+            X_sel=coord_x(indsel);
+            Y_sel=coord_y(indsel);
+            nbvar=0;
+            for iselect=1:numel(VarIndex)-2*testU
+                VarName=FieldData.ListVarName{VarIndex(iselect)};
+                eval(['ProjVar{iselect}=FieldData.' VarName '(indsel);']);%scalar value
+            end   
+            if testU
+                ProjVar{numel(VarIndex)-1}=cos(theta(ip))*vector_x(indsel)+sin(theta(ip))*vector_y(indsel);% longitudinal component
+                ProjVar{numel(VarIndex)}=-sin(theta(ip))*vector_x(indsel)+cos(theta(ip))*vector_y(indsel);%transverse component         
+            end
+            if isequal(ProjMode,'projection')
+                sintheta=sin(theta(ip));
+                costheta=cos(theta(ip));
+                Xproj=(X_sel-ObjectData.Coord(ip,1))*costheta + (Y_sel-ObjectData.Coord(ip,2))*sintheta; %projection on the line
+                [Xproj,indsort]=sort(Xproj);
+                for ivar=1:numel(ProjVar)
+                    if ~isempty(ProjVar{ivar})
+                        ProjVar{ivar}=ProjVar{ivar}(indsort);
+                     end
+                end
+            elseif isequal(ProjMode,'interp') %linear interpolation:
+                npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
+                Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
+                xreg=cos(theta(ip))*Xproj+ObjectData.Coord(ip,1);
+                yreg=sin(theta(ip))*Xproj+ObjectData.Coord(ip,2);
+                for ivar=1:numel(ProjVar)
+                     if ~isempty(ProjVar{ivar})
+                        ProjVar{ivar}=griddata_uvmat(X_sel,Y_sel,ProjVar{ivar},xreg,yreg);
+                     end
+                end
+            elseif isequal(ProjMode,'filter') %filtering
+                npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
+                Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
+                siz=size(X_sel);
+                xregij=cos(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,1);
+                yregij=sin(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,2);
+                xij=ones(npoint,1)*X_sel;
+                yij=ones(npoint,1)*Y_sel;
+                Aij=exp(-lambda*((xij-xregij).*(xij-xregij)+(yij-yregij).*(yij-yregij)));
+                norm=ones(1,siz(2))*Aij';
+                for ivar=1:numel(ProjVar)
+                     if ~isempty(ProjVar{ivar})
+                        ProjVar{ivar}=ProjVar{ivar}*Aij'./norm;
+                     end
+                end              
+            end
+            %prolongate the total record
+            for ivar=1:numel(ProjVar)
+                  if ~isempty(ProjVar{ivar})
+                     ProjLine{ivar}=[ProjLine{ivar}; ProjVar{ivar}];
+                  end
+            end
+            XLine=[XLine ;(Xproj+linelengthtot)];%along line abscissa
+            linelengthtot=linelengthtot+linelength;
+            %     circul=circul+(sum(U_sel))*linelength/npoint;
+            %     flux=flux+(sum(V_sel))*linelength/npoint;
+        end
+        ProjData.X=XLine';
+        cur_index=1;
+        ProjData.ListVarName=[ProjData.ListVarName {XName}];
+        ProjData.VarDimName=[ProjData.VarDimName {XName}];
+        ProjData.VarAttribute{1}.long_name='abscissa along line';
+        for iselect=1:numel(VarIndex)
+            VarName=FieldData.ListVarName{VarIndex(iselect)};
+            eval(['ProjData.' VarName '=ProjLine{iselect};'])
+            ProjData.ListVarName=[ProjData.ListVarName {VarName}];
+            ProjData.VarDimName=[ProjData.VarDimName {XName}];
+            ProjData.VarAttribute{iselect}=FieldData.VarAttribute{VarIndex(iselect)};
+            if strcmp(ProjMode,'projection')
+                ProjData.VarAttribute{iselect}.Role='discrete';
+            else
+                 ProjData.VarAttribute{iselect}.Role='continuous';
+            end
+        end
+    
+    %case of structured coordinates
+    elseif  numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
+        if ~isequal(ObjectData.Style,'line')% exclude polyline
+            errormsg=['no  projection available on ' ObjectData.Style 'for structured coordinates']; % 
+        else
+            test_Amat=1;%image or 2D matrix
+            test_interp2=0;%default
+%             if ~isempty(VarType.coord_y)  
+            AYName=FieldData.ListVarName{VarType.coord(1)};
+            AXName=FieldData.ListVarName{VarType.coord(2)};
+            eval(['AX=FieldData.' AXName ';']);% set of x positions
+            eval(['AY=FieldData.' AYName ';']);% set of y positions  
+            AName=FieldData.ListVarName{VarIndex(1)};
+            eval(['A=FieldData.' AName ';']);% scalar
+            npxy=size(A);
+            npx=npxy(2);
+            npy=npxy(1); 
+            if numel(AX)==2
+                DX=(AX(2)-AX(1))/(npx-1);
+            else
+                DX_vec=diff(AX);
+                DX=max(DX_vec);
+                DX_min=min(DX_vec);
+                if (DX-DX_min)>0.0001*abs(DX) 
+                    test_interp2=1;
+                    DX=DX_min;
+                end    
+            end
+            if numel(AY)==2
+                DY=(AY(2)-AY(1))/(npy-1);
+            else
+                DY_vec=diff(AY);
+                DY=max(DY_vec);
+                DY_min=min(DY_vec);
+                if (DY-DY_min)>0.0001*abs(DY)
+                   test_interp2=1;
+                    DY=DY_min;
+                end     
+            end              
+            AXI=linspace(AX(1),AX(end), npx);%set of  x  positions for the interpolated input data
+            AYI=linspace(AY(1),AY(end), npy);%set of  x  positions for the interpolated input data
+            if isfield(ObjectData,'DX')
+                DXY_line=ObjectData.DX;%mesh on the projection line
+            else
+                DXY_line=sqrt(abs(DX*DY));% mesh on the projection line
+            end
+            dlinx=ObjectData.Coord(2,1)-ObjectData.Coord(1,1);
+            dliny=ObjectData.Coord(2,2)-ObjectData.Coord(1,2);
+            linelength=sqrt(dlinx*dlinx+dliny*dliny);
+            theta=angle(dlinx+i*dliny);%angle of the line   
+            if isfield(FieldData,'RangeX')
+                XMin=min(FieldData.RangeX);%shift of the origin on the line
+            else
+                XMin=0;
+            end
+            eval(['ProjData.' AXName '=linspace(XMin,XMin+linelength,linelength/DXY_line+1);'])%abscissa of the new pixels along the line
+            y=linspace(-width,width,2*width/DXY_line+1);%ordintes of the new pixels (coordinate across the line)
+            eval(['npX=length(ProjData.' AXName ');'])
+            npY=length(y); %TODO: utiliser proj_grid
+            eval(['[X,Y]=meshgrid(ProjData.' AXName ',y);'])%grid in the line coordinates
+            XIMA=ObjectData.Coord(1,1)+(X-XMin)*cos(theta)-Y*sin(theta);
+            YIMA=ObjectData.Coord(1,2)+(X-XMin)*sin(theta)+Y*cos(theta);
+            XIMA=(XIMA-AX(1))/DX+1;%  index of the original image along x
+            YIMA=(YIMA-AY(1))/DY+1;% index of the original image along y
+            XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
+            YIMA=reshape(round(YIMA),1,npX*npY);
+            flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
+            ind_in=find(flagin);
+            ind_out=find(~flagin);
+            ICOMB=(XIMA-1)*npy+YIMA;
+            ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+            nbcolor=1; %color images
+            if numel(npxy)==2
+                nbcolor=1;
+            elseif length(npxy)==3
+                nbcolor=npxy(3);
+            else
+                errormsg='multicomponent field not projected';
+                display(errormsg)
+                return
+            end 
+            nbvar=length(ProjData.ListVarName);% number of var from previous cells
+            ProjData.ListVarName=[ProjData.ListVarName {AXName}];
+            ProjData.VarDimName=[ProjData.VarDimName {AXName}];
+            for ivar=VarIndex
+                VarName{ivar}=FieldData.ListVarName{ivar};
+                if test_interp2% interpolate on new grid
+                    eval(['FieldData.' VarName{ivar} '=interp2(FieldData.' AXName ',FieldData.' AYName ',FieldData.' VarName{ivar} ',AXI,AYI'');']) %TO TEST
+                end
+                eval(['vec_A=reshape(squeeze(FieldData.' VarName{ivar} '),npx*npy,nbcolor);']) %put the original image in colum
+                if nbcolor==1
+                    vec_B(ind_in)=vec_A(ICOMB);
+                    vec_B(ind_out)=zeros(size(ind_out));
+                    A_out=reshape(vec_B,npY,npX);
+                    eval(['ProjData.' VarName{ivar} '=((sum(A_out,1)/npY))'';']);
+                elseif nbcolor==3
+                    vec_B(ind_in,[1:3])=vec_A(ICOMB,:);
+                    vec_B(ind_out,1)=zeros(size(ind_out));
+                    vec_B(ind_out,2)=zeros(size(ind_out));
+                    vec_B(ind_out,3)=zeros(size(ind_out));
+                    A_out=reshape(vec_B,npY,npX,nbcolor);
+                    eval(['ProjData.' VarName{ivar} '=squeeze(sum(A_out,1)/npY);']);
+                end  
+                ProjData.ListVarName=[ProjData.ListVarName VarName{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
+            end
+            if testU
+                 eval(['vector_x =ProjData.' VarName{VarType.vector_x} ';'])
+                 eval(['vector_y =ProjData.' VarName{VarType.vector_y} ';'])
+                 eval(['ProjData.' VarName{VarType.vector_x} '=cos(theta)*vector_x+sin(theta)*vector_y;'])
+                 eval(['ProjData.' VarName{VarType.vector_y} '=-sin(theta)*vector_x+cos(theta)*vector_y;'])
+            end
+            ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line';
+            if nbcolor==3
+                ProjData.VarDimName{end}={AXName,'rgb'};
+            end
+        end      
+    end
+end
+
+% %shotarter case for horizontal or vertical line (A FAIRE 
+% %     Rangx=[0.5 npx-0.5];%image coordiantes of corners
+% %     Rangy=[npy-0.5 0.5];
+% %     if isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
+% %         Rangx=Rangx/Calib.Pxcmx;
+% %         Rangy=Rangy/Calib.Pxcmy;
+% %     else
+% %         [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[0 0]);%case of translations without rotation and quadratic deformation
+% %         [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[0 0]);
+% %     end 
+% 
+% %     test_scal=0;%default% 3- 'UserData':(get(handles.Tag,'UserData')
+
+
+%-----------------------------------------------------------------
+%project on a plane 
+% AJOUTER flux,circul,error
+ function  [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
+%-----------------------------------------------------------------
+
+%% initialisation of the input parameters of the projection plane
+ProjMode='projection';%direct projection by default
+if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
+
+%axis origin
+if isempty(ObjectData.Coord)
+    ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
+    ObjectData.Coord(1,2)=0;
+    ObjectData.Coord(1,3)=0;
+end
+
+%rotation angles 
+Phi=0;%default
+Theta=0;
+Psi=0;
+if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
+    Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
+end
+if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
+    Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
+end
+if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
+    Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
+end
+
+%components of the unity vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+
+%mesh sizes DX and DY
+DX=0;
+DY=0; %default 
+if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
+     DX=abs(ObjectData.DX);%mesh of interpolation points 
+end
+if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
+     DY=abs(ObjectData.DY);%mesh of interpolation points 
+end
+if  ~strcmp(ProjMode,'projection') && (DX==0||DY==0)
+        errormsg='DX or DY missing';
+        display(errormsg)
+        return
+end
+
+%extrema along each axis
+testXMin=0;
+testXMax=0;
+testYMin=0;
+testYMax=0;
+if isfield(ObjectData,'RangeX')
+        XMin=min(ObjectData.RangeX);
+        XMax=max(ObjectData.RangeX);
+        testXMin=XMax>XMin;
+        testXMax=1;
+end
+if isfield(ObjectData,'RangeY')
+        YMin=min(ObjectData.RangeY);
+        YMax=max(ObjectData.RangeY);
+        testYMin=YMax>YMin;
+        testYMax=1;
+end
+width=0;%default width of the projection band
+if isfield(ObjectData,'RangeZ')
+        width=max(ObjectData.RangeZ);
+end
+
+% initiate Matlab  structure for physical field
+[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
+ProjData.NbDim=2;
+ProjData.ListVarName={};
+ProjData.VarDimName={};
+if ~isequal(DX,0)&& ~isequal(DY,0)
+    ProjData.Mesh=sqrt(DX*DY);%define typical data mesh, useful for mouse selection in plots
+elseif isfield(FieldData,'Mesh')
+    ProjData.Mesh=FieldData.Mesh;
+end
+
+error=0;%default
+flux=0;
+testfalse=0;
+ListIndex={};
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+%-----------------------------------------------------------------
+idimvar=0;
+[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+    errormsg=['error in proj_field/proj_plane:' errormsg];
+    return
+end
+
+% LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% CellVarIndex=cells of variable index arrays
+ivar_new=0; % index of the current variable in the projected field
+icoord=0;
+nbcoord=0;%number of added coordinate variables brought by projection
+nbvar=0;
+for icell=1:length(CellVarIndex)
+    NbDim=NbDimVec(icell);
+    if NbDim<2
+        continue
+    end
+    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
+    VarType=VarTypeCell{icell};
+    ivar_X=VarType.coord_x;
+    ivar_Y=VarType.coord_y;
+    ivar_Z=VarType.coord_z;
+    ivar_U=VarType.vector_x;
+    ivar_V=VarType.vector_y;
+    ivar_W=VarType.vector_z;
+    ivar_C=VarType.scalar ;
+    ivar_Anc=VarType.ancillary;
+    test_anc=zeros(size(VarIndex));
+    test_anc(ivar_Anc)=ones(size(ivar_Anc));
+    ivar_F=VarType.warnflag;
+    ivar_FF=VarType.errorflag;
+    testX=~isempty(ivar_X) && ~isempty(ivar_Y);
+    DimCell=FieldData.VarDimName{VarIndex(1)};
+    if ischar(DimCell)
+        DimCell={DimCell};%name of dimensions
+    end
+
+%% case of input fields with unstructured coordinates
+    if testX
+        XName=FieldData.ListVarName{ivar_X};
+        YName=FieldData.ListVarName{ivar_Y};
+        eval(['coord_x=FieldData.' XName ';'])
+        eval(['coord_y=FieldData.' YName ';'])
+        if length(ivar_Z)==1
+            ZName=FieldData.ListVarName{ivar_Z};
+            eval(['coord_z=FieldData.' ZName ';'])
+        end
+
+        % translate  initial coordinates
+        coord_x=coord_x-ObjectData.Coord(1,1);
+        coord_y=coord_y-ObjectData.Coord(1,2);
+        if ~isempty(ivar_Z)
+            coord_z=coord_z-ObjectData.Coord(1,3);
+        end
+        
+        % selection of the vectors in the projection range (3D case)
+        if length(ivar_Z)==1 &&  width > 0
+            %components of the unitiy vector normal to the projection plane
+            fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane            
+            indcut=find(abs(fieldZ) <= width);
+            for ivar=VarIndex
+                VarName=FieldData.ListVarName{ivar};
+                eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])  
+                    % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE              
+            end
+            coord_x=coord_x(indcut);
+            coord_y=coord_y(indcut);
+            coord_z=coord_z(indcut);
+        end
+
+       %rotate coordinates if needed
+        if isequal(Phi,0)
+            coord_X=coord_x;
+            coord_Y=coord_y;
+            if ~isequal(Theta,0)
+                coord_Y=coord_Y *cos(Theta);
+            end
+        else
+            coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
+            coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
+        end
+        if ~isempty(ivar_Z)
+            coord_Y=coord_Y+coord_z *sin(Theta);
+        end
+        if ~isequal(Psi,0)
+                coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
+                coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
+        end
+        
+        %restriction to the range of x and y if imposed
+        testin=ones(size(coord_X)); %default
+        testbound=0;
+        if testXMin
+            testin=testin & (coord_X >= XMin);
+            testbound=1;
+        end
+        if testXMax
+            testin=testin & (coord_X <= XMax);
+            testbound=1;
+        end
+        if testYMin
+            testin=testin & (coord_Y >= YMin);
+            testbound=1;
+        end
+        if testYMin
+            testin=testin & (coord_Y <= YMax);
+            testbound=1;
+        end
+        if testbound
+            indcut=find(testin);
+            for ivar=VarIndex
+                VarName=FieldData.ListVarName{ivar};
+                eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])            
+            end
+            coord_X=coord_X(indcut);
+            coord_Y=coord_Y(indcut);
+            if length(ivar_Z)==1
+                coord_Z=coord_Z(indcut);
+            end
+        end
+        % different cases of projection
+        if isequal(ObjectData.ProjMode,'projection')
+            %the list of dimension
+            %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
+            %ProjData.DimValue=[ProjData.
+             %length(coord_X)];
+
+            for ivar=VarIndex %transfer variables to the projection plane
+                VarName=FieldData.ListVarName{ivar};
+                if ivar==ivar_X %x coordinate
+                    eval(['ProjData.' VarName '=coord_X;'])
+                elseif ivar==ivar_Y % y coordinate
+                    eval(['ProjData.' VarName '=coord_Y;'])
+                elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
+                    eval(['ProjData.' VarName '=FieldData.' VarName ';'])
+                end
+                if isempty(ivar_Z) || ivar~=ivar_Z 
+                    ProjData.ListVarName=[ProjData.ListVarName VarName];
+                    ProjData.VarDimName=[ProjData.VarDimName DimCell];
+                    nbvar=nbvar+1;
+                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
+                        ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
+                    end
+                end
+            end  
+        elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
+            coord_x_proj=[XMin:DX:XMax];
+            coord_y_proj=[YMin:DY:YMax];
+            DimCell={'coord_y','coord_x'};
+            ProjData.ListVarName={'coord_y','coord_x'};
+            ProjData.VarDimName={'coord_y','coord_x'};   
+            nbcoord=2;  
+            ProjData.coord_y=[YMin YMax];
+            ProjData.coord_x=[XMin XMax];
+            if isempty(ivar_X), ivar_X=0; end;
+            if isempty(ivar_Y), ivar_Y=0; end;
+            if isempty(ivar_Z), ivar_Z=0; end;
+            if isempty(ivar_U), ivar_U=0; end;
+            if isempty(ivar_V), ivar_V=0; end;
+            if isempty(ivar_W), ivar_W=0; end;
+            if isempty(ivar_F), ivar_F=0; end;
+            if isempty(ivar_FF), ivar_FF=0; end;
+            if ~isequal(ivar_FF,0)
+                VarName_FF=FieldData.ListVarName{ivar_FF};
+                eval(['indsel=find(FieldData.' VarName_FF '==0);'])
+                coord_X=coord_X(indsel);
+                coord_Y=coord_Y(indsel);
+            end
+            FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
+            testFF=0;
+            for ivar=VarIndex
+                VarName=FieldData.ListVarName{ivar};
+                if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)                 
+                    ivar_new=ivar_new+1;
+                    ProjData.ListVarName=[ProjData.ListVarName {VarName}];
+                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
+                        ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
+                    end
+                    if  ~isequal(ivar_FF,0)
+                        eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
+                    end
+                    eval(['ProjData.' VarName '=griddata_uvmat(double(coord_X),double(coord_Y),double(FieldData.' VarName '),coord_x_proj,coord_y_proj'');'])
+                    eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
+                    FFlag= isnan(varline); %detect undefined values NaN
+                    indnan=find(FFlag);
+                    if~isempty(indnan)
+                        varline(indnan)=zeros(size(indnan));
+                        eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
+                        FF(indnan)=ones(size(indnan));
+                        testFF=1;
+                    end
+                    if ivar==ivar_U
+                        ivar_U=ivar_new;
+                    end
+                    if ivar==ivar_V
+                        ivar_V=ivar_new;
+                    end
+                    if ivar==ivar_W
+                        ivar_W=ivar_new;
+                    end
+                end
+            end
+            if testFF
+                ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
+                ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
+               ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
+            end
+        end
+        
+%% case of input fields defined on a structured  grid 
+    else
+        VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
+        eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
+        DimValue(find(DimValue==1))=[];%remove singleton dimensions       
+        NbDim=numel(DimValue);%update number of space dimensions
+        nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
+        if NbDim>=3
+            if NbDim>3
+                errormsg='matrices with more than 3 dimensions not handled';
+                return
+            else
+                VarType.coord
+                if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate
+                    nbcolor=DimValue(3);
+                    DimValue(3)=[]; %number of 'color' components updated
+                    NbDim=2;% space dimension set to 2
+                end
+            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)    
+        eval(['AX=FieldData.' AXName ';'])
+        eval(['AY=FieldData.' AYName ';'])
+        ListDimName=FieldData.VarDimName{VarIndex(1)};
+        ProjData.ListVarName=[ProjData.ListVarName {AYName} {AXName}]; %TODO: check if it already exists in Projdata (several cells)
+        ProjData.VarDimName=[ProjData.VarDimName {AYName} {AXName}];
+
+%         for idim=1:length(ListDimName)
+%             DimName=ListDimName{idim};
+%             if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i')
+%                nbcolor=DimValue(idim);
+%                DimValue(idim)=[];
+%             end
+%             if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
+%                 DimValue(idim)=[];
+%             end
+%         end  
+        Coord_z=[];
+        Coord_y=[];
+        Coord_x=[];   
+
+        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
+            if ~isequal(ivar,0)%  a variable corresponds to the dimension #idim
+                eval(['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);
+                else
+                    DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
+                    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'])
+                                return
+                    end               
+                    test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
+                end
+                test_direct(idim)=(DCoord_min(idim)>0);
+            else  % no variable associated with the  dimension #idim, the coordinate value is set equal to the matrix index by default
+                Coord_i_str=['Coord_' num2str(idim)];
+                DCoord_min(idim)=1;%default
+                Coord{idim}=[0.5 DimValue(idim)-0.5];
+                test_direct(idim)=1;
+            end
+        end
+        if DY==0
+            DY=abs(DCoord_min(NbDim-1));
+        end
+        npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol 
+        if DX==0
+            DX=abs(DCoord_min(NbDim));
+        end
+        npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol 
+        for idim=[1:NbDim]
+            if test_interp(idim)
+                DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri
+            end
+        end       
+        Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
+        test_direct_y=test_direct(NbDim-1);
+        Coord_x=linspace(Coord{NbDim}(1),Coord{NbDim}(end),npX);
+        test_direct_x=test_direct(NbDim);
+        DAX=DCoord_min(NbDim);
+        DAY=DCoord_min(NbDim-1);  
+        minAX=min(Coord_x);
+        maxAX=max(Coord_x);
+        minAY=min(Coord_y);
+        maxAY=max(Coord_y);
+        xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
+        ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
+        xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
+        ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
+        if ~testXMax
+            XMax=max(xcor_new);
+        end
+        if ~testXMin
+            XMin=min(xcor_new);
+        end
+        if ~testYMax
+            YMax=max(ycor_new);
+        end
+        if ~testYMin
+            YMin=min(ycor_new);
+        end
+        DXinit=(maxAX-minAX)/(DimValue(NbDim)-1);
+        DYinit=(maxAY-minAY)/(DimValue(NbDim-1)-1);
+        if DX==0
+            DX=DXinit;
+        end
+        if DY==0
+            DY=DYinit;
+        end
+        if NbDim==3
+            DZ=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
+            if ~test_direct(1)
+                DZ=-DZ;
+            end
+            Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
+            test_direct_z=test_direct(1);
+        end
+        npX=floor((XMax-XMin)/DX+1);
+        npY=floor((YMax-YMin)/DY+1);   
+        if test_direct_y
+            coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
+        else
+            coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
+        end
+        if test_direct_x
+            coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
+        else
+            coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
+        end 
+        
+        % case with no rotation and interpolation
+        if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
+            if ~testXMin && ~testXMax && ~testYMin && ~testYMax && NbDim==2
+                ProjData=FieldData; 
+            else
+                indY=NbDim-1;
+                if test_direct(indY)
+                    min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1;
+                    max_indy=floor((YMax-Coord{indY}(1))/DYinit)+1;
+                    Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1);
+                    Ybound(2)=Coord{indY}(1)+DYinit*(max_indy-1);
+                else
+                    min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;
+                    max_indy=floor((Coord{indY}(1)-YMin)/DYinit)+1;
+                    Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1);
+                    Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1);
+                end   
+                if test_direct(NbDim)==1
+                    min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;
+                    max_indx=floor((XMax-Coord{NbDim}(1))/DXinit)+1;
+                    Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
+                    Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
+                else
+                    min_indx=ceil((Coord{NbDim}(1)-XMax)/DXinit)+1;
+                    max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1;
+                    Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
+                    Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
+                end 
+                if NbDim==3
+                    DimCell(1)=[]; %suppress z variable
+                    DimValue(1)=[];
+                                        %structured coordinates
+                    if test_direct(1)
+                        iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
+                    else
+                        iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
+                    end
+                end
+                min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
+                min_indx=max(min_indx,1);
+                max_indy=min(max_indy,DimValue(1));
+                max_indx=min(max_indx,DimValue(2));
+                for ivar=VarIndex% loop on non coordinate variables
+                    VarName=FieldData.ListVarName{ivar}; 
+                    ProjData.ListVarName=[ProjData.ListVarName VarName];
+                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
+                        ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
+                    end
+                    if NbDim==3
+                        eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']);
+                    else
+                        eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']);
+                    end
+                end  
+                eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
+                eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
+            end
+        else       % case with rotation and/or interpolation
+            if NbDim==2 %2D case
+                [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
+                XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
+                YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
+                XIMA=(XIMA-minAX)/DXinit+1;% image index along x
+                YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
+                XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
+                YIMA=reshape(round(YIMA),1,npX*npY);
+                flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image 
+                if isequal(ObjectData.ProjMode,'filter')
+                    npx_filter=ceil(abs(DX/DAX));
+                    npy_filter=ceil(abs(DY/DAY));
+                    Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
+                    test_filter=1;
+                else
+                    test_filter=0;
+                end
+                eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
+                eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
+                for ivar=VarIndex
+                    VarName=FieldData.ListVarName{ivar};
+                    if test_interp(1) || test_interp(2)%interpolate on a regular grid        
+                          eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
+                    end
+                    %filter the field (image) if option 'filter' is used
+                    if test_filter  
+                         Aclass=class(FieldData.A);
+                         eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
+                         if ~isequal(Aclass,'double')
+                             eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
+                         end
+                    end
+                    eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line              
+                    ind_in=find(flagin);
+                    ind_out=find(~flagin);
+                    ICOMB=(XIMA-1)*DimValue(1)+YIMA;
+                    ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+                    vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:); 
+                    for icolor=1:nbcolor
+                        vec_B(ind_out,icolor)=zeros(size(ind_out));
+                    end
+                    ProjData.ListVarName=[ProjData.ListVarName VarName];
+                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                    if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
+                        ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
+                    end     
+                    eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
+                end
+                ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur  
+                ProjData.ListVarName=[ProjData.ListVarName 'FF'];
+                ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
+            else %3D case
+                if isequal(Theta,0) & isequal(Phi,0)       
+                    % unstructured z coordinate
+                    test_sup=(Coord{1}>=ObjectData.Coord(1,3));
+                    iz_sup=find(test_sup);
+                    iz=iz_sup(1);
+                    if iz>=1 & iz<=npz
+                        %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
+                        %ProjData.DimValue=[ProjData.DimValue npY npX];
+                        for ivar=VarIndex
+                            VarName=FieldData.ListVarName{ivar}; 
+                            ProjData.ListVarName=[ProjData.ListVarName VarName];
+                            ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes  
+                            eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
+                            %TODO : do a vertical average for a thick plane
+                            if test_interp(2) || test_interp(3)
+                                eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');']) 
+                            end
+                        end
+                    end
+                else
+                    errormsg='projection of structured coordinates on oblique plane not yet implemented';
+                    %TODO: use interp3
+                    return
+                end
+            end
+        end
+    end
+
+    %% projection of  velocity components in the rotated coordinates
+    if ~isequal(Phi,0) && length(ivar_U)==1
+        if isempty(ivar_V)
+            msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
+            return
+        end
+        UName=FieldData.ListVarName{ivar_U};
+        VName=FieldData.ListVarName{ivar_V};    
+        eval(['ProjData.' UName  '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
+        eval(['ProjData.' VName  '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
+        if ~isempty(ivar_W)
+            WName=FieldData.ListVarName{ivar_W};
+            eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])% 
+            eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
+        end
+        if ~isequal(Psi,0)
+            eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
+            eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
+        end
+    end
+end
+
+%-----------------------------------------------------------------
+%project in a volume 
+% A FAIRE ....(copie de proj_plane)
+ function  [ProjData,errormsg] = proj_volume(FieldData, ObjectData)
+%-----------------------------------------------------------------
+
+%initialisation of the input parameters of the projection plane
+%-----------------------------------------------------------------
+ProjMode='projection';%direct projection by default
+if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
+
+%axis origin
+if isempty(ObjectData.Coord)
+    ObjectData.Coord(1,1)=0;%origin of the volume set to [0 0] by default
+    ObjectData.Coord(1,2)=0;
+    ObjectData.Coord(1,3)=0;
+end
+
+%rotation angles 
+Phi=0;%default
+Theta=0;
+Psi=0;
+if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
+    Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
+end
+if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
+    Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
+end
+if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
+    Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
+end
+
+%components of the unity vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+
+% test for 3D fields
+test3D=0;
+if isfield(FieldData,'NbDim')
+    test3D=isequal(FieldData.NbDim,3);
+end
+test3C=test3D; %default 3 vel components
+
+%mesh sizes DX and DY
+DX=0;
+DY=0; %default 
+if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
+     DX=abs(ObjectData.DX);%mesh of interpolation points 
+end
+if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
+     DY=abs(ObjectData.DY);%mesh of interpolation points 
+end
+if  ~isequal(ProjMode,'projection') & (DX==0|DY==0)
+        errormsg='DX or DY missing';
+        display(errormsg)
+        return
+end
+if isfield(ObjectData,'DZ')&~isempty(ObjectData.DZ)
+     DZ=abs(ObjectData.DZ);%mesh of interpolation points 
+end
+
+%extrema along each axis
+testXMin=0;
+testXMax=0;
+testYMin=0;
+testYMax=0;
+if isfield(ObjectData,'RangeX')
+        XMin=min(ObjectData.RangeX);
+        XMax=max(ObjectData.RangeX);
+        testXMin=XMax>XMin;
+        testXMax=1;
+end
+if isfield(ObjectData,'RangeY')
+        YMin=min(ObjectData.RangeY);
+        YMax=max(ObjectData.RangeY);
+        testYMin=YMax>YMin;
+        testYMax=1;
+end
+width=0;%default width of the projection band
+if isfield(ObjectData,'RangeZ')
+      ZMin=min(ObjectData.RangeZ);
+        ZMax=max(ObjectData.RangeZ);
+        testZMin=YMax>YMin;
+        testZMax=1;
+%         width=max(ObjectData.RangeZ);
+end
+
+% initiate Matlab  structure for physical field
+[ProjData,errormsg]=proj_heading(FieldData,ObjectData);
+ProjData.NbDim=3;
+%ProjData.ListDimName={};%name of dimension 
+%ProjData.DimValue=[];%values of dimension (nbre of vectors)
+ProjData.ListVarName={};
+ProjData.VarDimName={};
+
+error=0;%default
+flux=0;
+testfalse=0;
+ListIndex={};
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+%-----------------------------------------------------------------
+idimvar=0;
+[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
+if ~isempty(errormsg)
+    errormsg=['error in proj_field/proj_plane:' errormsg];
+    return
+end
+%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% CellVarIndex=cells of variable index arrays
+ivar_new=0; % index of the current variable in the projected field
+icoord=0;
+nbcoord=0;%number of added coordinate variables brought by projection
+for icell=1:length(CellVarIndex)
+    if NbDim(icell)<2
+        continue
+    end
+    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
+    VarType=VarTypeCell{icell};
+    ivar_X=VarType.coord_x;
+    ivar_Y=VarType.coord_y;
+    ivar_Z=VarType.coord_z;
+    ivar_U=VarType.vector_x;
+    ivar_V=VarType.vector_y;
+    ivar_W=VarType.vector_z;
+    ivar_C=VarType.scalar ;
+    ivar_Anc=VarType.ancillary;
+    test_anc=zeros(size(VarIndex));
+    test_anc(ivar_Anc)=ones(size(ivar_Anc));
+    ivar_F=VarType.warnflag;
+    ivar_FF=VarType.errorflag;
+    testX=~isempty(ivar_X) && ~isempty(ivar_Y);
+    DimCell=FieldData.VarDimName{VarIndex(1)};
+    if ischar(DimCell)
+        DimCell={DimCell};%name of dimensions
+    end
+    
+%case of input fields with unstructured coordinates
+    if testX
+        XName=FieldData.ListVarName{ivar_X};
+        YName=FieldData.ListVarName{ivar_Y};
+        eval(['coord_x=FieldData.' XName ';'])
+        eval(['coord_y=FieldData.' YName ';'])
+        if length(ivar_Z)==1
+            ZName=FieldData.ListVarName{ivar_Z};
+            eval(['coord_z=FieldData.' ZName ';'])
+        end
+
+        % translate  initial coordinates
+        coord_x=coord_x-ObjectData.Coord(1,1);
+        coord_y=coord_y-ObjectData.Coord(1,2);
+        if ~isempty(ivar_Z)
+            coord_z=coord_z-ObjectData.Coord(1,3);
+        end
+        
+        % selection of the vectors in the projection range (3D case)
+        if length(ivar_Z)==1 &&  width > 0
+            %components of the unitiy vector normal to the projection plane
+            fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane            
+            indcut=find(abs(fieldZ) <= width);
+            for ivar=VarIndex
+                VarName=FieldData.ListVarName{ivar};
+                eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
+%                 end      
+                    % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE              
+            end
+            coord_x=coord_x(indcut);
+            coord_y=coord_y(indcut);
+            coord_z=coord_z(indcut);
+        end
+
+       %rotate coordinates if needed
+        if isequal(Phi,0)
+            coord_X=coord_x;
+            coord_Y=coord_y;
+            if ~isequal(Theta,0)
+                coord_Y=coord_Y *cos(Theta);
+            end
+        else
+            coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
+            coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
+        end
+        if ~isempty(ivar_Z)
+            coord_Y=coord_Y+coord_z *sin(Theta);
+        end
+        if ~isequal(Psi,0)
+                coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
+                coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
+        end
+        coord_Z=coord_z; %TO UPDATE
+        %restriction to the range of x and y if imposed
+        testin=ones(size(coord_X)); %default
+        testbound=0;
+        if testXMin
+            testin=testin & (coord_X >= XMin);
+            testbound=1;
+        end
+        if testXMax
+            testin=testin & (coord_X <= XMax);
+            testbound=1;
+        end
+        if testYMin
+            testin=testin & (coord_Y >= YMin);
+            testbound=1;
+        end
+        if testYMin
+            testin=testin & (coord_Y <= YMax);
+            testbound=1;
+        end
+        if testbound
+            indcut=find(testin);
+            for ivar=VarIndex
+                VarName=FieldData.ListVarName{ivar};
+                eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])            
+            end
+            coord_X=coord_X(indcut);
+            coord_Y=coord_Y(indcut);
+            if length(ivar_Z)==1
+                coord_Z=coord_Z(indcut);
+            end
+        end
+        % different cases of projection
+        if isequal(ObjectData.ProjMode,'projection')
+            %the list of dimension
+            %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
+            %ProjData.DimValue=[ProjData.DimValue length(coord_X)];
+            nbvar=0;
+            for ivar=VarIndex %transfer variables to the projection plane
+                VarName=FieldData.ListVarName{ivar};
+                if ivar==ivar_X %x coordinate
+                    eval(['ProjData.' VarName '=coord_X;'])
+                elseif ivar==ivar_Y % y coordinate
+                    eval(['ProjData.' VarName '=coord_Y;'])
+                elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
+                    eval(['ProjData.' VarName '=FieldData.' VarName ';'])
+                end
+                if isempty(ivar_Z) || ivar~=ivar_Z 
+                    ProjData.ListVarName=[ProjData.ListVarName VarName];
+                    ProjData.VarDimName=[ProjData.VarDimName DimCell];
+                    nbvar=nbvar+1;
+                    if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
+                        ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
+                    end
+                end
+            end  
+        elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
+            coord_x_proj=(XMin:DX:XMax);
+            coord_y_proj=(YMin:DY:YMax);
+            coord_z_proj=(ZMin:DZ:ZMax);
+            [XI,YI,ZI]=meshgrid(coord_x_proj,coord_y_proj,coord_z_proj);
+            DimCell={'coord_y','coord_x'};
+            ProjData.ListVarName={'coord_z','coord_y','coord_x'};
+            ProjData.VarDimName={'coord_z','coord_y','coord_x'};   
+            nbcoord=3;  
+            ProjData.coord_z=[ZMin ZMax];
+            ProjData.coord_y=[YMin YMax];
+            ProjData.coord_x=[XMin XMax];
+            if isempty(ivar_X), ivar_X=0; end;
+            if isempty(ivar_Y), ivar_Y=0; end;
+            if isempty(ivar_Z), ivar_Z=0; end;
+            if isempty(ivar_U), ivar_U=0; end;
+            if isempty(ivar_V), ivar_V=0; end;
+            if isempty(ivar_W), ivar_W=0; end;
+            if isempty(ivar_F), ivar_F=0; end;
+            if isempty(ivar_FF), ivar_FF=0; end;
+            if ~isequal(ivar_FF,0)
+                VarName_FF=FieldData.ListVarName{ivar_FF};
+                eval(['indsel=find(FieldData.' VarName_FF '==0);'])
+                coord_X=coord_X(indsel);
+                coord_Y=coord_Y(indsel);
+            end
+            FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
+            testFF=0;
+            size(XI)
+            size(YI)
+            size(ZI)
+            for ivar=VarIndex
+                VarName=FieldData.ListVarName{ivar}; 
+                if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)                 
+                    ivar_new=ivar_new+1;
+                    ProjData.ListVarName=[ProjData.ListVarName {VarName}];
+                    ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                    if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
+                        ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
+                    end
+                    if  ~isequal(ivar_FF,0)
+                        eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
+                    end
+                    eval(['ProjData.' VarName '=griddata3(double(coord_X),double(coord_Y),double(coord_Z),double(FieldData.' VarName '),XI,YI,ZI);'])
+%                     eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
+%                     FFlag= isnan(varline); %detect undefined values NaN
+%                     indnan=find(FFlag);
+%                     if~isempty(indnan)
+%                         varline(indnan)=zeros(size(indnan));
+%                         eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
+%                         FF(indnan)=ones(size(indnan));
+%                         testFF=1;
+%                     end
+%                     if ivar==ivar_U
+%                         ivar_U=ivar_new;
+%                     end
+%                     if ivar==ivar_V
+%                         ivar_V=ivar_new;
+%                     end
+%                     if ivar==ivar_W
+%                         ivar_W=ivar_new;
+%                     end
+                end
+            end
+            if testFF
+                ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
+                ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
+               ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
+                ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
+            end
+        end
+%case of fields defined on a structured  grid 
+    else  
+        AYName=FieldData.ListVarName{VarType.coord(1)};
+        AXName=FieldData.ListVarName{VarType.coord(2)};
+        eval(['AX=FieldData.' AXName ';'])
+        eval(['AY=FieldData.' AYName ';'])
+        VarName=FieldData.ListVarName{VarIndex(1)};
+        eval(['DimValue=size(FieldData.' VarName ');'])
+        ListDimName=FieldData.VarDimName{VarIndex(1)};
+        ProjData.ListVarName=[{AYName} {AXName} ProjData.ListVarName]; %TODO: check if it already exists in Projdata (several cells)
+        ProjData.VarDimName=[{AYName} {AXName} ProjData.VarDimName];
+        nbcolor=1; %default
+        for idim=1:length(ListDimName)
+            DimName=ListDimName{idim};
+            if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
+               nbcolor=DimValue(idim);
+               DimIndices(idim)=[];
+               DimValue(idim)=[];
+            end
+            if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
+                DimIndices(idim)=[];
+                DimValue(idim)=[];
+            end
+        end  
+        ind_1=find(DimValue==1);
+        DimIndices(ind_1)=[]; %suppress singleton dimensions 
+%         indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
+        NbDim=length(DimIndices);%number of space dimensions
+        Coord_z=[];
+        Coord_y=[];
+        Coord_x=[];   
+    
+        for idim=1:NbDim %loop on space dimensions
+            test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
+            ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
+            if ~isequal(ivar,0)%  a variable corresponds to the current dimension
+                eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
+                DCoord=diff(Coord{idim});
+                DCoord_min(idim)=min(DCoord);
+                DCoord_max=max(DCoord);
+                test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
+                test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
+                if ~isequal(test_direct(idim),test_direct_min)
+                     msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim)  ' in proj_field.m'])
+                                return
+                end               
+                test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
+            else  % no variable associated with the first dimension, look for variable  attributes Coord_1, _2 or _3
+                Coord_i_str=['Coord_' num2str(idim)];
+                DCoord_min(idim)=1;%default
+                Coord{idim}=[0.5 DimValue(idim)-0.5];
+                test_direct(idim)=1;
+            end
+        end
+        if NbDim==2
+            if DY==0
+                DY=abs(DCoord_min(1));
+            end
+            npY=1+round(abs(Coord{1}(end)-Coord{1}(1))/DY);%nbre of points after interpolation 
+            DimValue(1)=1+round(abs(Coord{1}(end)-Coord{1}(1))/abs(DCoord_min(1)));%nbre of points after possible interpolation on a regular grid
+            if DX==0
+                DX=abs(DCoord_min(2));
+            end
+            npX=1+round(abs(Coord{2}(end)-Coord{2}(1))/DX);%nbre of points after interpol  
+            DimValue(2)=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points after possible interpolation on a regular grid 
+            Coord_y=linspace(Coord{1}(1),Coord{1}(end),npY);
+            test_direct_y=test_direct(1);
+            Coord_x=linspace(Coord{2}(1),Coord{2}(end),npX);
+            test_direct_x=test_direct(2);
+            DAX=DCoord_min(2);
+            DAY=DCoord_min(1);
+        elseif NbDim==3
+            DZ=abs(DCoord_min(1));
+            npz=1+round(abs(Coord{1}(end)-Coord{1}(1))/DZ);%nbre of points after interpolation
+            if DY==0
+                DY=abs(DCoord_min(2));
+            end
+            npY=1+round(abs(Coord{2}(end)-Coord{2}(1))/DY);%nbre of points after interpol 
+            DimValue(1)=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol 
+            if DX==0
+                DX=abs(DCoord_min(3));
+            end
+            npX=1+round(abs(Coord{3}(end)-Coord{3}(1))/DX);%nbre of points after interpol
+            DimValue(2)=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol 
+            Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz);
+            test_direct_z=test_direct(1);
+            Coord_y=linspace(Coord{2}(1),Coord{2}(end),npY);
+            test_direct_y=test_direct(2);
+            Coord_x=linspace(Coord{3}(1),Coord{3}(end),npX);
+            test_direct_x=test_direct(3);
+        end  
+        minAX=min(Coord_x);
+        maxAX=max(Coord_x);
+        minAY=min(Coord_y);
+        maxAY=max(Coord_y);
+        xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
+        ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
+        xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
+        ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
+        if ~testXMax
+            XMax=max(xcor_new);
+        end
+        if ~testXMin
+            XMin=min(xcor_new);
+        end
+        if ~testYMax
+            YMax=max(ycor_new);
+        end
+        if ~testYMin
+            YMin=min(ycor_new);
+        end
+        DXinit=(maxAX-minAX)/(DimValue(2)-1);
+        DYinit=(maxAY-minAY)/(DimValue(1)-1);
+        if DX==0
+            DX=DXinit;
+        end
+        if DY==0
+            DY=DYinit;
+        end
+        npX=floor((XMax-XMin)/DX+1);
+        npY=floor((YMax-YMin)/DY+1);    
+        if test_direct_y
+            coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
+        else
+            coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
+        end
+        if test_direct_x
+            coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
+        else
+            coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
+        end 
+        
+        % case with no rotation and interpolation
+        if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
+            if test_direct(1)
+                min_indy=ceil((YMin-Coord{1}(1))/DYinit)+1;
+                max_indy=floor((YMax-Coord{1}(1))/DYinit)+1;
+                Ybound(1)=Coord{1}(1)+DYinit*(min_indy-1);
+                Ybound(2)=Coord{1}(1)+DYinit*(max_indy-1);
+            else
+                min_indy=ceil((Coord{1}(1)-YMax)/DYinit)+1;
+                max_indy=floor((Coord{1}(1)-YMin)/DYinit)+1;
+                Ybound(2)=Coord{1}(1)-DYinit*(max_indy-1);
+                Ybound(1)=Coord{1}(1)-DYinit*(min_indy-1);
+            end              
+            if test_direct(2)==1
+                min_indx=ceil((XMin-Coord{2}(1))/DXinit)+1;
+                max_indx=floor((XMax-Coord{2}(1))/DXinit)+1;
+                Xbound(1)=Coord{2}(1)+DXinit*(min_indx-1);
+                Xbound(2)=Coord{2}(1)+DXinit*(max_indx-1);
+            else
+                min_indx=ceil((Coord{2}(1)-XMax)/DXinit)+1;
+                max_indx=floor((Coord{2}(1)-XMin)/DXinit)+1;
+                Xbound(2)=Coord{2}(1)+DXinit*(max_indx-1);
+                Xbound(1)=Coord{2}(1)+DXinit*(min_indx-1);
+            end 
+            min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
+            min_indx=max(min_indx,1);
+            max_indy=min(max_indy,DimValue(1));
+            max_indx=min(max_indx,DimValue(2));
+            for ivar=VarIndex
+                VarName=FieldData.ListVarName{ivar}; 
+                ProjData.ListVarName=[ProjData.ListVarName VarName];
+                %ProjData.VarDimIndex=[ProjData.VarDimIndex [NbDim-1 NbDim]];
+                if length(FieldData.VarAttribute)>=ivar
+                    ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
+                end
+                eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx) ;']);
+            end         
+        else
+        % case with rotation and/or interpolation
+            if isempty(Coord_z) %2D case
+                [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
+                XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
+                YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
+                XIMA=(XIMA-minAX)/DXinit+1;% image index along x
+                YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
+                XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
+                YIMA=reshape(round(YIMA),1,npX*npY);
+                flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image 
+                if isequal(ObjectData.ProjMode,'filter')
+                    npx_filter=ceil(abs(DX/DAX));
+                    npy_filter=ceil(abs(DY/DAY));
+                    Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
+                    test_filter=1;
+                else
+                    test_filter=0;
+                end
+                for ivar=VarIndex
+                    VarName=FieldData.ListVarName{ivar} ; 
+                    if test_interp(1) | test_interp(2)%interpolate on a regular grid         
+                          eval(['FieldData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
+                    end
+                    %filter the field (image) if option 'filter' is used
+                    if test_filter  
+                         Aclass=class(FieldData.A);
+                         eval(['FieldData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
+                         if ~isequal(Aclass,'double')
+                             eval(['FieldData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
+                         end
+                    end
+                    eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line              
+                    ind_in=find(flagin);
+                    ind_out=find(~flagin);
+                    ICOMB=(XIMA-1)*DimValue(1)+YIMA;
+                    ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
+                    vec_B(ind_in,1:nbcolor)=vec_A(ICOMB,:); 
+                    for icolor=1:nbcolor
+                        vec_B(ind_out,icolor)=zeros(size(ind_out));
+                    end
+                    ProjData.ListVarName=[ProjData.ListVarName VarName];                 
+                    if length(FieldData.VarAttribute)>=ivar
+                        ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
+                    end     
+                    eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
+                end
+                ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur  
+                ProjData.ListVarName=[ProjData.ListVarName 'FF'];
+                ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
+            else %3D case
+                if isequal(Theta,0) & isequal(Phi,0)       
+                    test_sup=(Coord{1}>=ObjectData.Coord(1,3));
+                    iz_sup=find(test_sup);
+                    iz=iz_sup(1);
+                    if iz>=1 & iz<=npz
+                        %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
+                        %ProjData.DimValue=[ProjData.DimValue npY npX];
+                        for ivar=VarIndex
+                            VarName=FieldData.ListVarName{ivar}; 
+                            ProjData.ListVarName=[ProjData.ListVarName VarName];
+                            ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes  
+                            eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
+                            %TODO : do a vertical average for a thick plane
+                            if test_interp(2) || test_interp(3)
+                                eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');']) 
+                            end
+                        end
+                    end
+                else
+                    errormsg='projection of structured coordinates on oblique plane not yet implemented';
+                    %TODO: use interp3
+                    return
+                end
+            end
+        end
+    end
+    %projection of  velocity components in the rotated coordinates
+    if ~isequal(Phi,0) && length(ivar_U)==1
+        if isempty(ivar_V)
+            msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
+            return
+        end
+        UName=FieldData.ListVarName{ivar_U};
+        VName=FieldData.ListVarName{ivar_V};    
+        eval(['ProjData.' UName  '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
+        eval(['ProjData.' VName  '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
+        if ~isempty(ivar_W)
+            WName=FieldData.ListVarName{ivar_W};
+            eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])% 
+            eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
+        end
+        if ~isequal(Psi,0)
+            eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
+            eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
+        end
+    end
+end
+
+%-----------------------------------------------------------------
+%transmit the global attributes
+function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
+%-----------------------------------------------------------------
+% ProjData=FieldData;
+ProjData=[];%default
+errormsg=[];%default
+if ~isfield(FieldData,'ListGlobalAttribute')
+    ProjData.ListGlobalAttribute={};
+else
+    ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
+end
+if isfield(FieldData,'Txt')
+    errormsg=FieldData.Txt; %transmit erreur message
+    return;
+end
+for iattr=1:length(ProjData.ListGlobalAttribute)
+    AttrName=ProjData.ListGlobalAttribute{iattr};
+    if isfield(FieldData,AttrName)
+        eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
+    end
+end
+if isfield(FieldData,'CoordUnit')
+    if isfield(ObjectData,'CoordUnit')&~isequal(FieldData.CoordUnit,ObjectData.CoordUnit)
+        errormsg=[ObjectData.Style ' in ' ObjectData.CoordUnit ' coordinates, while field in ' FieldData.CoordUnit ];
+        return
+    else
+         ProjData.CoordUnit=FieldData.CoordUnit;
+    end
+end
+
+ListObject={'Style','ProjMode','RangeX','RangeY','RangeZ','Phi','Theta','Psi','Coord'};
+for ilist=1:length(ListObject)
+    if isfield(ObjectData,ListObject{ilist})
+        eval(['val=ObjectData.' ListObject{ilist} ';'])
+        if ~isempty(val)
+            eval(['ProjData.Object' ListObject{ilist} '=val;']);
+            ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
+        end
+    end   
+end
Index: /trunk/src/set_object.m
===================================================================
--- /trunk/src/set_object.m	(revision 204)
+++ /trunk/src/set_object.m	(revision 204)
@@ -0,0 +1,893 @@
+%'set_object': GUI to edit a projection object
+%------------------------------------------------------------------------
+% function hset_object= set_object(data, PlotHandles,ZBounds)
+% associated with the GUI set_object.fig
+%
+% OUTPUT:
+% hset_object: handle of the GUI figure
+% 
+% INPUT:
+% data: structure describing the object properties
+%    .Style=...
+%    .ProjMode
+%    .CoordType: 'phys' or 'px'
+%    .DX,.DY,.DZ : mesh along each dirction
+%    .RangeX, RangeY
+%    .Coord(j,i), i=1, 2, 3,  components x, y, z of j=1...n position(s) characterizing the object components
+% PlotHandles: handles for projection plots NO MORE USED
+% Zbounds: bounds on Z ( 3D case)
+%
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+%     This file is part of the toolbox UVMAT.
+% 
+%     UVMAT is free software; you can redistribute it and/or modify
+%     it under the terms of the GNU General Public License as published by
+%     the Free Software Foundation; either version 2 of the License, or
+%     (at your option) any later version.
+% 
+%     UVMAT is distributed in the hope that it will be useful,
+%     but WITHOUT ANY WARRANTY; without even the implied warranty of
+%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
+%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+
+function varargout = set_object(varargin)
+
+% Last Modified by GUIDE v2.5 24-Nov-2008 14:29:06
+
+% Begin initialization code - DO NOT PLOT
+gui_Singleton = 1;
+gui_State = struct('gui_Name',       mfilename, ...
+                   'gui_Singleton',  gui_Singleton, ...
+                   'gui_OpeningFcn', @set_object_OpeningFcn, ...
+                   'gui_OutputFcn',  @set_object_OutputFcn, ...
+                   'gui_LayoutFcn',  [] , ...
+                   'gui_Callback',   []);
+if nargin & ischar(varargin{1})
+    gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+    gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT PLOT
+%------------------------------------------------------------------------
+%------------------------------------------------------------------------
+% --- Executes just before set_object is made visible.
+%INPUT: 
+% handles: handles of the set_object interface elements
+%'IndexObj': NON USED ANYMORE (To suppress) index of the object (on the UvData list) that set_object will modify
+%        if =[] or absent: index still undefined (create mode in uvmat)
+%        if=0; no associated object (used for series), the button 'PLOT' is  then unvisible
+%'data': read from an existing object selected in the interface
+%      .TITLE : class of object ('POINTS','LINE',....)
+%      .DX,DY,DZ; meshes for regular grids
+%      .Coord: object position coordinates
+%      .ParentButton: handle of the uicontrol object calling the interface
+% PlotHandles: set of handles of the elements contolling the plotting of the projected field:
+%  if =[] or absent, no plot (mask mode in uvmat)
+% parameters on the uvmat interface (obtained by 'get_plot_handle.m')
+function set_object_OpeningFcn(hObject, eventdata, handles, data, PlotHandles,ZBounds)
+%-------------------------------------------------------------------
+% Choose default command line output for set_object
+handles.output = hObject;
+% Update handles structure
+guidata(hObject, handles);
+
+%default
+if ~exist('ZBound','var')
+    ZBound=0; %default 
+end
+set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function (allow action on uvmat when set_object is in front)
+enable_plot=0;%default: does not allow plot of object and projection
+
+% fill the interface as set in the input data:
+if exist('data','var') 
+    if isfield(data,'enable_plot')
+        enable_plot=data.enable_plot;%test to desable button PLOT (display mode)
+    end
+    if isfield(data,'Name')
+        set(handles.TITLE,'String',data.Name)
+    end
+    if ~isfield(data,'NbDim')||~isequal(data.NbDim,3)%2D case
+        set(handles.ZObject,'Visible','off')
+        set(handles.z_slider,'Visible','off')
+    else
+        set(handles.ZObject,'Visible','on')
+        set(handles.z_slider,'Visible','on')
+        if isfield(data,'Coord') && size(data.Coord,2)==3
+            set(handles.ZObject,'String',num2str(data.Coord(1,3),4))
+        end
+    end
+    if isfield(data,'StyleMenu')
+        set(handles.ObjectStyle,'String',data.StyleMenu);
+    end
+    if isfield(data,'Style')
+        menu=get(handles.ObjectStyle,'String');
+        for iline=1:length(menu)
+            if isequal(menu{iline},data.Style)
+                set(handles.ObjectStyle,'Value',iline)
+                break
+            end
+        end
+    end
+    ObjectStyle_Callback(hObject, eventdata, handles)
+    if isfield(data,'ProjMenu')
+        set(handles.ProjMode,'String',data.ProjMenu);%overset the standard menu
+    end
+    if isfield(data,'ProjMode')
+        menu=get(handles.ProjMode,'String');
+        for iline=1:length(menu)
+            if isequal(menu{iline},data.ProjMode)
+                set(handles.ProjMode,'Value',iline)
+                break
+            end
+        end
+    end
+    ProjMode_Callback(hObject, eventdata, handles)
+    if isfield(data,'Coord')
+        if ischar(data.Coord)
+            data.Coord=str2num(data.Coord);
+        elseif iscell(data.Coord)
+            CoordCell=data.Coord;
+            data.Coord=zeros(numel(CoordCell),3);
+            data.Coord(:,3)=zeros(numel(CoordCell),1); % z component set to 0 by default
+            for iline=1:numel(CoordCell)
+                line_vec=str2num(CoordCell{iline});
+                if numel(line_vec)==2
+                    data.Coord(iline,1:2)=str2num(CoordCell{iline});
+                else
+                    data.Coord(iline,:)=str2num(CoordCell{iline});
+                end
+            end
+        end
+        if size(data.Coord,2)>=2
+            sizcoord=size(data.Coord);
+            for i=1:sizcoord(1)
+                XObject{i}=num2str(data.Coord(i,1),4);
+                YObject{i}=num2str(data.Coord(i,2),4);
+            end
+            set(handles.XObject,'String',XObject)
+            set(handles.YObject,'String',YObject)
+            if sizcoord(2)>3
+                for i=1:sizcoord(1)
+                    ZObject{i}=num2str(data.Coord(i,3),4);
+                end
+                set(handles.ZObject,'String',ZObject)
+            end
+        end
+    end
+    if isfield(data,'DX')
+        if ~ischar(handles.DX)
+            data.DX=num2str(data.DX,3);
+        end
+        set(handles.DX,'String',data.DX)
+    end
+    if isfield(data,'DY')
+        if ~ischar(handles.DY)
+            data.DY=num2str(data.DY,3);
+        end
+        set(handles.DY,'String',data.DX)
+    end
+    if isfield(data,'RangeZ') && length(ZBounds) >= 2
+        set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
+        DZ=max(data.RangeZ);%slider step
+        if ZBounds(2)~=ZBounds(1)
+            rel_step(1)=min(DZ/(ZBounds(2)-ZBounds(1)),0.2);%must be smaller than 1
+            rel_step(2)=0.1;
+            set(handles.z_slider,'Visible','on')
+            set(handles.z_slider,'Min',ZBounds(1))
+            set(handles.z_slider,'Max',ZBounds(2))
+            set(handles.z_slider,'SliderStep',rel_step)
+            set(handles.z_slider,'Value',(ZBounds(1)+ZBounds(2))/2)
+        end
+    end
+    if isfield(data,'RangeX')
+        if ischar(data.RangeX)
+            data.RangeX=str2num(data.RangeX);
+        end
+        set(handles.XMax,'String',num2str(max(data.RangeX),3))
+        set(handles.XMin,'String',num2str(min(data.RangeX),3))
+    end
+    if isfield(data,'RangeY')
+        if ischar(data.RangeY)
+            data.RangeY=str2num(data.RangeY);
+        end
+        set(handles.YMax,'String',num2str(max(data.RangeY),3))
+        set(handles.YMin,'String',num2str(min(data.RangeY),3))
+    end
+    if isfield(data,'RangeZ')
+        if ischar(data.RangeZ)
+            data.RangeZ=str2num(data.RangeZ);
+        end
+        set(handles.ZMax,'String',num2str(max(data.RangeZ),3))
+        if numel(data.RangeZ)>=2
+            set(handles.ZMin,'String',num2str(min(data.RangeZ),3))
+        end
+    end  
+    if isfield(data,'Phi')
+        if ~ischar(handles.Phi)
+            data.DY=num2str(data.Phi,3);
+        end
+         set(handles.Phi,'String',data.Phi)
+    end
+    if isfield(data,'Theta')
+        if ~ischar(handles.Theta)
+            data.DY=num2str(data.Theta,3);
+        end
+        set(handles.Theta,'String',data.Theta)
+    end
+    if isfield(data,'Psi')
+         if ~ischar(handles.Psi)
+            data.DY=num2str(data.Psi,3);
+        end
+         set(handles.Psi,'String',data.Psi)
+    end  
+    if isfield(data,'DZ')
+        if ~ischar(handles.DZ)
+            data.DY=num2str(data.DZ,3);
+        end
+        set(handles.DZ,'String',data.DZ)
+    end
+    if isfield(data,'CoordUnit')
+        set(handles.CoordUnit,'String',data.CoordUnit)
+    end
+end
+if enable_plot
+   set(handles.PLOT,'enable','on')
+else
+   set(handles.PLOT,'enable','off') 
+end
+huvmat=findobj(allchild(0),'tag','uvmat');
+UvData=get(huvmat,'UserData');
+pos_uvmat=get(huvmat,'Position');
+%position the set_object GUI with respect to uvmat
+if isfield(UvData,'SetObjectOrigin')
+    pos_set_object(1:2)=UvData.SetObjectOrigin + pos_uvmat(1:2);
+    pos_set_object(3:4)=UvData.SetObjectSize .* pos_uvmat(3:4);
+    set(hObject,'Position',pos_set_object)
+end
+
+%------------------------------------------------------------------------
+% --- Outputs from this function are returned to the command line.
+function varargout = set_object_OutputFcn(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+varargout{2}=handles;
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in ObjectStyle.
+function ObjectStyle_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+style_prev=get(handles.ObjectStyle,'UserData');%previous object style
+str=get(handles.ObjectStyle,'String');
+val=get(handles.ObjectStyle,'Value');
+style=str{val};
+% make correspondance between different object styles
+Xcolumn=get(handles.XObject,'String');
+Ycolumn=get(handles.YObject,'String');
+if ischar(Xcolumn)
+    sizchar=size(Xcolumn);
+    for icol=1:sizchar(1)
+        Xcolumn_cell{icol}=Xcolumn(icol,:);
+    end
+    Xcolumn=Xcolumn_cell;
+end
+if ischar(Ycolumn)
+    sizchar=size(Ycolumn);
+    for icol=1:sizchar(1)
+        Ycolumn_cell{icol}=Ycolumn(icol,:);
+    end
+    Ycolumn=Ycolumn_cell;
+end
+Zcolumn={};%default
+z_new={};
+if isequal(get(handles.ZObject,'Visible'),'on')
+    data.NbDim=3; %test 3D object
+    Zcolumn=get(handles.ZObject,'String');
+    if ischar(Zcolumn)
+        Zcolumn={Zcolumn};
+    end
+end
+x_new{1}=Xcolumn{1};
+y_new{1}=Ycolumn{1};
+if ~isempty(Zcolumn)
+    z_new{1}=Zcolumn{1};
+end
+if isequal(style,'line')
+    if strcmp(style_prev,'rectangle')||strcmp(style_prev,'ellipse')
+        XMax=get(handles.XMax,'String');
+        YMax=get(handles.YMax,'String');
+        x_new{2}=num2str(XMax,4);
+        y_new{2}=num2str(YMax,4);
+        set(handles.XObject,'String',x_new)
+        set(handles.YObject,'String',y_new)
+        set(handles.ZObject,'String',z_new)
+    end
+elseif isequal(style,'polyline')
+elseif strcmp(style,'rectangle')|| strcmp(style,'ellipse')
+     set(handles.XObject,'String',x_new)
+     set(handles.YObject,'String',y_new)
+     set(handles.ZObject,'String',z_new)
+end
+
+switch style
+    case {'points','line','polyline','plane'}
+        menu_proj={'projection';'interp';'filter';'none'}; 
+    case {'polygon','rectangle','ellipse'}
+        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
+    case 'volume'
+        menu_proj={'interp';'none'};
+end   
+proj_index=get(handles.ProjMode,'Value');
+if proj_index<numel(menu_proj)
+    set(handles.ProjMode,'Value',1);% value index must not exceed the menu length
+end
+set(handles.ProjMode,'String',menu_proj)
+ProjMode_Callback(hObject, eventdata, handles)
+%store the current option
+str=get(handles.ObjectStyle,'String');
+val=get(handles.ObjectStyle,'Value');
+set(handles.ObjectStyle,'UserData',style)
+
+%------------------------------------------------------------------------
+function xObject_Callback(hObject, eventdata, handles)
+
+%------------------------------------------------------------------------
+function yObject_Callback(hObject, eventdata, handles)
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in zObject.
+function zObject_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in ProjMode.
+function ProjMode_Callback(hObject, eventdata, handles)
+menu=get(handles.ProjMode,'String');
+value=get(handles.ProjMode,'Value');
+ProjMode=menu{value};
+menu=get(handles.ObjectStyle,'String');
+value=get(handles.ObjectStyle,'Value');
+ObjectStyle=menu{value};
+test3D=isequal(get(handles.ZObject,'Visible'),'on');%3D case
+
+%default setting
+set(handles.Phi,'Visible','off')
+set(handles.Theta,'Visible','off')
+set(handles.Psi,'Visible','off')
+set(handles.XMin,'Visible','off')
+set(handles.XMax,'Visible','off')
+set(handles.YMin,'Visible','off')
+if isequal(ProjMode,'interp')
+    set(handles.YMax,'Visible','off')
+else
+    set(handles.YMax,'Visible','on')
+end
+if strcmp(ObjectStyle,'rectangle')||strcmp(ObjectStyle,'ellipse')
+    set(handles.XMax,'Visible','on')
+else
+   set(handles.XMax,'Visible','off')
+end
+set(handles.ZMin,'Visible','off')
+set(handles.ZMax,'Visible','off')
+set(handles.DX,'Visible','off')
+set(handles.DY,'Visible','off')
+set(handles.DZ,'Visible','off')
+
+switch ObjectStyle
+    case 'points'
+        set(handles.YMax,'TooltipString','YMax: range of averaging around each point') 
+        set(handles.XObject,'TooltipString','XObject: set of x coordinates of the points')
+        set(handles.YObject,'TooltipString','YObject: set of y coordinates of the points')
+        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates of the points')
+    case {'line','polyline','polygon'}
+        set(handles.YMax,'TooltipString','YMax: range of averaging around the line')
+        set(handles.XObject,'TooltipString','XObject: set of x coordinates defining the line')
+        set(handles.YObject,'TooltipString','YObject: set of y coordinates defining the line')
+        set(handles.ZObject,'TooltipString','ZObject: set of z coordinates defining the line')
+        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
+            set(handles.DX,'Visible','on')
+            set(handles.DX,'TooltipString','DX: mesh for the interpolated field along the line')
+        end       
+    case {'rectangle','ellipse'}
+        set(handles.XMax,'TooltipString',['XMax: half length of the ' ObjectStyle])
+        set(handles.YMax,'TooltipString',['YMax: half width of the ' ObjectStyle])
+        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the ' ObjectStyle ' centre'])
+        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the ' ObjectStyle ' centre'])
+    case {'plane'}  
+        set(handles.Phi,'Visible','on')
+        set(handles.XMin,'Visible','on')
+        set(handles.XMax,'Visible','on')
+        set(handles.YMin,'Visible','on')
+        set(handles.YMax,'Visible','on')
+        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
+        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
+        set(handles.ZMax,'TooltipString','ZMax: range of projection normal to the plane')
+        if test3D
+            set(handles.Theta,'Visible','on')
+            set(handles.Psi,'Visible','on')
+            set(handles.ZMax,'Visible','on')
+        end
+        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
+            set(handles.DX,'Visible','on')
+            set(handles.DY,'Visible','on')
+        else
+            set(handles.DX,'Visible','off')
+            set(handles.DY,'Visible','off')
+        end
+        if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp')
+            set(handles.DZ,'Visible','on')  
+        end
+     case {'volume'}  
+        set(handles.Phi,'Visible','on')
+        set(handles.XMin,'Visible','on')
+        set(handles.XMax,'Visible','on')
+        set(handles.YMin,'Visible','on')
+        set(handles.YMax,'Visible','on')
+        set(handles.XObject,'TooltipString',['XObject:  x coordinate of the axis origin for the ' ObjectStyle])
+        set(handles.YObject,'TooltipString',['YObject:  y coordinate of the axis origin for the ' ObjectStyle])
+        if test3D
+            set(handles.Theta,'Visible','on')
+            set(handles.Psi,'Visible','on')
+            set(handles.ZMin,'Visible','on')
+            set(handles.ZMax,'Visible','on')
+        end
+        if isequal(ProjMode,'interp')|| isequal(ProjMode,'filter')
+            set(handles.DX,'Visible','on')
+            set(handles.DY,'Visible','on')
+        else
+            set(handles.DX,'Visible','off')
+            set(handles.DY,'Visible','off')
+        end
+        if isequal(ObjectStyle,'volume') && isequal(ProjMode,'interp')
+            set(handles.DZ,'Visible','on')  
+        end
+end
+%------------------------------------------------------------------------
+
+%------------------------------------------------------------------------
+function Phi_Callback(hObject, eventdata, handles)
+update_slider(hObject, eventdata,handles)
+%------------------------------------------------------------------------
+%------------------------------------------------------------------------
+function Theta_Callback(hObject, eventdata, handles)
+update_slider(hObject, eventdata,handles)
+%------------------------------------------------------------------------
+function update_slider(hObject, eventdata,handles)
+%rotation angles
+Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
+Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
+
+%components of the unitiy vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+if isfield(UvData,'X') & isfield(UvData,'Y') & isfield(UvData,'Z')
+    Z=NormVec_X *(UvData.X)+NormVec_Y *(UvData.Y)+NormVec_Z *(UvData.Z);
+    set(handles.z_slider,'Min',min(Z))
+    set(handles.z_slider,'Max',max(Z))
+    ZMax_Callback(hObject, eventdata, handles)
+end
+%------------------------------------------------------------------------
+function DX_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+%------------------------------------------------------------------------
+function DY_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+%------------------------------------------------------------------------
+function DZ_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+
+%------------------------------------------------------------------------
+%-----------------------------------------------------
+% --- Executes on button press in OPEN: DESACTIVATED use uvmat browser
+function OPEN_Callback(hObject, eventdata, handles)
+%get the object file 
+oldfile=' ';
+huvmat=findobj('Tag','uvmat');
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+if ~isempty(hrootpath)
+    oldfile=get(hrootpath,'String');
+    if iscell(oldfile)
+        oldfile=oldfile{1};
+    end
+end
+[FileName, PathName, filterindex] = uigetfile( ...
+       {'*.xml;*.mat', ' (*.xml,*.mat)';
+       '*.xml',  '.xml files '; ...
+        '*.mat',  '.mat matlab files '}, ...
+        'Pick a file',oldfile);
+fileinput=[PathName FileName];%complete file name 
+testblank=findstr(fileinput,' ');%look for blanks
+if ~isempty(testblank)
+    msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
+    return
+end
+sizf=size(fileinput);
+if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
+
+%read the file
+ t=xmltree(fileinput);
+ s=convert(t);
+ if ~isfield(s,'Style')
+     s.Style='points';
+ end
+ if ~isfield(s,'ProjMode')
+     s.ProjMode='none';
+ end
+teststyle=0;
+
+switch s.Style
+    case {'points','line','polyline','plane'}
+        menu_proj={'projection';'interp';'filter';'none'}; 
+    case {'polygon','rectangle','ellipse'}
+        menu_proj={'inside';'outside';'mask_inside';'mask_outside'};
+    case 'volume'
+        menu_proj={'none'};
+end
+set(handles.ObjectStyle,'String',menu_proj)
+menu=get(handles.ObjectStyle,'String');
+for iline=1:length(menu)
+    if isequal(menu{iline},s.Style)
+        set(handles.ObjectStyle,'Value',iline)
+        teststyle=1;
+        break
+    end
+end
+testmode=0;
+%menu=get(handles.ProjMode,'String');
+for iline=1:length(menu_proj)
+    if isequal(menu_proj{iline},s.ProjMode)
+        set(handles.ProjMode,'Value',iline)
+        testmode=1;
+        break
+    end
+end
+
+ProjMode_Callback(hObject, eventdata, handles);%visualize the appropriate edit boxes
+if isfield(s,'XMax')
+    set(handles.XMax,'String',s.XMax)
+end
+if isfield(s,'XMin')
+    set(handles.XMin,'String',s.XMin)
+end
+if isfield(s,'YMax')
+    set(handles.YMax,'String',s.YMax)
+end
+if isfield(s,'YMin')
+    set(handles.YMin,'String',s.YMin)
+end
+Range=0;
+if isfield(s,'Range')
+    if ischar(s.Range)
+        Range=str2num(s.Range);
+    else
+        Range(1,:)=str2num(s.Range{1});
+        Range(2,:)=str2num(s.Range{2});
+    end
+end
+if size(Range,2)>=3
+    if size(Range,1)>=2
+       set(handles.ZMin,'String',num2str(Range(2,3),3))
+    end
+    if size(Range,1)>=2
+       set(handles.ZMax,'String',num2str(Range(1,3),3))
+    end
+end
+if size(Range,2)>=2
+    if size(Range,1)>=2
+       set(handles.YMin,'String',num2str(Range(2,2),3))
+    end
+    if size(Range,1)>=2
+       set(handles.YMax,'String',num2str(Range(1,2),3))
+    end
+end
+if size(Range,2)>=1
+    if size(Range,1)>=2
+       set(handles.XMin,'String',num2str(Range(2,1),3))
+    end
+    if size(Range,1)>=2
+       set(handles.XMax,'String',num2str(Range(1,1),3))
+    end
+end
+if isfield(s,'RangeX') & ischar(s.RangeX)
+     RangeX=str2num(s.RangeX);
+    set(handles.XMax,'String',num2str(max(RangeX),3))
+    set(handles.XMin,'String',num2str(min(RangeX),3))
+end
+
+if isfield(s,'RangeY')
+    if ischar(s.RangeY)
+        RangeY=str2num(s.RangeY);
+        set(handles.YMax,'String',num2str(max(RangeY),3))
+        set(handles.YMin,'String',num2str(min(RangeY),3))
+    end
+end
+if isfield(s,'RangeZ')
+    if ischar(s.RangeZ)
+        RangeZ=str2num(s.RangeZ);
+        set(handles.ZMax,'String',num2str(max(RangeZ),3))
+        set(handles.ZMin,'String',num2str(min(RangeZ),3))
+    end
+end
+if isfield(s,'Phi')
+    set(handles.Phi,'String',s.Phi)
+end
+if isfield(s,'Theta')
+    set(handles.Theta,'String',s.Theta)
+end
+if isfield(s,'Psi')
+    set(handles.Psi,'String',s.Psi)
+end
+
+if isfield(s,'DX')
+    set(handles.DX,'String',s.DX)
+end
+if isfield(s,'DY')
+    set(handles.DY,'String',s.DY)
+end
+if ~isfield(s,'Coord')
+    XObject='0';%default
+    YObject='0';
+elseif ischar(s.Coord)
+    line=str2num(s.Coord);
+    XObject=num2str(line(1),4);
+    YObject=num2str(line(2),4);
+else
+    for i=1:length(s.Coord)
+        line=str2num(s.Coord{i});
+        XObject{i}=num2str(line(1),4);
+        YObject{i}=num2str(line(2),4);
+    end
+end
+set(handles.XObject,'String',XObject)
+set(handles.YObject,'String',YObject)
+%METTRA A JOUR ASPECT DE L'INTERFACE (COMME set_object_Opening
+%------------------------------------------------------------------------
+%----------------------------------------------------
+% executed when closing: set the parent interface button to value 0
+function closefcn(gcbo,eventdata,parent_button)
+
+huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
+if ~isempty(huvmat)
+    hhuvmat=guidata(huvmat);
+%     set(hhuvmat.create,'Value',0)
+%     set(hhuvmat.create,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+%     set(hhuvmat.LINE,'Value',0)
+%     set(hhuvmat.LINE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+%     set(hhuvmat.PATCH,'Value',0)
+%     set(hhuvmat.PATCH,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+%     set(hhuvmat.PLANE,'Value',0)
+%     set(hhuvmat.PLANE,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+%     set(hhuvmat.VOLUME,'Value',0)
+%     set(hhuvmat.VOLUME,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+    set(hhuvmat.edit,'Value',0)
+    set(hhuvmat.edit,'BackgroundColor',[0.7 0.7 0.7])%put unactivated buttons to gree
+end
+hseries=findobj(allchild(0),'Name','series');%find the current series interface handle
+if ~isempty(hseries)
+    hhseries=guidata(hseries);
+    set(hhseries.GetObject,'Value',0)
+    set(hhseries.GetObject,'BackgroundColor',[0 1 0])%put unactivated buttons to green
+end
+
+%------------------------------------------------------------------------
+% --- Executes on button press in PLOT: PLOT the defined object and its projected field
+function PLOT_Callback(hObject, eventdata, handles)
+
+%% reading the object parameters on the GUI uvmat
+huvmat=findobj('tag','uvmat');%find the current uvmat interface handle
+UvData=get(huvmat,'UserData');%Data associated to the GUI uvmat 
+hhuvmat=guidata(huvmat);%handles in the uvmat GUI
+ObjectName=get(handles.TITLE,'String');%name of the current object 
+ListObject=get(hhuvmat.list_object_1,'String');%position in the objet list
+IndexObj_1=get(hhuvmat.list_object_1,'Value');
+if isequal(get(hhuvmat.list_object_2,'Visible'),'on')
+    IndexObj_2=get(hhuvmat.list_object_2,'Value');
+    List2=get(hhuvmat.list_object_2,'String');
+    if IndexObj_2==length(List2)
+        IndexObj_2=[];% '...' selected
+    end
+else
+    IndexObj_2=[];
+end
+testnew=0;
+ObjectData=read_set_object(handles);%read the input parameters defining the object in the GUI set_object
+if strcmp(ListObject{IndexObj_1},ObjectName)% we are editing the object whose projection is viewed in the uvmat frame
+    IndexObj=IndexObj_1;
+    projview='uvmat';
+elseif ~isempty(IndexObj_2) && IndexObj_2<=numel(ListObject)&& strcmp(ListObject{IndexObj_2},ObjectName)% we are editing the object whose projection is viewed in view_field  
+    IndexObj=IndexObj_2;
+    projview='view_field';
+else %new object 
+    testnew=1;
+    IndexObj=numel(ListObject)+1;
+    projview='view_field';
+end
+if strcmp(projview,'view_field')
+    hview_field=findobj(allchild(0),'tag','view_field');
+    if isempty(hview_field)
+        hview_field=view_field;
+%     elseif strcmp(ObjectData.ProjMode,'none')||strcmp(ObjectData.ProjMode,'mask_inside')||strcmp(ObjectData.ProjMode,'mask_outside')
+    end
+    PlotHandles=guidata(hview_field);
+    plotaxes=PlotHandles.axes3;%handle of axes3 in view_field
+else
+    PlotHandles=hhuvmat;
+    plotaxes=hhuvmat.axes3;%handle of axes3 in view_field
+end   
+
+%% naming the object
+if length(ObjectName)<1% name of object not defined in set_object
+    ObjectName=[num2str(IndexObj) '-' ObjectData.Style];%default name
+elseif ~get(hhuvmat.edit_object,'Value')%not in edit mode (new object created)
+    detectname=1;
+    ObjectNameNew=ObjectName;
+    vers=0;
+    while detectname==1 
+        detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
+        if detectname% if the object name already exists
+            indstr=regexp(ObjectNameNew,'\D');
+            if indstr(end)<length(ObjectNameNew) %object name ends by a number
+                vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
+                ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
+            else
+                vers=vers+1;
+                ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];      
+            end
+        end
+    end
+    ObjectName=ObjectNameNew;
+end
+ListObject{IndexObj,1}=ObjectName;
+set(hhuvmat.list_object_1,'String',ListObject)
+set(hhuvmat.list_object_2,'String',[ListObject;{'...'}])
+
+%% update the object plot and projection field
+if testnew 
+    set(hhuvmat.list_object_2,'Value',IndexObj)
+    ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;
+    ObjectData.DisplayHandle_view_field=[];
+else
+    if isfield(UvData.Object{IndexObj},'DisplayHandle_uvmat')% save the previous object graph handles
+        ObjectData.DisplayHandle_uvmat=UvData.Object{IndexObj}.DisplayHandle_uvmat;
+    else
+        ObjectData.DisplayHandle_uvmat=hhuvmat.axes3;%there is no object handle, than the axes handles is used as input
+    end
+    if isfield(UvData.Object{IndexObj},'DisplayHandle_view_field')% save the previous object graph handles
+        ObjectData.DisplayHandle_view_field=UvData.Object{IndexObj}.DisplayHandle_view_field;
+    else
+        ObjectData.DisplayHandle_view_field=[];
+    end
+end
+UvData.Object{IndexObj}=ObjectData;%update the current object properties
+UvData.Object=update_obj(UvData,IndexObj_1,IndexObj_2);
+set(huvmat,'UserData',UvData)
+
+%% plot the field projected on the object and store in the corresponding figue
+ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
+PlotParam=read_plot_param(PlotHandles);
+[PlotType,Object_out{IndexObj}.PlotParam,plotaxes]=plot_field(ProjData,plotaxes,PlotParam);%update an existing field plot
+
+%% update the GUI uvmat
+hhuvmat=guidata(huvmat);%handles of elements in the uvmat GUI
+set(hhuvmat.MenuEditObject,'enable','on')
+set(hhuvmat.edit_object,'Value',1) % set uvmat to object edit mode to allow further object update
+set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
+%UvData.MouseAction='edit_object'; % set the edit button to 'on'
+
+%------------------------------------------------------------------------
+% --- Executes on button press in MenuCoord.
+function MenuCoord_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+%----------------------------------------------------
+function YMin_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+
+function ZMin_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+
+function ZMax_Callback(hObject, eventdata, handles)
+DZ=str2num(get(handles.ZMax,'String'));
+ZMin=get(handles.z_slider,'Min');
+ZMax=get(handles.z_slider,'Max');
+if ~isequal(ZMax-ZMin,0)
+    rel_step(1)=DZ/(ZMax-ZMin);
+    rel_step(2)=0.2;
+    set(handles.z_slider,'SliderStep',rel_step)
+end
+%------------------------------------------------------------------------
+function YMax_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+
+function XMin_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+
+function XMax_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+%------------------------------------------------------------------------
+function SAVE_Callback(hObject, eventdata, handles)
+% ------------------------------------------------------
+Object=read_set_object(handles);
+huvmat=findobj('Tag','uvmat');
+% UvData=get(huvmat,'UserData');
+if isempty(huvmat)
+    huvmat=findobj(allchild(0),'Name','series');
+end
+hchild=get(huvmat,'Children');
+hrootpath=findobj(hchild,'Tag','RootPath');
+if isempty(hrootpath)
+    RootPath='';
+else
+    RootPath=get(hrootpath,'String');
+    if iscell(RootPath)
+        RootPath=RootPath{1};
+    end
+end
+title={'object name'};
+dir_save=uigetdir(RootPath);
+ObjectName=get(handles.TITLE,'String');
+if ~isempty(ObjectName)&&~strcmp(ObjectName,'')
+    def={fullfile(dir_save,[ObjectName '.xml'])};
+else
+    def={fullfile(dir_save,[Object.Style '.xml'])};
+end
+displ_txt='save object as an .xml file';%default display
+menu=get(handles.ProjMode,'String');
+value=get(handles.ProjMode,'Value');
+ProjMode=menu{value};
+if strcmp(ProjMode,'mask_inside')||strcmp(ProjMode,'mask_outside')
+    displ_txt='save mask contour as an .xml file: to create a mask image, use save_mask on the GUI uvmat (lower right)';
+end
+answer=msgbox_uvmat('INPUT_TXT','save object as an .xml file',def);
+if ~isempty(answer)
+    t=struct2xml(Object);
+    save(t,answer{1})
+end
+msgbox_uvmat('CONFIRMATION',[answer{1}  ' saved'])
+%------------------------------------------------------------------------
+%------------------------------------------------------------------------
+% --- Executes on slider movement.
+function z_slider_Callback(hObject, eventdata, handles)
+%---------------------------------------------------------
+%A ADAPTER
+Z_value=get(handles.z_slider,'Value');
+
+%rotation angles
+Phi=(pi/180)*str2num(get(handles.Phi,'String'));%first Euler angle in radian
+Theta=(pi/180)*str2num(get(handles.Theta,'String'));%second Euler angle in radian
+
+%components of the unity vector normal to the projection plane
+NormVec_X=-sin(Phi)*sin(Theta);
+NormVec_Y=cos(Phi)*sin(Theta);
+NormVec_Z=cos(Theta);
+
+%set new plane position and update graph
+set(handles.XObject,'String',num2str(NormVec_X*Z_value,4))
+set(handles.YObject,'String',num2str(NormVec_Y*Z_value,4))
+set(handles.ZObject,'String',num2str(NormVec_Z*Z_value,4))
+PLOT_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+%------------------------------------------------------------------------
+% --- Executes on button press in HELP.
+function HELP_Callback(hObject, eventdata, handles)
+path_to_uvmat=which ('uvmat');% check the path of uvmat
+pathelp=fileparts(path_to_uvmat);
+helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
+if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
+else
+    addpath (fullfile(pathelp,'uvmat_doc'))
+    web([helpfile '#set_object']) 
+end
+%------------------------------------------------------------------------
+
+
Index: /trunk/src/write_plot_param.m
===================================================================
--- /trunk/src/write_plot_param.m	(revision 204)
+++ /trunk/src/write_plot_param.m	(revision 204)
@@ -0,0 +1,136 @@
+%'write_plot_param': update the plotting parameters on the uvmat interface after a plotting operation
+function write_plot_param(handles,PlotParam)
+%coordinates
+if isfield(PlotParam,'FixEqual')
+    if PlotParam.FixEqual
+        set(handles.FixEqual,'Value',1)
+        set(handles.FixEqual,'BackgroundColor',[1 1 0])
+    else
+        set(handles.FixEqual,'Value',0)
+        set(handles.FixEqual,'BackgroundColor',[0.7 0.7 0.7])
+    end
+end
+if isfield(PlotParam,'MinX')
+set(handles.MinX,'String',num2str(PlotParam.MinX,4));
+set(handles.MaxX,'String',num2str(PlotParam.MaxX,4));
+set(handles.MinY,'String',num2str(PlotParam.MinY,4));
+set(handles.MaxY,'String',num2str(PlotParam.MaxY,4));
+else
+    set(handles.MinX,'String','');
+set(handles.MaxX,'String','');
+set(handles.MinY,'String','');
+set(handles.MaxY,'String','');
+end
+
+%scalar or image parameters
+if isfield(PlotParam,'Scalar')
+    set_scal_display(handles,'on')
+    if isfield(PlotParam.Scalar,'MaxA')
+        set(handles.MaxA,'String',num2str(PlotParam.Scalar.MaxA,3));
+    end
+    if isfield(PlotParam.Scalar,'MinA')
+        set(handles.MinA,'String',num2str(PlotParam.Scalar.MinA,3));
+    end
+
+    if isfield(PlotParam.Scalar,'IncrA')
+        set(handles.IncrA,'String',num2str(PlotParam.Scalar.IncrA,3))
+    end
+else
+    set_scal_display(handles,'off')
+end
+
+% parameter for vector field
+if isfield(PlotParam,'Vectors')
+    set_vect_display(handles,'on')
+    if isfield(PlotParam.Vectors,'VecScale')
+        set(handles.VecScale,'String',num2str(PlotParam.Vectors.VecScale,3))
+    end
+    if isfield(PlotParam.Vectors,'MinC')&& isfield(PlotParam.Vectors,'MaxC')
+        MinC=PlotParam.Vectors.MinC;
+        MaxC=PlotParam.Vectors.MaxC;
+        set(handles.min_vec,'String', num2str(MinC,3));
+        set(handles.max_vec,'String',num2str(MaxC,3));
+        list=get(handles.color_code,'String');
+        ichoice=get(handles.color_code,'Value');
+    	color_option=list{ichoice};
+        test3color=strcmp(color_option,'rgb')||strcmp(color_option,'bgr');
+        if test3color% need to update color thresholds
+            set(handles.colcode1,'Visible','on')
+            set(handles.colcode2,'Visible','on')
+            set(handles.slider1,'Visible','on')
+            set(handles.slider2,'Visible','on')
+%             slider1=get(handles.slider1,'Value');
+%             slider2=get(handles.slider2,'Value');
+             colcode1=MinC+(MaxC-MinC)*PlotParam.Vectors.colcode1;
+             colcode2=MinC+(MaxC-MinC)*PlotParam.Vectors.colcode2;
+            set(handles.colcode1,'String',num2str(colcode1,3))
+            set(handles.colcode2,'String',num2str(colcode2,3))
+            set(handles.slider1,'Value',PlotParam.Vectors.colcode1)
+            set(handles.slider2,'Value',PlotParam.Vectors.colcode2)
+        else
+            set(handles.colcode1,'Visible','off')
+            set(handles.colcode2,'Visible','off')
+            set(handles.slider1,'Visible','off')
+            set(handles.slider2,'Visible','off')
+        end
+    end
+else
+    set_vect_display(handles,'off')
+    if isfield(handles,'edit_vect')
+        set(handles.edit_vect,'Visible','off')
+        set(handles.record,'Visible','off')
+    end
+end
+
+%------------------------------------------------------------------
+%prepare interface for scalar display: state ='on' or 'off'
+function set_scal_display(handles,state)
+%------------------------------------------------------------------
+% set(handles.SCALAR_title,'Visible',state)
+set(handles.MaxA,'Visible',state)
+set(handles.MinA,'Visible',state)
+%set(handles.IncrA,'Visible',state)
+set(handles.FixScal,'Visible',state)
+set(handles.BW,'Visible',state)
+set(handles.Contours,'Visible',state)
+set(handles.min_title,'Visible',state)
+set(handles.max_title,'Visible',state)
+%set(handles.frame_scal,'Visible',state)
+set(handles.npx,'Visible',state)
+set(handles.npy,'Visible',state)
+set(handles.npx_title,'Visible',state)
+set(handles.npy_title,'Visible',state)
+%set(handles.makemask,'Visible',state)
+
+%---------------------------------------------
+%prepare interface for vector display: state ='on' or 'off'
+function set_vect_display(handles,state)
+%------------------------------------------------------------------
+set(handles.frame_vect,'Visible',state)
+% set(handles.VECT_title,'Visible',state)
+set(handles.VecScale,'Visible',state)
+set(handles.FixVec,'Visible',state)
+set(handles.HideFalse,'Visible',state)
+set(handles.HideWarning,'Visible',state)
+% if isfield(handles,'record')
+%     set(handles.record,'Visible',state)
+% end
+set(handles.colcode1,'Visible',state)
+set(handles.colcode2,'Visible',state)
+set(handles.min_vec,'Visible',state)
+set(handles.max_vec,'Visible',state)
+set(handles.scale_title,'Visible',state)
+set(handles.slider1,'Visible',state)
+set(handles.slider2,'Visible',state)
+set(handles.col_vec,'Visible',state)
+set(handles.Color_title,'Visible',state)
+set(handles.color_code,'Visible',state)
+set(handles.vec_col_bar,'Visible',state)
+% set(handles.record,'Visible',state)
+set(handles.AutoVecColor,'Visible',state)
+set(handles.decimate4,'Visible',state)
+set(handles.min_C_title,'Visible',state)
+set(handles.max_C_title,'Visible',state)
+if isfield(handles,'MenuEditVectors')
+    set(handles.MenuEditVectors,'Enable',state)
+end
