Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 1168)
+++ /trunk/src/civ.m	(revision 1169)
@@ -44,10 +44,4 @@
 %% prepare measurement grid if not given as input
 if ~isfield(par_civ,'Grid')% grid points defining central positions of the sub-images in image A
-%     if ischar(par_civ.Grid)%read the grid file if the input is a file name (grid in x, y image coordinates)
-%         par_civ.Grid=dlmread(par_civ.Grid);
-%         par_civ.Grid(1,:)=[];%the first line must be removed (heading in the grid file)
-%     end
-%     % else par_civ.Grid is already an array, no action here
-% else% automatic grid in x, y image coordinates
     nbinterv_x=floor((npx_ima-1)/par_civ.Dx);
     gridlength_x=nbinterv_x*par_civ.Dx;
@@ -114,6 +108,4 @@
 checkmask=0;
 MinA=min(min(par_civ.ImageA));
-%MinB=min(min(par_civ.ImageB));
-%check_undefined=false(size(par_civ.ImageA));
 if isfield(par_civ,'Mask') && ~isempty(par_civ.Mask)
     checkmask=1;
@@ -126,5 +118,4 @@
 
 %% compute image correlations: MAINLOOP on velocity vectors
-corrmax=0;
 sum_square=1;% default
 mesh=1;% default
@@ -134,5 +125,5 @@
     par_civ.CorrSmooth=2;% use SUBPIX2DGAUSS (take into account more points near the max)
 end
- 
+
 if par_civ.CorrSmooth~=0 % par_civ.CorrSmooth=0 implies no civ computation (just input image and grid points given)
     for ivec=1:nbvec
@@ -141,7 +132,7 @@
         FF(ivec)=0;
         ibx2=floor(CorrBoxSizeX(ivec)/2);
-iby2=floor(CorrBoxSizeY(ivec)/2);
-isx2=ibx2+ceil(par_civ.SearchRange(1));
-isy2=iby2+ceil(par_civ.SearchRange(2));
+        iby2=floor(CorrBoxSizeY(ivec)/2);
+        isx2=ibx2+ceil(par_civ.SearchRange(1));
+        isy2=iby2+ceil(par_civ.SearchRange(2));
         subrange1_x=iref-ibx2:iref+ibx2;% x indices defining the first subimage
         subrange1_y=jref-iby2:jref+iby2;% y indices defining the first subimage
@@ -216,5 +207,5 @@
                 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
                 corrmax= max(max(result_conv));
-        
+                
                 %result_conv=(result_conv/corrmax); %normalize, peak=always 255
                 %Find the correlation max, at 255
@@ -280,9 +271,9 @@
 peaky = y; peakx=x;
 if y < npy && y > 1 && x < npx-1 && x > 1
-   FF=false; % no error by the limited search box
+    FF=false; % no error by the limited search box
     max_conv=result_conv(y,x);% max correlation
     %peak2noise= max(4,max_conv/std(reshape(result_conv,1,[])));% ratio of max conv to standard deviation of correlations (estiamtion of noise level), set to value 4 if it is too low
     peak2noise=100;% TODO: make this threshold more precise, depending on the image noise
-    result_conv=result_conv*peak2noise/max_conv;% renormalise the correlation with respect to the noise 
+    result_conv=result_conv*peak2noise/max_conv;% renormalise the correlation with respect to the noise
     result_conv(result_conv<1)=1; %set to 1 correlation values smaller than 1  (=0 by discretisation, to avoid divergence in the log)
     
Index: /trunk/src/mouse_motion.m
===================================================================
--- /trunk/src/mouse_motion.m	(revision 1168)
+++ /trunk/src/mouse_motion.m	(revision 1169)
@@ -238,25 +238,8 @@
             if test_piv
                [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2)));
-               if isfield(hhciv,'TestCiv2') && strcmp(get(hhciv.Civ2,'Visible'),'on')&& ...
-                                     strcmp(get(hhciv.TestCiv2,'Visible'),'on')&& get(hhciv.TestCiv2,'Value')% if TestCiv2 is activated
-                   CivOption='Civ2';
-                   Param.CheckCiv1=0;
-                   par_civ=read_GUI(hhciv.Civ2);%read the Civ2 panel in civ_input
-                   par_civ.Civ1_SubRange=Field.Civ1_SubRange;% get the subranges used for patch
-                   par_civ.Civ1_NbCentres=Field.Civ1_NbCentres;% get the nbre of civ1 data points in each subrange
-                   par_civ.Civ1_Coord_tps=Field.Civ1_Coord_tps;% get the positions of the centres (Civ1 data)
-                   par_civ.Civ1_U_tps=Field.Civ1_U_tps;% get the tps coefficients for spline, U component
-                   par_civ.Civ1_V_tps=Field.Civ1_V_tps;% get the tps coefficients for spline, V component
-                   par_civ.Civ1_Dt=Field.Civ1_Dt;
-                   par_civ.Civ2_Dt=Field.Civ2_Dt;
-                   shiftx=Field.ShiftX(ind_pt);% get field info stored in the cuirrent figure
-                   shifty=Field.ShiftY(ind_pt);
-               else
-                   CivOption='Civ1';
                    Param.CheckCiv2=0;
                    par_civ=read_GUI(hhciv.Civ1);%read the Civ1 panel in civ_input
                    shiftx=par_civ.SearchBoxShift(1);
                    shifty=par_civ.SearchBoxShift(2);
-               end
                 xround=Field.X(ind_pt);
                 yround=Field.Y(ind_pt);
@@ -284,10 +267,4 @@
                 
                 % perform the PIV calculation as the single point xround yround
-                Param.ActionInput.CheckCiv1=1;
-%                 Param.CheckFix1=0;
-%                 Param.CheckPatch1=0;%desactivate all calculations except Civ2 or Civ1
-                Param.Action.RUN=1;
-                Param.ActionInput.ListCompareMode='PIV';
-                Param.ActionInput.PairIndices=read_GUI(hhciv.PairIndices);
                 par_civ.ImageA=Field.A;
                 par_civ.ImageB=Field.B;
@@ -295,13 +272,8 @@
                 par_civ.ImageWidth=size(par_civ.ImageA,2);
                 par_civ.Grid=[xround yround];% PIV calculation with a single point 
-                Param.ActionInput.(CivOption)=par_civ;      
-                [Data,errormsg,result_conv]= civ_series(Param);
+                [~,~,utable,vtable,~,~,result_conv,errormsg]= civ(par_civ);
                 if ~isempty(errormsg)
                     text_displ_5=errormsg;
                 else
-%                     rangx(1)=-(isx2-ibx2)+shiftx;
-%                     rangx(2)=isx2-ibx2+shiftx;
-%                     rangy(1)=-(isy2-iby2)-shifty;
-%                     rangy(2)=(isy2-iby2)-shifty;
                     rangx(1)=-isx2+shiftx;
                     rangx(2)=isx2+shiftx;
@@ -320,5 +292,5 @@
                             set(0,'CurrentFigure',corrfig(1))
                             AxeData.CurrentCorrImage=imagesc(rangx,-rangy,result_conv,[0 1]);% plot the correlation map, with full colormap from 0 to 1
-                            AxeData.CurrentVector=line([0 Data.([CivOption '_U'])],[0 Data.([CivOption '_V'])],'Tag','vector');
+                            AxeData.CurrentVector=line([0 utable],[0 vtable],'Tag','vector');
                             AxeData.TitleHandle=title(['[x,y]= ' num2str(par_civ.Grid) ' px']);
                             colorbar
@@ -339,5 +311,5 @@
                          set(ParentAxe,'XLim',rangx)
                          set(ParentAxe,'YLim',[-rangy(2) -rangy(1)])
-                        set(AxeData.CurrentVector,'XData',[0 Data.([CivOption '_U'])],'YData',[0 Data.([CivOption '_V'])]);
+                        set(AxeData.CurrentVector,'XData',[0 utable],'YData',[0 vtable]);
                         set(AxeData.TitleHandle,'String',['[x,y]= ' num2str(par_civ.Grid) ' px'])
                     end
Index: /trunk/src/read_civdata.m
===================================================================
--- /trunk/src/read_civdata.m	(revision 1168)
+++ /trunk/src/read_civdata.m	(revision 1169)
@@ -93,5 +93,5 @@
 
 %% reading data
-[Data,tild,tild,errormsg]=nc2struct(FileName,'ListGlobalAttribute','Conventions','CivStage');
+[Data,tild,tild,errormsg]=nc2struct(FileName,'ListGlobalAttribute','Conventions','CivStage');% read the global attributes to get Data.CivStage
 if ~isempty(errormsg)
      errormsg=['read_civdata: ' errormsg];
Index: /trunk/src/series/civ_input.m
===================================================================
--- /trunk/src/series/civ_input.m	(revision 1168)
+++ /trunk/src/series/civ_input.m	(revision 1169)
@@ -1532,5 +1532,5 @@
 drawnow
 if get(handles.TestCiv1,'Value')
