Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 353)
+++ trunk/src/civ.m	(revision 354)
@@ -1210,5 +1210,7 @@
                     nbslice_mask=str2double(Param.Civ1.Mask(1:end-4)); %
                     i1_mask=mod(i1_civ1(ifile)-1,nbslice_mask)+1;
-                    Param.Civ1.Mask=name_generator(maskbase,i1_mask,1,'.png','_i');
+                    [RootPathMask,RootFileMask]=fileparts(maskbase);
+                    Param.Civ1.Mask=fullfile_uvmat(RootPathMask,[],RootFileMask,'.png','_1',i1_mask);
+                   % Param.Civ1.Mask=name_generator(maskbase,i1_mask,1,'.png','_i');
                 end
             end
@@ -1219,5 +1221,6 @@
                     if ~isnan(nbslice_grid)
                         i1_grid=mod(i1_civ1(ifile)-1,nbslice_grid)+1;
-                        Param.Civ1.Grid=[filecell.filebase '_' name_generator(Param.Civ1.Grid,i1_grid,1,'.grid','_i')];
+                        Param.Civ1.Grid=[filecell.filebase '_' fullfile_uvmat('','',Param.Civ1.Grid,'.grid','_1',i1_grid)];
+%                         Param.Civ1.Grid=[filecell.filebase '_' name_generator(Param.Civ1.Grid,i1_grid,1,'.grid','_i')];
                         if ~exist(Param.Civ1.GridName,'file')
                             msgbox_uvmat('ERROR','grid file absent for civ1')
@@ -1297,5 +1300,6 @@
                             if ~isnan(nbslice_grid)
                                 i1_grid=mod(i1_civ1(ifile)-1,nbslice_grid)+1;
-                                patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
+                                patch1.gridPatch=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
+%                                 patch1.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
                                 if ~exist(patch1.gridPatch,'file')
                                     msgbox_uvmat('ERROR','grid file absent for patch1')
@@ -1346,5 +1350,7 @@
                     nbslice_mask=str2double(Param.Civ2.Mask(1:end-4)); %
                     i1_mask=mod(i1_civ2(ifile)-1,nbslice_mask)+1;
-                    Param.Civ2.Mask=name_generator(maskbase,i1_mask,1,'.png','_i');
+                    [RootPathMask,RootFileMask]=fileparts(maskbase);
+                    Param.Civ2.Mask=fullfile_uvmat(RootPathMask,[],RootFileMask,'.png','_1',i1_mask);
+%                     Param.Civ2.Mask=name_generator(maskbase,i1_mask,1,'.png','_i');
                 end
             end
@@ -1355,5 +1361,6 @@
                     if ~isnan(nbslice_grid)
                         i1_grid=mod(i1_civ2(ifile)-1,nbslice_grid)+1;
-                        Param.Civ2.Grid=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
+                        Param.Civ2.Grid=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
+%                         Param.Civ2.Grid=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
                     end
                 end
@@ -1431,5 +1438,6 @@
                             if ~isnan(nbslice_grid)
                                 i1_grid=mod(i1_civ2(ifile)-1,nbslice_grid)+1;
-                                patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
+                                patch2.gridPatch=[filecell.filebase '_' fullfile_uvmat('','',gridname,'.grid','_1',i1_grid)];
+%                                 patch2.gridPatch=[filecell.filebase '_' name_generator(gridname,i1_grid,1,'.grid','_i')];
                                 if ~exist(patch2.gridPatch,'file')
                                     msgbox_uvmat('ERROR','grid file absent for patch2')
@@ -1654,5 +1662,5 @@
                 fprintf(fid,['sh ' batch_file_list{p} '\n']);
             else
-                fprintf(fid,['@call "' regexprep(filename_bat,'\\','\\\\') '"' '\n']);
+                fprintf(fid,['@call "' regexprep(batch_file_list{p},'\\','\\\\') '"' '\n']);
             end
         end
@@ -1809,7 +1817,9 @@
     filebase_nc=filebase_B;
 end
-    [RootPath_ima1,RootFile_ima1]=fileparts(filebase_ima1);
-    [RootPath_ima2,RootFile_ima2]=fileparts(filebase_ima2);
-    [RootPath_nc,RootFile_ima1]=fileparts(filebase_nc);
+[RootPath_ima1,RootFile_ima1]=fileparts(filebase_ima1);
+[RootPath_ima2,RootFile_ima2]=fileparts(filebase_ima2);
+[RootPath_nc,RootFile_nc]=fileparts(filebase_nc);
+[RootPath_A,RootFile_A]=fileparts(filebase_A);
+[RootPath_AB,RootFile_AB]=fileparts(filebase_AB);
     
 %determine reference files for fix:
