Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 44)
+++ trunk/src/civ.m	(revision 45)
@@ -65,5 +65,5 @@
 %default initial parameters
 filebase=''; % root file name ('filebase'.civ)
-nom_type=[]; % nomenclature type
+%nom_type=[]; % nomenclature type
 ext=[];
 testall=0; 
@@ -111,12 +111,17 @@
 path_uvmat=which('uvmat');% check the path detected for source file uvmat
 path_UVMAT=fileparts(path_uvmat); %path to UVMAT
+errormsg=[];%default error message
 if isunix
     syst='LINUX';
-    %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names
     xmlfile=fullfile(path_UVMAT,'PARAM_LINUX.xml');
-    display(xmlfile)
     if exist(xmlfile,'file')
+        try
         t=xmltree(xmlfile);
         sparam=convert(t);
+        catch
+             errormsg={[' Problem for reading ' xmlfile]; lasterr};   
+        end
+    else
+        erromsg=[xmlfile ' not found: path to civx binaries undefined'];
     end
 else
@@ -124,9 +129,18 @@
     xmlfile=fullfile(path_UVMAT,'PARAM_WIN.xml');
     if exist(xmlfile,'file')
+        try
         t=xmltree(xmlfile);
         sparam=convert(t);
-    end
-end
-display(syst)  
+        catch
+             errormsg={[' Problem for reading ' xmlfile]; lasterr};
+        end
+    else
+        erromsg=[xmlfile ' not found: path to civx binaries undefined'];
+    end
+end
+display(syst)
+if ~isempty(errormsg)
+       msgbox_uvmat('ERROR',errormsg);
+end
 patch_new_exe='';
 % todo_patch='';
@@ -143,5 +157,4 @@
 end   
 name_todo=fullfile(todo_path,'TODO.txt');
-display(name_todo)
 test_batch=1;
 if ~sge
@@ -296,9 +309,9 @@
     t_browse=xmltree(fileinput);
     head_element=get(t_browse,1);
-    if isfield(head_element,'name')& isequal(head_element.name,'ImaDoc')
+    if isfield(head_element,'name')&& isequal(head_element.name,'ImaDoc')
         testeditxml=0;
     end
 end
-if testeditxml==1 | isequal(ext,'.xls')
+if testeditxml==1 || isequal(ext,'.xls')
    heditxml=editxml({fileinput});
    set(heditxml,'Tag','browser')
@@ -314,6 +327,14 @@
    end
 end
-[RootPath,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput);
+[RootPath,RootFile,str1,str2,str_a,str_b,ext,nom_type,subdir]=name2display(fileinput)
 filebase=fullfile(RootPath,RootFile);
+if isequal(nom_type,'*')% all fields in a single file ( movie files)
+    num_i1=1;num_i2=1;num_j1=1;num_j2=1;
+else
+    num_i1=str2double(str1);
+    num_i2=str2double(str2);
+    num_j1=str2double(str_a);
+    num_j2=str2double(str_b);
+end
 if isequal(get(handles.compare,'Value'),1)
     browse=[];%initialisation
@@ -321,12 +342,12 @@
     browse=get(handles.browse_root,'UserData');
 end
-if length(ext)>1 & (~isempty(imformats(ext([2:end])))|...
-                       isequal(ext,'.avi')|isequal(ext,'.AVI'));%if an image file has been opened by uvmat
+if length(ext)>1 && (~isempty(imformats(ext([2:end])))||...
+                       isequal(ext,'.avi')||isequal(ext,'.AVI'));%if an image file has been opened by uvmat
     set(handles.ext_ima,'String',ext)
     browse.nom_type_ima=nom_type;
-    browse.field_count=str2num(field_count);
-    A=imread(fileinput);
-    npxy=size(A);
-    set(handles.ext_ima,'UserData',npxy)
+    browse.field_count=num_i1;
+%     A=imread(fileinput);
+%     npxy=size(A);
+%     set(handles.ext_ima,'UserData',npxy)
 end
 set(handles.ImaDoc,'String',ext);
@@ -362,9 +383,9 @@
 set(handles.displ_filebase,'String',filebase);
 set(handles.ImaDoc,'String',ext);
-if ~isempty(str2num(field_count))
-    ref_i=str2num(field_count);
-    if ~isempty(str2num(str2))
-        ref_i=floor((ref_i+str2num(str2))/2);% reference image number corresponding to the file
-        browse.incr_pair(1)=str2num(str2)-str2num(field_count);
+if ~isempty(num_i1)
+    ref_i=num_i1;
+    if ~isempty(num_i2)
+        ref_i=floor((ref_i+num_i2)/2);% reference image number corresponding to the file
+        browse.incr_pair(1)=num_i2-num_i1;
         browse.incr_pair(2)=0;
     end
@@ -373,11 +394,11 @@
     set(handles.ref_i,'String',num2str(ref_i)); 
 end
-if isempty(str2num(str_a))
+if isempty(num_j1)
     set(handles.ref_j,'String','1');
 else
-    ref_j=str2num(str_a);
-    if ~isempty(str2num(str_b))
-        ref_j=floor((str2num(str_a)+str2num(str_b))/2);
-        browse.incr_pair(2)=str2num(str_b)-str2num(str_a); 
+    ref_j=num_j1;
+    if ~isempty(num_j2)
+        ref_j=floor((num_j1+num_j2)/2);
+        browse.incr_pair(2)=num_j2-num_j1; 
     end
     set(handles.first_j,'String',num2str(ref_j));
@@ -448,6 +469,4 @@
 field_count=1;%default
 nom_type_nc=[];
-% npx=[];%default 
-% npy=[];
 time=[];
 TimeUnit=[]; %default
@@ -555,7 +574,7 @@
         [PP,FF,fc,str2,str_a,str_b,ext_ima_read,nom_type_read]=name2display(XmlData.Heading.ImageName);
         fullname=fullfile(fileparts(filebase),XmlData.Heading.ImageName); %full name (including path) of the first image defined by the xmle file, 
-        if exist(fullname,'file')
-            testima_xml=1;
-        else
+        if ~exist(fullname,'file')
+%             testima_xml=1;
+%         else
             msgbox_uvmat('WARNING',['FirstImage ' fullname ' defined in the xml file does not exist'])
         end
@@ -569,8 +588,8 @@
            if ~isempty(ImageSize)&& ~isempty(ImageSize)
                xindex=findstr(ImageSize,'x');
-               if length(xindex)>=2
-                    npx=str2num(ImageSize(1:xindex(1)-1));
-                    npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
-               end
+%                if length(xindex)>=2
+%                     npx=str2num(ImageSize(1:xindex(1)-1));
+%                     npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
+%                end
            end
        end
