Index: /trunk/src/calc_tps.m
===================================================================
--- /trunk/src/calc_tps.m	(revision 508)
+++ /trunk/src/calc_tps.m	(revision 508)
@@ -0,0 +1,21 @@
+function DataOut=calc_tps(DataIn)     
+DataOut=DataIn;%default
+SubDomain=1000; %default, estimated nbre of vectors in a subdomain used for tps
+if isfield(DataIn,'SubDomain')
+    SubDomain=DataIn.SubDomain;%
+end
+[DataOut.SubRange,DataOut.NbSites,DataOut.Coord_tps,DataOut.U_tps,DataOut.V_tps] =...
+    filter_tps([DataIn.X(DataIn.FF==0) DataIn.Y(DataIn.FF==0)],DataIn.U(DataIn.FF==0),DataIn.V(DataIn.FF==0),[],SubDomain,0);
+nbvar=numel(DataIn.ListVarName);
+DataOut.ListVarName=[DataIn.ListVarName {'SubRange','NbSites','Coord_tps','U_tps','V_tps'}];
+DataOut.VarDimName=[DataIn.VarDimName {{'nb_coord','nb_bounds','nb_subdomain'},{'nb_subdomain'},...
+    {'nb_tps','nb_coord','nb_subdomain'},{'nb_tps','nb_subdomain'},{'nb_tps','nb_subdomain'}}];
+DataOut.VarAttribute{nbvar+3}.Role='coord_tps';
+DataOut.VarAttribute{nbvar+4}.Role='vector_x';
+DataOut.VarAttribute{nbvar+5}.Role='vector_y';
+if isfield(DataOut,'ListDimName')%cleaning
+    DataOut=rmfield(DataOut,'ListDimName');
+end
+if isfield(DataOut,'DimValue')%cleaning
+    DataOut=rmfield(DataOut,'DimValue');
+end
Index: /trunk/src/check_field_structure.m
===================================================================
--- /trunk/src/check_field_structure.m	(revision 507)
+++ /trunk/src/check_field_structure.m	(revision 508)
@@ -28,5 +28,5 @@
     nbfield=numel(Data.ListVarName); 
 else
-    errormsg='input field does not contain the cell array of variable names .ListVarNames';
+    errormsg='input field does not contain the cell array of variable names .ListVarName';
     return
 end
Index: /trunk/src/datatree_browser.m
===================================================================
--- /trunk/src/datatree_browser.m	(revision 507)
+++ /trunk/src/datatree_browser.m	(revision 508)
@@ -80,5 +80,5 @@
         set(handles.UpdateLink,'String','create_link')
         set(handles.MarkupDir,'Visible','on')
-
+        
     else% opening by uvmat/Open
         InputDir=regexprep(InputName,'.xml$','');
@@ -94,10 +94,9 @@
                 set(handles.MarkupDir,'String','CreateLink')
             end
-        end
-                FillExperiments(handles)
-        set(handles.OK,'Visible','on')
-        drawnow
-        
+        end      
     end
+    FillExperiments(handles)
+    set(handles.OK,'Visible','on')
+    drawnow
 end
 
@@ -196,9 +195,9 @@
 MirrorPath='';
 if strcmp(get(handles.LinkDir,'Visible'),'on')
-MirrorPath=get(handles.LinkDir,'String');
+    MirrorPath=get(handles.LinkDir,'String');
 end
 ListExperiments=get(handles.ListExperiments,'String');
 if isequal(get(handles.ListExperiments,'Value'),1)
-    ListExperiments=ListExperiments(2:end); %choose all experiments
+    ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' has been selected
 else
     ListExperiments=ListExperiments(get(handles.ListExperiments,'Value'));
@@ -206,6 +205,9 @@
 ListDevices={};
 
+%% loop on the list of selected experiments
 for iexp=1:numel(ListExperiments)
-    hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and dirs
+    
+    % update the directory of the sources and update the links in the case of a link dir
+    hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and folders in the source
     for ilist=1:length(hdir)
         Device=hdir(ilist).name;
@@ -213,5 +215,5 @@
             if ~isempty(MirrorPath)% we list the links to the data directories of files
                 link=fullfile(MirrorPath,ListExperiments{iexp},Device);
-                if ~exist(link)
+                if ~exist(link)% create a link if it does not exist
                     source=fullfile(SourcePath,ListExperiments{iexp},Device);
                     system(['ln -s ' source ' ' link])%TODO translate for DOS