@@ -1955,6 +1965,7 @@
         for ifile=1:nbfield
             for j=1:nbslice
-                [RootPath,RootFile]=fileparts(ref.filebase_nc);
-                filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);
+                [RootPath,RootFile]=fileparts(filebase_nc);
+                filename=fullfile_uvmat(RootPath_nc,subdir_civ1_new,RootFile_nc,'.nc',nom_type_nc,num1_civ1(ifile),num2_civ1(ifile),num_a_civ1(j),num_b_civ1(j));
+               % filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);
                 detect=exist(filename,'file')==2;
                 if detect% if a netcdf file already exists
@@ -1999,5 +2010,6 @@
             for ifile=1:nbfield
                 for j=1:nbslice
-                    filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);%
+                     filename=fullfile_uvmat(RootPath_A,subdir_civ1_new,RootFile_A,'.nc',nom_type_nc,num1_civ1(ifile),num2_civ1(ifile),num_a_civ1(j),num_b_civ1(j));
+                   % filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1_new);%
                     detect=exist(filename,'file')==2;
                     if detect% if a netcdf file already exists
@@ -2045,8 +2057,10 @@
     for ifile=1:nbfield
         for j=1:nbslice
-            filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
+             filename=fullfile_uvmat(RootPath_ima1,'',RootFile_ima1,ext_ima,nom_type_ima1,num1_civ1(ifile),[],num_a_civ1(j));
+           % filename=name_generator(filebase_ima1, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
             idetect(j)=exist(filename,'file')==2;
             filecell.ima1.civ1(ifile,j)={filename}; %first image
-            filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
+            filename=fullfile_uvmat(RootPath_ima2,'',RootFile_ima2,ext_ima,nom_type_ima2,num2_civ1(ifile),[],num_b_civ1(j));
+          %  filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
             idetect_1(j)=exist(filename,'file')==2;
             filecell.ima2.civ1(ifile,j)={filename};%second image
@@ -2070,8 +2084,10 @@
         for ifile=1:nbfield
             for j=1:nbslice
-                filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
+                filename=fullfile_uvmat(RootPath_A,'',RootFile_A,ext_ima,nom_type_ima1,num1_civ1(ifile),[],num_a_civ1(j));
+               % filename=name_generator(filebase_A, num1_civ1(ifile),num_a_civ1(j),ext_ima,nom_type_ima1);
                 idetect(j)=exist(filename,'file')==2;
                 filecell.imaA1.civ1(ifile,j)={filename} ;%first image
-                filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
+                filename=fullfile_uvmat(RootPath_A,'',RootFile_A,ext_ima,nom_type_ima2,num2_civ1(ifile),[],num_b_civ1(j));
+               % filename=name_generator(filebase_A, num2_civ1(ifile),num_b_civ1(j),ext_ima,nom_type_ima2);
                 idetect_1(j)=exist(filename,'file')==2;
                 filecell.imaA2.civ1(ifile,j)={filename};%second image
@@ -2098,6 +2114,7 @@
     for ifile=1:nbfield
         for j=1:nbslice
-            filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
-                nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
+            filename=fullfile_uvmat(RootPath_nc,subdir_civ1,RootFile_nc,'.nc',nom_type_nc,num1_civ1(ifile),num2_civ1(ifile),num_a_civ1(j),num_b_civ1(j));
+           % filename=name_generator(filebase_nc,num1_civ1(ifile),num_a_civ1(j),'.nc',...
+           %     nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
             detect=exist(filename,'file')==2;
             if detect==0
@@ -2113,5 +2130,6 @@
         for ifile=1:nbfield
             for j=1:nbslice
-                filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
+                filename=fullfile_uvmat(RootPath_A,subdir_civ1,RootFile_A,'.nc',nom_type_nc,num1_civ1(ifile),num2_civ1(ifile),num_a_civ1(j),num_b_civ1(j));
+              %  filename=name_generator(filebase_A,num1_civ1(ifile),num_a_civ1(j),'.nc',nom_type_nc,1,num2_civ1(ifile),num_b_civ1(j),subdir_civ1);%
                 filecell.ncA.civ1(ifile,j)={filename};
                 if ~exist(filename,'file')
@@ -2139,5 +2157,6 @@
         for ifile=1:nbfield
             for j=1:nbslice
-                filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2_new);%
+                filename=fullfile_uvmat(RootPath_nc,subdir_civ2_new,RootFile_nc,'.nc',nom_type_nc,num1_civ2(ifile),num2_civ2(ifile),num_a_civ2(j),num_b_civ2(j));
+               % filename=name_generator(filebase_nc,num1_civ2(ifile),num_a_civ2(j),'.nc',nom_type_nc,1,num2_civ2(ifile),num_b_civ2(j),subdir_civ2_new);%
                 detect=exist(filename,'file')==2;
                 if detect% if a netcdf file already exists
@@ -2172,6 +2191,7 @@
             for ifile=1:nbfield
                 for j=1:nbslice
-                    filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
-                        nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
+                    filename=fullfile_uvmat(RootPath_A,subdir_civ2_new,RootFile_A,'.nc',nom_type_nc,num1_civ2(ifile),num2_civ2(ifile),num_a_civ2(j),num_b_civ2(j));
+                %   filename=name_generator(filebase_A,num1_civ2(ifile),num_a_civ2(j),'.nc',...
+                 %       nom_type_nc,1,num2_civ2(ifile),num_b_civ1(j),subdir_civ2_new);%
                     detect=exist(filename,'file')==2;
                     if detect% if a netcdf file already exists
@@ -2289,5 +2309,5 @@
         for ifile=1:nbfield
             for j=1:nbslice
-                filename=fullfile_uvmat(RootPath_ima1,[],RootFile_ima1,ext_ima,nom_type_ima1,num1_civ2(ifile),num2_civ2(ifile),num_a_civ2(j),num_b_civ2(j));
+                filename=fullfile_uvmat(RootPath_ima1,[],RootFile_ima1,ext_ima,nom_type_ima1,num1_civ2(ifile),[],num_a_civ2(j));
                 %filename=name_generator(filebase_ima1, num1_civ2(ifile),num_a_civ2(j),ext_ima,nom_type_ima1);
                 idetect_2(j)=exist(filename,'file')==2;
@@ -2309,5 +2329,5 @@
         for ifile=1:nbfield
             for j=1:nbslice
-                filename=fullfile_uvmat(RootPath_ima2,[],RootFile_ima2,ext_ima,nom_type_ima2,num1_civ2(ifile),num2_civ2(ifile),num_a_civ2(j),num_b_civ2(j));
+                filename=fullfile_uvmat(RootPath_ima2,[],RootFile_ima2,ext_ima,nom_type_ima2,num2_civ2(ifile),[],num_b_civ2(j));
                % filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),ext_ima,nom_type_ima2);
                 idetect_3(j)=exist(filename,'file')==2;