-    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch  
+    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
     set(handles.CheckFix1,'value',0)% desactivate next step
     set(handles.CheckPatch1,'value',0)% desactivate next step
@@ -1539,64 +1539,89 @@
     set(handles.CheckPatch2,'value',0)% desactivate next step
     update_CivOptions(handles,0)
-      hseries=findobj(allchild(0),'Tag','series');
-     Param=read_GUI(hseries);
-     Param.Action.RUN=1;
-     Param.ActionInput=read_GUI(handles.civ_input);
-     if isfield(Param.ActionInput,'Fix1')
-         Param.ActionInput=rmfield(Param.ActionInput,'Fix1');
-     end
-     if isfield(Param.ActionInput,'Patch1')
-         Param.ActionInput=rmfield(Param.ActionInput,'Patch1');
-     end
-     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
-         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
-     end
-     if isfield(Param.ActionInput,'Fix2')
-         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
-     end
-     if isfield(Param.ActionInput,'Patch2')
-         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
-     end
-     if isfield(Param,'OutputSubDir')
-     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
-     end
-     Param.ActionInput.Civ1.CorrSmooth=0;% launch Civ1 with no data point (to get the image names for A and B)
-     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
-     Param.IndexRange.last_i=str2num(get(handles.ref_i,'String'));
-     if strcmp(get(handles.ref_j,'Visible'),'on')
-         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
-         Param.IndexRange.last_j=Param.IndexRange.first_j;
-     else
-         Param.IndexRange.first_j=1;
-         Param.IndexRange.last_j=1;
-     end
-     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results 
-     if ~isempty(errormsg), return, end % rmq: error msg displayed in civ_series
-     
- %% create image data ImageData for display
-     ImageData.ListVarName={'ny','nx','A'};
-     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
-     ImageData.VarAttribute{1}.Role='coord_y';
-     ImageData.VarAttribute{2}.Role='coord_x';
-     ImageData.VarAttribute{3}.Role='scalar';
-     ImageData.A=imread(Data.Civ1_ImageA); % read the first image
-     if ndims(ImageData.A)==3 %case of color image
-         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
-     end
-     ImageData.ny=[size(ImageData.A,1) 1];
-     ImageData.nx=[1 size(ImageData.A,2)];
-     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly 
-
-     %% create the figure view_field for image visualization
-     hview_field=view_field(ImageData); %view the image in the GUI view_field 
-     set(0,'CurrentFigure',hview_field)
-     hhview_field=guihandles(hview_field);
-     set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
-     ViewData=get(hview_field,'UserData');
-     ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
-     ViewData.PlotAxes.X=Data.Civ1_X';
-     ViewData.PlotAxes.Y=Data.Civ1_Y';
-     ViewData.PlotAxes.B=imread(Data.Civ1_ImageB);%store the second image in the UserData of the GUI view_field
-     set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
+    % get info from the GUI 'series'
+    hseries=findobj(allchild(0),'Tag','series');
+    Param=read_GUI(hseries);
+    Param.Action.RUN=1;
+    Param.ActionInput=read_GUI(handles.civ_input);
+    i1=str2num(get(handles.ref_i,'String'));  %references indices
+    i2=i1;
+    j1=1;
+    if strcmp(get(handles.ref_j,'Visible'),'on')
+        j1=str2num(get(handles.ref_j,'String'));
+    end
+    j2=j1;
+    str_civ=Param.ActionInput.PairIndices.ListPairCiv1;
+    r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names');
+    if ~isempty(r)
+        if strmp(r.ind,'i')
+            i1=i1-str2num(r.num1);
+            i2=i2 +str2num(r.num2);
+        elseif strmp(r.ind,'j')
+            j1=j1-str2num(r.num1);
+            j2=j2 +str2num(r.num2);
+        end
+    else % mode='j1-j2';
+        r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
+        if isempty(r)
+            r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
+            if isempty(r)
+                r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
+            end
+        end
+        if isempty(r)
+            disp('wrong pair mode input option')
+        else
+            j1=stra2num(r.num1);
+            j2=stra2num(r.num2);
+        end
+    end
+    
+    par_civ1=Param.ActionInput.Civ1;
+      
+    if strcmp(Param.ActionInput.ListCompareMode,'displacement')
+        ImageName_A=Param.ActionInput.RefFile;
+    else
+        RootPath_A=Param.InputTable{1,1};
+        SubDir_A=Param.InputTable{1,2};
+        RootFile_A=Param.InputTable{1,3};
+        NomType_A=Param.InputTable{1,4};
+        FileExt_A=Param.InputTable{1,5};
+        ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1,[],j1);
+        ImageName_B=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i2,[],j2);
+    end
+    par_civ1.ImageA = read_image(ImageName_A);
+    par_civ1.ImageB = read_image(ImageName_B);
+    par_civ1.CorrSmooth=0;% will give only the grid of data points expected for PIV, computations will be activated by the fct mouse_motion.m
+    [Data.Civ1_X,Data.Civ1_Y,Data.Civ1_U,Data.Civ1_V,Data.Civ1_C,Data.Civ1_FF, ~, errormsg]=civ(par_civ1);
+    if ~isempty(errormsg)
+        disp(errormsg)
+        return
+    end % rmq: error msg displayed in civ_series
+    
+    %% create image data ImageData for display
+    ImageData.ListVarName={'ny','nx','A'};
+    ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
+    ImageData.VarAttribute{1}.Role='coord_y';
+    ImageData.VarAttribute{2}.Role='coord_x';
+    ImageData.VarAttribute{3}.Role='scalar';
+    ImageData.A=par_civ1.ImageA; % get the first image
+    if ndims(ImageData.A)==3 %case of color image
+        ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
+    end
+    ImageData.ny=[size(ImageData.A,1) 1];
+    ImageData.nx=[1 size(ImageData.A,2)];
+    ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
+    
+    %% create the figure view_field for image visualization
+    hview_field=view_field(ImageData); %view the image in the GUI view_field
+    set(0,'CurrentFigure',hview_field)
+    hhview_field=guihandles(hview_field);
+    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
+    ViewData=get(hview_field,'UserData');
+    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
+    ViewData.PlotAxes.X=Data.Civ1_X';
+    ViewData.PlotAxes.Y=Data.Civ1_Y';
+    ViewData.PlotAxes.B=par_civ1.ImageB;%store the second image in the UserData of the GUI view_field
+    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field, to be used by mouse_motion.m
     
     %% look for a current figure for image correlation display
@@ -1623,5 +1648,5 @@
     if ~isempty(hview_field)
         delete(hview_field)
-    end      
+    end
 end
 
@@ -1636,5 +1661,5 @@
 %---------------------------------------------------------------------
 function NomTypeNc=nomtype2pair(NomTypeIma,mode_selected)
-%---------------------------------------------------------------------           
+%---------------------------------------------------------------------
 % OUTPUT:
 % NomTypeNc
@@ -1645,21 +1670,21 @@
 NomTypeNc=NomTypeIma;%default
 switch mode_selected
-    case 'pair j1-j2'      
-    if ~isempty(regexp(NomTypeIma,'a$'))
-        NomTypeNc=[NomTypeIma 'b'];
-    elseif ~isempty(regexp(NomTypeIma,'A$'))
-        NomTypeNc=[NomTypeIma 'B'];
-    else
-        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
-        if ~isempty(r)
-            NomTypeNc='_1_1-2';
-        end
-    end
-    case 'series(Dj)'  
-%         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
-%         if ~isempty(r)
-            NomTypeNc='_1_1-2';
-%         end
-   case 'series(Di)'
+    case 'pair j1-j2'
+        if ~isempty(regexp(NomTypeIma,'a$'))
+            NomTypeNc=[NomTypeIma 'b'];
+        elseif ~isempty(regexp(NomTypeIma,'A$'))
+            NomTypeNc=[NomTypeIma 'B'];
+        else
+            r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
+            if ~isempty(r)
+                NomTypeNc='_1_1-2';
+            end
+        end
+    case 'series(Dj)'
+        %         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
+        %         if ~isempty(r)
+        NomTypeNc='_1_1-2';
+        %         end
+    case 'series(Di)'
         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
         if ~isempty(r)
Index: /trunk/src/series/civ_series.m
===================================================================
--- /trunk/src/series/civ_series.m	(revision 1168)
+++ /trunk/src/series/civ_series.m	(revision 1169)
@@ -3,5 +3,5 @@
 %   civ: PIV function itself
 %   detect_false: put a flag to false vectors after detection by various criteria
-%   filter_tps: make interpolation-smoothing 
+%   filter_tps: make interpolation-smoothing
 %------------------------------------------------------------------------
 % function [Data,errormsg,result_conv]= civ_series(Param)
@@ -15,5 +15,5 @@
 % Param: Matlab structure of input  parameters
 %     Param contains info of the GUI series using the fct read_GUI.
-%     Param.Action.RUN = 0 (to set the status of the GUI series) or =1 to RUN the computation 
+%     Param.Action.RUN = 0 (to set the status of the GUI series) or =1 to RUN the computation
 %     Param.InputTable: sets the input file(s)
 %           if absent, the fct looks for input data in Param.ActionInput     (test mode)