@@ -994,17 +1013,17 @@
 %reads .nc subdirectoy and image numbers from the interface
 subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
-first_i=str2num(get(handles.first_i,'String'));
-last_i=str2num(get(handles.last_i,'String'));
-incr=str2num(get(handles.incr_i,'String'));
-num1=first_i:incr:last_i;
-if isempty(num1)
-    set(handles.list_pair_civ1,'String',{''});
-    return
-end
-ref_i=str2num(get(handles.ref_i,'String'));
+% first_i=str2num(get(handles.first_i,'String'));
+% last_i=str2num(get(handles.last_i,'String'));
+% incr=str2num(get(handles.incr_i,'String'));
+% num1=first_i:incr:last_i;
+% if isempty(num1)
+%     set(handles.list_pair_civ1,'String',{''});
+%     return
+% end
+ref_i=str2double(get(handles.ref_i,'String'));
 if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
     ref_j=0;
 else
-    ref_j=str2num(get(handles.ref_j,'String'));
+    ref_j=str2double(get(handles.ref_j,'String'));
 end
 time=get(handles.displ_filebase,'UserData');%get the set of times
@@ -1012,5 +1031,5 @@
     time=[0 1];
 end 
-dt_unit=str2num(get(handles.dt,'String'));% used when there is no image documentation file
+dt_unit=str2double(get(handles.dt,'String'));% used when there is no image documentation file
 displ_num=get(handles.list_pair_civ1,'UserData');
 
@@ -1034,5 +1053,4 @@
 testpair=0;
 if get(handles.CIV1,'Value')==0 %
-    dirname=fullfile(filepath,subdir_civ1,ext_dir);
     if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir') 
          msgbox_uvmat('ERROR',['no civ1 file available: subdirectory ' subdir_civ1 ' does not exist']);
