Index: trunk/src/uvmat.m
===================================================================
--- trunk/src/uvmat.m	(revision 342)
+++ trunk/src/uvmat.m	(revision 353)
@@ -474,5 +474,5 @@
 end
 % detect root name, nomenclature and indices in the input file name:
-[~,SubDir,~,i1,i2,j1,j2,FileExt]=fileparts_uvmat(fileinput);
+[ff,SubDir,ii,i1,i2,j1,j2,FileExt]=fileparts_uvmat(fileinput);
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
 % [i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject]=find_file_series(fileinput);
@@ -510,13 +510,24 @@
         set(handles.i1,'String',num2str(i1));    
         set(handles.i2,'String',num2str(i2));
-        set(handles.j1,'String',num2str(j1));
-        set(handles.j2,'String',num2str(j2));
+        set(handles.j1,'String',num2stra(j1,NomType));
+        set(handles.j2,'String',num2stra(j2,NomType));
         
         % synchronise indices of the second  input file if it exists
         if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
-            [ff,rr,FileBase_1,ii,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
-            NomType_1=get(handles.NomType_1,'String'); 
+            Input=read_GUI(handles.InputFile);
+            if ~isfield(Input,'RootPath_1')
+                Input.RootPath_1=Input.RootPath;
+            end
+            if ~isfield(Input,'SubDir_1')
+                Input.SubDir_1=Input.SubDir;
+            end
+            if ~isfield(Input,'RootFile_1')
+                Input.SubDir_1=Input.RootFile;
+            end
+%             [ff,rr,FileBase_1,ii,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
+%             NomType_1=get(handles.NomType_1,'String'); 
 %             NomType_1=get(handles.FileIndex_1,'UserData');     
-            FileName_1=name_generator(FileBase_1,i1,i2,FileExt_1,NomType_1,1,j1,j2,SubDir_1);
+           % FileName_1=name_generator(FileBase_1,i1,i2,FileExt_1,NomType_1,1,j1,j2,SubDir_1);
+            FileName_1=fullfile_uvmat(Input.RootPath_1,Input.SubDir_1,Input.RootFile_1,Input.FileExt_1,Input.NomType_1,i1,i2,j1,j2);
             if exist(FileName_1,'file')
                 FileIndex_1=name_generator('',i1,i2,'',NomType_1,1,j1,j2,'');
@@ -555,5 +566,5 @@
 fileinput=read_file_boxes(handles);
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
-[RootPath,RootFile,i1_series,i2_series,j1_series,j2_series,~,FileType,MovieObject]=find_file_series(fileinput);
+[RootPath,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=find_file_series(fileinput);
 % initiate the input file series and refresh the current field view: 
 update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject);
@@ -578,5 +589,5 @@
 function FileIndex_Callback(hObject, eventdata, handles)
 %------------------------------------------------------------------------
-[~,~,~,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
+[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
 set(handles.i1,'String',num2str(i1));
 set(handles.i2,'String',num2str(i2));
@@ -599,4 +610,8 @@
 UvData.TestInputFile=1;
 UvData.FileType=FileType;
+UvData.i1_series=i1_series;
+UvData.i2_series=i2_series;
+UvData.j1_series=j1_series;
+UvData.j2_series=j2_series;
 set(handles.fix_pair,'Value',1) % activate by default the comp_input '-'input window
 set(handles.FixVelType,'Value',0); %desactivate fixed veltype
@@ -731,11 +746,11 @@
 
 %% store last index in handles.lat_i and .last_j
-nbfield=max(i2_series);
+nbfield=max(max(i2_series));
 if isempty(nbfield)
-    nbfield=max(i1_series);
-end
-nbfield_j=max(j2_series);
+    nbfield=max(max(i1_series));
+end
+nbfield_j=max(max(j2_series));
 if isempty(nbfield_j)
-    nbfield_j=max(j1_series);
+    nbfield_j=max(max(j1_series));
 end
 if ~isempty(XmlData.Time)
@@ -1040,5 +1055,5 @@
 
 %[path,name,ext]=fileparts(fileinput_1);
-[~,SubDir_1,~,i1,i2,j1,j2,FileExt_1]=fileparts_uvmat(fileinput_1);
+[tild,SubDir_1,tild,i1,i2,j1,j2,FileExt_1]=fileparts_uvmat(fileinput_1);
 [RootPath_1,RootFile_1,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject]=find_file_series(fileinput_1);
 % [RootPath_1,RootFile_1,field_count,str2,str_a,str_b,FileExt_1,NomType_1,SubDir_1]=name2display(fileinput_1);
@@ -1521,7 +1536,7 @@
         for ilist=1:length(maskfiles)
             maskname=maskfiles(ilist).name;% take the first mask file in the list
-            [~,~,~,~,~,~,~,MaskExt,Mask_NomType{ilist}]=fileparts_uvmat(maskname);
+            [tild,tild,tild,tild,tild,tild,tild,MaskExt,Mask_NomType{ilist}]=fileparts_uvmat(maskname);
 %             [rr,ff,x1,x2,xa,xb,xext,Mask_NomType{ilist}]=name2display(maskname);
-             [~,Name]=fileparts(maskname);
+             [tild,Name]=fileparts(maskname);
             Namedouble=double(Name);
             val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
@@ -1572,5 +1587,5 @@
             errormsg='no file browsed';
         end
-        [RootDir,~,RootFile,~,~,~,~,~,Mask.NomType]=fileparts_uvmat(maskname);
+        [RootDir,tild,RootFile,tild,tild,tild,tild,tild,Mask.NomType]=fileparts_uvmat(maskname);
 %         [RootDir,RootFile,x1,x2,xa,xb,xext,Mask.NomType]=name2display(maskname);
         Mask.Base=fullfile(RootDir,RootFile);
@@ -1834,6 +1849,6 @@
 NomType=get(handles.NomType,'String');
 % NomType=get(handles.FileIndex,'UserData');
-i1=stra2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
-i2=stra2num(get(handles.i2,'String'));
+i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
+i2=str2num(get(handles.i2,'String'));
 j1=stra2num(get(handles.j1,'String'));
 j2=stra2num(get(handles.j2,'String'));
@@ -1841,5 +1856,5 @@
 if sub_value % a second input file has been entered
     [FileName_1,RootPath_1,filebase_1,FileIndices_1,FileExt_1,SubDir_1]=read_file_boxes_1(handles);
-    [~,~,~,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndices_1);
+    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndices_1);
   %  [pp,ff,i1_1_str,i2_1_str,j1_1_str,j2_1_str]=name2display(FileIndices_1);
 %     i1_1=stra2num(i1_1_str);%current set of indices for the second field (may be set different than the main indices)
@@ -1855,22 +1870,49 @@
 
 %% increment (or decrement) the field indices and update the input filename(s)
-if get(handles.scan_i,'Value')==1% case of scanning along index i   
-     i1=i1+increment;
-     i2=i2+increment;
-     [filename,i1,j1,i2,j2]=name_generator(filebase,i1,j1,FileExt,NomType,comp_input,i2,j2,InputFile.SubDir);
-     if sub_value% set the second field name and indices
-        i1_1=i1_1+increment;
-        i2_1=i2_1+increment;
-        filename_1=name_generator(filebase_1,i1_1,j1_1,FileExt_1,NomType_1,1,i2_1,j2_1,SubDir_1);
-     end   
+if get(handles.scan_i,'Value')==1% case of scanning along index i
+    i1=i1+increment;
+    i2=i2+increment;
 else % case of scanning along index j (burst numbers)
     j1=j1+increment;
     j2=j2+increment;
-    [filename,i1,j1,i2,j2]=name_generator(filebase,i1,j1,FileExt,NomType,comp_input,i2,j2,InputFile.SubDir);
-    if sub_value 
-        j1_1=j1_1+increment;
-        j2_1=j2_1+increment;
-        filename_1=name_generator(filebase_1,i1_1,j1_1,FileExt_1,NomType_1,1,i2_1,j2_1,SubDir_1);
-    end    
+end
+if ~comp_input
+    UvData=get(handles.uvmat,'UserData');
+    ref_i=i1;
+    if ~isempty(i2)
+        ref_i=floor((i1+i2)/2);
+    end
+    ref_j=1;
+    if ~isempty(j1)
+        ref_j=j1;
+        if ~isempty(j2)
+            ref_j=floor((j1+j2)/2);
+        end
+    end
+    if ref_i+1>size(UvData.i1_series,1)
+        msgbox_uvmat('ERROR','maximum i index exceeded');
+        return
+    end
+    if ref_j+1>size(UvData.i1_series,2)
+        msgbox_uvmat('ERROR','maximum j index exceeded');
+        return
+    end
+    i1=UvData.i1_series(ref_i+1,ref_j+1,1);
+    if ~isempty(UvData.i2_series)
+        i2=UvData.i2_series(ref_i+1,ref_j+1,1);
+    end
+    if ~isempty(UvData.j1_series)
+        j1=UvData.j1_series(ref_i+1,ref_j+1,1);
+    end
+    if ~isempty(UvData.j2_series)
+        j2=UvData.j2_series(ref_i+1,ref_j+1,1);
+    end
+end
+filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2);
+% filename=name_generator(filebase,i1,j1,FileExt,NomType,comp_input,i2,j2,InputFile.SubDir);
+if sub_value
+    j1_1=j1_1+increment;
+    j2_1=j2_1+increment;
+    filename_1=name_generator(filebase_1,i1_1,j1_1,FileExt_1,NomType_1,1,i2_1,j2_1,SubDir_1);
 end
 
@@ -1892,5 +1934,6 @@
         set(handles.j2,'String',num2stra(j2,NomType,2));
     end
-    [indices]=name_generator('',i1,j1,'',NomType,1,i2,j2,'');
+   % [indices]=name_generator('',i1,j1,'',NomType,1,i2,j2,'');
+    indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
     set(handles.FileIndex,'String',indices);
     if ~isempty(filename_1)
@@ -2823,5 +2866,5 @@
 end
 if isfield(UvData,'XmlData_1') && isfield(UvData.XmlData_1,'Time')
-    [~,~,~,num_i1,num_i2,num_j1,num_j2]=fileparts_uvmat(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
+    [tild,tild,tild,num_i1,num_i2,num_j1,num_j2]=fileparts_uvmat(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
   %  [P,F,str1,str2,str_a,str_b,E]=name2display(['xx' get(handles.FileIndex_1,'String') get(handles.FileExt_1,'String')]);
     if isempty(num_i2)
@@ -3182,5 +3225,5 @@
 %read the rootfile input display
 [FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
-[~,~,~,i1,i2,j1,j2,~,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
+[tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
 % [P,F,str1,str2,str_a,str_b,E,NomType]=name2display(['xxx' get(handles.FileIndex,'String') FileExt]);
 NomTypeNew=NomType;%default
@@ -3223,5 +3266,6 @@
     end
 end
-indices=name_generator('',i1,j1,'',NomTypeNew,1,i2,j2,'');
+% indices=name_generator('',i1,j1,'',NomTypeNew,1,i2,j2,'');
+indices=fullfile_uvmat('','','',FileExt,NomTypeNew,i1,i2,j1,j2);
 set(handles.FileIndex,'String',indices)
 set(handles.NomType,'String',NomTypeNew)
@@ -3263,9 +3307,9 @@
 %read the rootfile input display
 [FileName,RootPath,FileBase,FileIndices,FileExt_1]=read_file_boxes_1(handles);
-[~,~,~,i1,i2,j1,j2,~,NomType_1]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt_1]);
+[tild,tild,tild,i1,i2,j1,j2,tild,NomType_1]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt_1]);
 % [P,F,str1,str2,str_a,str_b,E,NomType_1]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_1]);
 if isempty(NomType_1)|| strcmp(NomType_1,'')
     [FileName,RootPath,FileBase,FileIndices,FileExt_1]=read_file_boxes(handles);
-    [~,~,~,i1,i2,j1,j2,~,NomType_1]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt_1]);
+    [tild,tild,tild,i1,i2,j1,j2,tild,NomType_1]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt_1]);
  %   [P,F,str1,str2,str_a,str_b,E,NomType_1]=name2display(['xxx' get(handles.FileIndex,'String') FileExt_1]);
 end
@@ -3319,5 +3363,6 @@
         end  
     end
-    imagename=name_generator(FileBase,i1,j1,'.png',NomTypeNew,1,i2,j2,'');
+%     imagename=name_generator(FileBase,i1,j1,'.png',NomTypeNew,1,i2,j2,'');
+    imagename=fullfile_uvmat(RootPath,SubDir,FileName,'.png',NomTypeNew,i1,i2,j1,j2);
     if ~exist(imagename,'file')
         [FileName,PathName] = uigetfile( ...