@@ -2450,5 +2470,5 @@
             waitbar(ifile/nbfield);
             for j=1:nbslice
-                 filename=fullfile_uvmat(RootPath_ima1,[],RootFile_ima1,'.png',nom_type_imanew1,num1_civ1(ifile),num2_civ1(ifile),num_a_civ1(j),num_b_civ1(j));
+                 filename=fullfile_uvmat(RootPath_ima1,[],RootFile_ima1,'.png',nom_type_imanew1,num1_civ1(ifile),[],num_a_civ1(j));
 %                 filename=name_generator(filebase_ima1,num1_civ1(ifile),num_a_civ1(j),'.png',nom_type_imanew1);
                 if ~exist(filename,'file')
@@ -2457,5 +2477,5 @@
                 end
                 filecell.ima1.civ1(ifile,j)={filename};
-                filename=fullfile_uvmat(RootPath_ima2,[],RootFile_ima2,'.png',nom_type_imanew2,num2_civ1(ifile),num2_civ1(ifile),num_b_civ1(j),num_b_civ1(j));
+                filename=fullfile_uvmat(RootPath_ima2,[],RootFile_ima2,'.png',nom_type_imanew2,num2_civ1(ifile),[],num_b_civ1(j));
                 %filename=name_generator(filebase_ima2, num2_civ1(ifile),num_b_civ1(j),'.png',nom_type_imanew2);
                 if ~exist(filename,'file')
@@ -2473,5 +2493,5 @@
             waitbar(ifile/nbfield);
             for j=1:nbslice