@@ -228,5 +230,34 @@
         end
     end
-end
+    
+    % check for dir and files in the link dir which do not exist in the source dir
+    if ~isempty(MirrorPath)
+        hdir=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and folders in the link dir
+        for ilist=1:length(hdir)
+            Device=hdir(ilist).name;
+            if ~isequal(Device(1),'.')
+                if hdir(ilist).isdir
+                    Device=[Device '/'];
+                end
+                check_list=strcmp(Device,ListDevices) | strcmp(['@' Device],ListDevices);
+                if isempty(find(check_list))
+                    ListDevices=[ListDevices;Device];
+                end
+            end
+        end
+    end
+end
+
+%% display the updated list, keeping track of the previously selected item
+PreviousList=get(handles.ListDevices,'String');
+NewValue=[];
+if ~isempty(PreviousList)&&iscell(PreviousList)
+    PreviousDevice=PreviousList{get(handles.ListDevices,'Value')};
+    NewValue=find(strcmp(PreviousDevice,ListDevices));
+end
+if isempty(NewValue)
+    NewValue=1;
+end
+set(handles.ListDevices,'Value',NewValue)
 set(handles.ListDevices,'String',ListDevices)
 
@@ -237,6 +268,6 @@
 %------------------------------------------------------------------------    
 list_val=get(handles.ListExperiments,'Value');
-if numel(list_val)~=1
-    msgbox_uvmat('ERROR','select a single experiment')
+if isequal(list_val,1) || numel(list_val)~=1
+    msgbox_uvmat('ERROR','select a single experiment in the column ''Experiments''')
     return
 end
@@ -253,29 +284,33 @@
 Device=ListDevices{get(handles.ListDevices,'Value')};
 Device=regexprep(Device,'^@','');
+
+%% open the selected file
+% case of a directory, open a file inside
 if strcmp(Device(end),'/')
     DataDir=fullfile(RootPath,Experiment,Device(1:end-1));
     DirList=dir(DataDir);
     for ilist=1:numel(DirList)
-        [tild,tild,FileExt]=fileparts(DirList(ilist).name);
-        FileExt=regexprep(FileExt,'^.','');
-        if ~isempty(FileExt) && (~isempty(imformats(FileExt))||strcmp(lower(FileExt),'avi')||strcmp(lower(FileExt),'nc'))
-            uvmat(fullfile(DataDir,DirList(ilist).name))
-            return
+        if ~DirList(ilist).isdir
+            [tild,tild,FileExt]=fileparts(DirList(ilist).name);
+            FileExt=regexprep(FileExt,'^.','');
+            if ~isempty(FileExt) && (~isempty(imformats(FileExt))||strcmp(lower(FileExt),'avi')||strcmp(lower(FileExt),'nc'))
+                uvmat(fullfile(DataDir,DirList(ilist).name))
+                return
+            end
         end
     end