@@ -93,143 +93,135 @@
     return
 end
-iview_A=0;%default values
+%iview_A=0;%default values
 NbField=1;
 RUNHandle=[];
-CheckInputFile=isfield(Param,'InputTable');%= 1 in test use for TestCiv (no nc file involved)
-CheckOutputFile=isfield(Param,'OutputSubDir');%= 1 in test use for TestPatch (no nc file produced)
+% CheckInputFile=isfield(Param,'InputTable');%= 1 in test use for TestCiv (no nc file involved)
+% CheckOutputFile=isfield(Param,'OutputSubDir');%= 1 in test use for TestPatch (no nc file produced)
 
 %% input files and indexing (skipped in Test mode)
-if CheckInputFile
-    hseries=findobj(allchild(0),'Tag','series');
-    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
-    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
-    MaxIndex_i=Param.IndexRange.MaxIndex_i;
-    MinIndex_i=Param.IndexRange.MinIndex_i;
-    MaxIndex_j=ones(size(MaxIndex_i));MinIndex_j=ones(size(MinIndex_i));
-    if isfield(Param.IndexRange,'MaxIndex_j')&& isfield(Param.IndexRange,'MinIndex_j')
-        MaxIndex_j=Param.IndexRange.MaxIndex_j;
-        MinIndex_j=Param.IndexRange.MinIndex_j;
-    end
-    if isfield(Param,'InputTable')
-        [~,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
-        iview_A=0;% series index (iview) for the first image series
-        iview_B=0;% series index (iview) for the second image series (only non zero for option 'shift' comparing two image series )
-        if Param.ActionInput.CheckCiv1
-            iview_A=1;% usual PIV, the image series is on the first line of the table
-        else % Civ1 has been already stored in a netcdf file input 
-            iview_A=2;% the second line is used for the input images 
-        end
-        if iview_A~=0
-            RootPath_A=Param.InputTable{iview_A,1};
-            RootFile_A=Param.InputTable{iview_A,3};
-            SubDir_A=Param.InputTable{iview_A,2};
-            NomType_A=Param.InputTable{iview_A,4};
-            FileExt_A=Param.InputTable{iview_A,5};
-            if iview_B==0
-                iview_B=iview_A;% the second image series is the same as the first
-            end
-            RootPath_B=Param.InputTable{iview_B,1};
-            RootFile_B=Param.InputTable{iview_B,3};
-            SubDir_B=Param.InputTable{iview_B,2};
-            NomType_B=Param.InputTable{iview_B,4};
-            FileExt_B=Param.InputTable{iview_B,5};
-        end
-        
-        PairCiv2='';
-        switch Param.ActionInput.ListCompareMode
-            case 'PIV'
-                PairCiv1=Param.ActionInput.PairIndices.ListPairCiv1;
-                if isfield(Param.ActionInput.PairIndices,'ListPairCiv2')
-                    PairCiv2=Param.ActionInput.PairIndices.ListPairCiv2;%string which determines the civ2 pair
+hseries=findobj(allchild(0),'Tag','series');
+RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
+WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
+MaxIndex_i=Param.IndexRange.MaxIndex_i;
+MinIndex_i=Param.IndexRange.MinIndex_i;
+MaxIndex_j=ones(size(MaxIndex_i));MinIndex_j=ones(size(MinIndex_i));
+if isfield(Param.IndexRange,'MaxIndex_j')&& isfield(Param.IndexRange,'MinIndex_j')
+    MaxIndex_j=Param.IndexRange.MaxIndex_j;
+    MinIndex_j=Param.IndexRange.MinIndex_j;
+end
+if isfield(Param,'InputTable')
+    [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param);
+    %         iview_A=0;% series index (iview) for the first image series
+    iview_B=0;% series index (iview) for the second image series (only non zero for option 'shift' comparing two image series )
+    if Param.ActionInput.CheckCiv1
+        iview_A=1;% usual PIV, the image series is on the first line of the table
+    else % Civ1 has been already stored in a netcdf file input
+        iview_A=2;% the second line is used for the input images
+    end
+    %         if iview_A~=0
+    RootPath_A=Param.InputTable{iview_A,1};
+    RootFile_A=Param.InputTable{iview_A,3};
+    SubDir_A=Param.InputTable{iview_A,2};
+    NomType_A=Param.InputTable{iview_A,4};
+    FileExt_A=Param.InputTable{iview_A,5};
+    if iview_B==0
+        iview_B=iview_A;% the second image series is the same as the first
+    end
+    RootPath_B=Param.InputTable{iview_B,1};
+    RootFile_B=Param.InputTable{iview_B,3};
+    SubDir_B=Param.InputTable{iview_B,2};
+    NomType_B=Param.InputTable{iview_B,4};
+    FileExt_B=Param.InputTable{iview_B,5};
+    PairCiv2='';
+    
+    switch Param.ActionInput.ListCompareMode
+        case 'PIV'
+            PairCiv1=Param.ActionInput.PairIndices.ListPairCiv1;
+            if isfield(Param.ActionInput.PairIndices,'ListPairCiv2')
+                PairCiv2=Param.ActionInput.PairIndices.ListPairCiv2;%string which determines the civ2 pair
+            end
+            if iview_A==1% if Civ1 is performed
+                [i1_series_Civ1,i2_series_Civ1,j1_series_Civ1,j2_series_Civ1,check_bounds,NomTypeNc]=...
+                    find_pair_indices(PairCiv1,i1_series{1},j1_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j);
+                if ~isempty(PairCiv2)
+                    [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds_Civ2]=...
+                        find_pair_indices(PairCiv2,i1_series{1},j1_series{1},MinIndex_i(1),MaxIndex_i(1),MinIndex_j(1),MaxIndex_j(1));
+                    check_bounds=check_bounds | check_bounds_Civ2;
                 end
-                if iview_A==1% if Civ1 is performed
-                    [i1_series_Civ1,i2_series_Civ1,j1_series_Civ1,j2_series_Civ1,check_bounds,NomTypeNc]=...
-                        find_pair_indices(PairCiv1,i1_series{1},j1_series{1},MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j);
-                    if ~isempty(PairCiv2)
-                        [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds_Civ2]=...
-                            find_pair_indices(PairCiv2,i1_series{1},j1_series{1},MinIndex_i(1),MaxIndex_i(1),MinIndex_j(1),MaxIndex_j(1));
-                        check_bounds=check_bounds | check_bounds_Civ2;
-                    end
-                else% we start from an existing Civ1 file
-                    i1_series_Civ1=i1_series{1};
-                    i2_series_Civ1=i2_series{1};
-                    j1_series_Civ1=j1_series{1};
-                    j2_series_Civ1=j2_series{1};
-                    NomTypeNc=Param.InputTable{1,4};
-                    if ~isempty(PairCiv2)
-                        [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds,NomTypeNc]=...
-                            find_pair_indices(PairCiv2,i1_series{2},j1_series{2},MinIndex_i(2),MaxIndex_i(2),MinIndex_j(2),MaxIndex_j(2));
-                    end
+            else% we start from an existing Civ1 file
+                i1_series_Civ1=i1_series{1};
+                i2_series_Civ1=i2_series{1};
+                j1_series_Civ1=j1_series{1};
+                j2_series_Civ1=j2_series{1};
+                NomTypeNc=Param.InputTable{1,4};
+                if ~isempty(PairCiv2)
+                    [i1_series_Civ2,i2_series_Civ2,j1_series_Civ2,j2_series_Civ2,check_bounds,NomTypeNc]=...
+                        find_pair_indices(PairCiv2,i1_series{2},j1_series{2},MinIndex_i(2),MaxIndex_i(2),MinIndex_j(2),MaxIndex_j(2));
                 end
-            case 'displacement'
-                if isfield(Param.ActionInput,'OriginIndex')
+            end
+        case 'displacement'
+            if isfield(Param.ActionInput,'OriginIndex')
                 i1_series_Civ1=Param.ActionInput.OriginIndex*ones(size(i1_series{1}));
-                else
-                    i1_series_Civ1=ones(size(i1_series{1}));
-                end
-                i1_series_Civ2=i1_series_Civ1;
-                i2_series_Civ1=i1_series{1};
-                i2_series_Civ2=i1_series{1};
-                j1_series_Civ1=[];% no j index variation for the ref image
-                j1_series_Civ2=[];
-                if isempty(j1_series{1})
-                    j2_series_Civ1=ones(size(i1_series_Civ1));
-                else
-                    j2_series_Civ1=j1_series{1};% if j index exist  
-                end
-                j2_series_Civ2=j2_series_Civ1;
-                NomTypeNc='_1';
-        end
-        %determine frame indices for input with movie or other multiframe input file
-        if isempty(j1_series_Civ1)% simple movie with index i
-            FrameIndex_A_Civ1=i1_series_Civ1;
-            FrameIndex_B_Civ1=i2_series_Civ1;
-            j1_series_Civ1=ones(size(i1_series_Civ1));
+            else
+                i1_series_Civ1=ones(size(i1_series{1}));
+            end
+            i1_series_Civ2=i1_series_Civ1;
+            i2_series_Civ1=i1_series{1};
+            i2_series_Civ2=i1_series{1};
+            j1_series_Civ1=[];% no j index variation for the ref image
+            j1_series_Civ2=[];
+            if isempty(j1_series{1})
+                j2_series_Civ1=ones(size(i1_series_Civ1));
+            else
+                j2_series_Civ1=j1_series{1};% if j index exist
+            end
+            j2_series_Civ2=j2_series_Civ1;
+            NomTypeNc='_1';
+    end
+    %determine frame indices for input with movie or other multiframe input file
+    if isempty(j1_series_Civ1)% simple movie with index i
+        FrameIndex_A_Civ1=i1_series_Civ1;
+        FrameIndex_B_Civ1=i2_series_Civ1;
+        j1_series_Civ1=ones(size(i1_series_Civ1));
+        if strcmp(Param.ActionInput.ListCompareMode,'PIV')
+            j2_series_Civ1=ones(size(i1_series_Civ1));
+        end
+    else % movie for each burst or volume (index j)
+        FrameIndex_A_Civ1=j1_series_Civ1;
+        FrameIndex_B_Civ1=j2_series_Civ1;
+    end
+    if isempty(PairCiv2)
+        FrameIndex_A_Civ2=FrameIndex_A_Civ1;
+        FrameIndex_B_Civ2=FrameIndex_B_Civ1;
+    else
+        if isempty(j1_series_Civ2)
+            FrameIndex_A_Civ2=i1_series_Civ2;
+            FrameIndex_B_Civ2=i2_series_Civ2;
+            j1_series_Civ2=ones(size(i1_series_Civ2));
             if strcmp(Param.ActionInput.ListCompareMode,'PIV')
-            j2_series_Civ1=ones(size(i1_series_Civ1));
-            end
-        else % movie for each burst or volume (index j)
-            FrameIndex_A_Civ1=j1_series_Civ1;
-            FrameIndex_B_Civ1=j2_series_Civ1;
-        end
-        if isempty(PairCiv2)
-            FrameIndex_A_Civ2=FrameIndex_A_Civ1;
-            FrameIndex_B_Civ2=FrameIndex_B_Civ1;
+                j2_series_Civ2=ones(size(i1_series_Civ2));
+            end
         else
-            if isempty(j1_series_Civ2)
-                FrameIndex_A_Civ2=i1_series_Civ2;
-                FrameIndex_B_Civ2=i2_series_Civ2;
-                j1_series_Civ2=ones(size(i1_series_Civ2));
-                if strcmp(Param.ActionInput.ListCompareMode,'PIV')
-                j2_series_Civ2=ones(size(i1_series_Civ2));
-                end
-            else
-                FrameIndex_A_Civ2=j1_series_Civ2;
-                FrameIndex_B_Civ2=j2_series_Civ2;
-            end
-        end
-        if isempty(i1_series_Civ1)||(~isempty(PairCiv2) && isempty(i1_series_Civ2))
-            disp_uvmat('ERROR','no image pair for civ in the input file index range',checkrun)
-            return
-        end
-    end
-    
-    %% check the first image pair
-        if Param.ActionInput.CheckCiv1% Civ1 is performed
-            NbField=numel(i1_series_Civ1);
-        elseif Param.ActionInput.CheckCiv2 % Civ2 is performed without Civ1
-            NbField=numel(i1_series_Civ2);
-        else
-            NbField=numel(i1_series_Civ1);% no image used (only detect_false or patch) TO CHECK
-        end
-
-    %% Output directory
-    OutputDir='';
-    if CheckOutputFile
-        OutputDir=[Param.OutputSubDir Param.OutputDirExt];
-    end
+            FrameIndex_A_Civ2=j1_series_Civ2;
+            FrameIndex_B_Civ2=j2_series_Civ2;
+        end
+    end
+    if isempty(i1_series_Civ1)||(~isempty(PairCiv2) && isempty(i1_series_Civ2))
+        disp_uvmat('ERROR','no image pair for civ in the input file index range',checkrun)
+        return
+    end
+end
+
+%% check the first image pair
+if Param.ActionInput.CheckCiv1% Civ1 is performed
+    NbField=numel(i1_series_Civ1);
+elseif Param.ActionInput.CheckCiv2 % Civ2 is performed without Civ1
+    NbField=numel(i1_series_Civ2);
+else
+    NbField=numel(i1_series_Civ1);% no image used (only detect_false or patch) TO CHECK
 end
 
 %% prepare output Data
+OutputDir=[Param.OutputSubDir Param.OutputDirExt];
 ListGlobalAttribute={'Conventions','Program','CivStage'};
 Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
@@ -241,25 +233,25 @@
 
 %% get timing from the ImaDoc file or input video
-if iview_A~=0
-    XmlFileName=find_imadoc(RootPath_A,SubDir_A);
-    Time=[];
-    if ~isempty(XmlFileName)
-        XmlData=imadoc2struct(XmlFileName);
-        if isfield(XmlData,'Time')
-            Time=XmlData.Time;
-        end
-        if isfield(XmlData,'Camera')
-            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
-                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
-                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
-                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
-                end
-            end
-            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
-                TimeUnit=XmlData.Camera.TimeUnit;
-            end
-        end
-    end
-end
+% if iview_A~=0
+XmlFileName=find_imadoc(RootPath_A,SubDir_A);
+Time=[];
+if ~isempty(XmlFileName)
+    XmlData=imadoc2struct(XmlFileName);%read the time from XmlFileName
+    if isfield(XmlData,'Time')
+        Time=XmlData.Time;
+    end
+    if isfield(XmlData,'Camera')
+        if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
+            NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
+            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+                msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+            end
+        end
+        if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
+            TimeUnit=XmlData.Camera.TimeUnit;
+        end
+    end
+end
+% end
 
 %%%%% MAIN LOOP %%%%%%
@@ -284,51 +276,51 @@
         end
     end
-%     if CheckInputFile
-    if CheckOutputFile
-        OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
-        if iview_A==0 % no nc file has been entered
-            ncfile=fullfile_uvmat(OutputPath,Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},...
-                NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),j1_series_Civ1(ifield),j2_series_Civ1(ifield));
-        else% an existing nc file has been entered
-            if iview_A==1% if Civ1 is performed
-                Civ1Dir=OutputDir;
-            else
-                Civ1Dir=Param.InputTable{1,2};
-            end
-            if strcmp(Param.ActionInput.ListCompareMode,'PIV')
-                ncfile=fullfile_uvmat(OutputPath,Civ1Dir,RootFile_A,'.nc',NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),...
-                    j1_series_Civ1(ifield),j2_series_Civ1(ifield));
-            else
-                ncfile=fullfile_uvmat(OutputPath,Civ1Dir,RootFile_A,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...
-                    j1_series_Civ1(ifield),j2_series_Civ1(ifield));
-            end
-        end
-        ncfile_out=ncfile;% by default
-        
-        if isfield (Param.ActionInput,'Civ2')
-            i1_civ2=i1_series_Civ2(ifield);
-            i2_civ2=i1_civ2;
-            if ~isempty(i2_series_Civ2)
-                i2_civ2=i2_series_Civ2(ifield);
-            end
-            j1_civ2=1;
-            if ~isempty(j1_series_Civ2)
-                j1_civ2=j1_series_Civ2(ifield);
-            end
-            j2_civ2=i1_civ2;
-            if ~isempty(j2_series_Civ2)
-                j2_civ2=j2_series_Civ2(ifield);
-            end
-            if strcmp(Param.ActionInput.ListCompareMode,'PIV')
-                ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
-            else % displacement
-                ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_civ2,[],j2_civ2);
-            end
-        end
-        if ~CheckOverwrite && exist(ncfile_out,'file')
-            disp(['existing output file ' ncfile_out ' already exists, skip to next field'])
-            continue% skip iteration if the mode overwrite is desactivated and the result file already exists
-        end
-    end
+    %     %     if CheckInputFile
+    %     if CheckOutputFile
+    OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device);
+    %         if iview_A==0 % no nc file has been entered
+    %             ncfile=fullfile_uvmat(OutputPath,Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},...
+    %                 NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),j1_series_Civ1(ifield),j2_series_Civ1(ifield));
+    %         else% an existing nc file has been entered
+    %             if iview_A==1% if Civ1 is performed
+    %                 Civ1Dir=OutputDir;
+    %             else
+    %                 Civ1Dir=Param.InputTable{1,2};
+    %             end
+    if strcmp(Param.ActionInput.ListCompareMode,'PIV')
+        ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_series_Civ1(ifield),i2_series_Civ1(ifield),...
+            j1_series_Civ1(ifield),j2_series_Civ1(ifield));
+    else
+        ncfile=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...
+            j1_series_Civ1(ifield),j2_series_Civ1(ifield));
+    end
+    %         end
+    ncfile_out=ncfile;% by default
+    
+    if isfield (Param.ActionInput,'Civ2')
+        i1_civ2=i1_series_Civ2(ifield);
+        i2_civ2=i1_civ2;
+        if ~isempty(i2_series_Civ2)
+            i2_civ2=i2_series_Civ2(ifield);
+        end
+        j1_civ2=1;
+        if ~isempty(j1_series_Civ2)
+            j1_civ2=j1_series_Civ2(ifield);
+        end
+        j2_civ2=i1_civ2;
+        if ~isempty(j2_series_Civ2)
+            j2_civ2=j2_series_Civ2(ifield);
+        end
+        if strcmp(Param.ActionInput.ListCompareMode,'PIV')
+            ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i1_civ2,i2_civ2,j1_civ2,j2_civ2);
+        else % displacement
+            ncfile_out=fullfile_uvmat(OutputPath,OutputDir,RootFile_A,'.nc',NomTypeNc,i2_civ2,[],j2_civ2);
+        end
+    end
+    if ~CheckOverwrite && exist(ncfile_out,'file')
+        disp(['existing output file ' ncfile_out ' already exists, skip to next field'])
+        continue% skip iteration if the mode overwrite is desactivated and the result file already exists
+    end
+    %     end
     ImageName_A='';ImageName_B='';%default
     VideoObject_A=[];VideoObject_B=[];
