Index: trunk/src/uvmat.m
===================================================================
--- trunk/src/uvmat.m	(revision 36)
+++ trunk/src/uvmat.m	(revision 38)
@@ -12,5 +12,5 @@
 %
 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-%  Copyright Joel Sommeria, Louis Gostiaux, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
+%  Copyright Joel Sommeria,  2008, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr.
 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 %     This open is part of the toolbox UVMAT.
@@ -199,14 +199,4 @@
 handles.output = hObject;
 
-% %group handles for input file in a structure handles.InputFile
-% handlesInputFile={handles.RootPath,handles.SubDir,handles.RootFile,handles.FileIndex,handles.FileExt};
-% TagsInputFile={'RootPath','SubDir','RootFile','FileIndex','FileExt'};
-% handles.InputFile=cell2struct(handlesInputFile,TagsInputFile,2);
-% 
-% %group handles for the second input file in a structure handles.InputFile_1
-% handlesInputFile={handles.RootPath_1,handles.SubDir_1,handles.RootFile_1,handles.FileIndex_1,handles.FileExt_1};
-% TagsInputFile={'RootPath','SubDir','RootFile','FileIndex','FileExt'};
-% handles.InputFile_1=cell2struct(handlesInputFile,TagsInputFile,2);
-
 % Update handles structure
 guidata(hObject, handles);
@@ -271,9 +261,9 @@
 %check the path of menu_coord transform
 %set(handles.menu_coord,'String',{'';'phys';'px';'more...'})
-path_fct{1}='';
-path_fct{2}=fileparts(path_to_uvmat);
-path_fct{3}=fileparts(path_to_uvmat);
-path_fct{4}=fileparts(path_to_uvmat);
-set(handles.menu_coord,'UserData',path_fct)
+% path_fct{1}='';
+% path_fct{2}=fileparts(path_to_uvmat);
+% path_fct{3}=fileparts(path_to_uvmat);
+% path_fct{4}=fileparts(path_to_uvmat);
+% set(handles.menu_coord,'UserData',path_fct)
 
 %case of an input argument for uvmat
@@ -283,5 +273,5 @@
 if exist('input','var')
     if ~isempty(errormsg)
-        warndlg_uvmat(errormsg,'WARNING')
+        msgbox_uvmat('WARNING',errormsg)
     end
     if ishandle(handles.UVMAT_title)
@@ -298,5 +288,5 @@
         sizinput=size(input);
         if sizinput(1)<=1 || sizinput(2)<=1
-            warndlg_uvmat('bad input for uvmat: file name, structure or numerical matrix accepted','ERROR')
+            msgbox_uvmat('ERROR','bad input for uvmat: file name, structure or numerical matrix accepted')
             return
         end
@@ -354,4 +344,51 @@
     end
 end
+
+%TRANSFORM menu: loads the information stored in prefdir to initiate the browser and the list of functions
+menu_str={'';'phys';'px';'phys_polar'};
+nb_builtin=numel(menu_str); %number of functions
+[path_uvmat,name,ext]=fileparts(which('uvmat'));
+addpath(fullfile(path_uvmat,'transform_field'))
+fct_handle{1,1}=[];
+testexist(1)=1;
+for ilist=2:length(menu_str)
+    if exist(menu_str{ilist},'file')
+        fct_handle{ilist,1}=str2func(menu_str{ilist});
+        testexist(ilist)=1;
+    else
+        testexist(ilist)=0;
+    end
+%     fct_handle{ilist,1}=fullfile(path_uvmat,'transform_field');%path to  the transform functions path_transform;
+end
+rmpath(fullfile(path_uvmat,'transform_field'))
+% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
+dir_perso=prefdir; 
+profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
+if exist(profil_perso,'file')
+    h=load (profil_perso);
+    if isfield(h,'transform_fct') && iscell(h.transform_fct)
+         for ilist=1:length(h.transform_fct)
+             [path,file]=fileparts(h.transform{ilist});
+             addpath(path)
+             if exist(file,'file')
+                h_func=str2func(path);
+                testexist=[testexist 1];
+             else
+                h_func=[];
+                testexist=[testexist 0]; 
+             end
+             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
+             rmpath(path)
+            % fct_path=[fct_path; {path}];%concatene the list of paths
+             menu_str=[menu_str; {file}];
+         end
+    end
+end
+menu_str=menu_str(find(testexist));
+fct_handle=fct_handle(find(testexist));
+menu_str=[menu_str;{'more...'}];
+set(handles.menu_coord,'String',menu_str)
+set(handles.menu_coord,'UserData',fct_handle)% store the list of path in UserData of ACTION
+
 set_vec_col_bar(handles)
 
@@ -408,5 +445,5 @@
 testblank=findstr(fileinput,' ');%look for blanks
 if ~isempty(testblank)