@@ -1121,9 +1139,13 @@
 set(handles.list_pair_civ1,'String',displ_pair');
 ichoice=min(find(select));
-if (isempty(ichoice) | ichoice < 1); ichoice=1; end;
-initial=get(handles.list_pair_civ1,'Value');
-if initial>nbpair |~isequal(select(initial),1)
+if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
+initial=get(handles.list_pair_civ1,'Value');%initial choice of pair
+if initial>nbpair 
+     set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
+end
+if numel(select)>=initial && ~isequal(select(initial),1)
     set(handles.list_pair_civ1,'Value',ichoice);% first valid pair proposed by default in the menu
 end
+
 %set(handles.list_pair_civ2,'String',displ_pair');
 initial=get(handles.list_pair_civ2,'Value');
@@ -1187,13 +1209,13 @@
 subdir_civ1=get(handles.subdir_civ1,'String');%subdirectory subdir_civ1 for the netcdf data
 subdir_civ2=get(handles.subdir_civ2,'String');%subdirectory subdir_civ2 for the netcdf data
-first_i=str2num(get(handles.first_i,'String'));
-last_i=str2num(get(handles.last_i,'String'));
-incr=str2num(get(handles.incr_i,'String'));
-num1=first_i:incr:last_i;
-if isempty(num1)
-    set(handles.list_pair_civ2,'Value',1);
-    set(handles.list_pair_civ2,'String',{''});
-    return
-end
+% first_i=str2num(get(handles.first_i,'String'));
+% last_i=str2num(get(handles.last_i,'String'));
+% incr=str2num(get(handles.incr_i,'String'));
+% num1=first_i:incr:last_i;
+% if isempty(num1)
+%     set(handles.list_pair_civ2,'Value',1);
+%     set(handles.list_pair_civ2,'String',{''});
+%     return
+% end
 ref_i=str2num(get(handles.ref_i,'String'));
 if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
@@ -1319,12 +1341,12 @@
     find_pair_indices(handles,mode)
 %------------------------------------------------------------------------
-first_i=str2num(get(handles.first_i,'String'));%first index i 
-last_i=str2num(get(handles.last_i,'String'));%last index i 
-incr=str2num(get(handles.incr_i,'String'));% increment
+first_i=str2double(get(handles.first_i,'String'));%first index i 
+last_i=str2double(get(handles.last_i,'String'));%last index i 
+incr=str2double(get(handles.incr_i,'String'));% increment
 num_i=[first_i:incr:last_i];% list of i indices (reference values for each pair)
 if isequal(get(handles.first_j,'Visible'),'on')
-    first_j=str2num(get(handles.first_j,'String'));%first index j
-    last_j=str2num(get(handles.last_j,'String'));%last index j 
-    incr_j=str2num(get(handles.incr_j,'String'));% increment
+    first_j=str2double(get(handles.first_j,'String'));%first index j
+    last_j=str2double(get(handles.last_j,'String'));%last index j 
+    incr_j=str2double(get(handles.incr_j,'String'));% increment
 else
     first_j=1;
@@ -1360,9 +1382,9 @@
     str_raw=str_civ1(indsel);
     indsepar=find(str_raw=='|'); %character index of the separator
-    d1=str2num(str_civ1([indsel(indsepar-1)+1:indsel(indsepar)-1]));
+    d1=str2double(str_civ1([indsel(indsepar-1)+1:indsel(indsepar)-1]));
     if indsepar==length(str_raw)
-        d2=str2num(str_civ1([indsel(indsepar)+1:end]));
+        d2=str2double(str_civ1([indsel(indsepar)+1:end]));
     else
-        d2=str2num(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
+        d2=str2double(str_civ1([indsel(indsepar)+1:indsel(indsepar+1)-1]));
     end   
     num1_civ1=num_i-d1;% set of first image numbers
@@ -1609,5 +1631,5 @@
 
 %read names of the .exe file 
-if box_test(1)==1 | box_test(3)==1 | box_test(4)==1 | box_test(6)==1 
+if box_test(1)==1 || box_test(3)==1 || box_test(4)==1 || box_test(6)==1 
     path_uvmat=which('uvmat');% check the path detected for source file uvmat
     path_UVMAT=fileparts(path_uvmat); %path to UVMAT
@@ -1629,10 +1651,19 @@
     if isfield(sparam,'Civ1_exe')
         civ1_exe=sparam.Civ1_exe;
+        if isequal(civ1_exe(1:4),'civx')%the binary is defined in /civx, default setting
+            civ1_exe=fullfile(path_UVMAT,civ1_exe);
+        end
     end
     if isfield(sparam,'Civ2_exe')
         civ2_exe=sparam.Civ2_exe;
+        if isequal(civ2_exe(1:4),'civx')%the binary is defined in /civx, default setting
+            civ2_exe=fullfile(path_UVMAT,civ2_exe);
+        end
     end
     if isfield(sparam,'Patch_exe')
         patch_exe=sparam.Patch_exe;
+        if isequal(patch_exe(1:4),'civx')%the binary is defined in /civx, default setting
+            patch_exe=fullfile(path_UVMAT,patch_exe);
+        end
     end
     if isfield(sparam,'Stinterp_exe')
@@ -1640,5 +1671,5 @@
     end
     if isfield(sparam,'SGE')
-        sge=str2num(sparam.SGE);
+        sge=str2double(sparam.SGE);
     end 
     if ~isunix % for windows system, check whether the Matlab working dir is a UBC name
@@ -1692,14 +1723,14 @@
     field1.vel_type='civ1';
     field1.nb='nb_vectors';
-    field1.X='vec_X';
-    field1.Y='vec_Y';
-    field1.U='vec_U';
-    field1.V='vec_V';
+%     field1.X='vec_X';
+%     field1.Y='vec_Y';
+%     field1.U='vec_U';
+%     field1.V='vec_V';
     field1.fixflag='vec_FixFlag';
     flagindex(1)=get(handles.vec_Fmin2, 'Value');
     flagindex(2)=get(handles.vec_F3, 'Value');
     flagindex(3)=get(handles.vec_F2, 'Value');
-    thresh_vecC=str2num(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
-    thresh_vel=str2num(get(handles.thresh_vel,'String'));%threshold on velocity modulus
+    thresh_vecC=str2double(get(handles.thresh_vecC,'String'));%threshold on image correlation vec_C
+    thresh_vel=str2double(get(handles.thresh_vel,'String'));%threshold on velocity modulus
     inf_sup=get(handles.inf_sup1,'Value');
     menu=get(handles.field_ref1,'String');
@@ -1710,5 +1741,5 @@
         fieldchoice=menu{index};
     end   
-    h = waitbar(0,['removing velocity vectors, fix1']);% display a wait bar 
+    h = waitbar(0,'removing velocity vectors, fix1');% display a wait bar 
     test_mask=get(handles.get_mask_fix1,'Value');    
     if test_mask
@@ -1728,5 +1759,5 @@
                 maskflag=0;
             elseif test_mask==1
-                nbslice_mask=str2num(maskdispl(1:end-4)); % 
+                nbslice_mask=str2double(maskdispl(1:end-4)); % 
                 num1_mask=mod(num1_civ1(ifile)-1,nbslice_mask)+1;
                 maskname=name_generator(maskbase,num1_mask,1,'.png','_i');% mask corresponding to the first image of the pair
@@ -3291,15 +3322,56 @@
 
 %COPY IMAGES TO THE FORMAT .png IF NEEDED
-if isequal(nom_type_ima1,'*')
-    nom_type_imanew='_i';
+if isequal(nom_type_ima1,'*')%case of movie files
+    nom_type_imanew1='_i';
 else
     nom_type_imanew1=nom_type_ima1;
 end
-if isequal(nom_type_ima2,'*')
-    nom_type_imanew='_i';
+if isequal(nom_type_ima2,'*')%case of movie files
+    nom_type_imanew2='_i';
 else
     nom_type_imanew2=nom_type_ima2;
 end
 if ~isequal(ext_ima,'.png')
+    %%type of image file
+    type_ima1='none';%default
+    movieobject1=[];%default
+    if isequal(lower(ext_ima),'.avi')
+        hhh=which('mmreader');
+        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
+            type_ima1='movie';
+            movieobject1=mmreader([filebase_ima2 ext_ima]);
+        else
+            type_ima1='avi';
+        end
+    else 
+       form=imformats(ext_ima(2:end));
+       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
+           if isequal(nom_type_ima1,'*');
+               type_ima1='multimage';%image series in a single image file
+           else
+               type_ima1='image';
+           end
+       end
+    end
+    type_ima2='none';%default
+    movieobject2=[];
+    if isequal(lower(ext_ima),'.avi')
+        hhh=which('mmreader');
+        if ~isequal(hhh,'')&& mmreader.isPlatformSupported()% if the mmreader function is found (recent version of matlab)
+            type_ima2='movie';
+            movieobject2=mmreader([filebase_ima2 ext_ima]);
+        else
+            type_ima2='avi';
+        end
+    else 
+       form=imformats(ext_ima(2:end));
+       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
+           if isequal(nom_type_ima1,'*');
+               type_ima2='multimage';%image series in a single image file
+           else
+               type_ima2='image';
+           end
+       end
+    end
     %npxy=get(handles.ext_ima,'UserData');
 % %     if numel(npxy)<2
@@ -3318,5 +3390,5 @@
                     filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
                     if ~exist(filename,'file')
-                        A=read_image(filecell.ima1.civ1{ifile,j},nom_type_ima2,num1_civ1(ifile));
+                        A=read_image(filecell.ima1.civ1{ifile,j},type_ima1,num1_civ1(ifile),movieobject1);
                         imwrite(A,filename,'BitDepth',16); 
                     end
@@ -3324,5 +3396,5 @@
                     filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
                     if ~exist(filename,'file')
-                        A=read_image(filecell.ima2.civ1{ifile,j},nom_type_ima2,num2_civ1(ifile));
+                        A=read_image(filecell.ima2.civ1{ifile,j},type_ima2,num2_civ1(ifile),movieobject2);
                         imwrite(A,filename,'BitDepth',16);
                     end
@@ -4970,5 +5042,5 @@
 path_to_uvmat=which ('uvmat');% check the path of uvmat
 pathelp=fileparts(path_to_uvmat);
-helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
+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
@@ -4979,51 +5051,23 @@
 %------------------------------------------------------------------------
 %--read images and convert them to the uint16 format used for PIV
-function A=read_image(filename,nom_type,npx,npy,num);
-%------------------------------------------------------------------------
-%npx, npy are the dimensions needed for the raw SMD images
+function A=read_image(filename,type_ima,num,movieobject)
+%------------------------------------------------------------------------
 %num is the view number needed for an avi movie
-if isequal(nom_type,'avi')
-    mov=aviread(filename,num);
-    A=frame2im(mov(1));
+switch type_ima
+    case 'movie'
+        A=read(movieobject,num);
+    case 'avi'
+        mov=aviread(filename,num);
+        A=frame2im(mov(1));
+    case 'multimage'
+        A=imread(filename,num);
+    case 'image'    
+        A=imread(filename);
+end
+siz=size(A);
+if length(siz)==3;%color images
     A=sum(double(A),3);
     A=uint16(A);
-elseif isequal(nom_type,'raw_SMD')
-    [fid,message]=fopen(filename,'r');    
-    B=fread(fid,Inf,'int16',0,'ieee-le');%read 16 bit binary file
-    A=(reshape(B,npx,npy))'; %remplissage ligne par ligne avec une matrice colonne ? transposer(uB) pour avoir une matrice ligne
-    A=uint16(A);
-    fclose(fid);
-else
-    A=imread(filename);
-    siz=size(A);
-    if length(siz)==3;%color images
-        A=sum(double(A),3);
-    end
-    A=uint16(A);
-end
-
-% %----------------------------------------------------------------
-% %Executes on carriage return on the time interval dt
-% %----------------------------------------------------------------
-% function dt_Callback(hObject, eventdata, handles)
-% %determine the set of times and possible intervals for CIV
-% %                 answer=inputdlg('time interval between images?');
-%                 dt=(1/1000)*str2num(get(handles.dt,'String'));
-%                 nbfield=str2num(get(handles.nb_field,'String')); %last image number selected in the processing series
-%                 time=(dt*[0:nbfield-1])';
-% %                 set(handles.incr_i,'UserData',dt);%store the time interval between successive images
-%                 set(handles.displ_filebase,'UserData',time); %store the set of times
-%                 for index=1:min(nbfield-1,200)
-%                     displ_num(1,index)=1;
-%                     displ_num(2,index)=1;
-%                     displ_num(3,index)=-floor(index/2);
-%                     displ_num(4,index)=ceil(index/2);
-%                 end
-% set(handles.list_pair_civ1,'Value',1);
-% set(handles.list_pair_civ1,'UserData',displ_num);
-% set(handles.list_pair_civ2,'Value',1);
-% %update the list of time intervals
-% find_netcpair_civ1(hObject, eventdata, handles)
-% find_netcpair_civ2(hObject, eventdata, handles)
+end
 
 %------------------------------------------------------------------------
@@ -5033,9 +5077,7 @@
 mode_value=get(handles.mode,'Value');
 mode=mode_list{mode_value};
-%if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Di)') 
-    find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
-%end
+find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
 if isequal(mode,'series(Di)') || ...% we do patch2 only
-   (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
+   (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
     find_netcpair_civ2(hObject, eventdata, handles);
 end
@@ -5047,9 +5089,9 @@
 mode_value=get(handles.mode,'Value');
 mode=mode_list{mode_value};
-if isequal(get(handles.CIV1,'Value'),0)| isequal(mode,'series(Dj)') 
+if isequal(get(handles.CIV1,'Value'),0)|| isequal(mode,'series(Dj)') 
     find_netcpair_civ1(hObject, eventdata, handles);% update the menu of pairs depending on the available netcdf files
 end
-if isequal(mode,'series(Dj)') | ...
-   (get(handles.CIV2,'Value')==0 & get(handles.CIV1,'Value')==0 & get(handles.FIX1,'Value')==0 & get(handles.PATCH1,'Value')==0)
+if isequal(mode,'series(Dj)') || ...
+   (get(handles.CIV2,'Value')==0 && get(handles.CIV1,'Value')==0 && get(handles.FIX1,'Value')==0 && get(handles.PATCH1,'Value')==0)
     find_netcpair_civ2(hObject, eventdata, handles);
 end
@@ -5153,11 +5195,11 @@
 menu_field{1}='civ1';
 Data=nc2struct(fileinput,[]);
-if isfield(Data,'patch') & isequal(Data.patch,1)
+if isfield(Data,'patch') && isequal(Data.patch,1)
     menu_field{2}='filter1';
 end
-if isfield(Data,'civ2') & isequal(Data.civ2,1)
+if isfield(Data,'civ2') && isequal(Data.civ2,1)
     menu_field{3}='civ2';
 end
-if isfield(Data,'patch2') & isequal(Data.patch2,1)
+if isfield(Data,'patch2') && isequal(Data.patch2,1)
     menu_field{4}='filter2';
 end
@@ -5181,5 +5223,5 @@
     fileinput=[PathName FileName];
     sizf=size(fileinput);
-    if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
+    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
     [Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
     ref.filebase=fullfile(Path,File);
Index: trunk/src/nc2struct.m
===================================================================
--- trunk/src/nc2struct.m	(revision 44)
+++ trunk/src/nc2struct.m	(revision 45)
@@ -75,5 +75,9 @@
     if isequal(List{1},'ListGlobalAttribute')
         for ilist=2:numel(List)
+            try
             valuestr = netcdf.getAtt(nc,netcdf.getConstant('NC_GLOBAL'),List{ilist});
+            catch
+                valuestr=[];
+            end
             eval(['Data.' List{ilist} '=valuestr;'])
         end
Index: trunk/src/struct2nc.m
===================================================================
--- trunk/src/struct2nc.m	(revision 44)
+++ trunk/src/struct2nc.m	(revision 45)
@@ -102,5 +102,7 @@
                 for iattr=1:length(attr_names)
                     eval(['attr_val=VarAttribute{ivar}.' attr_names{iattr} ';']);
-                    netcdf.putAtt(nc,varid(ivar),attr_names{iattr},attr_val);
+                    if ~isempty(attr_names{iattr})&& ~isempty(attr_val)
+                        netcdf.putAtt(nc,varid(ivar),attr_names{iattr},attr_val);
+                    end
                 end
             end
Index: trunk/src/uvmat.m
===================================================================
--- trunk/src/uvmat.m	(revision 44)
+++ trunk/src/uvmat.m	(revision 45)
@@ -5,4 +5,5 @@
 %OUTPUT
 % huvmat=current handles of the GUI uvmat.fig
+%%
 %
 %INPUT:
@@ -80,5 +81,5 @@
 %               Main input open   second input open(_1)        second image (pair animation) 
 % read_ncfield.m         |                 |                             
-% read_image.m           |                 |                                                
+% read image.m           |                 |                                                
 %                     Field{1}         Field{2}               
 %                                                                         |
@@ -225,7 +226,8 @@
 menu_str={'';'phys';'px';'phys_polar'};
 nb_builtin=numel(menu_str); %number of functions
-[path_uvmat,name,ext]=fileparts(which('uvmat'));
+path_uvmat=fileparts(which('uvmat'));
 addpath(fullfile(path_uvmat,'transform_field'))
 fct_handle{1,1}=[];
+testexist=zeros(size(menu_str));%default
 testexist(1)=1;
 for ilist=2:length(menu_str)
@@ -270,17 +272,17 @@
              if exist(file,'file')
                 h_func=str2func(file);
-                testexist=[testexist 1];
+                testexist=[testexist 1]; %#ok<AGROW>
              else
                 h_func=[];
-                testexist=[testexist 0]; 
+                testexist=[testexist 0];  %#ok<AGROW>
              end
-             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
+             fct_handle=[fct_handle; {h_func}];%#ok<AGROW> %concatene the list of paths
              rmpath(path)
-             menu_str=[menu_str; {file}];
+             menu_str=[menu_str; {file}]; %#ok<AGROW>
          end
       end
  end
-menu_str=menu_str(find(testexist));
-fct_handle=fct_handle(find(testexist));
+menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
+fct_handle=fct_handle(testexist==1);
 menu_str=[menu_str;{'more...'}];
 set(handles.transform_fct,'String',menu_str)
@@ -295,5 +297,5 @@
 path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat
 [errormsg,date_str]=check_functions;%check the path of the functions called by uvmat.m
-
+date_str=['last modification: ' date_str];
 %case of an input argument for uvmat
 testinputfield=0;
@@ -346,5 +348,5 @@
        if fid~=-1
         a=textscan(fid,'%s%s%s',1,'HeaderLines',1,'Delimiter','|');
-        set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; ['at revision ' a{1}{1}]};a{3}{1};errormsg]);
+        set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; ['at revision ' a{1}{1}]};a{3}{1};date_str;errormsg]);
         fclose(fid);
        else