@@ -337,99 +329,94 @@
     % if Civ1 computation is requested
     if Param.ActionInput.CheckCiv1
-        if CheckInputFile
-            disp('civ1 started')
-        end
+        disp('civ1 started')
         par_civ1=Param.ActionInput.Civ1;% parameters for civ1
-        if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
-            try
-                if strcmp(Param.ActionInput.ListCompareMode,'displacement')
-                    ImageName_A=Param.ActionInput.RefFile;
-                else
-                    ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
+        %if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
+        try
+            if strcmp(Param.ActionInput.ListCompareMode,'displacement')
+                ImageName_A=Param.ActionInput.RefFile;
+            else
+                ImageName_A=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_series_Civ1(ifield),[],j1_series_Civ1(ifield));
+            end
+            if strcmp(FileExt_A,'.nc')% case of input images in format netcdf
+                FieldName_A=Param.InputFields.FieldName;
+                [DataIn,~,~,errormsg]=nc2struct(ImageName_A,{FieldName_A});
+                par_civ1.ImageA=DataIn.(FieldName_A);
+            else % usual image formats for image A
+                if isempty(FileType_A)% open the image object if not already done in case of movie input
+                    [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
+                    FileType_A=FileInfo_A.FileType;
+                    if isempty(Time) && ~isempty(find(strcmp(FileType_A,{'mmreader','video','cine_phantom'}), 1))% case of video input
+                        Time=zeros(FileInfo_A.NumberOfFrames+1,2);
+                        Time(:,2)=(0:1/FileInfo_A.FrameRate:(FileInfo_A.NumberOfFrames)/FileInfo_A.FrameRate)';
+                    end
+                    if ~isempty(FileType_A) && isempty(Time)% Time = index i +0.001 index j by default
+                        MaxIndex_i=max(i2_series_Civ1);
+                        MaxIndex_j=max(j2_series_Civ1);
+                        Time=(1:MaxIndex_i)'*ones(1,MaxIndex_j);
+                        Time=Time+0.001*ones(MaxIndex_i,1)*(1:MaxIndex_j);
+                        Time=[zeros(1,MaxIndex_j);Time];% insert a first line of zeros
+                        Time=[zeros(MaxIndex_i+1,1) Time];% insert a first column of zeros
+                    end
                 end
-                if strcmp(FileExt_A,'.nc')% case of input images in format netcdf
-                    FieldName_A=Param.InputFields.FieldName;
-                    [DataIn,~,~,errormsg]=nc2struct(ImageName_A,{FieldName_A});
-                    par_civ1.ImageA=DataIn.(FieldName_A);
-                else % usual image formats for image A
-                    if isempty(FileType_A)% open the image object if not already done in case of movie input
-                        [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A);
-                        FileType_A=FileInfo_A.FileType;
-                        if isempty(Time) && ~isempty(find(strcmp(FileType_A,{'mmreader','video','cine_phantom'}), 1))% case of video input
-                            Time=zeros(FileInfo_A.NumberOfFrames+1,2);
-                            Time(:,2)=(0:1/FileInfo_A.FrameRate:(FileInfo_A.NumberOfFrames)/FileInfo_A.FrameRate)';
-                        end
-                        if ~isempty(FileType_A) && isempty(Time)% Time = index i +0.001 index j by default
-                            MaxIndex_i=max(i2_series_Civ1);
-                            MaxIndex_j=max(j2_series_Civ1);
-                            Time=(1:MaxIndex_i)'*ones(1,MaxIndex_j);
-                            Time=Time+0.001*ones(MaxIndex_i,1)*(1:MaxIndex_j);
-                            Time=[zeros(1,MaxIndex_j);Time];% insert a first line of zeros
-                            Time=[zeros(MaxIndex_i+1,1) Time];% insert a first column of zeros
-                        end
-                    end
-                    if isempty(regexp(ImageName_A,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_A,'file')
-                        disp([ImageName_A ' missing'])
-                        continue
-                    end
-                    tsart_input=tic;
-                    [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A_Civ1(ifield));
-                    time_input=toc(tsart_input);
-                end
-                ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield));
-                if isempty(FileType_B)% determine the image type for the first field
-                    [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
-                    FileType_B=FileInfo_B.FileType;
-                end
-                if isempty(regexp(ImageName_B,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_B,'file')
-                    disp([ImageName_B ' missing'])
+                if isempty(regexp(ImageName_A,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_A,'file')
+                    disp([ImageName_A ' missing'])
                     continue
                 end
-                [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
-            catch ME % display errors in reading input images
-                if ~isempty(ME.message)
-                    disp_uvmat('ERROR', ['error reading input image: ' ME.message],checkrun)
-                    continue
-                end
-            end
-            
-            % par_civ1.ImageWidth=size(par_civ1.ImageA,2);
-            % par_civ1.ImageHeight=size(par_civ1.ImageA,1);
-            list_param=(fieldnames(Param.ActionInput.Civ1))';
-            list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list
-            Civ1_param=regexprep(list_param,'^.+','Civ1_$0');% insert 'Civ1_' before  each string in list_param
-            Civ1_param=[{'Civ1_ImageA','Civ1_ImageB','Civ1_Time','Civ1_Dt'} Civ1_param]; %insert the names of the two input images
-            %indicate the values of all the global attributes in the output data
-            Data.Civ1_ImageA=ImageName_A;
-            Data.Civ1_ImageB=ImageName_B;
-            i1=i1_series_Civ1(ifield);
-            i2=i1;
-            if ~isempty(i2_series_Civ1)
-                i2=i2_series_Civ1(ifield);
-            end
-            j1=1;
-            if ~isempty(j1_series_Civ1)
-                j1=j1_series_Civ1(ifield);
-            end
-            j2=j1;
-            if ~isempty(j2_series_Civ1)
-                j2=j2_series_Civ1(ifield);
-            end
-            if strcmp(Param.ActionInput.ListCompareMode,'displacement')
-                Data.Civ1_Time=Time(i2+1,j2+1);% the Time is the Time of the secodn image
-                Data.Civ1_Dt=1;% Time interval is 1, to yield displacement instead of velocity=displacement/Dt at reading
-            else
-                Data.Civ1_Time=(Time(i2+1,j2+1)+Time(i1+1,j1+1))/2;% the Time is the Time at the middle of the image pair
-                Data.Civ1_Dt=Time(i2+1,j2+1)-Time(i1+1,j1+1);
-            end
-            for ilist=1:length(list_param)
-                Data.(Civ1_param{4+ilist})=Param.ActionInput.Civ1.(list_param{ilist});
-            end
-            Data.ListGlobalAttribute=[ListGlobalAttribute Civ1_param];
-            
-            Data.CivStage=1;
+                tsart_input=tic;
+                [par_civ1.ImageA,VideoObject_A] = read_image(ImageName_A,FileType_A,VideoObject_A,FrameIndex_A_Civ1(ifield));
+                time_input=toc(tsart_input);
+            end
+            ImageName_B=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_series_Civ1(ifield),[],j2_series_Civ1(ifield));
+            if isempty(FileType_B)% determine the image type for the first field
+                [FileInfo_B,VideoObject_B]=get_file_info(ImageName_B);
+                FileType_B=FileInfo_B.FileType;
+            end
+            if isempty(regexp(ImageName_B,'(^http://)|(^https://)', 'once')) && ~exist(ImageName_B,'file')
+                disp([ImageName_B ' missing'])
+                continue
+            end
+            [par_civ1.ImageB,VideoObject_B] = read_image(ImageName_B,FileType_B,VideoObject_B,FrameIndex_B_Civ1(ifield));
+        catch ME % display errors in reading input images
+            if ~isempty(ME.message)
+                disp_uvmat('ERROR', ['error reading input image: ' ME.message],checkrun)
+                continue
+            end
+        end
+        
+        % par_civ1.ImageWidth=size(par_civ1.ImageA,2);
+        % par_civ1.ImageHeight=size(par_civ1.ImageA,1);
+        list_param=(fieldnames(Param.ActionInput.Civ1))';
+        list_param(strcmp('TestCiv1',list_param))=[];% remove the parameter TestCiv1 from the list
+        Civ1_param=regexprep(list_param,'^.+','Civ1_$0');% insert 'Civ1_' before  each string in list_param
+        Civ1_param=[{'Civ1_ImageA','Civ1_ImageB','Civ1_Time','Civ1_Dt'} Civ1_param]; %insert the names of the two input images
+        %indicate the values of all the global attributes in the output data
+        Data.Civ1_ImageA=ImageName_A;
+        Data.Civ1_ImageB=ImageName_B;
+        i1=i1_series_Civ1(ifield);
+        i2=i1;
+        if ~isempty(i2_series_Civ1)
+            i2=i2_series_Civ1(ifield);
+        end
+        j1=1;
+        if ~isempty(j1_series_Civ1)
+            j1=j1_series_Civ1(ifield);
+        end
+        j2=j1;
+        if ~isempty(j2_series_Civ1)
+            j2=j2_series_Civ1(ifield);
+        end
+        if strcmp(Param.ActionInput.ListCompareMode,'displacement')
+            Data.Civ1_Time=Time(i2+1,j2+1);% the Time is the Time of the second image
+            Data.Civ1_Dt=1;% Time interval is 1, to yield displacement instead of velocity=displacement/Dt at reading
         else
-            i1=Param.ActionInput.PairIndices.ref_i; %case of TESTmode
-        end
+            Data.Civ1_Time=(Time(i2+1,j2+1)+Time(i1+1,j1+1))/2;% the Time is the Time at the middle of the image pair
+            Data.Civ1_Dt=Time(i2+1,j2+1)-Time(i1+1,j1+1);
+        end
+        for ilist=1:length(list_param)
+            Data.(Civ1_param{4+ilist})=Param.ActionInput.Civ1.(list_param{ilist});
+        end
+        Data.ListGlobalAttribute=[ListGlobalAttribute Civ1_param];
+        Data.CivStage=1;
+        
         % set the list of variables
         Data.ListVarName={'Civ1_X','Civ1_Y','Civ1_U','Civ1_V','Civ1_C','Civ1_FF'};%  cell array containing the names of the fields to record
@@ -489,5 +476,4 @@
         
         % caluclate velocity data
-       % tstart_civ1=tic;
         [Data.Civ1_X,Data.Civ1_Y,Data.Civ1_U,Data.Civ1_V,Data.Civ1_C,Data.Civ1_FF, result_conv, errormsg] = civ (par_civ1);
         if ~isempty(errormsg)
@@ -495,29 +481,6 @@
             return
         end
-%         
-%         if exist('ncfile','var')
-%             CivFile=ncfile;
-%             % [Data,tild,tild,errormsg]=nc2struct(CivFile,'ListGlobalAttribute','absolut_time_T0'); %look for the constant 'absolut_time_T0' to detect old civx data format
-%             % if ~isempty(errormsg)
-%             %     disp_uvmat('ERROR',errormsg,checkrun)
-%             %     return
-%             % end
-%             [Data,tild,tild,errormsg]=nc2struct(CivFile);%read civ1 and fix1 data in the existing netcdf file
-%             if ~isempty(errormsg)
-%                 disp(errormsg)
-%                 return
-%             end
-%         elseif isfield(Param,'Civ1_X')
-%             Data.ListGlobalAttribute={};
-%             Data.ListVarName={};
-%             Data.VarDimName={};
-%             Data.Civ1_X=Param.Civ1_X;
-%             Data.Civ1_Y=Param.Civ1_Y;
-%             Data.Civ1_U=Param.Civ1_U;
-%             Data.Civ1_V=Param.Civ1_V;
-%             Data.Civ1_FF=Param.Civ1_FF;
-%         end
-    end
-
+    end
+    
     
     %% Fix1
@@ -542,8 +505,8 @@
     end
     %% Patch1
-    if isfield (Param.ActionInput,'Patch1')
+    if Param.ActionInput.CheckPatch1 && isfield (Param.ActionInput,'Patch1')
         disp('patch1 started')
-         tstart_patch1=tic;
-       
+        tstart_patch1=tic;
+        
         % record the processing parameters of Patch1 as global attributes in the result nc file
         list_param=fieldnames(Param.ActionInput.Patch1)';
@@ -574,8 +537,8 @@
         end
         if isempty(ind_good)
-                        disp_uvmat('ERROR','all vectors of civ1 are bad, check input parameters' ,checkrun)
-                        return
-        end
-
+            disp_uvmat('ERROR','all vectors of civ1 are bad, check input parameters' ,checkrun)
+            return
+        end
+        
         % perform Patch calculation using the UVMAT fct 'filter_tps'
         [Data.Civ1_SubRange,Data.Civ1_NbCentres,Data.Civ1_Coord_tps,Data.Civ1_U_tps,Data.Civ1_V_tps,~,Ures, Vres,~,FFres]=...
@@ -593,63 +556,62 @@
         tstart_civ2=tic;
         par_civ2=Param.ActionInput.Civ2;
-        if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
-            par_civ2.ImageA=[];
-            par_civ2.ImageB=[];
-            if strcmp(Param.ActionInput.ListCompareMode,'displacement')
-                ImageName_A_Civ2=Param.ActionInput.RefFile;
-            else
-                ImageName_A_Civ2=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_civ2,[],j1_civ2);
-            end
-            if strcmp(ImageName_A_Civ2,ImageName_A) && isequal(FrameIndex_A_Civ1(ifield),FrameIndex_A_Civ2(ifield))
-                par_civ2.ImageA=par_civ1.ImageA;
-            else
-                [par_civ2.ImageA,VideoObject_A] = read_image(ImageName_A_Civ2,FileType_A,VideoObject_A,FrameIndex_A_Civ2(ifield));
-            end
-            ImageName_B_Civ2=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_civ2,[],j2_civ2);
-            if strcmp(ImageName_B_Civ2,ImageName_B) && isequal(FrameIndex_B_Civ1(ifield),FrameIndex_B_Civ2)
-                par_civ2.ImageB=par_civ1.ImageB;
-            else
-                [par_civ2.ImageB,VideoObject_B] = read_image(ImageName_B_Civ2,FileType_B,VideoObject_B,FrameIndex_B_Civ2(ifield));
-            end
-            [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A_Civ2);
-            [npy_ima,npx_ima]=size(par_civ2.ImageA(:,:));
-            % par_civ2.ImageWidth=FileInfo_A.Width;
-            % par_civ2.ImageHeight=FileInfo_A.Height;
-
-            if par_civ2.CheckGrid &&~isempty(par_civ2.Grid) % case of input grid
-                GridData=nc2struct(Param.ActionInput.Civ2.Grid);
-                par_civ2.Grid=GridData.Grid;
-                par_civ2.CorrBoxSize=GridData.CorrBox;
-
-            else% automatic grid
-                nbinterv_x=floor((npx_ima-1)/par_civ2.Dx);
-                gridlength_x=nbinterv_x*par_civ2.Dx;
-                minix=ceil((npx_ima-gridlength_x)/2);
-                nbinterv_y=floor((npy_ima-1)/par_civ2.Dy);
-                gridlength_y=nbinterv_y*par_civ2.Dy;
-                miniy=ceil((npy_ima-gridlength_y)/2);
-                [GridX,GridY]=meshgrid(minix:par_civ2.Dx:npx_ima-1,miniy:par_civ2.Dy:npy_ima-1);
-                par_civ2.Grid=zeros(numel(GridX),2);
-                par_civ2.Grid(:,1)=reshape(GridX,[],1);
-                par_civ2.Grid(:,2)=reshape(GridY,[],1);% increases with array index
-
-            end
-        end
-
+        %         if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
+        par_civ2.ImageA=[];
+        par_civ2.ImageB=[];
+        if strcmp(Param.ActionInput.ListCompareMode,'displacement')
+            ImageName_A_Civ2=Param.ActionInput.RefFile;
+        else
+            ImageName_A_Civ2=fullfile_uvmat(RootPath_A,SubDir_A,RootFile_A,FileExt_A,NomType_A,i1_civ2,[],j1_civ2);
+        end
+        if strcmp(ImageName_A_Civ2,ImageName_A) && isequal(FrameIndex_A_Civ1(ifield),FrameIndex_A_Civ2(ifield))
+            par_civ2.ImageA=par_civ1.ImageA;
+        else
+            [par_civ2.ImageA,VideoObject_A] = read_image(ImageName_A_Civ2,FileType_A,VideoObject_A,FrameIndex_A_Civ2(ifield));
+        end
+        ImageName_B_Civ2=fullfile_uvmat(RootPath_B,SubDir_B,RootFile_B,FileExt_B,NomType_B,i2_civ2,[],j2_civ2);
+        if strcmp(ImageName_B_Civ2,ImageName_B) && isequal(FrameIndex_B_Civ1(ifield),FrameIndex_B_Civ2)
+            par_civ2.ImageB=par_civ1.ImageB;
+        else
+            [par_civ2.ImageB,VideoObject_B] = read_image(ImageName_B_Civ2,FileType_B,VideoObject_B,FrameIndex_B_Civ2(ifield));
+        end
+        %  [FileInfo_A,VideoObject_A]=get_file_info(ImageName_A_Civ2);
+        npy_ima=size(par_civ2.ImageA,1);
+        npx_ima=size(par_civ2.ImageA,2);
+        if par_civ2.CheckGrid &&~isempty(par_civ2.Grid) % case of input grid
+            GridData=nc2struct(Param.ActionInput.Civ2.Grid);
+            par_civ2.Grid=GridData.Grid;
+            par_civ2.CorrBoxSize=GridData.CorrBox;
+        else% automatic grid
+            nbinterv_x=floor((npx_ima-1)/par_civ2.Dx);
+            gridlength_x=nbinterv_x*par_civ2.Dx;
+            minix=ceil((npx_ima-gridlength_x)/2);
+            nbinterv_y=floor((npy_ima-1)/par_civ2.Dy);
+            gridlength_y=nbinterv_y*par_civ2.Dy;
+            miniy=ceil((npy_ima-gridlength_y)/2);
+            [GridX,GridY]=meshgrid(minix:par_civ2.Dx:npx_ima-1,miniy:par_civ2.Dy:npy_ima-1);
+            par_civ2.Grid=zeros(numel(GridX),2);
+            par_civ2.Grid(:,1)=reshape(GridX,[],1);
+            par_civ2.Grid(:,2)=reshape(GridY,[],1);% increases with array index
+        end
+        
         % get the guess from patch1 or patch2 (case 'CheckCiv3')
-        % if CheckInputFile % read input images (except in mode Test where it is introduced directly in Param.ActionInput.Civ1.ImageNameA and B)
-        if isfield (par_civ2,'CheckCiv3') && par_civ2.CheckCiv3 %get the guess from  patch2
-            SubRange= Data.Civ2_SubRange;
-            NbCentres=Data.Civ2_NbCentres;
-            Coord_tps=Data.Civ2_Coord_tps;
-            U_tps=Data.Civ2_U_tps;
-            V_tps=Data.Civ2_V_tps;
-            CivStage=Data.CivStage;%store the current CivStage
-            Civ1_Dt=Data.Civ2_Dt;
+        if iview_A==2 && isfield (par_civ2,'CheckCiv3') && strcmp(par_civ2.CheckCiv3,'iterate(civ3)') %get the guess from  patch2% Civ1 data read in a netcdf file
+            [DataIn,~,~,errormsg]=nc2struct(filecell{1,ifield});
+            if ~isempty(errormsg)
+                disp(errormsg)
+                return
+            end
+            SubRange= DataIn.Civ2_SubRange;
+            NbCentres=DataIn.Civ2_NbCentres;
+            Coord_tps=DataIn.Civ2_Coord_tps;
+            U_tps=DataIn.Civ2_U_tps;
+            V_tps=DataIn.Civ2_V_tps;
+            %CivStage=DataIn.CivStage;%store the current CivStage
+            Civ1_Dt=DataIn.Civ2_Dt;
             Data=[];%reinitialise the result structure Data
             Data.ListGlobalAttribute={'Conventions','Program','CivStage'};
             Data.Conventions='uvmat/civdata';% states the conventions used for the description of field variables and attributes
             Data.Program='civ_series';
-            Data.CivStage=CivStage+1;%update the current civStage after reinitialisation of Data
+           % Data.CivStage=CivStage+1;%update the current civStage after reinitialisation of Data
             Data.ListVarName={};
             Data.VarDimName={};
@@ -661,18 +623,18 @@
             V_tps=Data.Civ1_V_tps;
             Civ1_Dt=Data.Civ1_Dt;
-            Data.CivStage=4;
-        end
-        % else
-        %     SubRange= par_civ2.Civ1_SubRange;
-        %     NbCentres=par_civ2.Civ1_NbCentres;
-        %     Coord_tps=par_civ2.Civ1_Coord_tps;
-        %     U_tps=par_civ2.Civ1_U_tps;
-        %     V_tps=par_civ2.Civ1_V_tps;
-        %     Civ1_Dt=par_civ2.Civ1_Dt;
-        %     Civ2_Dt=par_civ2.Civ1_Dt;
-        %     Data.ListVarName={};
-        %     Data.VarDimName={};
-        % end
-        Shiftx=zeros(size(par_civ2.Grid,1),1);% shift expected from civ1 data
+%             Data.CivStage=4;
+        end
+         Data.CivStage=4;
+        %             SubRange= par_civ2.Civ1_SubRange;
+        %             NbCentres=par_civ2.Civ1_NbCentres;
+        %             Coord_tps=par_civ2.Civ1_Coord_tps;
+        %             U_tps=par_civ2.Civ1_U_tps;
+        %             V_tps=par_civ2.Civ1_V_tps;
+        %             Civ1_Dt=par_civ2.Civ1_Dt;
+        %             Civ2_Dt=par_civ2.Civ1_Dt;
+        %             Data.ListVarName={};
+        %             Data.VarDimName={};
+        %         end
+        Shiftx=zeros(size(par_civ2.Grid,1),1);% initialise the shift expected from civ1 data
         Shifty=zeros(size(par_civ2.Grid,1),1);
         nbval=zeros(size(par_civ2.Grid,1),1);% nbre of interpolated values at each grid point (from the different patch subdomains)
@@ -713,5 +675,5 @@
         Shiftx(nbval>0)=Shiftx(nbval>0)./nbval(nbval>0);
         Shifty(nbval>0)=Shifty(nbval>0)./nbval(nbval>0);
-
+        
         % introduce mask
         if par_civ2.CheckMask && ~isempty(par_civ2.Mask)
@@ -753,19 +715,16 @@
             end
         end
-
-        if CheckInputFile % else Dt given by par_civ2
-            if strcmp(Param.ActionInput.ListCompareMode,'displacement')
-                Civ1_Dt=1;
-                Civ2_Dt=1;
-            else
-                Civ2_Dt=Time(i2_civ2+1,j2_civ2+1)-Time(i1_civ2+1,j1_civ2+1);
-            end
+        
+        
+        if strcmp(Param.ActionInput.ListCompareMode,'displacement')
+            Civ1_Dt=1;
+            Civ2_Dt=1;
+        else
+            Civ2_Dt=Time(i2_civ2+1,j2_civ2+1)-Time(i1_civ2+1,j1_civ2+1);
         end
         par_civ2.SearchBoxShift=zeros(size(par_civ2.Grid));
-        par_civ2.SearchBoxShift(:,1)=(Civ2_Dt/Civ1_Dt)*Shiftx;
+        par_civ2.SearchBoxShift(:,1)=(Civ2_Dt/Civ1_Dt)*Shiftx;%rescale the shift in case of Dt different for Civ1 and Civ2
         par_civ2.SearchBoxShift(:,2)=(Civ2_Dt/Civ1_Dt)*Shifty;
-        % shift the grid points by half the expected shift to provide the correlation box position in image A
-        %par_civ2.Grid=[par_civ2.Grid(nbval>=1,1)-par_civ2.SearchBoxShift(:,1)/2 par_civ2.Grid(nbval>=1,2)-par_civ2.SearchBoxShift(:,2)/2];
-
+        
         if par_civ2.CheckDeformation
             par_civ2.DUDX(nbval>0)=DUDX(nbval>0)./nbval(nbval>0);
@@ -774,9 +733,9 @@
             par_civ2.DVDY(nbval>0)=DVDY(nbval>0)./nbval(nbval>0);
         end
-
+        
         % calculate velocity data (y and v in image indices, reverse to y component)
-
+        
         [Data.Civ2_X,Data.Civ2_Y,Data.Civ2_U,Data.Civ2_V,Data.Civ2_C,Data.Civ2_FF,~, errormsg] = civ (par_civ2);
-
+        
         list_param=(fieldnames(Param.ActionInput.Civ2))';
         list_param(strcmp('TestCiv2',list_param))=[];% remove the parameter TestCiv2 from the list
@@ -799,5 +758,5 @@
         end
         Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ2_param];