-    warndlg_uvmat(['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'],'ERROR')
+    msgbox_uvmat('ERROR',['The input file name ' fileinput ' contains blank character : This is not allowed. Please change name'])
     return
 end
@@ -906,5 +943,5 @@
 testblank=findstr(fileinput_1,' ');%look for blanks
 if ~isempty(testblank)
-    warndlg_uvmat(['The input file name ' fileinput_1 ' contains blank character : This is not allowed. Please change name'],'ERROR')
+    msgbox_uvmat('ERROR',['The input file name ' fileinput_1 ' contains blank character : This is not allowed. Please change name'])
     return
 end
@@ -1008,5 +1045,5 @@
 %         set(handles.FileIndex,'UserData',NomType_1);
     otherwise
-        warndlg_uvmat(['invalid input file extension ' FileExt_1 ' for uvmat'],'ERROR')
+        msgbox_uvmat(['invalid input file extension ' FileExt_1 ' for uvmat'],'ERROR')
         return
 end
@@ -1015,5 +1052,5 @@
 if nbfield_1 >1 %case of image with multiple frames
     if nbfield_1 < num_i1
-        warndlg_uvmat('current frame index beyond the input movie length','ERROR')
+        msgbox_uvmat('ERROR','current frame index beyond the input movie length')
         return
     else
@@ -1037,5 +1074,5 @@
         indices=''; %default
         if ~idetect
-            warndlg_uvmat('second input file with indices corresponding to the first one does not exist','ERROR')
+            msgbox_uvmat('ERROR','second input file with indices corresponding to the first one does not exist')
             return
         end 
@@ -1195,5 +1232,5 @@
 end   
 if ~isempty(TimeUnit_1) && ~isequal(TimeUnit_1,TimeUnit)
-        warndlg_uvmat('the time units for the second series differs from the first one','WARNING')
+        msgbox_uvmat('WARNING','the time units for the second series differs from the first one')
 end
         
@@ -1218,5 +1255,5 @@
 set(handles.last_j,'String',last_j_cell);
 if ~isequal(last_i_cell{1},last_i_cell{2}) || ~isequal(last_j_cell{1},last_j_cell{2})
-        warndlg_uvmat('the numbers of input file of the second series differs from the first one','WARNING')
+        msgbox_uvmat('WARNING','the numbers of input file of the second series differs from the first one')
 end
 
@@ -1244,5 +1281,5 @@
 
 if ~isequal(warntext,'')
-    warndlg_uvmat(warntext,'WARNING')
+    msgbox_uvmat('WARNING',warntext)
 end
 
@@ -1479,11 +1516,13 @@
         end
         %px to phys or other transform on field
-        menu_transform=get(handles.menu_coord,'String');
+         menu_transform=get(handles.menu_coord,'String');
         choice_value=get(handles.menu_coord,'Value');
-        transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
-        if  ~isequal(transform,'') && ~isequal(transform,'px')
+        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
+        transform_list=get(handles.menu_coord,'UserData');
+        transform=transform_list{choice_value};
+        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
             if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
                 Calib=UvData.XmlData.GeometryCalib;
-                Mask=feval(transform,Mask,UvData.XmlData);
+                Mask=transform(Mask,UvData.XmlData);
             end
         end
@@ -1675,5 +1714,5 @@
     UvData=get(huvmat,'UserData');
 else
-    warndlg_uvmat('an image or movie must be first introduced as input','ERROR')
+    msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
     return
 end
@@ -1686,5 +1725,5 @@
     [imaname_1,idetect]=name_generator(filebase,num_i1,num_j2,Ext,NomType);
     if idetect==0
-        warndlg_uvmat(['second input open (-)  ' imaname_1 ' not found'],'ERROR');
+        msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
         return
     end
@@ -1694,9 +1733,9 @@
     [imaname_1,idetect]=name_generator(filebase,num_i2,num_j1,Ext,NomType);
     if idetect==0
-        warndlg_uvmat(['second input open (-)  ' imaname_1 ' not found'],'ERROR');
+        msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
         return
     end
 else   
-    warndlg_uvmat('a second image index i2 or j2 is needed to show the pair as a movie','ERROR')
+    msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
     return
 end 
@@ -1704,7 +1743,4 @@
 %read the second image
 Field.AName='image';
-% Field.ListDimName={'AY','AX'}; %A FAIRE
-% Field.DimValue=[];
-% Field.ListVarName={'A'};
 Field.AX=UvData.Field.AX;
 Field.AY=UvData.Field.AY;
@@ -1716,8 +1752,10 @@
 menu_transform=get(handles.menu_coord,'String');
 choice_value=get(handles.menu_coord,'Value');
-transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
-if  ~isequal(transform,'') && ~isequal(transform,'px')
+transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
+transform_list=get(handles.menu_coord,'UserData');
+transform=transform_list{choice_value};
+if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
     if isfield(UvData,'XmlData') && isfield(UvData.XmlData,'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
-        Field=feval(transform,Field,UvData.XmlData);
+        Field=transform(Field,UvData.XmlData);
     end
 end
@@ -1996,12 +2034,12 @@
             [Field{2},var_detect]=nc2struct(filename_1,SubField.ListVarName); %read the corresponding input data                
             Field{2}.VarAttribute=SubField.VarAttribute;
-            if isequal(get(hhget_field.menu_coord,'Visible'),'on')
-                list_transform=get(hhget_field.menu_coord,'String');
-                val_list=get(hhget_field.menu_coord,'Value');
-                transf=list_transform{val_list};
-                if ~isempty(transf)
-                    Field{2}=feval(transf,Field{2});
-                end
-            end
+%             if isequal(get(hhget_field.menu_coord,'Visible'),'on')
+%                 list_transform=get(hhget_field.menu_coord,'String');
+%                 val_list=get(hhget_field.menu_coord,'Value');
+%                 transf=list_transform{val_list};
+%                 if ~isempty(transf)
+%                     Field{2}=feval(transf,Field{2});
+%                 end
+%             end
 
             %update the display on get_field
@@ -2135,5 +2173,7 @@
 menu_transform=get(handles.menu_coord,'String');
 choice_value=get(handles.menu_coord,'Value');
-transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
+%transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
+transform_list=get(handles.menu_coord,'UserData')
+transform=transform_list{choice_value}%selected function handles
 
 % z index
@@ -2142,13 +2182,15 @@
 end
 %px to phys or other transform on field
-if  ~isequal(transform,'') 
+if  ~isempty(transform) 
     if length(Field)>=2
         Field{2}.ZIndex=mod(num_i1-1,nbslice)+1;
-        [Field{1},Field{2}]=feval(transform,Field{1},XmlData,Field{2},XmlData_1);
+        [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
         if isempty(Field{2})
             Field(2)=[];
         end
     else
-        Field{1}=feval(transform,Field{1},XmlData);
+        'TESTrun'
+        Field{1}=transform(Field{1},XmlData);
+         Field{1}
     end
 end 
@@ -2612,5 +2654,5 @@
 nc=netcdf(filename,'write'); %open netcdf file
 result=redef(nc);
-if isempty(result), warndlg_uvmat('##Bad redef operation.','ERROR'),end
+if isempty(result), msgbox_uvmat('ERROR','##Bad redef operation.'),end
 test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
 if ~test_civ2
@@ -3708,5 +3750,5 @@
 imflag=flipdim(imflag,1);
 % imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
-warndlg_uvmat([mask_name ' saved'],'CONFIRMATION')
+msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
 imwrite(imflag,mask_name,'BitDepth',8); 
 
@@ -3968,5 +4010,5 @@
 ind_coord=get(handles.menu_coord,'Value');
 coord_option=menu{ind_coord};
-list_path=get(handles.menu_coord,'UserData');
+list_transform=get(handles.menu_coord,'UserData');
     
 if isequal(coord_option,'more...'); 
@@ -3995,9 +4037,11 @@
            msgbox_uvmat('ERROR',['image procesing fct ' coord_fct ' not found'])
     else
-       transform=FileName(1:end-2);% 
+       [ppp,transform]=fileparts(FileName);% removes extension .m
        menu=update_menu(handles.menu_coord,transform);%add the selected fct to the menu
        ind_coord=get(handles.menu_coord,'Value');
-       list_path{ind_coord}=PathName;
-       set(handles.menu_coord,'UserData',list_path)
+       addpath(PathName)
+       list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
+       set(handles.menu_coord,'UserData',list_transform)
+       rmpath(PathName)
        if exist(profil_perso,'file')
             save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
@@ -4007,12 +4051,13 @@
 
 %check the current path to the selected function
-PathName=list_path{ind_coord};
-CurrentPath=fileparts(which(coord_option));
-if ~isequal(PathName,CurrentPath)&&~isequal(CurrentPath,fullfile(PathName,'private'))
-    addpath(PathName) 
-    errormsg=check_functions;
-    msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
-end
-set(handles.path_transform,'String',fullfile(PathName,' ')); %show the path to the senlected function
+func=functions(list_transform{ind_coord})
+set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
+%CurrentPath=fileparts(which(coord_option));
+% if ~isequal(PathName,CurrentPath)
+%     addpath(PathName) 
+%     errormsg=check_functions;
+%     msgbox_uvmat('WARNING',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
+% end
+%set(handles.path_transform,'String',fullfile(PathName,' ')); %show the path to the senlected function
 set(handles.FixedLimits,'Value',0)
 set(handles.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