@@ -819,12 +821,12 @@
    set(handles.Fields,'Value',1) % set menu to 'image'
    set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
-elseif isequal(FileExt,'.nc')|isequal(FileExt,'.cdf')
+elseif isequal(FileExt,'.nc')||isequal(FileExt,'.cdf')
    Data=nc2struct(FileName,[]);
    col_vec=get(handles.col_vec,'String');
-   if isfield(Data,'absolut_time_T0')&& (isfield(Data,'civ1')||isfield(Data,'civ'))
+   if isfield(Data,'absolut_time_T0')%&& (isfield(Data,'civ1')||isfield(Data,'civ'))
        set(handles.Fields,'String',{'image';'get_field...';'velocity';'vort';'div';'more...'})
        set(handles.Fields,'Value',3) % set menu to 'velocity'
        col_vec{1}='ima_cor';
-   else
+   else %general netcdf file (not civx)
        set(handles.Fields,'Value',1) % set menu to 'get_field...
        set(handles.Fields,'String',{'get_field...'})
@@ -1270,5 +1272,4 @@
 set_scan_options(hObject, eventdata, handles)
 
-
 %---------------------------------------------------
 % switch file index scanning options scan_i and scan_j in an exclusive way
@@ -1284,9 +1285,8 @@
     set(handles.scan_j,'BackgroundColor',[1 1 0])
 end