-
+        
         nbvar=numel(Data.ListVarName);
         % define the Civ2 variable (if Civ2 data are not replaced from previous calculation)
@@ -817,5 +776,5 @@
         if exist('ncfile','var')
             CivFile=ncfile;
-            [Data,tild,tild,errormsg]=nc2struct(CivFile);%read civ1 and detect_false1 data in the existing netcdf file
+            [Data,~,~,errormsg]=nc2struct(CivFile);%read civ1 and detect_false1 data in the existing netcdf file
             if ~isempty(errormsg)
                 disp_uvmat('ERROR',errormsg,checkrun)
@@ -824,7 +783,7 @@
         end
     end
-
+    
     %% Fix2
-    if isfield (Param.ActionInput,'Fix2')
+    if Param.ActionInput.CheckFix2 && isfield (Param.ActionInput,'Fix2')% if Fix2 computation is requested
         disp('detect_false2 started')
         list_param=fieldnames(Param.ActionInput.Fix2)';
@@ -840,5 +799,6 @@
     
     %% Patch2
-    if isfield (Param.ActionInput,'Patch2')
+    if Param.ActionInput.CheckPatch2 && isfield (Param.ActionInput,'Patch2')% if Patch2 computation is requested
+        
         disp('patch2 started')
         tstart_patch2=tic;