-end
-% 
-% set(handles.ListRecords,'Value',1)
-% set(handles.ListXml,'Value',1)
-% ListDevices=get(handles.ListDevices,'String');
-% list_val=get(handles.ListDevices,'Value');
-% if isequal(list_val,1)
-%     ListDevices=ListDevices(2:end);
-% else
-%     ListDevices=ListDevices(list_val);
-% end
-% [ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
-% set(handles.ListRecords,'String',[{'*'};ListRecords'])
-% set(handles.ListXml,'String',[{'*'};ListXml'])
+    % open browser if no valid input file has been detected
+    [FileName, PathName] = uigetfile( ...
+            { '*.*', 'All Files (*.*)'}, ...
+            'Pick a mask file *.png',DataDir);
+    if ~isempty(FileName)
+        uvmat(fullfile(PathName,FileName));
+        return
+    end
+else %case of a file
+    uvmat(fullfile(RootPath,Experiment,Device))
+    return
+end
+
 
 
Index: /trunk/src/editxml.m
===================================================================
--- /trunk/src/editxml.m	(revision 507)
+++ /trunk/src/editxml.m	(revision 508)
@@ -55,5 +55,5 @@
 % set(handles.replicate,'String',['copy';'<---'])
 if nargin
-    CurrentFile=varargin{1}
+    CurrentFile=varargin{1};
 else
     CurrentFile=[];
@@ -330,34 +330,34 @@
     head_name=get(t,1,'name');
     %Path to shemas:
-    path_uvmat=which('editxml');% check the path detected for source file uvmat
-    path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+    path_uvmat=fileparts(which('editxml'));% check the path detected for source file uvmat
+    % path_UVMAT=fileparts(path_uvmat); %path to UVMAT
     %     xmlparam=fullfile(path_UVMAT,'PARAM.xml');
-    xmlparam='PARAM.xml'; %will find PARAM.xml whose path is set in priority
-    if exist(xmlparam,'file')
-        tparam=xmltree(xmlparam);
-        sparam=convert(tparam);
-        if isfield(sparam,'SchemaPath')
-            schemafile=[fullfile(sparam.SchemaPath,head_name) '.xsd'];           
-            if ~exist(schemafile,'file')
-                schemafile=fullfile(path_UVMAT,schemafile);%look for relative path definition
-            end
-            if exist(schemafile,'file')
-                xs=xmltree(schemafile);
-            else
-                msgbox_uvmat('ERROR',['The needed xml schema  ' sparam.SchemaPath ' is not found, check the file PARAM.xml'])
-                [FileName, PathName]=uigetfile( ...
-                    {'*.xsd', '(*.xsd)';
-                    '*.xsd',  '.xsd files '; ...
-                    '*.*',  'All Files (*.*)'}, ...
-                    'Pick a .xsd schema' ,schemafile); %file browser
-                if ischar(PathName) && ischar(FileName) && exist(fullfile(PathName,FileName),'file')
-                    DataIn.Schema=fullfile(PathName,FileName);
-                    xs=xmltree(DataIn.Schema);%open the associated schema file
-                else
-                    xs=[];
-                end
-            end
-        end
-    end
+    %     xmlparam='PARAM.xml'; %will find PARAM.xml whose path is set in priority
+    %     if exist(xmlparam,'file')
+    %         tparam=xmltree(xmlparam);
+    %         sparam=convert(tparam);
+    %         if isfield(sparam,'SchemaPath')
+    schemafile=[fullfile(path_uvmat,'xml_shemas',head_name) '.xsd'];
+    if ~exist(schemafile,'file')
+        schemafile=fullfile(path_UVMAT,schemafile);%look for relative path definition
+    end
+    if exist(schemafile,'file')
+        xs=xmltree(schemafile);
+    else
+        msgbox_uvmat('ERROR',['The needed xml schema  ' sparam.SchemaPath ' is not found, check the file PARAM.xml'])
+        [FileName, PathName]=uigetfile( ...
+            {'*.xsd', '(*.xsd)';
+            '*.xsd',  '.xsd files '; ...
+            '*.*',  'All Files (*.*)'}, ...
+            'Pick a .xsd schema' ,schemafile); %file browser
+        if ischar(PathName) && ischar(FileName) && exist(fullfile(PathName,FileName),'file')
+            DataIn.Schema=fullfile(PathName,FileName);
+            xs=xmltree(DataIn.Schema);%open the associated schema file
+        else
+            xs=[];
+        end
+    end
+    %         end
+    %     end
 end
 DataIn.CurrentUid=1;
Index: /trunk/src/set_object.m
===================================================================
--- /trunk/src/set_object.m	(revision 507)
+++ /trunk/src/set_object.m	(revision 508)
@@ -417,4 +417,7 @@
 function PLOT_Callback(hObject, eventdata, handles)
 
+set(handles.PLOT,'BackgroundColor',[1 1 0])
+drawnow
+
 %% read the object parameters in the GUI set_object
 ObjectData=read_GUI(handles.set_object);%read the parameters defining the object in the GUI set_object
@@ -482,7 +485,12 @@
     PlotType='text';
 else
+    % create tps coeff if needed for ProjMode 'filter'
+    if strcmp(ObjectData.ProjMode,'filter')&&~isfield(UvData.Field,'Coord_tps')     
+        UvData.Field=calc_tps(UvData.Field);
+    end
     [ProjData,errormsg]= proj_field(UvData.Field,ObjectData);%project the current field of uvmat on ObjectData
     if ~isempty(errormsg)
         msgbox_uvmat('ERROR', errormsg)
+        set(handles.PLOT,'enable','on')
         return
     end   
@@ -546,5 +554,6 @@
 set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
 set(hhuvmat.ViewField,'Value',1)
-
+% set(handles.PLOT,'enable','on')
+set(handles.PLOT,'BackgroundColor',[1 0 0])
 %------------------------------------------------------------------------
 % --- Executes on button press in MenuCoord.
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 507)
+++ /trunk/src/uvmat.m	(revision 508)
@@ -232,8 +232,8 @@
 
 %% refresh projection plane
-set(handles.ListObject,'Value',1)% default: empty projection objectproj_field
-set(handles.ListObject,'String',{'plane'})
-set(handles.ListObject_1,'Value',1)% default: empty projection objectproj_field
-set(handles.ListObject_1,'String',{'plane'})
+% set(handles.ListObject,'Value',1)% default: empty projection objectproj_field
+% set(handles.ListObject,'String',{''})
+% set(handles.ListObject_1,'Value',1)% default: empty projection objectproj_field
+% set(handles.ListObject_1,'String',{''})
 set(handles.Fields,'Value',1)
 set(handles.Fields,'string',{''})
@@ -685,20 +685,11 @@
     case 'xml'                % edit xml files
         t=xmltree(fileinput);
+        % the xml file marks a project or project link, open datatree_browser
         if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir')
             datatree_browser(fileinput)
-        else
+        else % other xml file, open the xml editor
             editxml(fileinput);
         end
-        %             if exist(regexprep(fileinput,'.project.xml$','.link'),'dir')
-        %                 datatree_browser(regexprep(fileinput,'.project.xml$','.link'))
-        %                 check_project=1;
-        %         elseif exist(regexprep(fileinput,'.project.xml$',''),'dir')
-        %                 datatree_browser(regexprep(fileinput,'.project.xml$',''))
-        %                 check_project=1;
-        %             end
-        %         end
-        %         if ~check_project
-        %         editxml(fileinput);
-    case 'xls'
+    case 'xls'% Excel file opended by editxml
         editxml(fileinput);
     otherwise
@@ -833,6 +824,4 @@
     return
 end
-% nbfield=[];%default
-% nbfield_j=[];%default
 
 %% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
@@ -849,5 +838,4 @@
     imainfo=get(VideoObject);
     testima=1;
-%     nbfield_j=1;
     TimeUnit='s';
     if isempty(j1_series); %frame index along i
@@ -987,6 +975,5 @@
             set(handles.transform_fct,'Value',2); % phys transform by default if fixedLimits is off
         end
-        if isfield(GeometryCalib,'SliceCoord')
-            
+        if isfield(GeometryCalib,'SliceCoord')            
            siz=size(GeometryCalib.SliceCoord);
            if siz(1)>1
@@ -1099,6 +1086,7 @@
 end
 
-%% view the field  
-run0_Callback([],[], handles); %view field
+%% apply the effect of the transform fct and view the field  
+transform_fct_Callback([],[],handles)
+%run0_Callback([],[], handles); %view field
 mask_test=get(handles.CheckMask,'value');
 if mask_test
@@ -1935,5 +1923,5 @@
 
 %% determine the main input file information for action
-FileType=[];%default
+% UvData.FileType{1}=[];%default
 if ~exist(FileName,'file')
     errormsg=['input file ' FileName ' does not exist'];
@@ -1945,5 +1933,4 @@
     NomType_1=get(handles.NomType_1,'String');
 end
-% NomType=get(handles.FileIndex,'UserData');
 %update the z position index
 nbslice_str=get(handles.num_NbSlice,'String');
@@ -1972,5 +1959,4 @@
     case {'civx','civdata','netcdf'};
         list_fields=get(handles.Fields,'String');% list menu fields
-%          index_fields=get(handles.Fields,'Value');% selected string index
         FieldName= list_fields{get(handles.Fields,'Value')}; % selected field
         if ~strcmp(FieldName,'get_field...')
@@ -2282,7 +2268,4 @@
 set(handles.abs_time,'String',num2str(abstime,5))
 set(handles.abs_time_1,'String',num2str(abstime_1,5))
-% if testimedoc && isfield(UvData,'dt')
-%     dt=UvData.dt;
-% end 
 if isempty(dt)||isequal(dt,0)
     set(handles.Dt_txt,'String','')
@@ -2327,5 +2310,6 @@
     end
 end
-    %% check whether tps is needed, then calculate tps coefficients if needed
+
+%% check whether tps is needed, then calculate tps coefficients if needed
 check_proj_tps=0;
 if isfield(UvData,'Object')&& (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx'))
@@ -2339,34 +2323,15 @@
 check_tps=0;         
 if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamOut.FieldName,'velocity')&&~strcmp(ParamOut.FieldName,'get_field...')
-       check_tps=1;
+       check_tps=1;%tps needed to get the requested field
 end
 if (check_tps ||check_proj_tps)&&~isfield(Field{1},'Coord_tps')
-    SubDomain=1000; %default, estimated nbre of vectors in a subdomain used for tps
-    if isfield(Field{1},'SubDomain')
-        SubDomain=Field{1}.SubDomain;% 
-    end
-    [Field{1}.SubRange,Field{1}.NbSites,Field{1}.Coord_tps,Field{1}.U_tps,Field{1}.V_tps,tild,U_smooth,V_smooth,W_smooth,FF] =...
-       filter_tps([Field{1}.X(Field{1}.FF==0) Field{1}.Y(Field{1}.FF==0)],Field{1}.U(Field{1}.FF==0),Field{1}.V(Field{1}.FF==0),[],SubDomain,0);
-    nbvar=numel(Field{1}.ListVarName);
-    Field{1}.ListVarName=[Field{1}.ListVarName {'SubRange','NbSites','Coord_tps','U_tps','V_tps'}];
-    Field{1}.VarDimName=[Field{1}.VarDimName {{'nb_coord','nb_bounds','nb_subdomain'},{'nb_subdomain'},...
-        {'nb_tps','nb_coord','nb_subdomain'},{'nb_tps','nb_subdomain'},{'nb_tps','nb_subdomain'}}];
-    Field{1}.VarAttribute{nbvar+3}.Role='coord_tps';
-    Field{1}.VarAttribute{nbvar+4}.Role='vector_x_tps';
-    Field{1}.VarAttribute{nbvar+5}.Role='vector_y_tps';
-    if isfield(Field{1},'ListDimName')%cleaning 
-        Field{1}=rmfield(Field{1},'ListDimName');
-    end
-    if isfield(Field{1},'DimValue')%cleaning 
-        Field{1}=rmfield(Field{1},'DimValue');
-    end
-end
+    Field{1}=calc_tps(Field{1});
+end
+Field{1}.FieldList=[{ParamOut.FieldName} {ParamOut.ColorVar}];
 
 %% calculate scalar
 if isstruct(ParamOut)&&~strcmp(ParamOut.FieldName,'get_field...')&& (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx'))...
          &&~strcmp(ParamOut.FieldName,'velocity') && ~strcmp(ParamOut.FieldName,'get_field...') 
-    if check_proj_tps
-        Field{1}.FieldList=[{ParamOut.FieldName} {ParamOut.ColorVar}];
-    else
+    if ~check_proj_tps
         Field{1}=calc_field([{ParamOut.FieldName} {ParamOut.ColorVar}],Field{1});
     end
@@ -2382,5 +2347,4 @@
 
 %% combine the two input fields (e.g. substract velocity fields)
-%Field{1}.FieldList=[{ParamOut.FieldName} {ParamOut.ColorVar}];
 if numel(Field)==2
    [UvData.Field,errormsg]=sub_field(Field{1},Field{2});  
@@ -2511,5 +2475,5 @@
     end
     % default projection plane
-    if ~isfield(UvData,'Object')
+    if ~isfield(UvData,'Object')||isempty(UvData.Object{1})
         UvData.Object{1}.Type='plane';%main plotting plane
         UvData.Object{1}.ProjMode='projection';%main plotting plane
@@ -2576,7 +2540,4 @@
     [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.axes3,read_GUI(handles.uvmat));
     write_plot_param(handles,PlotParamOut) %update the auto plot parameters
-%     if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
-%         ObjectData.Mesh=Field.Mesh; % gives an estimated mesh size (useful for mouse action on the plot)
-%     end
     
 %% 2D or 3D fields are generally projected
@@ -2590,6 +2551,12 @@
     list_object=get(handles.ListObject_1,'String');
     if isequal(list_object,{''})%refresh list of objects if the menu is empty
-        UvData.Object={[]};
+        set(handles.ListObject,'Value',1)
+        set(handles.ListObject,'String',{'plane'})
+        UvData.Object{1}.Type='plane';%main plotting plane
+        UvData.Object{1}.ProjMode='projection';%main plotting plane
+        UvData.Object{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
+        UvData.Object{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
         set(handles.ListObject_1,'Value',1)
+        set(handles.ListObject_1,'String',{'plane'})
     end
     IndexObj(1)=get(handles.ListObject_1,'Value');%selected projection object for main view
@@ -2636,9 +2603,5 @@
     for imap=1:numel(IndexObj)
         iobj=IndexObj(imap);
-        %      if imap==2 || check_proj==0  % field not yet projected) && ~isfield(UvData.Object{iobj},'Type')% case with no projection (only for the first empty object)
-        % %          [ObjectData,errormsg]=calc_field(UvData.Field.FieldList,UvData.Field);
-        % %      else
         [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object
-        %      end
         if ~isempty(errormsg)
             return
@@ -2706,12 +2669,4 @@
                 end
             end
-%             if isequal(PlotType,'none')
-%                 hget_field=findobj(allchild(0),'name','get_field');
-%                 if isempty(hget_field)
-%                     get_field(FileName)% the projected field cannot be automatically plotted: use get_field to specify the variablesdelete(hget_field)
-%                 end
-%                 errormsg='The field defined by get_field cannot be plotted';
-%                 return
-%             end
         end
     end
@@ -3424,5 +3379,5 @@
 else
     set(handles.VOLUME,'BackgroundColor',[0 1 0])
-    UvData.MouseAction='none';
+%     UvData.MouseAction='none';
 end
 set(handles.uvmat,'UserData',UvData)
@@ -3452,7 +3407,5 @@
     set(handles.record,'Visible','off')
     set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
-%     UvData.MouseAction='none';
-end
-% set(handles.uvmat,'UserData',UvData)
+end
 
 %----------------------------------------------
@@ -3546,8 +3499,9 @@
 %-------------------------------------------------------------
 % --- Executes on selection change in transform_fct.
+
 function transform_fct_Callback(hObject, eventdata, handles)
 %-------------------------------------------------------------
 UvData=get(handles.uvmat,'UserData');
-menu=get(handles.transform_fct,'String');
+menu=get(handles.transform_fct,'String');refresh
 ichoice=get(handles.transform_fct,'Value');%item number in the menu
 transform_name=menu{ichoice};% choice of the transform fct
@@ -3555,4 +3509,8 @@
 
 %% add a new item to the menu if the option 'more...' has been selected
+prev_path=fullfile(get(handles.path_transform,'String'));
+if ~exist(prev_path,'dir')
+    prev_path=fullfile(fileparts(which('uvmat')),'transform_field');
+end
 if strcmp(transform_name,'more...');
     [FileName, PathName] = uigetfile( ...
@@ -3560,5 +3518,5 @@
         '*.m',  '.m files '; ...
         '*.*', 'All Files (*.*)'}, ...
-        'Pick the transform function', get(handles.path_transform,'String'));
+        'Pick the transform function', prev_path);
     path_transform_fct =fullfile(PathName,FileName);
     if ~exist(path_transform_fct,'file')% cancel has been activated
@@ -3577,4 +3535,6 @@
     end
     list_path{ichoice}=PathName;%update the list fo fct paths
+    set(handles.transform_fct,'String',menu)
+    set(handles.transform_fct,'Value',ichoice)
     
     % save the new menu in the personal file 'uvmat_perso.mat'
@@ -3584,5 +3544,5 @@
         nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat
         for ilist=nb_builtin+1:numel(list_path)
-            transform_fct{ilist-nb_builtin}=fullfile(list_path{ilist},menu{ilist});
+            transform_fct{ilist-nb_builtin}=[fullfile(list_path{ilist},menu{ilist}) '.m'];
         end
         save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
@@ -3603,4 +3563,5 @@
     cd(current_dir)
 end
+set(handles.path_transform,'String',list_path{ichoice})
 set(handles.path_transform,'UserData',transform_handle)
 
@@ -3618,12 +3579,22 @@
 
 %% adapt the GUI to the input/output conditions of the selected transform fct
-if isempty(list_path{ichoice})% case of no selected fct
-    DataOut=[];
-else
-    if nargin(transform_handle)>1
-        if isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
-            XmlData=UvData.XmlData{1};
-            DataOut=feval(transform_handle,'*',XmlData);
-        end
+DataOut=[];
+CoordUnit='';
+CoordUnitPrev='';
+if isfield(UvData,'Field')&&isfield(UvData.Field,'CoordUnit')
+    CoordUnitPrev=UvData.Field.CoordUnit;
+end
+if ~isempty(list_path{ichoice}) 
+    if nargin(transform_handle)>1 && isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
+        XmlData=UvData.XmlData{1};
+        DataOut=feval(transform_handle,'*',XmlData);
+        if isfield(DataOut,'CoordUnit')
+            CoordUnit=DataOut.CoordUnit;
+        end
+        if isfield(DataOut,'InputFieldType')
+            UvData.InputFieldType=DataOut.InputFieldType;
+        end
+    else
+        DataOut=feval(transform_handle,'*');
     end
 end
@@ -3632,37 +3603,40 @@
 set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
 
-%% execute the function to set input an output conditions
-
-
-%% delete drawn objects
-hother=findobj('Tag','proj_object');%find all the proj objects
-for iobj=1:length(hother)
-    delete_object(hother(iobj))
-end
-hother=findobj('Tag','DeformPoint');%find all the proj objects
-for iobj=1:length(hother)
-    delete_object(hother(iobj))
-end
-hh=findobj('Tag','calib_points');
-if ~isempty(hh)
-    delete(hh)
-end
-hhh=findobj('Tag','calib_marker');
-if ~isempty(hhh)
-    delete(hhh)
-end
-if isfield(UvData,'Object')
-     UvData.Object=UvData.Object(1);
-end 
-set(handles.ListObject,'Value',1)
-set(handles.ListObject,'String',{'plane'})
-set(handles.ListObject_1,'Value',1)
-set(handles.ListObject_1,'String',{'plane'})
-
-%delete mask if it is displayed 
-% if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
-%    UvData=rmfield(UvData,'MaskName'); %will impose mask refresh  
-% end
+%% delete drawn objects if the output CooordUnit is different from the previous one
+if ~strcmp(CoordUnit,CoordUnitPrev)
+    hother=findobj('Tag','proj_object');%find all the proj objects
+    for iobj=1:length(hother)
+        delete_object(hother(iobj))
+    end
+    hother=findobj('Tag','DeformPoint');%find all the proj objects
+    for iobj=1:length(hother)
+        delete_object(hother(iobj))
+    end
+    hh=findobj('Tag','calib_points');
+    if ~isempty(hh)
+        delete(hh)
+    end
+    hhh=findobj('Tag','calib_marker');
+    if ~isempty(hhh)
+        delete(hhh)
+    end
+%     if isfield(UvData,'Object')
+%         UvData.Object=UvData.Object(1);
+%     end
+    set(handles.ListObject,'Value',1)
+    set(handles.ListObject,'String',{''})
+    set(handles.ListObject_1,'Value',1)
+    set(handles.ListObject_1,'String',{''})
+    set(handles.ViewObject,'value',0)
+    ViewObject_Callback(hObject, eventdata, handles)
+    set(handles.ViewField,'value',0)
+    ViewField_Callback(hObject, eventdata, handles)
+    set(handles.edit_object,'Value',0)
+    edit_object_Callback(hObject, eventdata, handles)
+    UvData.Object={[]};
+end
 set(handles.uvmat,'UserData',UvData)
+
+%% refresh the current plot
 run0_Callback(hObject, eventdata, handles)
 
@@ -4341,20 +4315,11 @@
 colorbar
 
-% %------------------------------------------------------
-% % --- Executes on button press in Menu/Export/extract figure.
-% %------------------------------------------------------
-% function MenuExport_plot_Callback(hObject, eventdata, handles)
-% huvmat=get(handles.MenuExport_plot,'parent');
-% UvData=get(huvmat,'UserData');
-% hfig=figure;
-% newaxes=copyobj(handles.axes3,hfig);
-% map=colormap(handles.axes3);
-% colormap(map);%transmit the current colormap to the zoom fig
-% colorbar
-
-% 
-% % --------------------------------------------------------------------
-% function Insert_Callback(hObject, eventdata, handles)
-% 
+% --------------------------------------------------------------------
+function MenuExportAxis_Callback(hObject, eventdata, handles)
+answer=msgbox_uvmat('CONFIRMATION','select a figure/axis on which the current uvmat plot will be exported')
+if strcmp(answer,'Yes')
+hchild=get(handles.axes3,'children');
+copyobj(hchild,gca);
+end
 
 %------------------------------------------------------------------------
@@ -4879,2 +4844,5 @@
 ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project source directory');
 datatree_browser(ProjectDir)
+
+
+