-%-------------------------------------------------------------------
-%---------------------------------------------------
+
+%-------------------------------------------------------------------
 % switch file index scanning options scan_i and scan_j in an exclusive way
 function scan_j_Callback(hObject, eventdata, handles)
-%---------------------------------------------------
 %-------------------------------------------------------------------
 if get(handles.scan_j,'Value')==1
@@ -1304,5 +1304,5 @@
 %-------------------------------------------------------------------
 % [filebase,num1,num_a,num2,num_b,ext,NomType,subdir]=read_input_file(handles);
-[FileName,RootPath,filebase,xx,FileExt]=read_file_boxes(handles);
+%[FileName,RootPath,filebase,xx,FileExt]=read_file_boxes(handles);
 NomType=get(handles.FileIndex,'UserData');
 num1=stra2num(get(handles.i1,'String'));
@@ -1690,8 +1690,8 @@
 index_fields=get(handles.Fields,'Value');% selected string index
 FieldName=list_fields{index_fields}; % selected field
-huvmat=get(handles.movie_pair,'parent');
+%huvmat=get(handles.movie_pair,'parent');
 if isequal(FieldName,'image')
     run0_Callback(hObject, eventdata, handles)%display the first image
-    UvData=get(huvmat,'UserData');
+    UvData=get(handles.uvmat,'UserData');
 else
     msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
@@ -1727,6 +1727,34 @@
 Field.AY=UvData.Field.AY;
 Field.CoordType='px';
-[Field.A,error]=read_image(imaname_1,NomType,num_i2);
-
+%determine the input file type
+if isfield(UvData,'MovieObject')
+    FileType='movie';
+elseif isequal(lower(Ext),'.avi')
+    FileType='avi';
+elseif isequal(lower(Ext),'.vol')
+    FileType='vol';
+else 
+   form=imformats(Ext([2:end]));
+   if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
+       if isequal(NomType,'*');
+           FileType='multimage';
+       else
+           FileType='image';
+       end
+   end
+end
+switch FileType
+        case 'movie'
+            Field.A=read(UvData.MovieObject,num_i2);
+        case 'avi'
+            mov=aviread(imaname_1,num_i2);
+            Field.A=frame2im(mov(1));
+        case 'vol'
+            Field.A=imread(imaname_1);
+        case 'multimage'
+            Field.A=imread(imaname_1,num_i2);
+        case 'image'
+            Field.A=imread(imaname_1);
+end 
 
 %px to phys or other transform on field
@@ -1747,5 +1775,5 @@
 set(handles.speed,'Visible','on')
 set(handles.speed_txt,'Visible','on')
-while get(handles.speed,'Value')~=0 & isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
+while get(handles.speed,'Value')~=0 && isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
     % read and plot the series of images in non erase mode
     set(hima,'CData',Field.A); 
@@ -1755,6 +1783,4 @@
 end
 set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
-
-%run0_Callback(hObject, eventdata, handles)
 
 %-------------------------------------------------------
@@ -1769,8 +1795,8 @@
 abstime_1=[];
 dt=[];
-CalibCell={};%default 
+% CalibCell={};%default 
 Field={};
-huvmat=get(handles.run0,'parent');
-UvData=get(huvmat,'UserData');
+%huvmat=get(handles.run0,'parent');
+UvData=get(handles.uvmat,'UserData');
 if isfield(UvData,'Txt')
     UvData=rmfield(UvData,'Txt');%erase previous error message
@@ -1787,6 +1813,7 @@
 end
 num_i1=[];%default
+FileType=[];%default
 if TestInputFile
-    [filename,RootPath,filebase,xx,Ext,SubDir]=read_file_boxes(handles);
+    [filename,RootPath,filebase,xx,Ext]=read_file_boxes(handles);
     if ~exist(filename,'file')
         msgbox_uvmat('ERROR',['input file ' filename ' does not exist'])
@@ -1802,6 +1829,6 @@
 %         set(handles.z_index,'String',get(handles.j1,'String'));
 %     else