@@ -869,9 +829,9 @@
             ind_good=1:numel(Data.Civ2_X);
         end
-                if isempty(ind_good)
-                        disp_uvmat('ERROR','all vectors of civ2 are bad, check input parameters' ,checkrun)
-                        return
-                end
-              
+        if isempty(ind_good)
+            disp_uvmat('ERROR','all vectors of civ2 are bad, check input parameters' ,checkrun)
+            return
+        end
+        
         [Data.Civ2_SubRange,Data.Civ2_NbCentres,Data.Civ2_Coord_tps,Data.Civ2_U_tps,Data.Civ2_V_tps,tild,Ures,Vres,tild,FFres]=...
             filter_tps([Data.Civ2_X(ind_good) Data.Civ2_Y(ind_good)],Data.Civ2_U(ind_good),Data.Civ2_V(ind_good),[],Data.Patch2_SubDomainSize,Data.Patch2_FieldSmooth,Data.Patch2_MaxDiff);
@@ -884,24 +844,24 @@
     end
     
-    %% write result in a netcdf file if requested
-    if CheckOutputFile
-        errormsg=struct2nc(ncfile_out,Data);
-        if isempty(errormsg)
-            disp([ncfile_out ' written'])
-        else
-            disp(errormsg)
-        end
-        time_total=toc(tstart);
-        disp(['ellapsed time ' num2str(time_total/60,2) ' minutes'])
-        disp(['time civ1 ' num2str(time_civ1,2) ' s'])
-        disp(['time patch1 ' num2str(time_patch1,2) ' s'])
-        disp(['time civ2 ' num2str(time_civ2,2) ' s'])
-        disp(['time patch2 ' num2str(time_patch2,2) ' s'])
-        if exist('time_input','var')
-            disp(['time image reading ' num2str(time_input,2) ' s'])
-            disp(['time other ' num2str((time_total-time_input-time_civ1-time_patch1-time_civ2-time_patch2),2) ' s'])
-        end
-    end
-end
+    %% write result in a netcdf file
+    errormsg=struct2nc(ncfile_out,Data);
+    if isempty(errormsg)
+        disp([ncfile_out ' written'])
+    else
+        disp(errormsg)
+    end
+    time_total=toc(tstart);
+    disp(['ellapsed time ' num2str(time_total/60,2) ' minutes'])
+    disp(['time civ1 ' num2str(time_civ1,2) ' s'])
+    disp(['time patch1 ' num2str(time_patch1,2) ' s'])
+    disp(['time civ2 ' num2str(time_civ2,2) ' s'])
+    disp(['time patch2 ' num2str(time_patch2,2) ' s'])
+    if exist('time_input','var')
+        disp(['time image reading ' num2str(time_input,2) ' s'])
+        disp(['time other ' num2str((time_total-time_input-time_civ1-time_patch1-time_civ2-time_patch2),2) ' s'])
+    end
+end
+
+
 
 %------------------------------------------------------------------------