-                filename=fullfile_uvmat(RootPath_ima1,[],RootFile_ima1,'.png',nom_type_imanew1,num1_civ2(ifile),[],num_a_civ1(j));
+                filename=fullfile_uvmat(RootPath_ima1,[],RootFile_ima1,'.png',nom_type_imanew1,num1_civ2(ifile),[],num_a_civ2(j));
                 %filename=name_generator(filebase_ima1,num1_civ2(ifile),num_a_civ2(j),'.png',nom_type_imanew1);
                 if ~exist(filename,'file')
@@ -2480,5 +2500,6 @@
                 end
                 filecell.ima1.civ2(ifile,j)={filename};
-                filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
+                filename=fullfile_uvmat(RootPath_ima2,[],RootFile_ima2,'.png',nom_type_imanew2,num2_civ2(ifile),[],num_b_civ2(j));
+               % filename=name_generator(filebase_ima2, num2_civ2(ifile),num_b_civ2(j),'.png',nom_type_imanew2);
                 if ~exist(filename,'file')
                     A=read_image(cell2mat(filecell.ima2.civ2(ifile,j)),type_ima2,num2_civ2(ifile));
@@ -3054,4 +3075,5 @@
 
 %% case with no Civ1 operation, netcdf files need to exist for reading
+[RootPath,RootFile]=fileparts(filebase);
 if ~get(handles.CheckCiv1,'Value') %
     if ~exist(fullfile(filepath,subdir_civ1,ext_dir),'dir')
@@ -3061,6 +3083,8 @@
     end
     for ipair=1:nbpair
-        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
-            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
+        filename=fullfile_uvmat(RootPath,subdir_civ1,RootFile,'.nc',nom_type_nc,...
+            ref_i+displ_num(3,ipair),ref_i+displ_num(4,ipair),ref_j+displ_num(1,ipair),ref_j+displ_num(2,ipair));
+      %  filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
+       %     ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
         select(ipair)=exist(filename,'file')==2;% put flag to 0 if the file does not exist
     end   
@@ -3072,5 +3096,6 @@
             num_j1=ref_j-floor(browse.incr_pair(2)/2);
             num_j2=ref_j+ceil(browse.incr_pair(2)/2);
-            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
+            filename=fullfile_uvmat(RootPath,subdir_civ1,RootFile,'.nc',nom_type_nc,num_i1,num_i2,num_j1,num_j2);
+            %filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ1);
             select(1)=exist(filename,'file')==2;
             testpair=1;
@@ -3251,4 +3276,5 @@
 displ_pair={''}; %default
 select=ones(size(1:nbpair));%default =1 for numbers of displayed pairs
+[RootPath,RootFile]=fileparts(filebase);
 if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
     if ~exist(fullfile(filepath,subdir_civ2,ext_dir),'dir')
@@ -3259,6 +3285,8 @@
     end
     for ipair=1:nbpair
-        filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
-            ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
+        filename=fullfile_uvmat(RootPath,subdir_civ1,RootFile,'.nc',nom_type_nc,...
+            ref_i+displ_num(3,ipair),ref_i+displ_num(4,ipair),ref_j+displ_num(1,ipair),ref_j+displ_num(2,ipair));
+       % filename=name_generator(filebase,ref_i+displ_num(3,ipair),ref_j+displ_num(1,ipair),'.nc',nom_type_nc,1,...
+        %    ref_i+displ_num(4,ipair),ref_j+displ_num(2,ipair),subdir_civ1);
         select(ipair)=exist(filename,'file')==2;
     end
@@ -3269,11 +3297,12 @@
             num_j1=ref_j-floor(browse.incr_pair(2)/2);
             num_j2=ref_j+floor((browse.incr_pair(2)+1)/2);
-            filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
+            filename=fullfile_uvmat(RootPath,subdir_civ2,RootFile,'.nc',nom_type_nc,num_i1,num_i2,num_j1,num_j2);
+            %filename=name_generator(filebase,num_i1,num_j1,'.nc',nom_type_nc,1,num_i2,num_j2,subdir_civ2);
             select(1)=exist(filename,'file')==2;
         else
             if  isequal(mode,'series(Dj)')% | isequal(mode,'st_series(Dj)')
-                errordlg(['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
+                msgbox_uvmat('ERROR',['no civ2 file available for the selected reference index j=' num2str(ref_j) ' and subdirectory ' subdir_civ2])
             else
-                errordlg(['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
+                msgbox_uvmat('ERROR',['no civ2 file available for the selected reference index i=' num2str(ref_i) ' and subdirectory ' subdir_civ2])
             end
             set(handles.ListPairCiv2,'Value',1);