-    nbslice=str2num(get(handles.nb_slice,'String'));
-    z_index=mod(num_i1-1,nbslice)+1;
+    nbslice=str2double(get(handles.nb_slice,'String'));
+%     z_index=mod(num_i1-1,nbslice)+1;
     if ~isempty(nbslice)
         z_index=mod(num_i1-1,nbslice)+1;
@@ -1813,14 +1840,24 @@
         end
     end
-%     end
-    % choose the main field 
-    testima=0;
-    if isequal(lower(Ext),'.avi')||isequal(lower(Ext),'.vol')
-       testima=1; 
-       FieldName='image';
+    % determine the input file type
+    if isequal(Ext,'.nc')||isequal(Ext,'.cdf')
+        FileType='netcdf';
+    elseif isfield(UvData,'MovieObject')
+        FileType='movie';
+        FieldName='image';
+    elseif isequal(lower(Ext),'.avi')
+        FileType='avi';
+        FieldName='image';
+    elseif isequal(lower(Ext),'.vol')
+        FileType='vol';
+        FieldName='image';
     else 
        form=imformats(Ext([2:end]));
        if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
-           testima=1;
+           if isequal(NomType,'*');
+               FileType='multimage';
+           else
+               FileType='image';
+           end
            FieldName='image';
        end
@@ -1828,10 +1865,9 @@
 else
     filename=[];
+    FileType='netcdf';
     FieldName='get_field...';
-    testima=0;
 end
 VelType=[];%default
-
-if ~testima
+if isequal(FileType,'netcdf')
     list_fields=get(handles.Fields,'String');% list menu fields
     index_fields=get(handles.Fields,'Value');% selected string index
@@ -1842,5 +1878,4 @@
     else
        VelType=setfield(handles);
-       %enable_transform(handles,'on')% no field transform (possible transform in the GUI get_field)
     end
 end
@@ -1848,11 +1883,11 @@
 % choose a second field if Subfield option is 'on'
 filename_1=[];
-VelType_1=[];%default
 FieldName_1=[];
 scal_color=[];
-testvel=0;
-testX=0;%default
+% testvel=0;
+% testX=0;%default
 VelType_1=setfield_1(handles);
 sub_value=get(handles.SubField,'Value');
+FileType_1='none';%default
 if sub_value==1
     filename_1=read_file_boxes_1(handles);
@@ -1862,14 +1897,40 @@
     end
     NomType_1=get(handles.FileIndex_1,'UserData');
-    list_fields=get(handles.Fields_1,'String');% list menu fields
-    index_fields=get(handles.Fields_1,'Value');% selected string index
-    FieldName_1= list_fields{index_fields}; % selected field
-    if isequal(VelType_1,'*')% free veltype choice
-        VelType_1=[];
-    elseif isequal(VelType_1,'"')% veltype the same as for the first field
-        if isempty(VelType)
+    Ext_1=get(handles.FileExt_1,'String');
+    % determine the input file type
+    if isequal(Ext_1,'.nc')||isequal(Ext_1,'.cdf')
+        FileType_1='netcdf';
+    elseif isfield(UvData,'MovieObject_1')
+        FileType_1='movie';
+        FieldName_1='image';
+    elseif isequal(lower(Ext_1),'.avi')
+        FileType='avi';
+        FieldName_1='image';
+    elseif isequal(lower(Ext_1),'.vol')
+        FileType_1='vol';
+        FieldName_1='image';
+    else 
+       form=imformats(Ext([2:end]));
+       if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
+           if isequal(NomType_1,'*');
+               FileType_1='multimage';
+           else
+               FileType_1='image';
+           end
+           FieldName_1='image';
+       end
+    end
+    if ~isequal(FieldName_1,'image')
+        list_fields=get(handles.Fields_1,'String');% list menu fields
+        index_fields=get(handles.Fields_1,'Value');% selected string index
+        FieldName_1= list_fields{index_fields}; % selected field
+        if isequal(VelType_1,'*')% free veltype choice
             VelType_1=[];
-        else
-            VelType_1=VelType;
+        elseif isequal(VelType_1,'"')% veltype the same as for the first field
+            if isempty(VelType)
+                VelType_1=[];
+            else
+                VelType_1=VelType;
+            end
         end
     end
@@ -1881,7 +1942,7 @@
 if sub_value>=2
     if ~isequal(NomType_1,'*')%in cas of a series of files (not avi movie)
-        if isfield(UvData,'filename_1')& isfield(UvData,'VelType_1') & isfield(UvData,'FieldName_1')
-            test_keepdata_1= isequal(filename_1,UvData.filename_1)&...
-                isequal(VelType_1,UvData.filename_1) & isequal(FieldName_1,UvData.FieldName_1);
+        if isfield(UvData,'filename_1')&& isfield(UvData,'VelType_1') && isfield(UvData,'FieldName_1')
+            test_keepdata_1= isequal(filename_1,UvData.filename_1)&&...
+                isequal(VelType_1,UvData.filename_1) && isequal(FieldName_1,UvData.FieldName_1);
 
         end
@@ -1890,15 +1951,20 @@
 
 %read the input field(s)
-testima_1=isequal(FieldName_1,'image');
+% testima_1=isequal(FieldName_1,'image');
+
 %read images
-if  ~isempty(filename) && testima
-    if isfield(UvData,'MovieObject')
-        A=read(UvData.MovieObject,num_i1);
-    else
-        [A,error]=read_image(filename,NomType,num_i1);
-        if ~isequal(error,0)
-            msgbox_uvmat('ERROR',error)
-            return
-        end
+if ~isempty(filename) && isequal(FieldName,'image')
+     switch FileType
+        case 'movie'
+            A=read(UvData.MovieObject,num_i1);
+        case 'avi'
+            mov=aviread(filename,num_i1);
+            A=frame2im(mov(1));
+        case 'vol'
+            A=imread(filename);
+        case 'multimage'
+            A=imread(filename,num_i1);
+        case 'image'
+            A=imread(filename);
     end 
     npxy=size(A);
@@ -1907,9 +1973,4 @@
     Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
     Rangy=[npxy(1)-0.5 0.5]; %
-    npx=str2num(get(handles.npx,'String'));
-    npy=str2num(get(handles.npy,'String'));
-    if isfield(UvData.XmlData,'Time')
-        abs_time=UvData.XmlData.Time;
-    end
     Field{1}.AName='image';
     Field{1}.ListVarName={'AY','AX','A'}; % 
@@ -1925,10 +1986,18 @@
     Field{1}.CoordUnit='pixel'; %used for mouse_motion
 end