@@ -967,4 +927,6 @@
 end
 
+%------------------------------------------------------------------------
+% --- set the flag for false vectors
 function FF=detect_false(Param,C,U,V,FFIn)
 FF=FFIn;%default, good vectors
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 1168)
+++ /trunk/src/uvmat.m	(revision 1169)
@@ -2898,38 +2898,41 @@
 %case of view mask selection
 if isequal(get(handles.CheckMask,'Value'),1)
-   [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
-% if isempty(regexp(RootPath,'^http://'))
-%     fileinput=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
-% else
-%     fileinput=[RootPath '/' SubDir '/' RootFile FileIndex FileExt];%
-% end
-%  FileInfo=get_file_info(fileinput);
-     
-%     MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
-%     MaskPath=fullfile(RootPath,[MaskSubDir '.mask']);
-    mdetect=0;
-%     if exist(MaskPath,'dir')
-%         ListStruct=dir(MaskPath);%look for a mask file
-%         ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
-%         check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
-%         ListFiles=ListCells(1,:);%list of file and dri names
-%         ListFiles=ListFiles(~check_dir);%list of file names (excluding dir)
-%         if ~isempty(ListFiles)
-%             for ifile=1:numel(ListFiles)
-%                 [tild,tild,MaskExt]=fileparts(ListFiles{1});
-%                 [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileInfo]=find_file_series(MaskPath,ListFiles{ifile},0);
-%                 MaskFileType=MaskFileInfo.FileType;
-%                 if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series)
-%                     mdetect=1;
-%                 end
-%                 if ~strcmp(MaskFile{ifile},MaskFile{1})
-%                     mdetect=0;% cancel detection test in case of multiple masks, use the brower for selection
-%                     break
-%                 end
-%             end
-%         end
-%         RootPath=MaskPath;
-%     end
-    filemask= uigetfile_uvmat('pick a mask image file:',RootPath,'image');
+    [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
+    if isempty(regexp(RootPath,'^http://'))
+        fileinput=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
+    else
+        fileinput=[RootPath '/' SubDir '/' RootFile FileIndex FileExt];%
+    end
+    FileInfo=get_file_info(fileinput);
+    if isfield(FileInfo,'MaskFile')&& exist(FileInfo.MaskFile,'file')
+        filemask=FileInfo.MaskFile;
+    else
+        %     MaskSubDir=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
+        %     MaskPath=fullfile(RootPath,[MaskSubDir '.mask']);
+        %    mdetect=0;
+        %     if exist(MaskPath,'dir')
+        %         ListStruct=dir(MaskPath);%look for a mask file
+        %         ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
+        %         check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
+        %         ListFiles=ListCells(1,:);%list of file and dri names
+        %         ListFiles=ListFiles(~check_dir);%list of file names (excluding dir)
+        %         if ~isempty(ListFiles)
+        %             for ifile=1:numel(ListFiles)
+        %                 [tild,tild,MaskExt]=fileparts(ListFiles{1});
+        %                 [tild,tild,MaskFile{ifile},i1_series,i2_series,j1_series,j2_series,MaskNomType,MaskFileInfo]=find_file_series(MaskPath,ListFiles{ifile},0);
+        %                 MaskFileType=MaskFileInfo.FileType;
+        %                 if strcmp(MaskFileType,'image') && isempty(i2_series) && isempty(j2_series)
+        %                     mdetect=1;
+        %                 end
+        %                 if ~strcmp(MaskFile{ifile},MaskFile{1})
+        %                     mdetect=0;% cancel detection test in case of multiple masks, use the brower for selection
+        %                     break
+        %                 end
+        %             end
+        %         end
+        %         RootPath=MaskPath;
+        %     end
+        filemask= uigetfile_uvmat('pick a mask image file:',RootPath,'image');
+    end
     if ~isempty(filemask)
         [MaskPath,FileName,FileExt]=fileparts(filemask);
@@ -2949,5 +2952,5 @@
         errormsg=update_mask(handles);
         if ~isempty(errormsg)
-             msgbox_uvmat(['ERROR','error in displaying mask, ' errormsg]);
+            msgbox_uvmat(['ERROR','error in displaying mask, ' errormsg]);
         end
         testmask=1;
@@ -2956,5 +2959,6 @@
     MaskData=get(handles.CheckMask,'UserData');
     if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
-        delete(MaskData.maskhandle)
+       % delete(MaskData.maskhandle)
+       set(MaskData.maskhandle,'Visible','off')
     end
     set(handles.CheckMask,'UserData',[])
@@ -3037,5 +3041,5 @@
             if ~isempty(hmask)
                 set(hmask,'CData',imflag)
-                set(hmask,'AlphaData',flagmask*0.6)
+                set(hmask,'AlphaData',flagmask*0.3)
                 set(hmask,'XData',MaskField.Coord_x);
                 set(hmask,'YData',MaskField.Coord_y);
@@ -3044,5 +3048,5 @@
                 axes(handles.PlotAxes)
                 hold on
-                MaskInfo.maskhandle=image(MaskField.Coord_x,MaskField.Coord_y,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
+                MaskInfo.maskhandle=image(MaskField.Coord_x,MaskField.Coord_y,imflag,'Tag','mask','HitTest','off','AlphaData',0.3*ones(size(flagmask)));
                 set(handles.CheckMask,'UserData',MaskInfo)
             end