-if ~isfield(UvData,'Txt')& ~isempty(filename_1) & testima_1
-    [A,error]=read_image(filename_1,NomType_1,num_i1);
-    if ~isequal(error,0)
-        msgbox_uvmat('ERROR',error)
-        return
-    end
+if ~isfield(UvData,'Txt')&& ~isempty(filename_1) && isequal(FieldName_1,'image')
+    switch FileType_1
+        case 'movie'
+            A=read(UvData.MovieObject_1,num_i1);
+        case 'avi'
+            mov=aviread(filename,num_i1);
+            A=frame2im(mov(1));
+        case 'vol'
+            A=imread(filename);
+        case 'multimage'
+            A=imread(filename,num_i1);
+        case 'image'
+            A=imread(filename);
+    end 
     npxy=size(A);
     set(handles.npx,'String',num2str(npxy(2)));% display image size on the interface
@@ -1936,9 +2005,9 @@
     Rangx=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
     Rangy=[npxy(1)-0.5 0.5]; %
-    npx=str2num(get(handles.npx,'String'));
-    npy=str2num(get(handles.npy,'String'));
-    if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
-        abs_time=UvData.XmlData_1.Time;
-    end
+%     npx=str2num(get(handles.npx,'String'));
+%     npy=str2num(get(handles.npy,'String'));
+%     if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
+%         abs_time=UvData.XmlData_1.Time;
+%     end
     Field{2}.AName='image';
     Field{2}.ListVarName={'AY','AX','A'}; % 
@@ -1960,5 +2029,5 @@
 InputField={FieldName};
 InputField_1={FieldName_1};
-if ~isfield(UvData,'Txt') && ((~isempty(filename)&~testima) || (~isempty(filename_1)&~testima_1)) ;
+if ~isfield(UvData,'Txt') && ((~isempty(filename)&& isequal(FileType,'netcdf')) || (~isempty(filename_1)&& isequal(FileType,'netcdf'))) ;
     %read the velocity field(s) from netcdf rootfile(s)
     list_code=get(handles.col_vec,'String');% list menu fields
@@ -1971,7 +2040,7 @@
         InputField_1=[InputField_1 scal_color];
     end
-    if ~testima  %read the first nc field
+    if isequal(FileType,'netcdf')  %read the first nc field
         if isequal(FieldName,'get_field...')% read the field names on the interface get_field.
-            test_detect=0;%default
+%             test_detect=0;%default
             VelType=get(handles.Fields,'UserData');
             hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
@@ -1979,5 +2048,5 @@
                 hget_field= get_field(filename);%open the get_field GUI    
             end
-            test_detect=1;
+%             test_detect=1;
             hhget_field=guidata(hget_field);
             set(hhget_field.inputfile,'String',filename)% update the list of input fields in get_field
@@ -2001,7 +2070,7 @@
         end
     end
-    if ~isempty(filename_1) && ~testima_1 %read the second file
+    if ~isempty(filename_1) && isequal(FileType_1,'netcdf') %read the second file
         if isequal(FieldName_1,'get_field...')% read the field names on the interface get_field.
-            test_detect=0;%default
+%             test_detect=0;%default
             hget_field=findobj(allchild(0),'Name','get_field_1');%find the get_field... GUI
              if isempty(hget_field)
@@ -2010,5 +2079,5 @@
 %                 enable_transform(handles,'off')% no field transform (possible transform in the GUI get_field)
              end
-            test_detect=1;
+%             test_detect=1;
             hhget_field=guidata(hget_field);%handles of GUI elements in get_field
             SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI 
@@ -2023,5 +2092,4 @@
 %                 end
 %             end
-
             %update the display on get_field
             set(hhget_field.inputfile,'String',filename_1)
@@ -2051,5 +2119,5 @@
             CivStage_1=Field{2}.CivStage;
         end
-        if testima
+        if ~isequal(FileType,'netcdf')
             VelType_out=VelType_out_1;
         end
@@ -2059,5 +2127,5 @@
 %update the display buttons for the first velocity type (first menuline)
 veltype_handles=[handles.civ1 handles.interp1 handles.filter1 handles.civ2 handles.interp2 handles.filter2];
-if testima
+if ~isequal(FileType,'netcdf')
     reset_vel_type(veltype_handles)
 elseif isempty(VelType)
@@ -2073,5 +2141,5 @@
 %update the display buttons for the second velocity type (second menuline)
 veltype_handles_1=[handles.civ1_1 handles.interp1_1 handles.filter1_1 handles.civ2_1 handles.interp2_1 handles.filter2_1];
-if testima_1
+if ~isequal(FileType_1,'netcdf')
     reset_vel_type(veltype_handles_1)
 elseif isempty(VelType_1)
@@ -2090,8 +2158,8 @@
 end
 %put W as background image by default if NbDim=2:
-if ~isfield(UvData,'NbDim')|isempty(UvData.NbDim)|~isequal(UvData.NbDim,3)
+if ~isfield(UvData,'NbDim')||isempty(UvData.NbDim)||~isequal(UvData.NbDim,3)
     if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W);
         set(handles.SubField,'Value',1);
-        menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
+        %menu=update_menu(handles.Fields_1,'w');%update the menu for the background scalar nd set the choice to 'w'
         set(handles.RootPath_1,'String','"')
         set(handles.RootFile_1,'String','"')
@@ -2176,8 +2244,8 @@
 
 %calculate scalar
-if ~testima && ~isequal(FieldName,'get_field...')%
+if isequal(FileType,'netcdf') && ~isequal(FieldName,'get_field...')%
     Field{1}=calc_field(InputField,Field{1});
 end
-if length(Field)==2 && ~testima_1 && ~isequal(FieldName,'get_field...')
+if length(Field)==2 && isequal(FileType_1,'netcdf') && ~isequal(FieldName_1,'get_field...')
     Field{2}=calc_field(InputField_1,Field{2});
 end
@@ -2185,5 +2253,5 @@
 % combine the two input fields (e.g. substract velocity fields)
 if numel(Field)==2
-    if ~(isequal(get(handles.movie_pair,'Value'),1) & isequal(FieldName,'image') & isequal(FieldName_1,'image')) %combine fields if not viewing image pairs
+    if ~(isequal(get(handles.movie_pair,'Value'),1) && isequal(FieldName,'image') && isequal(FieldName_1,'image')) %combine fields if not viewing image pairs
         UvData.Field=sub_field(Field{1},Field{2}); %TO UPDATE FOR MORE GENERAL INPUT
     end
@@ -2206,20 +2274,20 @@
 [NbDim,imax]=max(NbDim);
 if isempty(imax)
-   DimVarIndex=0;    
+%    DimVarIndex=0;    
     coord_x=[];
 else
-    VarIndex=CellVarIndex{imax};
+%     VarIndex=CellVarIndex{imax};
     coord_x=VarType{imax}.coord_x;
 end
-if isfield(UvData,'NbDim') & ~isempty(UvData.NbDim)
+if isfield(UvData,'NbDim') && ~isempty(UvData.NbDim)
     NbDim=UvData.NbDim;
 else  
     UvData.NbDim=NbDim;
 end
-if ~isempty(CellVarIndex) & ~isempty(VarType{imax}.coord_x)  & ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
+if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_x)  && ~isempty(VarType{imax}.coord_y)    %unstructured coordinate z
     XName=UvData.Field.ListVarName{VarType{imax}.coord_x};
     YName=UvData.Field.ListVarName{VarType{imax}.coord_y};
     test_x=1;
-elseif isfield(UvData.Field,'X')&isfield(UvData.Field,'Y')
+elseif isfield(UvData.Field,'X') && isfield(UvData.Field,'Y')
     XName='X';
     YName='Y';
@@ -2233,5 +2301,5 @@
     eval(['nbvec=length(UvData.Field.' XName ');'])
     if NbDim==3%
-        if ~isempty(CellVarIndex) & ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
+        if ~isempty(CellVarIndex) && ~isempty(VarType{imax}.coord_z)%unstructured coordinate z
             ZName=UvData.Field.ListVarName{VarType{imax}.coord_z};
             eval(['UvData.ZMax=max(UvData.Field.' ZName ');'])
@@ -2456,5 +2524,5 @@
 %display the updated plotting parameters for the base menuplane
 write_plot_param(handles,UvData.Object{1}.PlotParam);% update the display of the plotting parameters
-set(huvmat,'UserData',UvData)
+set(handles.uvmat,'UserData',UvData)
 
 %update the mask
@@ -2606,6 +2674,6 @@
 %-------------------------------------------------------------------
 function zoom_Callback(hObject, eventdata, handles)
-huvmat=get(handles.zoom,'parent');%general input
-UvData=get(huvmat,'UserData');
+%huvmat=get(handles.zoom,'parent');%general input
+UvData=get(handles.uvmat,'UserData');
 if (get(handles.zoom,'Value') == 1); 
     set(handles.zoom,'BackgroundColor',[1 1 0])
@@ -2617,5 +2685,5 @@
     %UvData.ZoomOn=0;  %test for mouse action
 end
-set(huvmat,'UserData',UvData);
+set(handles.uvmat,'UserData',UvData);
 
 %-------------------------------------------------------------------
@@ -2845,10 +2913,10 @@
     if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')|| isequal(NomType,'#_ab')|| isequal(NomType,'_i1-i2')
         UvData.SubDir=get(handles.SubDir,'String'); %preserve the subdir in memory
-        if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')|isequal(UvData.SubDir(1),'/'))
+        if ~isempty(UvData.SubDir) && (isequal(UvData.SubDir(1),'/')||isequal(UvData.SubDir(1),'/'))
             UvData.SubDir(1)=[];
         end
         set(handles.SubDir,'String','')
         set(handles.FileExt,'String','.png');
-        if isequal(NomType,'_i1-i2_j')|isequal(NomType,'_i_j1-j2')
+        if isequal(NomType,'_i1-i2_j')||isequal(NomType,'_i_j1-j2')
             NomTypeNew='_i_j';
         elseif isequal(NomType,'#_ab')
@@ -2874,5 +2942,5 @@
         set(handles.civ2,'BackgroundColor',[0.702 0.702 0.702])
         str=calc_field;%get the list of available scalars by the function calc_scal
-        [ind_answer,v] = listdlg('PromptString','Select a file:',...
+        [ind_answer] = listdlg('PromptString','Select a file:',...
                 'SelectionMode','single',...
                 'ListString',str);
@@ -2884,9 +2952,9 @@
     end
 end
-indices=name_generator('',str2num(str1),str2num(str_a),'',NomTypeNew,1,str2num(str2),str2num(str_b),'');
+indices=name_generator('',str2double(str1),str2double(str_a),'',NomTypeNew,1,str2double(str2),str2double(str_b),'');
 set(handles.FileIndex,'String',indices)
 set(handles.FileIndex,'UserData',NomTypeNew)
 %common to Fields_1_Callback
-if isequal(field,'image')|isequal(field_1,'image')
+if isequal(field,'image')||isequal(field_1,'image')
     set(handles.npx_title,'Visible','on')% visible npx,pxcm... buttons
     set(handles.npy_title,'Visible','on')
@@ -2901,17 +2969,17 @@
     set(handles.fix_pair,'Value',1)
 end
-if isequal(field,'velocity')|isequal(field_1,'velocity');
-    state_vect='on';
-else
-    state_vect='off';
-end 
-if ~isequal(field,'velocity')|(~isequal(field_1,'velocity'));
-    state_scal='on';
-else
-    state_scal='off';
-end 
+% if isequal(field,'velocity')|isequal(field_1,'velocity');
+%     state_vect='on';
+% else
+%     state_vect='off';
+% end 
+% if ~isequal(field,'velocity')|(~isequal(field_1,'velocity'));
+%     state_scal='on';
+% else
+%     state_scal='off';
+% end 
 setfield(handles);% update the field structure ('civ1'....)
 
-if ~isfield(UvData,'NewSeries')|isequal(UvData.NewSeries,0)
+if ~isfield(UvData,'NewSeries')||isequal(UvData.NewSeries,0)
     run0_Callback(hObject, eventdata, handles)
 end
@@ -4751,9 +4819,8 @@
  
 [FileName,RootPath,filebase,FileIndices,ext,SubDir]=read_file_boxes(handles);
-[P,F,str1,str2,str_a,str_b]=name2display(FileName);
-num1=stra2num(str1);
-num2=stra2num(str2);
-num_a=stra2num(str_a);
-num_b=stra2num(str_b);
+num1=stra2num(get(handles.i1,'String'));
+num2=stra2num(get(handles.i2,'String'));
+num_a=stra2num(get(handles.j1,'String'));
+num_b=stra2num(get(handles.j2,'String'));
 NomType=get(handles.FileIndex,'UserData');
 ind_opening=1; % default (images): will advice civ1 option by default in the civ interface
@@ -4840,7 +4907,11 @@
 % ------------------------------------------------------------------
 function Menupolygon_Callback(hObject, eventdata, handles)
-set(handles.create,'Visible','on')
-set(handles.create,'Value',1)
-PATCH_Callback(hObject,eventdata,handles)
+% set(handles.create,'Visible','on')
+% set(handles.create,'Value',1)
+% PATCH_Callback(hObject,eventdata,handles)
+data.Style='polygon';
+data.ProjMode='inside';%default
+PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
+create_object(data,handles.uvmat,PlotHandles)
 
 %------------------------------------------------------------------------
