Index: trunk/src/civ.m
===================================================================
--- trunk/src/civ.m	(revision 598)
+++ trunk/src/civ.m	(revision 599)
@@ -433,5 +433,5 @@
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-[RootPath,SubDirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,MovieObject]=find_file_series(FilePath,[FileName ImaExt]);
+[RootPath,SubDirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,FileInfo,MovieObject]=find_file_series(FilePath,[FileName ImaExt]);
 switch FileType
     case {'image','multimage','video','mmreader'}
@@ -2562,5 +2562,5 @@
             % detect the file type, get the movie object if relevant, and look for the corresponding file series:
             % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-            [RootPath,SubDir,RootFile_1,i1_series,i2_series,j1_series,j2_series,nom_type_1,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName Ext]);
+            [RootPath,SubDir,RootFile_1,i1_series,i2_series,j1_series,j2_series,nom_type_1,FileType,FileInfo,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName Ext]);
             
             %check image nom type
Index: trunk/src/find_file_series.m
===================================================================
--- trunk/src/find_file_series.m	(revision 598)
+++ trunk/src/find_file_series.m	(revision 599)
@@ -37,5 +37,5 @@
 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
 
-function [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1_input,i2_input,j1_input,j2_input]=find_file_series(FilePath,fileinput)
+function [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1_input,i2_input,j1_input,j2_input]=find_file_series(FilePath,fileinput)
 %------------------------------------------------------------------------
 
@@ -230,5 +230,5 @@
         %% update the file type if the input file does not exist (pb of 0001)
         if isempty(FileType)
-            [FileType,tild,MovieObject]=get_file_type(fullfile(FilePath,dirpair(ifile_min).name));
+            [FileType,FileInfo,MovieObject]=get_file_type(fullfile(FilePath,dirpair(ifile_min).name));
         end
     end
Index: trunk/src/get_file_series.m
===================================================================
--- trunk/src/get_file_series.m	(revision 598)
+++ trunk/src/get_file_series.m	(revision 599)
@@ -57,5 +57,5 @@
         FilePath=fullfile(InputTable{iview,1},InputTable{iview,2});
         fileinput=[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}];
-        [tild,tild,tild,i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview},NomType,FileType,MovieObject,i1_input,i2_input,j1_input,j2_input]=find_file_series(FilePath,fileinput);
+        [tild,tild,tild,i1_series{iview},i2_series{iview},j1_series{iview},j2_series{iview},NomType,FileType,FileInfo,MovieObject,i1_input,i2_input,j1_input,j2_input]=find_file_series(FilePath,fileinput);
         i1_series{iview}=squeeze(i1_series{iview}(1,:,:)); %first  pair index
         check_select=i1_series{iview}>=first_i & i1_series{iview}<=last_i;
Index: trunk/src/msgbox_uvmat.m
===================================================================
--- trunk/src/msgbox_uvmat.m	(revision 598)
+++ trunk/src/msgbox_uvmat.m	(revision 599)
@@ -196,5 +196,5 @@
 function varargout = msgbox_uvmat_OutputFcn(hObject, eventdata, handles)
 %------------------------------------------------------------------------
-
+varargout{1}='Cancel';%deg
 % Get default command line output from handles structure
 if isfield(handles,'output')
@@ -214,6 +214,7 @@
     end
     % The figure can be deleted now
-end
- delete(handles.figure1);
+    delete(handles.figure1);
+end
+%  delete(handles.figure1);
 
 %------------------------------------------------------------------------ 
Index: trunk/src/series.m
===================================================================
--- trunk/src/series.m	(revision 598)
+++ trunk/src/series.m	(revision 599)
@@ -282,5 +282,5 @@
      oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
  end
-[FileName, PathName, filterindex] = uigetfile( ...
+[FileName, PathName] = uigetfile( ...
        {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
        '*.xml',  '.xml files '; ...
@@ -304,5 +304,5 @@
             set_object(Param.ProjObject)
         end
-        set(handles.REFRESH,'UserData',[1:size(Param.InputTable,1)])
+        set(handles.REFRESH,'UserData',1:size(Param.InputTable,1))
         REFRESH_Callback([],[], handles)
         return
@@ -456,5 +456,5 @@
         RootPath=fileparts(RootPath); %will try the upped forldr
     else
-        [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=...
+        [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=...
             find_file_series(fullfile(InputTable{iview,1},InputTable{iview,2}),[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
     end
@@ -475,5 +475,5 @@
         display_file_name(handles,fileinput,iview)
     else
-        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,iview)
+        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview)
     end
 end
@@ -514,5 +514,5 @@
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
+[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
 if isempty(RootFile)&&isempty(i1_series)
     errormsg='no input file in the series';
@@ -581,10 +581,10 @@
 
 %% initiate input file series and refresh the current field view:     
-update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,iview);
+update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview);
 
 %------------------------------------------------------------------------
 % --- Update information about a new field series (indices to scan, timing,
 %     calibration from an xml file
-function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,iview)
+function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,VideoObject,iview)
 %------------------------------------------------------------------------
 %% update the output dir
@@ -708,4 +708,5 @@
 NbSlice_calib={};
 XmlFileName=find_imadoc(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5});
+TimeUnit='';
 if ~isempty(XmlFileName)
         [XmlData,warntext]=imadoc2struct(XmlFileName);
@@ -769,8 +770,12 @@
 %% number of slices
 NbSlice=1;%default
-if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
+heck_calib=0;
+if isfield(XmlData,'GeometryCalib') 
+    check_calib=1;
+    if isfield(XmlData.GeometryCalib,'SliceCoord')
     siz=size(XmlData.GeometryCalib.SliceCoord);
     if siz(1)>1
         NbSlice=siz(1);
+    end
     end
 end
@@ -793,5 +798,12 @@
 SeriesData.j2_series{iview}=j2_series;
 SeriesData.FileType{iview}=FileType;
+SeriesData.FileInfo{iview}=FileInfo;
 SeriesData.Time{iview}=time;
+if ~isempty(TimeUnit)
+    SeriesData.TimeUnit=TimeUnit;
+end
+if check_calib
+SeriesData.GeometryCalib{iview}=XmlData.GeometryCalib;
+end
 set(handles.series,'UserData',SeriesData)
 
@@ -1313,5 +1325,8 @@
 [Series,OutputDir,errormsg]=prepare_jobs(handles);% get parameters form the GUI series
 if ~isempty(errormsg)
+    if ~strcmp(errormsg,'Cancel')
     msgbox_uvmat('ERROR',errormsg)
+    end
+    STOP_Callback([],[], handles)
     return
 end
@@ -1681,5 +1696,8 @@
     while detect
         answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
-        if isequal(answer,'Yes')
+        if strcmp(answer,'Cancel')
+            errormsg='Cancel';
+            return
+        elseif strcmp(answer,'Yes')
             detect=0;
             check_create=0;
@@ -1849,5 +1867,7 @@
 [Series,tild,errormsg]=prepare_jobs(handles);% read the parameters from the GUI series
 if ~isempty(errormsg)
+    if ~strcmp(errormsg,'Cancel')
     msgbox_uvmat('ERROR',errormsg)
+    end
     return
 end
@@ -2386,4 +2406,8 @@
     Param=read_GUI(handles.series);
     RootPath=Param.InputTable{1,1};
+    if ~isfield(Param,'OutputSubDir')   
+        msgbox_uvmat('ERROR','no directory defined for output files')
+        return
+    end
     OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files
     OutputDir=fullfile(RootPath,OutputSubDir);
Index: trunk/src/series/civ_input.m
===================================================================
--- trunk/src/series/civ_input.m	(revision 598)
+++ trunk/src/series/civ_input.m	(revision 599)
@@ -57,6 +57,10 @@
 guidata(hObject, handles); % Update handles structure
 set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
-
-%% set visibility options
+SeriesData.ParentHandle=gcbf;
+SeriesData=get(gcbf,'UserData');
+% relevant data in gcbf:.FileType,.FileInfo,.Time,.TimeUnit,.GeometryCalib{1};
+
+%% set visibility options: case civ_matlab
+if strcmp(Param.Action.ActionName,'civ_series')
         set(handles.num_MaxDiff,'Visible','on')
         set(handles.num_MaxVel,'Visible','on')
@@ -73,22 +77,266 @@
         set(handles.CheckDeformation,'Value',0)% desactivate (work in progress)
         set(handles.CheckDecimal,'Value',0)% desactivate (work in progress)
+end
+
+%% input file info
+RootPath=Param.InputTable{1,1};
+RootFile=Param.InputTable{1,3};
+SubDir=Param.InputTable{1,2};
+NomTypeInput=Param.InputTable{1,4};
+FileExt=Param.InputTable{1,5};
+FileType=SeriesData.FileType{1};
+FileInfo=SeriesData.FileInfo{1};
+
+%% case of netcdf file as input, get the processing stage and look for corresponding images
+% imageinput=fileinput;%default
+% TODO: insert image input in the GUI series
+ind_opening=0;%default
+NomTypeNc='';
+switch FileType
+    case 'civdata'
+        NomTypeNc=NomTypeInput;
+        ind_opening=FileInfo.CivStage;
+        if isempty(regexp(NomTypeInput,'[ab|AB|-]', 'once'))
+            set(handles.ListCompareMode,'Value',2) %mode displacement advised if the nomencalture does not involve index pairs
+            set(handles.RootFile_1,'Visible','On');
+        else
+            set(handles.ListCompareMode,'Value',1)
+            set(handles.RootFile_1,'Visible','Off');
+        end
+        imageinput='';
+        set(handles.Program,'Value',1) %select civ/Matlab by default
+        %         if  ~isempty(Data.Civ2_ImageB)%get the corresponding input image in the netcdf file
+        %             imageinput=Data.Civ2_ImageB;
+        %             [tild,ImaName,ImaExt]=fileparts(Data.Civ2_ImageA);
+        %             set(handles.RootFile_1,'String',[ImaName ImaExt])
+        %         elseif ~isempty(Data.Civ1_ImageB)
+        %             imageinput=Data.Civ1_ImageB;
+        %             [tild,ImaName,ImaExt]=fileparts(Data.Civ1_ImageA);
+        %             set(handles.RootFile_1,'String',[ImaName ImaExt])
+        %         end
+        % settings for civx data,        
+        % look for the corresponding input images
+        check_letter=~isempty(regexp(NomTypeInput,'[ab|AB]$','once'));%detect pair label by letter
+        NomTypeIma=NomTypeInput;
+        if check_letter
+            NomTypeIma=NomTypeInput(1:end-1);
+        else
+            r=regexp(NomTypeIma,'.-(?<num2>\d+)$','names');
+            if ~isempty(r)
+                NomTypeIma=regexprep(NomTypeIma,['-' r.num2],'');
+            end
+            r=regexp(NomTypeIma,'.-(?<num2>\d+)','names');
+            if ~isempty(r)
+                NomTypeIma=regexprep(NomTypeIma,['-' r.num2],'');
+            end
+        end
+        if ~exist(imageinput,'file')
+            imageinput=fullfile_uvmat(RootPath,regexprep(SubDir,'.civ(_?)(\d*)$',''),RootFile,'.png',NomTypeIma,i1,[],j1);
+        end
+    case 'civxdata'% case of  civx data,
+        NomTypeNc=NomTypeInput;
+        ind_opening=FileInfo.CivStage;
+        set(handles.Program,'Value',3) %select Cix by default
+        msgbox_uvmat('ERROR','old civX convention, use the GUI civ')
+        return
+     case {'image','multimage','video','mmreader'}
+          NomTypeIma=NomTypeInput;      
+end
+
+%% TODO: get corresponding image in nc case
+
+%% reinitialise menus
+set(handles.ListPairMode,'Value',1)
+set(handles.ListPairMode,'String',{''})
+set(handles.ListPairCiv1,'Value',1)
+set(handles.ListPairCiv1,'String',{''})
+set(handles.ListPairCiv2,'Value',1)
+set(handles.ListPairCiv2,'String',{''}) 
+fill_GUI(Param,hObject);%fill the GUI with the parameters retrieved from the input Param
+
         
 %% prepare the GUI with input parameters 
-% from the GUI series
-
-%from the input file
-filecell=get_file_series(Param);
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-errormsg=display_file_name(handles,filecell{1});
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
-if isfield(Param,'ActionInput')&&isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
-    fill_GUI(Param.ActionInput,handles.civ_input)
-end
+set(handles.ListCompareMode,'Visible','on')
+
+%display the parameters stored on the GUI series
+set(handles.first_i,'String',num2str(Param.IndexRange.first_i))
+set(handles.incr_i,'String',num2str(Param.IndexRange.incr_i))
+set(handles.last_i,'String',num2str(Param.IndexRange.last_i))
+set(handles.ref_i,'String',num2str(Param.IndexRange.first_i))
+if isfield(Param.IndexRange,'first_j')
+    set(handles.first_j,'String',num2str(Param.IndexRange.first_j))
+    set(handles.incr_j,'String',num2str(Param.IndexRange.incr_j))
+    set(handles.last_j,'String',num2str(Param.IndexRange.last_j))
+    set(handles.ref_i,'String',num2str(Param.IndexRange.first_j))
+end
+
+%% set the civ_input options depending on the input file content when a nc file has been opened
+ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
+checkbox=zeros(size(ListOptions));%default
+if ind_opening==0%case of image opening, start with Civ1
+    for index=1:numel(ListOptions)
+        checkbox(index)=get(handles.(ListOptions{index}),'Value');
+    end
+    index_max=find(checkbox, 1, 'last' );
+    if isempty(index_max),index_max=1;end
+    for index=1:index_max
+        set(handles.(ListOptions{index}),'Value',1)% select all operations starting from CIV1
+    end
+else
+    for index = 1:min(ind_opening,5)
+        set(handles.(ListOptions{index}),'value',0)
+    end
+    set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
+    for index = ind_opening+2:6
+        set(handles.(ListOptions{index}),'value',0)
+    end
+end
+%list_operation={'CheckCiv1','CheckFix1','CheckPatch1','CheckCiv2','CheckFix2','CheckPatch2'};
+
+%set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
+update_CivOptions(handles,ind_opening)
+
+%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
+%check_letter=~isempty(regexp(NomTypeIma,'[ab|AB]$'));%detect pair label by letter
+%if  isequal(NomTypeNc,'_1-2')||isempty(MaxIndex_j)|| (MaxIndex_j==1)
+MaxIndex_i=Param.IndexRange.MaxIndex{1};
+MaxIndex_j=Param.IndexRange.MaxIndex{1,2};
+MinIndex_i=Param.IndexRange.MinIndex{1};
+MinIndex_j=Param.IndexRange.MinIndex{1,2};
+if ~isfield(Param.IndexRange,'first_j')
+    set(handles.ListPairMode,'Value',1)
+    set(handles.ListPairMode,'String',{'series(Di)'})
+elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
+    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)'})
+    if  MaxIndex_j <= 10
+        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
+    end
+elseif ~(strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
+    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
+    if strcmp(NomTypeNc,'_1-2_1')
+        set(handles.ListPairMode,'Value',3)% advise 'series(Di)'
+    elseif  MaxIndex_j <= 10
+        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
+    end
+end
+
+%%  transfer the time from the GUI series, or use file index by default
+time=[];
+TimeUnit='frame'; %default
+CoordUnit='';%default
+pxcm_search=1;
+if isfield(SeriesData,'Time') && ~isempty(SeriesData.Time{1})
+    time=SeriesData.Time{1};
+    %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
+    if isequal(MaxIndex_i,1) && ~isequal(MaxIndex_j,1)% .Time is a line vector
+        if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D','once'))
+            time=time';
+            MaxIndex_i=MaxIndex_j;
+            MaxIndex_j=1;
+        end
+    end
+end
+if isfield(SeriesData,'TimeUnit')
+    TimeUnit=SeriesData.TimeUnit;
+end
+if isfield(SeriesData,'GeometryCalib')
+    tsai=SeriesData.GeometryCalib;
+    if isfield(tsai,'fx_fy')
+        pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
+    end
+    if isfield(tsai,'CoordUnit')
+        CoordUnit=tsai.CoordUnit;
+    end
+end
+% timing set by video input
+if isempty(time) && (strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
+    set(handles.ListPairMode,'Value',1);
+    dt=1/get(MovieObject,'FrameRate');%time interval between successive frames
+    if strcmp(NomTypeIma,'*')
+        set(handles.ListPairMode,'String',{'series(Di)'})
+        time=(dt*(0:MaxIndex_i-1))';%list of image times
+    else
+        set(handles.ListPairMode,'String',[{'series(Dj)'};{'series(Di)'}])
+        time=ones(MaxIndex_i,1)*(dt*(0:MaxIndex_j-1));%list of image times
+        enable_j(handles,'on')
+    end
+    TimeUnit='s';
+    set(handles.ImaDoc,'BackgroundColor',[1 1 1])% set display box back to whiter
+end
+
+%% timing display
+%show the reference image edit box if relevant (not needed for movies or in the absence of time information
+if numel(time)>=2 % if there are at least two time values to define dt
+    if size(time,1)<MaxIndex_i;
+        msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
+    elseif size(time,2)<MaxIndex_j
+        msgbox_uvmat('WARNING','maximum j index restricted by the timing of the xml file');
+    end
+    MaxIndex_i=min(size(time,1),MaxIndex_i);%possibly adjust the max index according to time data
+    MaxIndex_j=min(size(time,2),MaxIndex_j);
+else
+    set(handles.ImaDoc,'String',''); %xml file not used for timing
+    %    time=(i1_series(:,1)+0:size(i1_series,3)-1);% time=index i
+    %    time=time'*ones(1,size(i1_series,2),1); %makes a time matrix with the same time for all j indices
+    TimeUnit='frame';
+    time=ones(MaxIndex_j-MinIndex_j+1,1)*(MinIndex_i:MaxIndex_i);
+    time=time+0.001*(MinIndex_j:MaxIndex_j)'*ones(1,MaxIndex_i-MinIndex_i+1);
+end
+time=[zeros(size(time,1),1) time]; %insert a vertical line of zeros (to deal with zero file indices)
+time=[zeros(1,size(time,2)); time]; %insert a horizontal line of zeros
+CivInputData.Time=time;
+set(handles.civ_input,'UserData',CivInputData)
+%set(handles.ImaDoc,'UserData',time); %store the matrix of times
+set(handles.NomType,'String',NomTypeIma)
+set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
+set(handles.TimeUnit,'String',TimeUnit);
+set(handles.nb_field,'String',num2str(MaxIndex_i));
+set(handles.nb_field2,'String',num2str(MaxIndex_j));
+set(handles.CoordUnit,'String',CoordUnit)
+set(handles.SearchRange,'UserData', pxcm_search);
+
+% set(handles.ImaExt,'String',ImaExt)
+% set(handles.NomType,'String',NomTypeIma)
+
+%% set the reference indices from the input file indices
+num_ref_i=str2num(get(handles.ref_i,'String'));
+num_ref_j=str2num(get(handles.ref_j,'String'));
+
+
+%% list the possible index pairs, depending on the option set in ListPairMode
+ListPairMode_Callback([], [], handles)
+
+% for movies don't modify except if the current ref is outside index bounds
+%if strcmp(ExtInput,'.nc')|| ~(strcmp(FileType,'mmreader')||strcmp(FileType,'VideoReader') && num_ref_i<=MaxIndex_i && num_ref_j<=MaxIndex_j)
+% if ~isempty(i1)% if i1 has been selected by the input
+%     num_ref_i=i1;%default ref index
+%     if ~isempty(i2)
+%         num_ref_i=floor((num_ref_i+i2)/2);
+%     end
+%     if ~isempty(j1)
+%         num_ref_j=j1;
+%         if ~isempty(j2)
+%             num_ref_j=floor((num_ref_j+j2)/2);
+%         end
+%     end
+% end
+% if num_ref_i>MaxIndex_i||num_ref_i<MinIndex_i
+%     num_ref_i=round((MinIndex_i+MaxIndex_i)/2);
+% end
+% if ~isempty(num_ref_j)&&~isempty(MaxIndex_j)&& ~isempty(MinIndex_j)
+%     if (num_ref_j>MaxIndex_j||num_ref_j<MinIndex_j)
+%         num_ref_j=round((MinIndex_j+MaxIndex_j)/2);
+%     end
+% end
+% if isempty(num_ref_j)
+%     num_ref_j=1;
+% end
+% 
+%% set the GUI to modal: wait for OK to close
 set(handles.civ_input,'WindowStyle','modal')% Make the GUI modal
 drawnow
 uiwait(handles.civ_input);
+
+
 
 %Program_Callback([],[], handles)
@@ -111,136 +359,6 @@
     delete(handles.civ_input);
 end
-%------------------------------------------------------------------------
-% --- Function activated by the Open/Browse... option in the upper menu bar.
-function MenuBrowse_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-%% get the current input root file name to initiate the browser
-filebase=get(handles.RootPath,'String');
-oldfile=''; %default
-if isempty(filebase)|| isequal(filebase,'')%loads the previously stored root file name
-    dir_perso=prefdir;
-    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
-    if exist(profil_perso,'file')
-        h=load (profil_perso);
-        if isfield(h,'filebase')&& ischar(h.filebase)
-            oldfile=h.filebase;
-        end
-        if isfield(h,'RootPath') && ischar(h.RootPath)
-            oldfile=h.RootPath;
-        end
-    end
-else
-    oldfile=filebase;
-end
-
-%% get the new input file with the browser
-menu={'*.xml;*.civ;*.png;*.jpg;*.tif;*.avi;*.AVI;*.nc;', ' (*.xml,*.civ,*.png,*.jpg ,.tif, *.avi,*.nc)';
-    '*.xml',  '.xml files '; ...
-    '*.civ',  '.civ files '; ...
-    '*.png','.png image files'; ...
-    '*.jpg',' jpeg image files'; ...
-    '*.tif','.tif image files'; ...
-    '*.avi;*.AVI','.avi movie files'; ...
-    '*.nc','.netcdf files'; ...
-    '*.*',  'All Files (*.*)'};
-[FileName, PathName, filtindex] = uigetfile( menu, 'Pick a file',oldfile);
-fileinput=[PathName FileName];%complete file name
-sizf=size(fileinput);
-if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
-
-%% case of the xml file opened as input (TODO: check and see whether it is useful)
-[path,name,ext]=fileparts(fileinput);
-testeditxml=0;
-% if isequal(ext,'.xml')
-%     testeditxml=1;
-%     t_browse=xmltree(fileinput);
-%     head_element=get(t_browse,1);
-%     if isfield(head_element,'name')&& isequal(head_element.name,'ImaDoc')
-%         testeditxml=0;
-%     end
-% end
-% if testeditxml==1 || isequal(ext,'.xls')
-%     heditxml=editxml({fileinput});
-%     set(heditxml,'Tag','browser')
-%     waitfor(heditxml,'Tag','idle')
-%     if ~ishandle(heditxml)
-%         return
-%     end
-%     attr=findobj(get(heditxml,'children'),'Tag','CurrentAttributes');
-%     set(handles.browse,'UserData',fileinput)% store for future opening with browser
-%     fileinput=get(attr,'UserData');
-%     if ~exist(fileinput,'file')
-%         return
-%     end
-% end
-[tild,tild,tild,i1,i2,j1,j2,FileExt,NomType]=fileparts_uvmat(fileinput);
-
-%% prepare the GUI with parameters from the input file 
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-errormsg=display_file_name(handles,fileinput);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',erromsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
-
-%------------------------------------------------------------------------
-% --- Open again the file whose name has been recorded in MenuFile_1
-function MenuFile_1_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-fileinput=get(handles.MenuFile_1,'Label');
-errormsg=display_file_name(handles,fileinput);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
-
-% -----------------------------------------------------------------------
-% --- Open again the file whose name has been recorded in MenuFile_2
-function MenuFile_2_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-fileinput=get(handles.MenuFile_2,'Label');
-errormsg=display_file_name(handles,fileinput);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
-
-% -----------------------------------------------------------------------
-% --- Open again the file whose name has been recorded in MenuFile_3
-function MenuFile_3_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-fileinput=get(handles.MenuFile_3,'Label');
-errormsg=display_file_name(handles,fileinput);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
-
-% -----------------------------------------------------------------------
-% --- Open again the file whose name has been recorded in MenuFile_4
-function MenuFile_4_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-fileinput=get(handles.MenuFile_4,'Label');
-errormsg=display_file_name(handles,fileinput);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
-
-% -----------------------------------------------------------------------
-% --- Open again the file whose name has been recorded in MenuFile_5
-function MenuFile_5_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-fileinput=get(handles.MenuFile_5,'Label');
-errormsg=display_file_name(handles,fileinput);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
+
+
 
 % -----------------------------------------------------------------------
@@ -258,22 +376,4 @@
 end
 
-%------------------------------------------------------------------------
-% --- Function activated when a new filebase (image series) is introduced
-function RootPath_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.RootPath,'BackgroundColor',[1 1 0])%paint RootName edit box in yellow to indicate that the file input is proceeding
-RootPath=get(handles.RootPath,'String');
-SubDirImages=get(handles.SubDirImages,'String');
-RootFile=get(handles.RootFile,'String');
-ref_i=str2num(get(handles.ref_i,'String'));
-ref_j=str2num(get(handles.ref_j,'String'));
-NomType=get(handles.NomType,'String');
-ImaExt=get(handles.ImaExt,'String');
-fileinput=fullfile_uvmat(RootPath,SubDirImages,RootFile,ImaExt,NomType,ref_i,[],ref_j);
-errormsg=display_file_name(handles,fileinput);
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',errormsg)
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])%paint RootName back to white to indicate that the file input is finished
 
 %------------------------------------------------------------------------
@@ -281,7 +381,5 @@
 function errormsg=display_file_name(handles,fileinput)
 %------------------------------------------------------------------------
-set(handles.ListCompareMode,'Visible','on')
-errormsg='';%default empty error message
-drawnow
+
 
 %% enable OK, BATCH button and 'status' display
@@ -294,118 +392,15 @@
 
 %% determine nomenclature types and extension of the input files
-[RootPath,SubDir,RootFile,i1,i2,j1,j2,ExtInput,NomTypeInput]=fileparts_uvmat(fileinput);
-NomTypeNc='';%default
-
-%% case of xml file as input, read the civ_input parameters
-ind_opening=0;%default
-if strcmp(ExtInput,'.xml')
-    %reinitialise menus
-        set(handles.ListPairMode,'Value',1)
-    set(handles.ListPairMode,'String',{''})
-    set(handles.ListPairCiv1,'Value',1)
-    set(handles.ListPairCiv1,'String',{''})
-        set(handles.ListPairCiv2,'Value',1)
-    set(handles.ListPairCiv2,'String',{''}) 
-    Param=xml2struct(fileinput);  %read parameters from the xml input file
-    fill_GUI(Param,handles);%fill the GUI with the parameters retrieved from the xml file 
-    return
-end
-
-%% case of netcdf file as input, get the civ_input processing stage and look for a coresponding image
-imageinput=fileinput;%default
-if strcmp(ExtInput,'.nc')
-    NomTypeNc=NomTypeInput;
-    if isempty(regexp(NomTypeInput,'[ab|AB|-]', 'once'))
-        set(handles.ListCompareMode,'Value',2) %mode displacement advised if the nomencalture does not involve index pairs
-        set(handles.RootFile_1,'Visible','On');
-    else
-        set(handles.ListCompareMode,'Value',1)
-        set(handles.RootFile_1,'Visible','Off');
-    end
-    imageinput='';
-    Data=nc2struct(fileinput,'ListGlobalAttribute','Conventions','absolut_time_T0','CivStage','Civ2_ImageA','Civ1_ImageA','Civ2_ImageB','Civ1_ImageB','fix','patch','civ2','fix2');
-    if isfield(Data,'Txt')
-        errormsg=Data.Txt;
-        return
-    end
-    % settings for  new civ_input data,
-    if strcmp(Data.Conventions,'uvmat/civdata')% case of new civ data,
-        set(handles.Program,'Value',1) %select civ/Matlab by default
-        Program_Callback([],[], handles)
-        if ~isempty(Data.CivStage)%test for civ files
-            ind_opening=Data.CivStage;
-        end
-        if  ~isempty(Data.Civ2_ImageB)%get the corresponding input image in the netcdf file
-            imageinput=Data.Civ2_ImageB;
-            [tild,ImaName,ImaExt]=fileparts(Data.Civ2_ImageA);
-            set(handles.RootFile_1,'String',[ImaName ImaExt])
-        elseif ~isempty(Data.Civ1_ImageB)
-            imageinput=Data.Civ1_ImageB;
-            [tild,ImaName,ImaExt]=fileparts(Data.Civ1_ImageA);
-            set(handles.RootFile_1,'String',[ImaName ImaExt])
-        end
-        % settings for civx data,
-    elseif ~isempty(Data.absolut_time_T0')% case of  civx data,
-        set(handles.Program,'Value',3) %select Cix by default
-        Program_Callback([],[], handles)
-        if ~isempty(Data.fix2)
-            ind_opening=5;
-        elseif ~isempty(Data.civ2)
-            ind_opening=4;
-        elseif ~isempty(Data.patch)
-            ind_opening=3;
-        elseif ~isempty(Data.fix)
-            ind_opening=2;
-        end
-    else
-        errormsg='the input netcdf file is not civ data';
-        return
-    end
-    % look for the corresponding input images
-    check_letter=~isempty(regexp(NomTypeInput,'[ab|AB]$','once'));%detect pair label by letter
-    NomTypeIma=NomTypeInput;
-    if check_letter
-        NomTypeIma=NomTypeInput(1:end-1);
-    else
-        r=regexp(NomTypeIma,'.-(?<num2>\d+)$','names');
-        if ~isempty(r)
-            NomTypeIma=regexprep(NomTypeIma,['-' r.num2],'');
-        end
-        r=regexp(NomTypeIma,'.-(?<num2>\d+)','names');
-        if ~isempty(r)
-            NomTypeIma=regexprep(NomTypeIma,['-' r.num2],'');
-        end
-    end
-    if ~exist(imageinput,'file')
-    imageinput=fullfile_uvmat(RootPath,regexprep(SubDir,'.civ(_?)(\d*)$',''),RootFile,'.png',NomTypeIma,i1,[],j1);
-    end
-end
-
-%% no corresponding image found, select manually with the browser
-ImaExt=ExtInput;
-if ~isempty(NomTypeNc)
-    %no corresponding image found, select manually with the browser
-    if ~exist(imageinput,'file')
-        menu={'*.png;*.jpg;*.tif;*.avi;*.AVI', '(*.png,*.jpg ,*.tif, *.avi,*.AVI)';
-            '*.png','.png image files'; ...
-            '*.jpg',' jpeg image files'; ...
-            '*.tif','.tif image files'; ...
-            '*.avi;*.AVI','.avi movie files'; ...
-            '*.*',  'All Files (*.*)'};
-        [FileName, PathName] = uigetfile( menu, 'Pick an input image file',fileparts(fileparts(fileinput)));
-        imageinput=[PathName FileName];%complete file name
-        if ~exist(imageinput,'file')
-            return %abandon of the browser is cancelled
-        end
-    end    
-    %fileinput=imageinput;
-end
-
-%% scan the image file series 
+% [RootPath,SubDir,RootFile,i1,i2,j1,j2,ExtInput,NomTypeInput]=fileparts_uvmat(fileinput);
+% NomTypeNc='';%default
+
+
+
+%% scan the image file series
 [FilePath,FileName,ImaExt]=fileparts(imageinput);
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-[RootPath,SubDirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,MovieObject]=find_file_series(FilePath,[FileName ImaExt]);
-switch FileType
+%[RootPath,SubDirImages,RootFile,i1_series,tild,j1_series,tild,NomTypeIma,FileType,MovieObject]=find_file_series(FilePath,[FileName ImaExt]);
+switch Param.FileType{1}
     case {'image','multimage','video','mmreader'}
     otherwise
@@ -445,134 +440,27 @@
 set(handles.ImaDoc,'String',ext_imadoc)% display the extension name for the image documentation file used
 
-%%  read the time in the image documentation file  
-time=[];
-TimeUnit=''; %default
-CoordUnit='';%default
-pxcm_search=1;
-if ~isempty(XmlFileName)
-    set(handles.ImaDoc,'BackgroundColor',[1 1 0]) % set edit box to yellow cloro to indicate that the file reading is beginning
-    drawnow
-    [XmlData,warntext]=imadoc2struct(XmlFileName);
-    nom_type_read=[];
-    if isfield(XmlData,'Time') && ~isempty(XmlData.Time)
-        time=XmlData.Time;
-        %transform .Time to a column vector if it is a line vector thenomenclature uses a single index: correct possible bug in xml
-        if isequal(MaxIndex_i,1) && ~isequal(MaxIndex_j,1)% .Time is a line vector
-            if numel(nom_type_read)>=2 && isempty(regexp(nom_type_read(2:end),'\D','once'))
-                time=time';
-                MaxIndex_i=MaxIndex_j;
-                MaxIndex_j=1;
-            end
-        end
-    end
-    if isfield(XmlData,'Camera') && isfield(XmlData.Camera,'TimeUnit')
-        TimeUnit=XmlData.Camera.TimeUnit;
-    end
-    if isfield(XmlData,'GeometryCalib')
-        tsai=XmlData.GeometryCalib;
-        if isfield(tsai,'fx_fy')
-            pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
-        end
-        if isfield(tsai,'CoordUnit')
-            CoordUnit=tsai.CoordUnit;
-        end
-    end
-end
-if isempty(time) && (strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
-    set(handles.ListPairMode,'Value',1);
-    dt=1/get(MovieObject,'FrameRate');%time interval between successive frames
-    if strcmp(NomTypeIma,'*')
-        set(handles.ListPairMode,'String',{'series(Di)'})
-        MaxIndex_i=get(MovieObject,'NumberOfFrames');
-        time=(dt*(0:MaxIndex_i-1))';%list of image times
-    else
-        set(handles.ListPairMode,'String',[{'series(Dj)'};{'series(Di)'}])
-        MaxIndex_i=max(i1_series(i1_series>0));
-        MaxIndex_j=get(MovieObject,'NumberOfFrames');
-        time=ones(MaxIndex_i,1)*(dt*(0:MaxIndex_j-1));%list of image times
-        enable_j(handles,'on')
-    end
-    TimeUnit='s';
-    set(handles.ImaDoc,'BackgroundColor',[1 1 1])% set display box back to whiter
-end
-
-%% timing display
-%show the reference image edit box if relevant (not needed for movies or in the absence of time information
-if numel(time)>=2 % if there are at least two time values to define dt
-    if size(time,1)<MaxIndex_i;
-        msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
-    elseif size(time,2)<MaxIndex_j
-        msgbox_uvmat('WARNING','maximum j index restricted by the timing of the xml file');
-    end
-    MaxIndex_i=min(size(time,1),MaxIndex_i);%possibly adjust the max index according to time data
-    MaxIndex_j=min(size(time,2),MaxIndex_j);
-    time=[zeros(size(time,1),1) time]; %insert a vertical line of zeros (to deal with zero file indices)
-    time=[zeros(1,size(time,2)); time]; %insert a horizontal line of zeros
-else
-    set(handles.ImaDoc,'String',''); %xml file not used for timing
-    time=(i1_series(:,1)+0:size(i1_series,3)-1);% time=index i
-    time=time'*ones(1,size(i1_series,2),1); %makes a time matrix with the same time for all j indices
-    TimeUnit='frame';
-end
-set(handles.ImaDoc,'UserData',time); %store the matrix of times
-set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
-set(handles.TimeUnit,'String',TimeUnit);
-set(handles.nb_field,'String',num2str(MaxIndex_i));
-set(handles.nb_field2,'String',num2str(MaxIndex_j));
-set(handles.CoordUnit,'String',CoordUnit)
-set(handles.SearchRange,'UserData', pxcm_search);
-set(handles.ImaExt,'String',ImaExt)
-set(handles.NomType,'String',NomTypeIma)
-
-%% set the reference indices from the input file indices
-num_ref_i=str2num(get(handles.ref_i,'String'));
-num_ref_j=str2num(get(handles.ref_j,'String'));
-% for movies don't modify except if the current ref is outside index bounds
-%if strcmp(ExtInput,'.nc')|| ~(strcmp(FileType,'mmreader')||strcmp(FileType,'VideoReader') && num_ref_i<=MaxIndex_i && num_ref_j<=MaxIndex_j)
-if ~isempty(i1)% if i1 has been selected by the input
-    num_ref_i=i1;%default ref index
-    if ~isempty(i2)
-        num_ref_i=floor((num_ref_i+i2)/2);
-    end
-    if ~isempty(j1)
-    num_ref_j=j1;
-    if ~isempty(j2)
-        num_ref_j=floor((num_ref_j+j2)/2);
-    end
-    end
-end
-if num_ref_i>MaxIndex_i||num_ref_i<MinIndex_i
-    num_ref_i=round((MinIndex_i+MaxIndex_i)/2);
-end
-if ~isempty(num_ref_j)&&~isempty(MaxIndex_j)&& ~isempty(MinIndex_j)
-    if (num_ref_j>MaxIndex_j||num_ref_j<MinIndex_j)
-        num_ref_j=round((MinIndex_j+MaxIndex_j)/2);
-    end
-end
-if isempty(num_ref_j)
-    num_ref_j=1;
-end
-
-%% update i and j index range if a nc file has been opened or pb withmin max image indices: 
+
+
+%% update i and j index range if a nc file has been opened or pb withmin max image indices:
 % then set first and last to the inputfile index by default
 first_i=str2num(get(handles.first_i,'String'));
 last_i=str2num(get(handles.last_i,'String'));
 if isempty(first_i) || isempty(last_i)||isempty(MinIndex_i)||isempty(MaxIndex_i)||ind_opening~=0 || isempty(first_i) || isempty(last_i)|| first_i<MinIndex_i || last_i>MaxIndex_i
-   first_i=num_ref_i;
-   last_i=num_ref_i;
+    first_i=num_ref_i;
+    last_i=num_ref_i;
     set(handles.first_i,'String',num2str(first_i));
     set(handles.last_i,'String',num2str(last_i));%
 end
 
-%j index range 
+%j index range
 first_j=str2num(get(handles.first_j,'String'));
 last_j=str2num(get(handles.last_j,'String'));
 if isempty(first_j) || isempty(last_j)||isempty(MinIndex_j)||isempty(MaxIndex_j)||ind_opening~=0 || first_j<MinIndex_j || last_j>MaxIndex_j
-       first_j=num_ref_j;
-   last_j=num_ref_j;
+    first_j=num_ref_j;
+    last_j=num_ref_j;
     set(handles.first_j,'String',num2str(first_j));
     set(handles.last_j,'String',num2str(last_j));%
 end
-if num_ref_i>last_i || num_ref_i<first_i 
+if num_ref_i>last_i || num_ref_i<first_i
     num_ref_i=round((first_i+last_i)/2);
 end
@@ -583,48 +471,5 @@
 set(handles.ref_j,'String',num2str(num_ref_j))
 
-%% set the civ_input options depending on the input file content when a nc file has been opened
-ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
-checkbox=zeros(size(ListOptions));%default
-if ind_opening==0%case of image opening, start with Civ1
-    for index=1:numel(ListOptions)
-        checkbox(index)=get(handles.(ListOptions{index}),'Value');
-    end
-    index_max=find(checkbox, 1, 'last' );
-    if isempty(index_max),index_max=1;end        
-    for index=1:index_max
-        set(handles.(ListOptions{index}),'Value',1)% select all operations starting from CIV1
-    end
-else
-    for index = 1:min(ind_opening,5)
-        set(handles.(ListOptions{index}),'value',0)
-    end
-    set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
-    for index = ind_opening+2:6
-        set(handles.(ListOptions{index}),'value',0)
-    end
-end
-%list_operation={'CheckCiv1','CheckFix1','CheckPatch1','CheckCiv2','CheckFix2','CheckPatch2'};
-
-%set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
-update_CivOptions(handles,ind_opening)
-
-%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
-%check_letter=~isempty(regexp(NomTypeIma,'[ab|AB]$'));%detect pair label by letter
-if  isequal(NomTypeNc,'_1-2')||isempty(MaxIndex_j)|| (MaxIndex_j==1)
-    set(handles.ListPairMode,'Value',1)
-    set(handles.ListPairMode,'String',{'series(Di)'})   
-elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
-    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)'})
-    if  MaxIndex_j <= 10
-        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
-    end
-elseif ~(strcmp(FileType,'video') || strcmp(FileType,'mmreader'))
-    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
-    if strcmp(NomTypeNc,'_1-2_1')
-        set(handles.ListPairMode,'Value',3)% advise 'series(Di)'
-    elseif  MaxIndex_j <= 10
-        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
-    end
-end
+
 
 %% scan files to update the subdirectory list display
@@ -644,24 +489,8 @@
 
 %% store info
-set(handles.RootPath,'UserData',browse)% store the nomenclature type
+%set(handles.RootPath,'UserData',browse)% store the nomenclature type
 
 %% list the possible index pairs, depending on the option set in ListPairMode
 ListPairMode_Callback([], [], handles)
-
-%% store the root input filename for future opening
-profil_perso=fullfile(prefdir,'uvmat_perso.mat');
-if exist(profil_perso,'file')
-    save (profil_perso,'RootPath','-append'); %store the root name for future opening of uvmat
-else
-    txt=ver('MATLAB');
-    Release=txt.Release;
-    relnumb=str2double(Release(3:4));
-    if relnumb >= 14
-        save (profil_perso,'RootPath','-V6'); %store the root name for future opening of uvmat
-    else
-        save (profil_perso,'RootPath'); %store the root name for future opening of uvmat
-    end
-end
-set(handles.RootPath,'BackgroundColor',[1 1 1])
 
 %------------------------------------------------------------------------
@@ -757,11 +586,11 @@
 checkbox(6)=get(handles.CheckPatch2,'Value');
 ind_selected=find(checkbox,1);
-if ~isempty(ind_selected)
-    RootPath=get(handles.RootPath,'String');
-    if isempty(RootPath)
-        msgbox_uvmat('ERROR','Please open an image or PIV .nc file with the upper bar menu Open/Browse...')
-        return
-    end
-end
+% if ~isempty(ind_selected)
+%     RootPath=get(handles.RootPath,'String');
+%     if isempty(RootPath)
+%         msgbox_uvmat('ERROR','Please open an image or PIV .nc file with the upper bar menu Open/Browse...')
+%         return
+%     end
+% end
 set(handles.PairIndices,'Visible','on')
 set(handles.SubdirCiv1,'Visible','on')
@@ -829,1551 +658,5 @@
 end
 
-% %-------------------------------------------------------------------
-% % --- Executes on button press in status.
-% function status_Callback(hObject, eventdata, handles)
-% %-------------------------------------------------------------------
-% val=get(handles.status,'Value');
-% if val==0
-%     set(handles.status,'BackgroundColor',[0 1 0])
-%     hfig=findobj(allchild(0),'name','civ_status');
-%     if ~isempty(hfig)
-%         delete(hfig)
-%     end
-%     return
-% end
-% set(handles.status,'BackgroundColor',[1 1 0])
-% drawnow
-% listtype={'civ1','fix1','patch1','civ2','fix2','patch2'};
-% Param.CheckCiv1=get(handles.CheckCiv1,'Value');
-% Param.CheckFix1=get(handles.CheckFix1,'Value');
-% Param.CheckPatch1=get(handles.CheckPatch1,'Value');
-% Param.CheckCiv2=get(handles.CheckCiv2,'Value');
-% Param.CheckFix2=get(handles.CheckFix2,'Value');
-% Param.CheckPatch2=get(handles.CheckPatch2,'Value');
-% box_test=[Param.CheckCiv1 Param.CheckFix1 Param.CheckPatch1 Param.CheckCiv2 Param.CheckFix2 Param.CheckPatch2];
-% 
-% option_civ=find(box_test,1,'last');%last selected option (non-zero index of box_test)
-% filecell=get(handles.civ_input,'UserData');%retrieve the list of output files expected for PIV
-% test_new=0;
-% if ~isfield(filecell,'nc')
-%     test_new=1;
-%     [ref_i,ref_j,errormsg]=find_ref_indices(handles);
-%     if ~isempty(errormsg)
-%         msgbox_uvmat('ERROR',errormsg)
-%         return
-%     end
-%     filecell=set_civ_filenames(handles,ref_i,ref_j,box_test);%determine the output file expected from the GUI status
-% end
-% if ~isequal(box_test(4:6),[0 0 0])
-%     civ_files=filecell.nc.civ2;%case of civ2 operations
-% else
-%     civ_files=filecell.nc.civ1;
-% end
-% [root,filename,ext]=fileparts(civ_files{1});
-% [rootroot,SubDir,extdir]=fileparts(root);
-% hfig=findobj(allchild(0),'name','civ_status');
-% if isempty(hfig)
-%     hfig=figure('DeleteFcn',@stop_status);
-%     set(hfig,'MenuBar','none')% suppress the menu bar
-%     set(hfig,'NumberTitle','off')%suppress the fig number in the title
-%     set(hfig,'name','civ_status')
-%     set(hfig,'tag','civ_status')
-%     set(hfig,'UserData',civ_files)
-%     hlist= uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', {'open_uvmat'},'tag','list');
-%     uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','msgbox','Max',2,'String','checking files...');
-%     uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]);
-%     %uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','Close','FontWeight','bold','FontUnits','normalized','FontSize',0.9,'Callback',@close_GUI);
-%     uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','Close','FontWeight','bold','FontUnits','normalized','FontSize',0.9,'Callback',@stop_status);
-%     hrefresh=uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.1 0.01 0.2 0.07],'String','Refresh','FontWeight','bold','FontUnits','normalized','FontSize',0.9,'Callback',@refresh_GUI);
-%     BarPosition=[0.05 0.81 0.01 0.05];
-%     uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar');
-%     drawnow 
-% end
-% StatusData.time_ref=get(handles.OK,'UserData');% get the time of launch
-% StatusData.option_civ=option_civ;
-% set(hrefresh,'UserData',StatusData)
-% filepath=fileparts(civ_files{1});
-% set(hlist,'UserData',fileparts(filepath))
-% refresh_GUI(hrefresh,[])
-
-% %------------------------------------------------------------------------   
-% % launched by refreshing the status figure
-% function refresh_GUI(hObject, eventdata)
-% %------------------------------------------------------------------------
-% Tabchar={};
-% BarPosition=[0.05 0.81 0.01 0.05];
-% hfig=get(hObject,'parent');
-% StatusData=get(hObject,'UserData');
-% civ_files=get(hfig,'UserData');
-% [filepath,filename,ext]=fileparts(civ_files{1});
-% [tild,SubDir,extdir]=fileparts(filepath);
-% SubDir=[SubDir extdir];
-% option_civ=StatusData.option_civ;
-% nbfiles=numel(civ_files);
-% testrecent=0;
-% count=0;
-% datnum=zeros(1,nbfiles);
-% filefound=cell(1,nbfiles);
-% for ifile=1:nbfiles
-%     detect=exist(civ_files{ifile},'file'); % check the existence of the file
-%     option=0;
-%     if detect==0
-%         option_str='not created';
-%     else
-%         datfile=dir(civ_files{ifile});
-%         if isfield(datfile,'datenum')
-%             datnum(ifile)=datfile.datenum;%only available in recent matlab versions
-%             testrecent=1;
-%         end
-%         filefound(ifile)={datfile.name};
-%         
-%         % check the content  netcdf file
-%         Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','CivStage','patch2','fix2','civ2','patch','fix');
-%         option_list={'civ1','fix1','patch1','civ2','fix2','patch2'};
-%         if ~isempty(Data.CivStage)
-%             option=Data.CivStage;%case of Matlab civ
-%         else
-%             if ~isempty(Data.patch2) && isequal(Data.patch2,1)
-%                 option=6;
-%             elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
-%                 option=5;
-%             elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
-%                 option=4;
-%             elseif ~isempty(Data.patch) && isequal(Data.patch,1);
-%                 option=3;
-%             elseif ~isempty(Data.fix) && isequal(Data.fix,1);
-%                 option=2;
-%             else
-%                 option=1;
-%             end
-%         end
-%         option_str=option_list{option};
-%         if datnum(ifile)<StatusData.time_ref
-%             option_str=[option_str '  --OLD--'];
-%         end
-%     end
-%     if option >= option_civ
-%         count=count+1;
-%     end
-%     [filepath,filename,ext]=fileparts(civ_files{ifile});
-%     Tabchar{ifile,1}=[fullfile(SubDir,filename) ext  '...' option_str];
-% end
-% datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
-% if isempty(datnum)
-%     if testrecent
-%         message='no civ result created yet';
-%     else
-%         message='';
-%     end
-% else
-%     datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files
-%     [first,ind]=min(datnum);
-%     [last,indlast]=max(datnum);
-%     message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
-%         ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
-% end
-% hlist=findobj(hfig,'tag','list');
-% hmsgbox=findobj(hfig,'tag','msgbox');
-% hwaitbar=findobj(hfig,'tag','waitbar');
-% set(hlist,'String',Tabchar)
-% set(hmsgbox,'String', message)
-% if count>0 %&& ~test_new
-%     BarPosition(3)=0.9*count/nbfiles;
-%     set(hwaitbar,'Position',BarPosition)
-% end
-% 
-% 
-% %------------------------------------------------------------------------   
-% % launched by deleting the status figure
-% function stop_status(hObject, eventdata)
-% %------------------------------------------------------------------------
-% hciv=findobj(allchild(0),'tag','civ');
-% hhciv=guidata(hciv);
-% set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ
-% set(hhciv.status,'BackgroundColor',[0 1 0])
-% 
-% % %------------------------------------------------------------------------   
-% % % launched by pressing OK on the status figure
-% % function close_GUI(hObject, eventdata)
-% % %------------------------------------------------------------------------
-% %     delete(gcbf)
-% 
-
-% %------------------------------------------------------------------------
-% % --- Main lauch command, called by OK and BATCH
-% function errormsg=launch_jobs(hObject, eventdata, handles)
-% %------------------------------------------------------------------------
-% errormsg='';%default
-% 
-% %% read the input parameters from the  GUI civ_input
-% Param=read_GUI(handles.civ_input);
-% 
-% %% check the selected list of operations:
-% operations={'Civ1','Fix1','Patch1','Civ2','Fix2','Patch2'};
-% box_test=[Param.CheckCiv1 Param.CheckFix1 Param.CheckPatch1 Param.CheckCiv2 Param.CheckFix2 Param.CheckPatch2];
-% index_first=find(box_test==1,1);
-% if isempty(index_first)
-%     errormsg='no selected operation';
-%     return
-% end
-% index_last=find(box_test==1,1,'last');
-% box_used=box_test(index_first : index_last);
-% [box_missing,ind_missing]=min(box_used);
-% if isequal(box_missing,0); %there is a missing step in the sequence of operations
-%     errormsg=['missing' cell2mat(operations(ind_missing))];
-%     return
-% end
-% 
-% %% check mask if selecetd 
-% %could be included in get_mask callback ?
-% if isequal(get(handles.CheckMask,'Value'),1)
-%     maskname=get(handles.Mask,'String');
-%     if ~exist(maskname,'file')
-%         get_mask_civ1_Callback(hObject, eventdata, handles);
-%     end
-% end
-% if isequal(get(handles.CheckMask,'Value'),1)
-%     maskname=get(handles.Mask,'String');
-%     if ~exist(maskname,'file')
-%         get_mask_fix1_Callback(hObject, eventdata, handles);
-%     end
-% end
-% if isequal(get(handles.CheckMask,'Value'),1)
-%     maskname=get(handles.Mask,'String');
-%     if ~exist(maskname,'file')
-%         get_mask_civ2_Callback(hObject, eventdata, handles);
-%     end
-% end
-% if isequal(get(handles.CheckMask,'Value'),1)
-%     maskname=get(handles.Mask,'String');
-%     if ~exist(maskname,'file')
-%         get_mask_fix2_Callback(hObject, eventdata, handles);
-%     end
-% end
-% 
-% %% reinitialise status callback 
-% if isfield(handles,'status')
-%     set(handles.status,'Value',0);%suppress status display
-%     status_Callback([], [], handles)
-% end
-% 
-% %% read the PARAM.xml file to get the binaries (and batch_mode if batch)
-% % path_civ=fileparts(which('civ')); %path to the source directory of uvmat
-% % xmlfile=fullfile(path_civ,'PARAM.xml');
-% % s=[];
-% % if exist(xmlfile,'file')% search parameter xml file in the whole matlab path
-% %     t=xmltree(xmlfile);
-% %     s=convert(t);
-% % end% default configuration
-% % if ~isfield(s,'RunParam')
-% %     Param.xml.Civ1Bin=fullfile('bin','civ1');
-% %     Param.xml.Civ2Bin=fullfile('bin','civ2');
-% %     Param.xml.FixBin=fullfile('bin','fix_flag');
-% %     Param.xml.PatchBin=fullfile('bin','patch_up');
-% % end
-% % if strcmp(Param.RunMode,'cluster') %computation dispatched on a cluster
-% %     if isfield(s,'BatchParam')
-% %         Param.xml=s.BatchParam;
-% %         if isfield(Param.xml,'BatchMode')
-% %             batch_mode=Param.xml.BatchMode;
-% %             if ~ismember(batch_mode,{'sge','oar'})
-% %                 errormsg=['batch mode ' batch_mode ' not supported by UVMAT'];
-% %                 return
-% %             end
-% %         end
-% %     else
-% %         %default configuration
-% %         Param.xml.Civ1Bin=fullfile('bin','civ1');
-% %         Param.xml.Civ2Bin=fullfile('bin','civ2');
-% %         Param.xml.FixBin=fullfile('bin','fix_flag');
-% %         Param.xml.PatchBin=fullfile('bin','patch_up');
-% %    %     Param.xml.CivmBin=fullfile('bin','civ_matlab');
-% %         Param.xml.BatchMode='oar';% TODO : allow choice for sge
-% %     end
-% % else % run
-% %     if isfield(s,'RunParam')
-% %         Param.xml=s.RunParam;
-% %     else %default configuration
-% %         Param.xml.Civ1Bin=fullfile('bin','civ1');
-% %         Param.xml.Civ2Bin=fullfile('bin','civ2');
-% %         Param.xml.FixBin=fullfile('bin','fix_flag');
-% %         Param.xml.PatchBin=fullfile('bin','patch_up');
-% %     end
-% % end
-% % %Param.xml.CivmBin=fullfile('bin','civ_matlab');
-% % 
-% % %% check if the binaries exist : to move in civ_opening
-% % binary_list={};
-% % switch Param.Program
-% %     case 'CivX'
-% %         binary_list={'Civ1Bin','Civ2Bin','PatchBin','FixBin'};
-% %     case 'CivAll'% desactivated option
-% %         binary_list={'Civ'};
-% % %     case 'civ_matlab.sh'% compiled version of civ_matlab 
-% % %         binary_list={'CivmBin'};         
-% % end
-% % for bin_name=binary_list %loop on the list of binaries
-% %     if isfield(Param.xml,bin_name{1})% bin_name{1} =current name in the list
-% %         if ~isunix
-% %         Param.xml.(bin_name{1})=[regexprep(Param.xml.(bin_name{1}),'/','\') '.exe'];
-% %         end
-% %         if exist(Param.xml.(bin_name{1}),'file')
-% %             [path,name,ext]=fileparts(Param.xml.(bin_name{1}));
-% %             currentdir=pwd;
-% %             if isempty(path)
-% %                 path=fileparts(which('civ.m'));
-% %             end
-% %             if exist(path,'dir')
-% %                 cd(path);
-% %                 binpath=pwd;%path of the binary
-% %                 Param.xml.(bin_name{1})=fullfile(binpath,[name ext]);
-% %                 cd(currentdir);
-% %             else
-% %                 errormsg=['path ' path ' for binaries specified in PARAM.xml does not exist'];
-% %                 return
-% %             end          
-% %         else  %look for the full path if the file name has been defined with a relative path in PARAM.xm
-% %             fullname=fullfile(path_civ,Param.xml.(bin_name{1}));
-% %             if exist(fullname,'file')
-% %                 Param.xml.(bin_name{1})=fullname;
-% %             else
-% %                 errormsg=['Binary ' Param.xml.(bin_name{1}) ' specified in PARAM.xml does not exist'];
-% %                 return
-% %             end
-% %         end
-% %     end
-% % end
-% % if strcmp(Param.Program,'civ_matlab.sh')
-% %     if ~exist(fullfile(path_civ,'civ_matlab.sh'),'file')
-% %         errormsg=[{'no file civ_matlab.sh found'}; {'run compile_functions.m to create it by compiling civ_matlab.m'}];
-% %             return
-% %     end
-% % end
-% % 
-% % %% set the list of files and check them
-% % display('checking the files...')
-% % [ref_i,ref_j,errormsg]=find_ref_indices(handles);
-% % if ~isempty(errormsg)
-% %     return
-% % end
-% % [filecell,i1_civ1,i2_civ1,j1_civ1,j2_civ1,i1_civ2,i2_civ2,j1_civ2,j2_civ2,nom_type_nc,tild,tild,compare,errormsg]=...
-% %     set_civ_filenames(handles,ref_i,ref_j,box_test);
-% % if ~isempty(errormsg)
-% %     return
-% % end
-% % set(handles.civ_input,'UserData',filecell);%store for futur use of status callback
-% % display('files OK, processing...')
-% % 
-% % %% create subfolders for log, cmx, nml, xml, bat
-% % RootBat=fileparts(filecell.nc.civ1{1,1});
-% % switch(Param.Program)
-% %     case {'CivX','CivAll'}
-% % dir_list={'0_BAT','0_CMX','0_LOG'};
-% %     case {'civ_matlab','civ_matlab.sh'}
-% %         dir_list={'0_BAT','0_XML'};
-% % end
-% % for k=1:length(dir_list)
-% %     if ~exist(fullfile(RootBat,dir_list{k}),'dir')
-% %         mkdir(fullfile(RootBat,dir_list{k}));
-% %     end
-% % end
-% 
-% %% get information on input images or movies
-% nbfield=numel(i1_civ1);
-% nbslice=numel(j1_civ1);
-% % if strcmp(Param.Program,'civ_matlab')
-%     if Param.CheckCiv1
-%         [Param.Civ1.FileTypeA,ImageInfoA_civ1,Param.Civ1.ImageA]=get_file_type(filecell.ima1.civ1{1});
-%         [Param.Civ1.FileTypeB,ImageInfoB_civ1,Param.Civ1.ImageB]=get_file_type(filecell.ima2.civ1{1});
-%     end
-%     if Param.CheckCiv2
-%         [Param.Civ2.FileTypeA,ImageInfoA_civ2,Param.Civ2.ImageA]=get_file_type(filecell.ima1.civ2{1});
-%         [Param.Civ2.FileTypeB,ImageInfoB_civ2,Param.Civ2.ImageB]=get_file_type(filecell.ima2.civ2{1});
-%     end
-% % end
-% 
-% %% MAIN LOOP
-% time=get(handles.ImaDoc,'UserData'); %get the set of times
-% TimeUnit=get(handles.TimeUnit,'String');
-% checkframe=strcmp(TimeUnit,'frame');
-% batch_file_list=[];%should be renamed file_list, can be used for xml or bash files
-% NomTypeIma=get(handles.NomType,'String');
-% for ifile=1:nbfield
-%     for j=1:nbslice
-%             
-%         % define output file name
-%         if Param.CheckCiv2==1 || Param.CheckFix2==1 || Param.CheckPatch2==1
-%             Param.OutputFile=filecell.nc.civ2{ifile,j};
-%         else
-%             Param.OutputFile=filecell.nc.civ1{ifile,j};
-%         end
-%         Param.OutputFile=regexprep(Param.OutputFile,'.nc','');
-% 
-%         if Param.CheckCiv1
-%             % read image-dependent parameters          
-%             if ~checkframe% && size(time,1)>=i2_civ1(ifile) && size(time,2)>=j2_civ1(j)
-%                 Param.Civ1.Dt=(time(i2_civ1(ifile)+1,j2_civ1(j)+1)-time(i1_civ1(ifile)+1,j1_civ1(j)+1));
-%             else
-%                 Param.Civ1.Dt=1;
-%             end
-%             Param.Civ1.Time=((time(i2_civ1(ifile)+1,j2_civ1(j)+1)+time(i1_civ1(ifile)+1,j1_civ1(j)+1))/2);
-%             if strcmp(Param.Program,'CivX')
-%                 Param.Civ1.term_a=num2stra(j1_civ1(j),nom_type_nc);%UTILITE?
-%                 Param.Civ1.term_b=num2stra(j2_civ1(j),nom_type_nc);%
-%             end
-%             Param.Civ1.ImageA=filecell.ima1.civ1{ifile,j};
-%             Param.Civ1.ImageB=filecell.ima2.civ1{ifile,j};
-%             Param.Civ1.ImageBitDepth=ImageInfoA_civ1.BitDepth;
-%             Param.Civ1.ImageWidth=ImageInfoA_civ1.Width;
-%             Param.Civ1.ImageHeight=ImageInfoA_civ1.Height;
-%             if strcmp(NomTypeIma,'*')
-%                 Param.Civ1.FrameIndexA=i1_civ1(ifile);
-%                 Param.Civ1.FrameIndexB=i2_civ1(ifile);
-%             else% case of movies indexed with i, the frame index is then in j
-%                 Param.Civ1.FrameIndexA=j1_civ1(j);
-%                 Param.Civ1.FrameIndexB=j2_civ1(j);
-%             end
-%             % read mask )parameters
-%             if Param.Civ1.CheckMask % the lines below should be changed with the new gui
-%                 if ~exist(Param.Civ1.Mask,'file')
-%                     maskbase=[filecell.filebase '_' Param.Civ1.Mask]; %
-%                     nbslice_mask=str2double(Param.Civ1.Mask(1:end-4)); %
-%                     i1_mask=mod(i1_civ1(ifile)-1,nbslice_mask)+1;
-%                     [RootPathMask,RootFileMask]=fileparts(maskbase);
-%                     Param.Civ1.Mask=fullfile_uvmat(RootPathMask,[],RootFileMask,'.png','_1',i1_mask);
-%                 end
-%             end
-%             % read grid parameters
-%             if Param.Civ1.CheckGrid
-%                 if numel(Param.Civ1.Grid)>=4 && isequal(Param.Civ1.Grid(end-3:end),'grid')
-%                     nbslice_grid=str2double(Param.Civ1.Grid(1:end-4)); %
-%                     if ~isnan(nbslice_grid)
-%                         i1_grid=mod(i1_civ1(ifile)-1,nbslice_grid)+1;
-%                         Param.Civ1.Grid=[filecell.filebase '_' fullfile_uvmat('','',Param.Civ1.Grid,'.grid','_1',i1_grid)];
-%                         if ~exist(Param.Civ1.GridName,'file')
-%                             errormsg='grid file absent for civ1';
-%                             return
-%                         end
-%                     elseif ~exist(Param.Civ1.Grid,'file')
-%                         errormsg='grid file absent for civ1';
-%                         return
-%                     end
-%                 end
-%             end
-%             
-%         end
-%         
-%         if Param.CheckCiv2==1
-%             Param.Civ2.ImageA=filecell.ima1.civ2{ifile,j};
-%             Param.Civ2.ImageB=filecell.ima2.civ2{ifile,j};          
-%             if ~checkframe %&& size(time,1)>=i2_civ2(ifile) && size(time,2)>=j2_civ2(j)
-%                 Param.Civ2.Dt=time(i2_civ2(ifile)+1,j2_civ2(j)+1)-time(i1_civ2(ifile)+1,j1_civ2(j)+1);
-%             else
-%                 Param.Civ2.Dt=1;
-%             end
-%             Param.Civ2.Time=(time(i2_civ2(ifile)+1,j2_civ2(j)+1)+time(i1_civ2(ifile)+1,j1_civ2(j)+1))/2;
-%             if strcmp(Param.Program,'CivX')
-%                 Param.Civ2.term_a=num2stra(j1_civ2(j),nom_type_nc);
-%                 Param.Civ2.term_b=num2stra(j2_civ2(j),nom_type_nc);
-%             end
-%             Param.Civ2.filename_nc1=filecell.nc.civ1{ifile,j};
-%             Param.Civ2.filename_nc1(end-2:end)=[]; % remove '.nc'
-%             
-%             % mask
-%             if Param.Civ2.CheckMask
-%                 if ~exist(Param.Civ2.Mask,'file')
-%                     maskbase=[filecell.filebase '_' Param.Civ2.Mask]; %
-%                     nbslice_mask=str2double(Param.Civ2.Mask(1:end-4)); %
-%                     i1_mask=mod(i1_civ2(ifile)-1,nbslice_mask)+1;
-%                     [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
-%             %grid
-%             if Param.Civ2.CheckGrid
-%                 if numel(Param.Civ2.Grid)>=4 && isequal(Param.Civ2.Grid(end-3:end),'grid')
-%                     nbslice_grid=str2double(Param.Civ2.Grid(1:end-4)); %
-%                     if ~isnan(nbslice_grid)
-%                         i1_grid=mod(i1_civ2(ifile)-1,nbslice_grid)+1;
-%                         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
-%             end
-% 
-%             Param.Civ2.ImageBitDepth=ImageInfoA_civ2.BitDepth;
-%             Param.Civ2.ImageWidth=ImageInfoA_civ2.Width;
-%             Param.Civ2.ImageHeight=ImageInfoA_civ2.Height;
-%             if strcmp(NomTypeIma,'*')
-%                 Param.Civ2.FrameIndexA=i1_civ2(ifile);
-%                 Param.Civ2.FrameIndexB=i2_civ2(ifile);
-%             else% case of movies indexed with i, the frame index is then in j
-%                 Param.Civ2.FrameIndexA=j1_civ2(j);
-%                 Param.Civ2.FrameIndexB=j2_civ2(j);
-%             end
-%         end
-%        
-%         % write the command and eventually the cmx, xml or nml files
-%         cmd=write_cmd(Param);
-%         write_param(Param);
-%               
-%         % create the command file name .m, .bat or .sh depending on the ok option
-%         switch Param.Program
-%             case {'civ_matlab'}
-%                 filename_bat=regexprep(Param.OutputFile,'(.+)([/\\])(.+$)','$1$20_BAT$2$3.m');           
-%                 [BatRoot,BatFile]=fileparts(filename_bat);
-%                  BatFile=regexprep(BatFile,'-','__');%transform name to suppress'-' (not valid for .m files)
-%                  filename_bat=[fullfile(BatRoot,BatFile) '.m'];
-%             case {'CivX','CivAll','civ_matlab.sh'}
-%                 switch computer
-%                     case {'PCWIN','PCWIN64'}
-%                         filename_bat=regexprep(Param.OutputFile,'(.+)([/\\])(.+$)','$1$20_BAT$2$3.bat');
-%                     case {'GLNX86','GLNXA64','MACI64'}
-%                         filename_bat=regexprep(Param.OutputFile,'(.+)([/\\])(.+$)','$1$20_BAT$2$3.sh');
-%                 end
-%         end
-%         
-%         % print the command in the bat file
-%         [fid,message]=fopen(filename_bat,'w');
-%         if isequal(fid,-1)
-%             errormsg=['creation of .bat file: ' message];
-%             return
-%         end
-%         fprintf(fid,cmd);
-%         fclose(fid);
-%         
-%         % special case for civ_matlab on cluster
-%         if strcmp(Param.Program,'civ_matlab') && strcmp(Param.RunMode,'cluster')
-%             filename_bat2=regexprep(Param.OutputFile,'(.+)([/\\])(.+$)','$1$20_BAT$2$3.sh');
-%             [fid,message]=fopen(filename_bat2,'w');
-%             if isequal(fid,-1)
-%                 errormsg=['creation of .bat file: ' message];
-%                 return
-%             end
-%             fprintf(fid,['#!/bin/bash \n' ...
-%                 '/etc/sysprofile \n'...
-%                 'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
-%                 'addpath(''' path_civ ''');\n']);
-% %             for p=1:length(batch_file_list)
-%                 fprintf(fid,['run ' filename_bat '\n']);
-% %             end
-%             fprintf(fid, 'exit\nEND_MATLAB\n');
-%             fclose(fid);
-%             filename_bat=filename_bat2;
-%         end
-%         
-%         switch computer
-%             case {'GLNX86','GLNXA64','MACI64'}
-%                 system(['chmod +x ' filename_bat]);
-%         end
-%         batch_file_list{length(batch_file_list)+1}=filename_bat; 
-%     end
-% end
-% 
-% %% start calculation
-% %computation on cluster
-% %if batch ==3
-% switch Param.RunMode,
-%     case 'cluster'
-%         switch batch_mode
-%             case 'sge' %at the moment only psmn ENS Lyon uses it
-%                 for p=1:length(batch_file_list)
-%                     %cmd=['!qsub -p ' pvalue ' -q civ_input.q -e ' flname '.errors -o ' flname '.log' ' ' batch_file_list{p}];
-%                     cmd=['!qsub -q piv1,piv2,piv3 '...
-%                         '-e ' regexprep(batch_file_list{p},'.bat','.errors') ' -o ' regexprep(batch_file_list{p},'.bat','.log ')...
-%                         ' -v ' 'LD_LIBRARY_PATH=/home/sjoubaud/matlab_sylvain/civx/lib ' batch_file_list{p}];
-%                     display(cmd);eval(cmd);
-%                 end
-%             case 'oar_old' % to remove
-%                 for p=1:length(batch_file_list)
-%                     oar_command=['!oarsub -n CIVX -q nicejob '...
-%                         '-E ' regexprep(batch_file_list{p},'.bat','.errors') ' -O ' regexprep(batch_file_list{p},'.bat','.log ')...
-%                         '-l "/core=1+{type = ''smalljob''}/licence=1,walltime=00:60:00"   ' batch_file_list{p}];
-%                     display(oar_command);eval(oar_command);
-%                 end
-%             case 'oar'
-%                 max_walltime=3600*12; % 12h max
-%                 oar_modes={'oar-parexec','oar-dispatch','mpilauncher'};
-%                 text={'Batch processing on servcalcul3 LEGI';...
-%                     'Please choose one of the followint modes';...
-%                     '* oar-parexec : default and best choice';...
-%                     '* oar-dispatch : jobs in a container of several cores';...
-%                     '* mpilauncher : one single parallel mpi job using several cores';...
-%                     '**********************************'...
-%                     };
-%                 [S,v]=listdlg('PromptString',text,'ListString',oar_modes,...
-%                     'SelectionMode','single','ListSize',[400 100],'Name','LEGI job mode');
-%                 switch oar_modes{S}
-%                     case 'oar-parexec' %oar-dispatch.pl
-%                         if strcmp(Param.Program,'civ_matlab')
-%                             ncores=1;
-%                             msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing');
-%                         else
-%                         answer=inputdlg({'Number of cores (max 36)','extra oar options'},'oarsub parameter',1,{'12',''});
-%                         ncores=str2double(answer{1});
-%                         end
-% 
-%                         extra_oar=answer{2};
-%                         walltime_onejob=600;%seconds
-%                         filename_joblist=fullfile(RootBat,'job_list.txt');
-%                         fid=fopen(filename_joblist,'w');
-%                         for p=1:length(batch_file_list)
-%                             fprintf(fid,[batch_file_list{p} '\n']);
-%                         end
-%                         fclose(fid);
-%                         oar_command=['oarsub -n CIVX '...
-%                             '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '...
-%                             '-l /core=' num2str(ncores) ','...
-%                             'walltime=' datestr(min(1.05*walltime_onejob/86400*max(length(batch_file_list),ncores)/ncores,max_walltime/86400),13) ' '...
-%                             '-E ' regexprep(filename_joblist,'\.txt\>','.stderr') ' '...
-%                             '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '...
-%                             extra_oar ' '...
-%                             '"oar-parexec -s -f ' filename_joblist ' '...
-%                             '-l ' filename_joblist '.log"\n'];
-%                         filename_oarcommand=fullfile(RootBat,'oar_command');
-%                         fid=fopen(filename_oarcommand,'w');
-%                         fprintf(fid,oar_command);
-%                         fclose(fid);
-%                         fprintf(oar_command);% display in command line
-%                         system(oar_command);
-% %                         eval(['! . ' filename
-% %                             _oarcommand])
-%                     case 'oar-dispatch' %oar-dispatch.pl
-%                         ncores=str2double(...
-%                             inputdlg('Number of cores (max 36)','oarsub parameter',1,{'6'})...
-%                             );
-%                         walltime_onejob=600;%seconds
-%                         filename_joblist=fullfile(RootBat,'job_list.txt');
-%                         fid=fopen(filename_joblist,'w');
-%                         for p=1:length(batch_file_list)
-%                             oar_command=['oarsub -n CIVX '...
-%                                 '-E ' regexprep(batch_file_list{p},'\.bat\>','.stderr') ' -O ' regexprep(batch_file_list{p},'\.bat\>','.stdout ')...
-%                                 '-l "/core=1,walltime=' datestr(walltime_onejob/86400,13) '"   ' batch_file_list{p}];
-%                             fprintf(fid,[oar_command '\n']);
-%                         end
-%                         fclose(fid);
-%                         oar_command=['oarsub -t container -n civx-container '...
-%                             '-l /core=' num2str(ncores)...
-%                             ',walltime=' datestr(1.05*walltime_onejob/86400*max(length(batch_file_list),ncores)/ncores,13) ' '...
-%                             '-E ' regexprep(filename_joblist,'\.txt\>','.stderr') ' '...
-%                             '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '...
-%                             '"oar-dispatch -f ' filename_joblist '"'];
-%                         filename_oarcommand=fullfile(RootBat,'oar_command');
-%                         fid=fopen(filename_oarcommand,'w');
-%                         fprintf(fid,[oar_command '\n']);
-%                         fclose(fid);
-%                         display(oar_command);
-%                         eval(['! . ' filename_oarcommand])
-%                     case 'mpilauncher'
-%                         filename_joblist=fullfile(RootBat,'job_list.txt');
-%                         fid=fopen(filename_joblist,'w');
-%                         
-%                         for p=1:length(batch_file_list)
-%                             fprintf(fid,[batch_file_list{p} '\n']);
-%                         end
-%                         fclose(fid)
-%                         text_oarscript=[...
-%                             '#!/bin/bash \n'...
-%                             '#OAR -n Mylauncher \n'...
-%                             '#OAR -l node=4/core=5,walltime=0:15:00 \n'...
-%                             '#OAR -E ' fullfile(RootBat,'stderrfile.log') ' \n'...
-%                             '#OAR -O ' fullfile(RootBat,'stdoutfile.log') ' \n'...
-%                             '# ========================================================= \n'...
-%                             '# This simple program launch a multinode parallel OpenMPI mpilauncher \n'...
-%                             '# application for coriolis PIV post-processing. \n'...
-%                             '# OAR uses oarshmost wrapper to propagate the user environement. \n'...
-%                             '# This wrapper assert that the user has the same environment on all the \n'...
-%                             '# allocated nodes (basic behavior needed by most MPI applications).  \n'...
-%                             '# \n'...
-%                             '# REQUIREMENT: \n'...
-%                             '# the oarshmost wrapper should be installed in $HOME/bin directory. \n'...
-%                             '# If a different location is used, change the line following the comment "Bidouille" \n'...
-%                             '# ========================================================= \n'...
-%                             '#   USER should only modify these 2 lines  \n'...
-%                             'WORKDIR=' pwd ' \n'...
-%                             'COMMANDE="mpilauncher  -f ' filename_joblist '" \n'...
-%                             '# ========================================================= \n'...
-%                             '# DO NOT MODIFY the FOLOWING LINES. (or be carefull) \n'...
-%                             'echo "job starting on: "`hostname` \n'...
-%                             'MPINODES="-host `tr [\\\\\\n] [,] <$OAR_NODEFILE |sed -e "s/,$/ /"`" \n'...
-%                             'NCPUS=`cat $OAR_NODEFILE |wc -l` \n'...
-%                             '#========== Bidouille ============== \n'...
-%                             'export OMPI_MCA_plm_rsh_agent=oar-envsh \n'...%                     'cd $WORKDIR \n'...
-%                             'CMD="mpirun -np $NCPUS -wdir $WORKDIR $MPINODES $COMMANDE" \n'...
-%                             'echo "I run: $CMD"  \n'...
-%                             '$CMD \n'...
-%                             'echo "job ending" \n'...
-%                             ];
-%                         %                 oarsub -S ./oar.sub
-%                         filename_oarscript=fullfile(RootBat,'oar_command');
-%                         fid=fopen(filename_oarscript,'w');
-%                         fprintf(fid,[text_oarscript]);
-%                         fclose(fid);
-%                         eval(['!chmod +x  ' filename_oarscript]);
-%                         eval(['!oarsub -S ' filename_oarscript]);
-%                 end
-%         end
-%     case {'background','local'}
-%         switch Param.Program
-%             case {'civ_matlab'}
-%                 switch Param.RunMode
-%                     case 'background'
-%                         switch computer
-%                             case {'PCWIN','PCWIN64'}
-%                                 filename_superbat=fullfile(RootBat,'job_list.bat');
-%                                 fid=fopen(filename_superbat,'w');
-%                                 if fid==-1
-%                                     msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
-%                                     return
-%                                 end
-%                                  fprintf(fid,['matlab -automation '...
-%                                      '-r "addpath(''' regexprep(path_civ,'\\','\\\\') ''');']);
-%                                 for p=1:length(batch_file_list)
-%                                     fprintf(fid,['run ' regexprep(batch_file_list{p},'\\','\\\\') ';']);
-%                                 end
-%                                  fprintf(fid, 'exit"');
-%                                 fclose(fid);
-%                                 dos([filename_superbat ' &']);
-%                             case {'GLNX86','GLNXA64','MACI64'} 
-%                                 filename_superbat=fullfile(RootBat,'job_list.sh');
-%                                 fid=fopen(filename_superbat,'w');
-%                                 if fid==-1
-%                                     msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
-%                                     return
-%                                 end
-%                                 fprintf(fid,['#!/bin/bash \n' ...
-%                                     '/etc/sysprofile \n'...
-%                                     'matlab -nodisplay -nosplash -nojvm -logfile  <<END_MATLAB \n'...
-%                                     'addpath(''' path_civ ''');\n']);
-%                                 for p=1:length(batch_file_list)
-%                                     fprintf(fid,['run ' batch_file_list{p} '\n']);
-%                                 end
-%                                 fprintf(fid, 'exit\nEND_MATLAB\n');
-%                                 fclose(fid);
-%                                 system(['chmod +x ' filename_superbat]);
-%                                 system([filename_superbat ' &']);
-%                         end
-%                     case 'local'
-%                         for p=1:length(batch_file_list)
-%                             fid=fopen(batch_file_list{p});
-%                             eval(fscanf(fid,'%s'));
-%                             fclose(fid);
-%                         end
-%                 end
-%             case {'CivX','CivAll','civ_matlab.sh'}
-%                     switch computer
-%                         case {'PCWIN','PCWIN64'}
-%                             filename_superbat=fullfile(RootBat,'job_list.bat');
-%                             fid=fopen(filename_superbat,'w');
-%                             if fid==-1
-%                                 msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
-%                                 return
-%                             end
-%                             for p=1:length(batch_file_list)
-%                                 fprintf(fid,['@call "' regexprep(batch_file_list{p},'\\','\\\\') '"' '\n']);
-%                             end
-%                             fclose(fid);
-%                             system(['chmod +x ' filename_superbat]);
-%                         case {'GLNX86','GLNXA64','MACI64'}
-%                             filename_superbat=fullfile(RootBat,'job_list.bat');
-%                             fid=fopen(filename_superbat,'w');
-%                             if fid==-1
-%                                 msgbox_uvmat('ERROR',['cannot create the command file ' filename_superbat])
-%                                 return
-%                             end
-%                             for p=1:length(batch_file_list)
-%                                 fprintf(fid,['sh ' batch_file_list{p} '\n']);
-%                             end
-%                             fclose(fid);
-%                             system(['chmod +x ' filename_superbat]);
-%                     end
-%                 switch Param.RunMode
-%                     case 'background'
-%                         system([filename_superbat ' &']);% execute main commmand see what it does in dos ?
-%                     case 'local'
-%                         system(filename_superbat);
-%                 end
-%         end
-% end
-% 
-% 
-% %% save interface state
-% if isfield(filecell,'nc')
-%     if isfield(filecell.nc,'civ2')
-%         fileresu=filecell.nc.civ2{1,1};
-%     else
-%         fileresu=filecell.nc.civ1{1,1};
-%     end
-% end
-% [RootPath,SubDir,RootFile]=fileparts_uvmat(fileresu);
-% namedoc=fullfile(RootPath,SubDir,RootFile);
-% detect=1;
-% while detect==1
-%     namefigfull=[namedoc '.fig'];
-%     hh=dir(namefigfull);
-%     if ~isempty(hh)
-%         detect=1;
-%         namedoc=[namedoc '.0'];
-%     else
-%         detect=0;
-%     end
-% end
-% Param=rmfield(Param,'status');
-% Param=rmfield(Param,'xml');
-% t=struct2xml(Param);
-% t=set(t,1,'name','Civ');% set the head label
-% save(t,[namedoc '.civ.xml']); %save GUI  parameters as xml file
-% % saveas(gcbf,namefigfull);%save the interface with name namefigfull (A CHANGER EN FICHIER  .xml)
-% 
-% %Save info in personal profile (initiate browser next time) TODO
-% MenuFile={};
-% dir_perso=prefdir;
-% profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
-% if exist(profil_perso,'file')
-%     hh=load (profil_perso);
-%       if isfield(hh,'MenuFile')
-%           MenuFile=hh.MenuFile;
-%       end
-%       if isfield(filecell.nc,'civ2')
-%           MenuFile=[filecell.nc.civ2{1,1}; MenuFile];
-%       else
-%            MenuFile=[filecell.nc.civ1{1,1}; MenuFile];
-%       end
-%       save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
-% else
-%     MenuFile=filecell.ima1.civ1(1,1);
-%     save (profil_perso,'MenuFile')
-% end
-
-% %------------------------------------------------------------------------
-% % --- determine the list of reference indices of processing file
-% function [ref_i,ref_j,errormsg]=find_ref_indices(handles)
-% %------------------------------------------------------------------------
-% errormsg=''; %default error message
-% first_i=str2double(get(handles.first_i,'String'));%first index i
-% last_i=str2double(get(handles.last_i,'String'));%last index i
-% incr_i=str2double(get(handles.incr_i,'String'));% increment
-% if isequal(get(handles.first_j,'Visible'),'on')
-%     first_j=str2double(get(handles.first_j,'String'));%first index j
-%     last_j=str2double(get(handles.last_j,'String'));%last index j
-%     incr_j=str2double(get(handles.incr_j,'String'));% increment
-% else
-%     first_j=1;
-%     last_j=1;
-%     incr_j=1;
-% end
-% ref_i=first_i:incr_i:last_i;% list of i indices (reference values for each pair)
-% ref_j=first_j:incr_j:last_j;% list of j indices (reference values for each pair)
-% if isnan(first_i)||isnan(first_j)
-%     errormsg='first field number not defined';
-% elseif isnan(last_i)||isnan(last_j)
-%     errormsg='last field number not defined';
-% elseif isnan(incr_i)||isnan(incr_j)
-%     errormsg='increment in field number not defined';
-% elseif last_i < first_i || last_j < first_j 
-%     errormsg='last field number must be larger than the first one';
-% end
-
-%------------------------------------------------------------------------
-% --- determine the list of filenames and indices needed for launch_job
-%------------------------------------------------------------------------
-% OUTPUT:
-% filecell: structure of cell arrays {ref_i,ref_j} containing all the filenames involved in the civ_input process
-%    the indices ref_i and ref_j correspond to the list of reference indices
-%       .filebase=fullfile(RootPath,RootFile) used to construct mask names, grid names, CivDoc xml file
-%       .ima1.civ1,.ima1.civ2: first image for civ1 and civ2 respectively (possibly different)
-%       .ima2.civ1,.ima2.civ2: second image for civ1 and civ2 respectively (possibly different)
-%       .nc.civ1,.nc.civ2: netcdf files containing civ1 and civ2 data respectively (possibly different)
-% i1_civ1,i2_civ1,j1_civ1,j2_civ1,i1_civ2,i2_civ2,j1_civ2,j2_civ2: arrays of files indices, needed for timing records
-function [filecell,i1_civ1,i2_civ1,j1_civ1,j2_civ1,i1_civ2,i2_civ2,j1_civ2,j2_civ2,NomType_nc,file_ref_fix1,file_ref_fix2,compare,errormsg]=...
-    set_civ_filenames(handles,ref_i,ref_j,checkbox)
-%------------------------------------------------------------------------
-filecell=[];%default
-errormsg='';
-ListProgram=get(handles.Program,'String');
-CivMode=ListProgram{get(handles.Program,'Value')};%Program to use , CivX or Matlab
-
-%% get the root name and check dir
-RootPath=get(handles.RootPath,'String');
-SubDirImages=get(handles.SubDirImages,'String');
-RootFile=get(handles.RootFile,'String');
-filecell.filebase=fullfile(RootPath,SubDirImages,RootFile);
-if isempty(filecell.filebase)
-    errormsg='please open an image with the upper menu option Open/Browse...';
-    return
-end
-if ~exist(RootPath,'dir')
-    errormsg=['path to images ' RootPath ' not found'];
-    return
-end
-[tild,message]=fileattrib(RootPath);
-if ~isempty(message) && ~isequal(message.UserWrite,1)
-    errormsg=['No writting access to ' RootPath];
-    return
-end
-%check result directory
-subdir_civ1=regexprep(get(handles.SubdirCiv1,'String'),'^.','');%subdirectory subdir_civ1 for the netcdf output data
-subdir_civ2=regexprep(get(handles.SubdirCiv2,'String'),'^.','');
-if isequal(subdir_civ1,''),subdir_civ1='civ'; end% put default subdir
-% subdir_civ1=[ '.' subdir_civ1];
-% subdir_civ2=[ '.' subdir_civ2];
-if isequal(subdir_civ2,''),subdir_civ2=subdir_civ1; end% put default subdir
-subdir_civ1=[SubDirImages '.' subdir_civ1];
-subdir_civ2=[SubDirImages '.' subdir_civ2];
-
-%% choose root names depending on ListCompareMode =displacement, shift, PIV or stereo PIV
-ListCompareMode=get(handles.ListCompareMode,'String');
-compare=ListCompareMode{get(handles.ListCompareMode,'Value')};
-
-% set the nomenclature type of the nc files depending on the pair mode
-if strcmp(compare,'displacement')||strcmp(compare,'shift')
-    mode='displacement';
-else
-    mode_list=get(handles.ListPairMode,'String');
-    mode_value=get(handles.ListPairMode,'Value');
-    mode=mode_list{mode_value};
-end
-NomType_ima2=get(handles.NomType,'String');
-NomType_nc=nomtype2pair(NomType_ima2,mode);
-
-% set the rootfile and image indexing
-RootFile_ima2=get(handles.RootFile,'String');%root file for the second image series
-ext_ima=get(handles.ImaExt,'String'); % image extension (the same for all images)
-switch compare
-    case {'PIV','PIV volume'}
-       RootFile_ima1=RootFile_ima2;% root name of the two image series is the same
-       NomType_ima1=NomType_ima2;% the index of the first image follows the index of the second one
-       RootFile_nc=RootFile_ima2;
-    case 'displacement'
-       RootFile_ima1=get(handles.RootFile_1,'String');% root name of the first image series set by handles.RootFile_1
-       NomType_ima1='';% no indexing of the first image, a fixed reference for the whole series
-       RootFile_nc=RootFile_ima2;
-    case 'shift'
-       RootFile_ima1=get(handles.RootFile_1,'String');% root name of the first image series set by handles.RootFile_1
-       NomType_ima1=NomType_ima2;% the index of the first image follows the index of the second one
-       RootFile_nc=[RootFile_ima1 '-' RootFile_ima2];
-end
-
-%determine the list of file indices involved
-[i1_civ1,i2_civ1,j1_civ1,j2_civ1,i1_civ2,i2_civ2,j1_civ2,j2_civ2]=...
-    find_pair_indices(handles,ref_i,ref_j,mode);
-
-%determine the new filebase for 'displacement' ListPairMode (comparison of two series)
-%filebase_B=filebase;% root name of the second field series for stereo
-% filebase_A=filebase;%default
-% if strcmp(compare,'PIV') 
-%     filebase_AB=filebase;
-% else
-%     [Path2,Name2]=fileparts(filebase_B);
-%     Name1=RootFile_ima1;
-%     filebase_AB=fullfile(Path2,[Name2 '-' Name1]);   
-% end
-% [RootPath_AB,RootFile_AB]=fileparts(filebase_AB);
-% % [RootPath_ima1,RootFile_ima1]=fileparts(filebase_B);
-% [RootPath_ima2,RootFile_ima2]=fileparts(filebase_B);
-% [RootPath_nc,RootFile_nc]=fileparts(filebase_B);%default
-% if strcmp(compare,'displacement')
-% %     [RootPath_ima1,RootFile_ima1]=fileparts(filebase_B);
-% %     [RootPath_ima2,RootFile_ima2]=fileparts(filebase_B);
-%     [RootPath_nc,RootFile_nc]=fileparts(filebase_B);
-% elseif strcmp(compare,'shift')
-%     RootPath_nc=RootPath_AB;
-%     RootFile_nc=RootFile_AB;
-% end
-% else
-%     filebase_ima1=filebase_B;
-%     filebase_ima2=filebase_B;
-%     filebase_nc=filebase_B;
-% [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);
-
-    
-%% determine reference files for fix:
-file_ref_fix1={};%default
-file_ref_fix2={};
-nbfield=length(i1_civ1);
-nbslice=length(j1_civ1);
-if checkbox(2)==1% fix1 performed
-    ref=get(handles.ref_fix1,'UserData');%read data on the ref file stored by get_ref_fix1_Callback
-    if ~isempty(ref)
-        first_i=str2double(get(handles.first_i,'String'));
-        last_i=str2double(get(handles.last_i,'String'));
-        incr_i=str2double(get(handles.incr_i,'String'));
-        first_j=str2double(get(handles.first_j,'String'));
-        last_j=str2double(get(handles.last_j,'String'));
-        incr_j=str2double(get(handles.incr_j,'String'));
-        num_i_ref=first_i:incr_i:last_i;
-        num_j_ref=first_j:incr_j:last_j;
-        if isequal(mode,'displacement')
-            num_i1=num_i_ref;
-            num_i2=num_i_ref;
-            num_j1=num_j_ref;
-            num_j2=num_j_ref;
-        elseif isequal(mode,'pair j1-j2')% isequal(mode,'st_pair j1-j2')
-            num_i1=num_i_ref;
-            num_i2=num_i1;
-            num_j1=ref.num_a*ones(size(num_i_ref));
-            num_j2=ref.num_b*ones(size(num_i_ref));
-        elseif isequal(mode,'series(Di)') % isequal(mode,'st_series(Di)')
-            delta1=floor((ref.num2-ref.num1)/2);
-            delta2=ceil((ref.num2-ref.num1)/2);
-            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
-            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
-            if isempty(ref.num_a)
-                ref.num_a=1;
-            end
-            num_j1=ref.num_a*ones(size(num_i1));
-            num_j2=num_j1;
-        elseif isequal(mode,'series(Dj)')%| isequal(mode,'st_series(Dj)')
-            delta1=floor((ref.num_b-ref.num_a)/2);
-            delta2=ceil((ref.num_b-ref.num_a)/2);
-            num_i1=ref.num1*ones(size(num_i_ref));
-            num_i2=num_i1;
-            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
-            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
-        end
-        for ifile=1:nbfield
-            for j=1:nbslice
-                [RootPathRef,RootFile]=fileparts(ref.filebase);
-                file_ref=fullfile_uvmat(RootPathRef,ref.subdir,RootFile,'.nc',ref.NomType,num_i1(ifile),num_i2(ifile),num_j1(j),num_j2(j));
-                file_ref_fix1(ifile,j)={file_ref};
-                if ~exist(file_ref,'file')
-                    errormsg=['reference file ' file_ref ' not found for fix1'];
-                    return
-                end
-            end
-        end
-    end
-end
-
-%% determine reference files for fix2:
-if checkbox(5)==1% fix2 performed
-    ref=get(handles.ref_fix2,'UserData');
-    if ~isempty(ref)
-        first_i=str2double(get(handles.first_i,'String'));
-        last_i=str2double(get(handles.last_i,'String'));
-        incr_i=str2double(get(handles.incr_i,'String'));
-        first_j=str2double(get(handles.first_j,'String'));
-        last_j=str2double(get(handles.last_j,'String'));
-        incr_j=str2double(get(handles.incr_j,'String'));
-        num_i_ref=first_i:incr_i:last_i;
-        num_j_ref=first_j:incr_j:last_j;
-        if isequal(mode,'displacement')
-            num_i1=num_i_ref;
-            num_i2=num_i_ref;
-            num_j1=num_j_ref;
-            num_j2=num_j_ref;
-        elseif isequal(mode,'pair j1-j2')
-            num_i1=num_i_ref;
-            num_i2=num_i1;
-            num_j1=ref.num_a;
-            num_j2=ref.num_b;
-        elseif isequal(mode,'series(Di)')
-            delta1=floor((ref.num2-ref.num1)/2);
-            delta2=ceil((ref.num2-ref.num1)/2);
-            num_i1=num_i_ref-delta1*ones(size(num_i_ref));
-            num_i2=num_i_ref+delta2*ones(size(num_i_ref));
-            num_j1=ref.num_a*ones(size(num_i1));
-            num_j2=num_j1;
-        elseif isequal(mode,'series(Dj)')
-            delta1=floor((ref.num_b-ref.num_a)/2);
-            delta2=ceil((ref.num_b-ref.num_a)/2);
-            num_i1=ref.num1*ones(size(num_i_ref));
-            num_i2=num_i1;
-            num_j1=num_j_ref-delta1*ones(size(num_j_ref));
-            num_j2=num_j_ref+delta2*ones(size(num_j_ref));
-        end
-        for ifile=1:nbfield
-            for j=1:nbslice
-                [RootPathRef,RootFile]=fileparts(ref.filebase);
-                file_ref=fullfile_uvmat(RootPathRef,ref.subdir,RootFile,'.nc',ref.NomType,num_i1(ifile),num_i2(ifile),num_j1(j),num_j2(j));
-                file_ref_fix2(ifile,j)={file_ref};
-                if ~exist(file_ref,'file')
-                    errormsg=['reference file ' file_ref ' not found for fix2'];
-                    return
-                end
-            end
-        end
-    end
-end
-
-%% check the existence of the netcdf and image files involved
-% %%%%%%%%%%%%  case CheckCiv1 activated   %%%%%%%%%%%%%
-if checkbox(1)==1;
-    detect=1;
-    vers=0;
-    subdir_civ1_new=subdir_civ1;
-    answer='No';
-    while detect==1 %create a new subdir if the netcdf files already exist
-        for ifile=1:nbfield
-            for j=1:nbslice
-                filename=fullfile_uvmat(RootPath,subdir_civ1_new,RootFile_nc,'.nc',NomType_nc,i1_civ1(ifile),i2_civ1(ifile),j1_civ1(j),j2_civ1(j));
-                detect=exist(filename,'file')==2;
-                if detect% if a netcdf file already exists
-                    if strcmp(answer,'No')
-                        answer=msgbox_uvmat('INPUT_Y-N',['overwrite existing civ files in ' subdir_civ1_new]);
-                    end
-                    if strcmp(answer,'Yes')
-                        detect=0;
-                        filecell.nc.civ1(ifile,j)={filename};
-                    else
-                        r=regexp(subdir_civ1_new,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
-                        if isempty(r)
-                            r(1).root=[subdir_civ1_new '_'];
-                            r(1).num1='0';
-                        end
-                        subdir_civ1_new=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
-                        subdir_civ2=subdir_civ1_new;
-                    end
-                    break
-                end
-                filecell.nc.civ1(ifile,j)={filename};
-            end
-            if detect% if a netcdf file already exists
-                break
-            end
-        end
-  
-        %create the new SubdirCiv1
-        if ~exist(fullfile(RootPath,subdir_civ1_new),'dir')     
-            [xx,msg1]=mkdir(fullfile(RootPath,subdir_civ1_new));
-            if ~strcmp(msg1,'')
-                errormsg=['cannot create ' subdir_civ1_new ': ' msg1];%error message for directory creation
-                return
-            elseif isunix          
-                [xx,msg2] = fileattrib(fullfile(RootPath,subdir_civ1_new),'+w','g'); %yield writing access (+w) to user group (g)
-                if ~strcmp(msg2,'')
-                    errormsg=['pb of permission for  ' fullfile(RootPath,subdir_civ1_new) ': ' msg2];%error message for directory creation
-                    return
-                end
-            end
-        end
-        if strcmp(compare,'stereo PIV')&&(strcmp(mode,'pair j1-j2')||strcmp(mode,'series(Dj)')||strcmp(mode,'series(Di)'))%check second nc series
-            for ifile=1:nbfield
-                for j=1:nbslice
-                     filename=fullfile_uvmat(RootPath,subdir_civ1_new,RootFile_A,'.nc',NomType_nc,i1_civ1(ifile),i2_civ1(ifile),j1_civ1(j),j2_civ1(j));
-                    detect=exist(filename,'file')==2;
-                    if detect% if a netcdf file already exists
-                       indstr=regexp(subdir_civ1_new,'\D');
-                       if indstr(end)<length(subdir_civ1_new) %subdir_civ1 ends by a number
-                           vers=str2double(subdir_civ1_new(indstr(end)+1:end))+1;
-                           subdir_civ1_new=[subdir_civ1_new(1:indstr(end)) num2str(vers)];
-                       else
-                           vers=vers+1;
-                           subdir_civ1_new=[subdir_civ1_new '_' num2str(vers)];
-                       end
-                       subdir_civ2=subdir_civ1;
-                       break
-                    end
-                    filecell.ncA.civ1(ifile,j)={filename};
-                end
-                if detect% if a netcdf file already exists
-                    break
-                end
-            end
-            %create the new SubdirCiv1
-            if ~exist(fullfile(RootPath,subdir_civ1_new),'dir')        
-                [xx,msg1]=mkdir(fullfile(RootPath,subdir_civ1_new));
-                if ~strcmp(msg1,'')
-                    errormsg=['cannot create ' subdir_civ1_new ': ' msg1];
-                    return
-                else
-                    [xx,msg2] = fileattrib(fullfile(RootPath,subdir_civ1_new),'+w','g'); %yield writing access (+w) to user group (g)
-                    if ~strcmp(msg2,'')
-                        errormsg=['pb of permission for ' subdir_civ1_new ': ' msg2];%error message for directory creation
-                        return
-                    end
-                end
-            end
-        end
-    end
-    subdir_civ1=subdir_civ1_new;
-    % get image names
-    for ifile=1:nbfield
-        for j=1:nbslice
-             filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima1,ext_ima,NomType_ima1,i1_civ1(ifile),[],j1_civ1(j));
-            idetect(j)=exist(filename,'file')==2;
-            filecell.ima1.civ1(ifile,j)={filename}; %first image
-            filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima2,ext_ima,NomType_ima2,i2_civ1(ifile),[],j2_civ1(j));
-            idetect_1(j)=exist(filename,'file')==2;
-            filecell.ima2.civ1(ifile,j)={filename};%second image
-        end
-        [idetectmin,indexj]=min(idetect);
-        if idetectmin==0,
-            errormsg=[filecell.ima1.civ1{ifile,indexj} ' not found'];
-            return
-        end
-        [idetectmin,indexj]=min(idetect_1);
-        if idetectmin==0,
-            errormsg=[filecell.ima2.civ1{ifile,indexj} ' not found'];
-            return
-        end
-    end
-    if strcmp(compare,'stereo PIV') && (strcmp(mode,'pair j1-j2') || strcmp(mode,'series(Dj)') || strcmp(mode,'series(Di)'))
-        for ifile=1:nbfield
-            for j=1:nbslice
-                filename=fullfile_uvmat(RootPath,'',RootFile_A,ext_ima,NomType_ima1,i1_civ1(ifile),[],j1_civ1(j));
-                idetect(j)=exist(filename,'file')==2;
-                filecell.imaA1.civ1(ifile,j)={filename} ;%first image
-                filename=fullfile_uvmat(RootPath,'',RootFile_A,ext_ima,NomType_ima2,i2_civ1(ifile),[],j2_civ1(j));
-                idetect_1(j)=exist(filename,'file')==2;
-                filecell.imaA2.civ1(ifile,j)={filename};%second image
-            end
-            [idetectmin,indexj]=min(idetect);
-            if idetectmin==0,
-                errormsg=[filecell.imaA1.civ1{ifile,indexj} ' not found'];
-                return
-            end
-            [idetectmin,indexj]=min(idetect_1);
-            if idetectmin==0,
-                errormsg=[filecell.imaA2.civ1{ifile,indexj} ' not found'];
-                return
-            end
-        end
-    end
-    
-    %%%%%%%%%%%%%  checkfix1 or checkpatch1 activated but no checkciv1   %%%%%%%%%%%%%
-elseif (checkbox(2)==1 || checkbox(3)==1);
-    for ifile=1:nbfield
-        for j=1:nbslice
-            filename=fullfile_uvmat(RootPath,subdir_civ1,RootFile_nc,'.nc',NomType_nc,i1_civ1(ifile),i2_civ1(ifile),j1_civ1(j),j2_civ1(j));
-            detect=exist(filename,'file')==2;
-            if detect==0
-                errormsg=[filename ' not found'];
-                return
-            end
-            filecell.nc.civ1(ifile,j)={filename};
-        end
-    end
-    if strcmp(compare,'stereo PIV')
-        for ifile=1:nbfield
-            for j=1:nbslice
-                filename=fullfile_uvmat(RootPath,subdir_civ1,RootFile_A,'.nc',NomType_nc,i1_civ1(ifile),i2_civ1(ifile),j1_civ1(j),j2_civ1(j));
-                filecell.ncA.civ1(ifile,j)={filename};
-                if ~exist(filename,'file')
-                    errormsg=['input file ' filename ' not found'];
-                    return
-                end
-            end
-        end
-    end
-end
-
-%%%%%%%%%%%%%  if checkciv2 performed with pairs different than checkciv1  %%%%%%%%%%%%%
-testdiff=0;
-if (checkbox(4)==1)&&...
-        ((get(handles.ListPairCiv1,'Value')~=get(handles.ListPairCiv2,'Value'))||~strcmp(subdir_civ2,subdir_civ1))
-    testdiff=1;
-    detect=1;
-    vers=0;
-    subdir_civ2_new=subdir_civ2;
-    while detect==1 %create a new subdir if the netcdf files already exist
-        for ifile=1:nbfield
-            for j=1:nbslice
-                filename=fullfile_uvmat(RootPath,subdir_civ2_new,RootFile_nc,'.nc',NomType_nc,i1_civ2(ifile),i2_civ2(ifile),j1_civ2(j),j2_civ2(j));
-                detect=exist(filename,'file')==2;
-                if detect% if a netcdf file already exists
-                    indstr=regexp(subdir_civ2,'\D');
-                    if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
-                        vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
-                        subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
-                    else
-                        vers=vers+1;
-                        subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
-                    end
-                    break
-                end
-                filecell.nc.civ2(ifile,j)={filename};
-            end
-            if detect% if a netcdf file already exists
-                break
-            end
-        end
-        %create the new subdir_civ2_new
-        if ~exist(fullfile(RootPath,subdir_civ2_new),'dir')
-            [xx,m2]=mkdir(fullfile(RootPath,subdir_civ2_new));
-            [xx,msg2] = fileattrib(fullfile(RootPath,subdir_civ2_new),'+w','g'); %yield writing access (+w) to user group (g)
-            if ~isequal(m2,'')
-                errormsg=['cannot create ' fullfile(RootPath,subdir_civ2_new) ': ' m2];
-                return
-            end
-        end
-        if strcmp(compare,'stereo PIV')%check second nc series
-            for ifile=1:nbfield
-                for j=1:nbslice
-                    filename=fullfile_uvmat(RootPath,subdir_civ2_new,RootFile_A,'.nc',NomType_nc,i1_civ2(ifile),i2_civ2(ifile),j1_civ2(j),j2_civ2(j));
-                    detect=exist(filename,'file')==2;
-                    if detect% if a netcdf file already exists
-                        indstr=regexp(subdir_civ2,'\D');
-                        if indstr(end)<length(subdir_civ2) %subdir_civ1 ends by a number
-                           vers=str2double(subdir_civ2(indstr(end)+1:end))+1;
-                           subdir_civ2_new=[subdir_civ2(1:indstr(end)) num2str(vers)];
-                        else
-                           vers=vers+1;
-                           subdir_civ2_new=[subdir_civ1 '_' num2str(vers)];
-                        end
-                        break
-                    end
-                    filecell.ncA.civ2(ifile,j)={filename};
-                end
-                if detect% if a netcdf file already exists
-                    break
-                end
-            end
-            subdir_civ2=subdir_civ2_new;
-            %create the new SubdirCiv1
-            if ~exist(fullfile(RootPath,subdir_civ2_new),'dir')
-                [xx,m2]=mkdir(subdir_civ2_new);
-                 [xx,msg2] = fileattrib(fullfile(RootPath,subdir_civ2_new),'+w','g'); %yield writing access (+w) to user group (g)
-                if ~isequal(m2,'')
-                    errormsg= ['cannot create ' fullfile(RootPath,subdir_civ2_new) ': ' m2];%error message for directory creation
-                    return
-                end
-            end
-        end
-    end
-    subdir_civ2=subdir_civ2_new;
-end
-
-%%%%%%%%%%%%%  if checkciv2 results are obtained or used  %%%%%%%%%%%%%
-if checkbox(4)==1 || checkbox(5)==1 || checkbox(6)==1 %civ2
-    %check source netcdf file of checkciv1 estimates
-    if checkbox(1)==0; %no civ1 performed
-        for ifile=1:nbfield
-            for j=1:nbslice
-                filename=fullfile_uvmat(RootPath,subdir_civ1,RootFile_nc,'.nc',NomType_nc,i1_civ1(ifile),i2_civ1(ifile),j1_civ1(j),j2_civ1(j));%
-                filecell.nc.civ1(ifile,j)={filename};% name of the civ1 file
-                if ~exist(filename,'file')
-                    errormsg=['input file ' filename ' not found'];
-                    return
-                end
-                if ~testdiff % civ2 or patch2 are written in the same file as civ1
-                    if checkbox(4)==0 ; %check the existence of civ2 if it is not calculated
-                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
-                        if isfield(Data,'Txt')
-                            errormsg=Data.Txt; 
-                            return
-                        elseif ~isempty(Data.CivStage)% case of new civ files
-                            if Data.CivStage<4 %test for civ files
-                            errormsg=['no civ2 data in ' filename];
-                            return
-                            end
-                        elseif isempty(Data.civ2)||isequal(Data.civ2,0)
-                            errormsg=['no civ2 data in ' filename];
-                            return
-                        end
-                    elseif checkbox(3)==0; %check the existence of patch if it is not calculated
-                        Data=nc2struct(filename,'ListGlobalAttribute','CivStage','patch');
-                        if isfield(Data,'Txt')
-                            errormsg=Data.Txt;
-                            return
-                        elseif ~isempty(Data.CivStage)
-                            if Data.CivStage<3 %test for civ files
-                                errormsg=['no patch data in ' filename];
-                                return
-                            end
-                        elseif isempty(Data.patch)||isequal(Data.patch,0)
-                            errormsg=['no patch data in ' filename];
-                            return
-                        end
-                    end
-                end
-            end
-        end
-        if strcmp(compare,'stereo PIV')
-            for ifile=1:nbfield
-                for j=1:nbslice
-                    filename=fullfile_uvmat(RootPath,subdir_civ2,RootFile_A,'.nc',NomType_nc,i1_civ2(ifile),i2_civ2(ifile),j1_civ2(j),j2_civ2(j));
-                    filecell.ncA.civ2(ifile,j)={filename};
-                    if ~exist(filename,'file')
-                        errormsg=['input file ' filename ' not found'];
-                        return
-                    end
-                end
-            end
-        end
-    end
-    
-    detect=1;
-    %     while detect==1%creates a new subdir if the netcdf files already contain checkciv2 data
-    for ifile=1:nbfield
-        for j=1:nbslice
-            filename=fullfile_uvmat(RootPath,subdir_civ2,RootFile_nc,'.nc',NomType_nc,i1_civ2(ifile),i2_civ2(ifile),j1_civ2(j),j2_civ2(j));
-            detect=exist(filename,'file')==2;
-            filecell.nc.civ2(ifile,j)={filename};
-        end
-    end
-    %get first image names for checkciv2
-    if checkbox(1)==1 && isequal(i1_civ1,i1_civ2) && isequal(j1_civ1,j1_civ2)
-        filecell.ima1.civ2=filecell.ima1.civ1;
-    elseif checkbox(4)==1
-        for ifile=1:nbfield
-            for j=1:nbslice
-                filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima1,ext_ima,NomType_ima1,i1_civ2(ifile),[],j1_civ2(j));
-                idetect_2(j)=exist(filename,'file')==2;
-                filecell.ima1.civ2(ifile,j)={filename};%first image
-            end
-            [idetectmin,indexj]=min(idetect_2);
-            if idetectmin==0,
-               errormsg=['input image ' filecell.ima1.civ2{ifile,indexj} ' not found'];
-                return
-            end
-        end
-    end
-    
-    %get second image names for checkciv2
-    if checkbox(1)==1 && isequal(i2_civ1,i2_civ2) && isequal(j2_civ1,j2_civ2)
-        filecell.ima2.civ2=filecell.ima2.civ1;
-    elseif checkbox(4)==1
-        for ifile=1:nbfield
-            for j=1:nbslice
-                filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima2,ext_ima,NomType_ima2,i2_civ2(ifile),[],j2_civ2(j));
-                idetect_3(j)=exist(filename,'file')==2;
-                filecell.ima2.civ2(ifile,j)={filename};%first image
-            end
-            [idetectmin,indexj]=min(idetect_3);
-            if idetectmin==0,
-                errormsg=['input image ' filecell.ima2.civ2{ifile,indexj} ' not found'];
-                return
-            end
-        end
-    end
-end
-if (checkbox(5) || checkbox(6)) && ~checkbox(4)  % need to read an existing netcdf civ2 file
-    if ~testdiff
-        filecell.nc.civ2=filecell.nc.civ1;% file already checked
-    else     % check the civ2 files
-        for ifile=1:nbfield
-            for j=1:nbslice
-                 filename=fullfile_uvmat(RootPath,subdir_civ2,RootFile_nc,'.nc',NomType_nc,i1_civ2(ifile),i2_civ2(ifile),j1_civ2(j),j2_civ2(j));
-                filecell.nc.civ2(ifile,j)={filename};
-                if ~exist(filename,'file')
-                    errormsg=['input file ' filename ' not found'];
-                    return
-                else
-                    Data=nc2struct(filename,'ListGlobalAttribute','CivStage','civ2');
-                    if ~isempty(Data.CivStage) && Data.CivStage<4 %test for civ files
-                            errormsg=['no civ2 data in ' filename];
-                            return
-                    elseif isempty(Data.civ2)||isequal(Data.civ2,0)
-                        errormsg=['no civ2 data in ' filename];
-                        return
-                    end
-                end
-            end
-        end
-    end
-end
-
-%%%%%%%%%%%%%  if stereo fields are calculated by PATCH %%%%%%%%%%%%%
-if strcmp(compare,'stereo PIV')
-    if  checkbox(3) && isequal(get(handles.test_stereo1,'Value'),1)
-        for ifile=1:nbfield
-            for j=1:nbslice
-                 filename=fullfile_uvmat(RootPath,subdir_civ1,RootFile_AB,'.nc',NomType_nc,i1_civ1(ifile),i2_civ1(ifile),j1_civ1(j),j2_civ1(j));
-                filecell.st(ifile,j)={filename};
-            end
-        end
-    end
-    if  checkbox(6) && isequal(get(handles.CheckStereo,'Value'),1)
-        for ifile=1:nbfield
-            for j=1:nbslice
-                 filename=fullfile_uvmat(RootPath,subdir_civ2,RootFile_AB,'.nc',NomType_nc,i1_civ2(ifile),i2_civ2(ifile),j1_civ2(j),j2_civ2(j));
-                filecell.st(ifile,j)={filename};
-            end
-        end
-    end
-end
-set(handles.SubdirCiv1,'String',regexprep(subdir_civ1,['^' SubDirImages],''));%suppress the root  SuddirImages;);%update the edit box
-set(handles.SubdirCiv2,'String',regexprep(subdir_civ2,['^' SubDirImages],''));%update the edit box
-
-% For CivX COPY IMAGES TO THE FORMAT .png IF NEEDED 
-if strcmp(CivMode,'CivX')
-    NomType_imanew1=NomType_ima1;
-    NomType_imanew2=NomType_ima2;
-    if ~isequal(ext_ima,'.png')
-        if checkbox(1) %if civ1 is performed
-             [FileType,FileInfo,MovieObject]=get_file_type(filecell.ima1.civ1{1});
-            check_j=0;
-            if strcmp(FileType,'mmreader')||strcmp(FileType,'VideoReader')||strcmp(FileType,'multimage')
-                if max(j1_civ1)>1
-                    check_j=1;
-                    NomType_imanew1='_1_1';
-                else
-                    NomType_imanew1='_1';
-                end
-            end
-            h = waitbar(0,'copy images to the .png format for civ1');% display a wait bar
-            for ifile=1:nbfield
-                waitbar(ifile/nbfield);
-                for j=1:nbslice
-                    filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima1,'.png',NomType_imanew1,i1_civ1(ifile),[],j1_civ1(j));
-                    if ~exist(filename,'file')
-                        if check_j
-                        A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,j1_civ1(j));
-                        else
-                            A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,i1_civ1(ifile));
-                        end
-                        imwrite(uint16(sum(A,3)),filename,'BitDepth',16);
-                    end
-                    filecell.ima1.civ1(ifile,j)={filename};
-                    filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima2,'.png',NomType_imanew1,i2_civ1(ifile),[],j2_civ1(j));
-                    if ~exist(filename,'file')
-                         if check_j
-                            A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,j2_civ1(j));
-                        else
-                            A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,i2_civ1(ifile));
-                         end
-                        imwrite(uint16(sum(A,3)),filename,'BitDepth',16);
-                    end
-                    filecell.ima2.civ1(ifile,j)={filename};
-                end
-            end
-            close(h)
-        end
-        if checkbox(4) %if civ2 is performed
-             [FileType,FileInfo,MovieObject]=get_file_type(filecell.ima1.civ2{1});
-            check_j=0;
-            if strcmp(FileType,'mmreader')||strcmp(FileType,'VideoReader')||strcmp(FileType,'multimage')
-                if max(j1_civ2)>1
-                    check_j=1;
-                    NomType_imanew1='_1_1';
-                else
-                    NomType_imanew1='_1';
-                end
-            end
-            h = waitbar(0,'copy images to the .png format for civ2');% display a wait bar
-            for ifile=1:nbfield
-                waitbar(ifile/nbfield);
-                for j=1:nbslice
-                    filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima1,'.png',NomType_imanew1,i1_civ2(ifile),[],j1_civ2(j));
-                    if ~exist(filename,'file')
-                        if check_j
-                        A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,j1_civ2(j));
-                        else
-                            A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,i1_civ2(ifile));
-                        end
-                        imwrite(uint16(sum(A,3)),filename,'BitDepth',16);
-                    end
-                    filecell.ima1.civ2(ifile,j)={filename};
-                    filename=fullfile_uvmat(RootPath,SubDirImages,RootFile_ima2,'.png',NomType_imanew2,i2_civ2(ifile),[],j2_civ2(j));
-                    if ~exist(filename,'file')
-                        if check_j
-                        A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,j1_civ2(j));
-                        else
-                            A=read_image(filecell.ima1.civ1{ifile,j},FileType,MovieObject,i1_civ2(ifile));
-                        end
-                        imwrite(uint16(sum(A,3)),filename,'BitDepth',16);
-                    end
-                    filecell.ima2.civ2(ifile,j)={filename};
-                end
-            end
-            close(h);
-        end
-    end
-end
+
 
 %------------------------------------------------------------------------
@@ -2407,5 +690,5 @@
     i2_civ2=ref_i+ceil(index_civ2/2)*ones(size(ref_i));
     j1_civ2=ref_j;
-    j2_civ2=ref_j;   
+    j2_civ2=ref_j;
     
     % adjust the first and last field number
@@ -2545,5 +828,5 @@
             % detect the file type, get the movie object if relevant, and look for the corresponding file series:
             % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-            [RootPath,SubDir,RootFile_1,i1_series,i2_series,j1_series,j2_series,nom_type_1,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName Ext]);
+            [RootPath,SubDir,RootFile_1,i1_series,i2_series,j1_series,j2_series,nom_type_1,FileType,FileInfo,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName Ext]);
             
             %check image nom type
@@ -2587,10 +870,11 @@
 ref_i=str2double(get(handles.ref_i,'String'));
 % last_i=str2num(get(handles.last_i,'String'));
-time=get(handles.ImaDoc,'UserData'); %get the set of times
+CivInputData=get(handles.civ_input,'UserData');
 TimeUnit=get(handles.TimeUnit,'String');
 checkframe=strcmp(TimeUnit,'frame');
-siztime=size(time);
-nbfield=siztime(1)-1;
-nbfield2=siztime(2)-1;
+time=CivInputData.Time;
+siztime=size(CivInputData.Time);
+nbfield=siztime(2)-1;
+nbfield2=siztime(1)-1;
 indchosen=1;  %%first pair selected by default
 %displ_num used to define the indices of the civ_input pairs
@@ -2612,5 +896,5 @@
             numlist_b(index)=numod_b;
             if size(time,2)>1 && ~checkframe
-                dt(numod_a,numod_b)=time(ref_i+1,numod_b+1)-time(ref_i+1,numod_a+1);%first time interval dt
+                dt(numod_a,numod_b)=CivInputData.Time(ref_i+1,numod_b+1)-CivInputData.Time(ref_i+1,numod_a+1);%first time interval dt
                 displ_dt(index)=dt(numod_a,numod_b);
             else
@@ -2810,5 +1094,5 @@
 %% initialisation
 errormsg='';
-browse=get(handles.RootPath,'UserData');
+%browse=get(handles.RootPath,'UserData');
 compare_list=get(handles.ListCompareMode,'String');
 val=get(handles.ListCompareMode,'Value');
Index: trunk/src/series/civ_series.m
===================================================================
--- trunk/src/series/civ_series.m	(revision 598)
+++ trunk/src/series/civ_series.m	(revision 599)
@@ -55,4 +55,5 @@
         Data.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
         Data.OutputDirExt='.civ';%set the output dir extension
+       
     return
 end
Index: trunk/src/series/relabel_i_j.m
===================================================================
--- trunk/src/series/relabel_i_j.m	(revision 598)
+++ trunk/src/series/relabel_i_j.m	(revision 599)
@@ -3,44 +3,38 @@
 % function ParamOut=relabel_i_j(Param)
 %------------------------------------------------------------------------
-
+%
 %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-% This function is used in four modes by the GUI series:
-%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
-%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
-%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
-%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
-%
-% This function is used in four modes by the GUI series:
-%           1) config GUI: with no input argument, the function determine the suitable GUI configuration
-%           2) interactive input: the function is used to interactively introduce input parameters, and then stops
-%           3) RUN: the function itself runs, when an appropriate input  structure Param has been introduced. 
-%           4) BATCH: the function itself proceeds in BATCH mode, using an xml file 'Param' as input.
-%
 %OUTPUT
-% GUI_input=list of options in the GUI series.fig needed for the function
+% ParamOut: sets options in the GUI series.fig needed for the function
 %
 %INPUT:
 % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
 % In batch mode, Param is the name of the corresponding xml file containing the same information
-% In the absence of input (as activated when the current Action is selected
-% in series), the function ouput GUI_input set the activation of the needed GUI elements
+% when Param.Action.RUN=0 (as activated when the current Action is selected
+% in series), the function ouput paramOut set the activation of the needed GUI elements
 %
-% Param contains the elements:(use the menu bar command 'export/GUI config' in series to see the current structure Param)
+% Param contains the elements:(use the menu bar command 'export/GUI config' in series to 
+% see the current structure Param)
 %    .InputTable: cell of input file names, (several lines for multiple input)
 %                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
 %    .OutputSubDir: name of the subdirectory for data outputs
-%    .OutputDir: directory for data outputs, including path
+%    .OutputDirExt: directory extension for data outputs
 %    .Action: .ActionName: name of the current activated function
 %             .ActionPath:   path of the current activated function
+%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
+%             .RUN =0 for GUI input, =1 for function activation
+%             .RunMode='local','background', 'cluster': type of function  use
+%             
 %    .IndexRange: set the file or frame indices on which the action must be performed
 %    .FieldTransform: .TransformName: name of the selected transform function
 %                     .TransformPath:   path  of the selected transform function
-%                     .TransformHandle: corresponding function handle
 %    .InputFields: sub structure describing the input fields withfields
-%              .FieldName: name of the field
+%              .FieldName: name(s) of the field
 %              .VelType: velocity type
 %              .FieldName_1: name of the second field in case of two input series
 %              .VelType_1: velocity type of the second field in case of two input series
+%              .Coord_y: name of y coordinate variable
+%              .Coord_x: name of x coordinate variable
 %    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -49,35 +43,28 @@
 
 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName
-if ~exist('Param','var') % case with no input parameter 
-    ParamOut={'NbViewMax';1;...% max nbre of input file series (default='' , no limitation)
-        'AllowInputSort';'off';...% allow alphabetic sorting of the list of input files (options 'off'/'on', 'off' by default)
-        'WholeIndexRange';'on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
-        'NbSlice';'off'; ...%nbre of slices ('off' by default)
-        'VelType';'off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
-        'FieldName';'off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-        'FieldTransform'; 'off';...%can use a transform function
-        'ProjObject';'off';...%can use projection object(option 'off'/'on',
-        'Mask';'off';...%can use mask option   (option 'off'/'on', 'off' by default)
-        'OutputDirExt';'';...%set the output dir extension
-               ''};
-        return
-end
-
-%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
-%% select different modes,  RUN, parameter input, BATCH
-% BATCH  case: read the xml file for batch case
+if isstruct(Param) && isequal(Param.Action.RUN,0)
+    ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
+    ParamOut.WholeIndexRange='on';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+    ParamOut.NbSlice='one'; ...%nbre of slices, 'one' prevents splitting in several processes, ('off' by default)
+    ParamOut.VelType='off';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+    ParamOut.FieldName='off';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+    ParamOut.FieldTransform = 'off';...%can use a transform function
+    ParamOut.ProjObject='off';...%can use projection object(option 'off'/'on',
+    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
+    ParamOut.OutputDirExt='';%set the output dir extension
+    if size(Param.InputTable,1)>1
+        msgbox_uvmat('WARNING', 'this function acts only on the first input file line')
+    end
+return
+end
+
+ParamOut=[];
+%%%%%%%%%%%% STANDARD PART  %%%%%%%%%%%%
+%% read input parameters from an xml file if input is a file name (batch mode)
+checkrun=1;
 if ischar(Param)
-        Param=xml2struct(Param);
-        checkrun=0;
-% RUN case: parameters introduced as the input structure Param
-else
-    hseries=guidata(Param.hseries);%handles of the GUI series
-    if isfield(Param,'Specific')&& strcmp(Param.Specific,'?')
-        checkrun=1;% will only search interactive input parameters (preparation of BATCH mode)
-    else
-        checkrun=2; % indicate the RUN option is used
-    end
-end
-ParamOut=Param; %default output
+    Param=xml2struct(Param);% read Param as input file (batch case)
+    checkrun=0;
+end
 
 %% root input file(s) and type
@@ -94,32 +81,18 @@
 % numbers of slices and file indices
 
-NbSlice=1;%default
-if isfield(Param.IndexRange,'NbSlice')&&~isempty(Param.IndexRange.NbSlice)
-    NbSlice=Param.IndexRange.NbSlice;
-end
-nbview=numel(i1_series);%number of input file series (lines in InputTable)
 nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices)
 nbfield_i=size(i1_series{1},2); %nb of fields for the i index
 nbfield=nbfield_j*nbfield_i; %total number of fields
-nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
-nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
 
 %determine the file type on each line from the first input file 
 ImageTypeOptions={'image','multimage','mmreader','video'};
-NcTypeOptions={'netcdf','civx','civdata'};
-for iview=1:nbview
-    if ~exist(filecell{iview,1}','file')
-        msgbox_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'])
-        return
-    end
-    [FileType{iview},FileInfo{iview},MovieObject{iview}]=get_file_type(filecell{iview,1});
-    CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images
-    CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files
-    if ~isempty(j1_series{iview})
-        frame_index{iview}=j1_series{iview};
-    else
-        frame_index{iview}=i1_series{iview};
-    end
-end
+
+if ~exist(filecell{1,1}','file')
+    msgbox_uvmat('ERROR',['the first input file ' filecell{1,1} ' does not exist'])
+    return
+end
+[FileType{1},FileInfo{1},MovieObject{1}]=get_file_type(filecell{1,1});
+CheckImage=~isempty(find(strcmp(FileType{1},ImageTypeOptions)));% =1 for images
+
 
 %% calibration data and timing: read the ImaDoc files
@@ -128,29 +101,27 @@
 itime=0;
 NbSlice_calib={};
-XmlData=cell(1,nbview);%initiate the structures containing the data from the xml file (calibration and timing)
-for iview=1:nbview%Loop on views
-    SubDirBase=regexprep(SubDir{iview},'\..*','');%take the root part of SubDir, before the first dot '.'
-    filexml=[fullfile(RootPath{iview},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
+
+SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
+filexml=[fullfile(RootPath{1},SubDirBase) '.xml'];%new convention: xml at the level of the image folder
+if ~exist(filexml,'file')
+    filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.xml']; % old convention: xml inside the image folder
     if ~exist(filexml,'file')
-        filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.xml']; % old convention: xml inside the image folder
+        filexml=[fullfile(RootPath{1},SubDir{1},RootFile{1}) '.civ']; % very old convention: .civ file
         if ~exist(filexml,'file')
-            filexml=[fullfile(RootPath{iview},SubDir{iview},RootFile{iview}) '.civ']; % very old convention: .civ file
-            if ~exist(filexml,'file')
-                filexml='';
-            end
-        end
-    end
-    if ~isempty(filexml)
-        [XmlData{iview},error]=imadoc2struct_special(filexml);
-    end
-    if isfield(XmlData{iview},'Time')
-        itime=itime+1;
-        timecell{itime}=XmlData{iview}.Time;
-    end
-    if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord')
-        NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%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
+            filexml='';
+        end
+    end
+end
+if ~isempty(filexml)
+    [XmlData,error]=imadoc2struct_special(filexml);
+end
+if isfield(XmlData,'Time')
+    itime=itime+1;
+    timecell{itime}=XmlData.Time;
+end
+if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
+    NbSlice_calib{1}=size(XmlData.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform
+    if ~isequal(NbSlice_calib{1},NbSlice_calib{1})
+        msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
     end
 end
@@ -164,24 +135,4 @@
  % EDIT FROM HERE
 
-%% check the validity of  input file types
-if CheckImage{1}
-    FileExtOut='.png'; % write result as .png images for image inputs
-elseif CheckNc{1}
-    FileExtOut='.nc';% write result as .nc files for netcdf inputs
-else 
-    msgbox_uvmat('ERROR',['invalid file type input ' FileType{1}])
-    return
-end
-if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
-        msgbox_uvmat('ERROR','input must be two image series or two netcdf file series')
-    return
-end
-% NomTypeOut='_1-2_1';% output file index will indicate the first and last ref index in the series
-% if NbSlice~=nbfield_j
-%     answer=msgbox_uvmat('INPUT_Y-N',['will not average slice by slice: for so cancel and set NbSlice= ' num2str(nbfield_j)]);
-%     if ~strcmp(answer,'Yes')
-%         return
-%     end
-% end
 
 %% Set field names and velocity types
@@ -194,5 +145,5 @@
 display('RDvision system')
 first_label=0; %image numbers start from 0
-if ~strcmp(NomType{1},'_000001')
+if ~CheckImage || ~strcmp(NomType{1},'_000001')
     msgbox_uvmat('WARNING','the input is not a file from RDvision: this function relabel_i_j has no action');%error message for directory creation
     return
@@ -206,5 +157,5 @@
 %% copy and adapt the xml file
 NomTypeNew='_1_1';
-if ~isempty(XmlData{1})
+if ~isempty(XmlData)
         t=xmltree(filexml);
         
@@ -233,23 +184,23 @@
         
         %%%% correction RDvision %%%%
-        if isfield(XmlData{1},'NbDtj')
+        if isfield(XmlData,'NbDtj')
             uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
             uid_value=children(t,uid_NbDtj);
             if ~isempty(uid_value)
-                t=set(t,uid_value(1),'value',num2str(XmlData{1}.NbDtj));
-            end
-        end
-        if isfield(XmlData{1},'NbDtk')
+                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtj));
+            end
+        end
+        if isfield(XmlData,'NbDtk')
             uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
             uid_value=children(t,uid_NbDtk);
             if ~isempty(uid_value)
-                t=set(t,uid_value(1),'value',num2str(XmlData{1}.NbDtk));
-            end
-        end
-        if isempty(j1_series{1}) && isfield(XmlData{1},'NbDti')
+                t=set(t,uid_value(1),'value',num2str(XmlData.NbDtk));
+            end
+        end
+        if isempty(j1_series{1}) && isfield(XmlData,'NbDti')
             uid_Dti=find(t,'ImaDoc/Camera/BurstTiming/Dti');
-            t=add(t,uid_Dti,'chardata',num2str(XmlData{1}.Dti));
+            t=add(t,uid_Dti,'chardata',num2str(XmlData.Dti));
             uid_NbDti=find(t,'ImaDoc/Camera/BurstTiming/NbDti');
-            t=add(t,uid_NbDti,'chardata',num2str(XmlData{1}.NbDti));
+            t=add(t,uid_NbDti,'chardata',num2str(XmlData.NbDti));
             uid_NbDtj=find(t,'ImaDoc/Camera/BurstTiming/NbDtj');
             uid_NbDtk=find(t,'ImaDoc/Camera/BurstTiming/NbDtk');
@@ -264,35 +215,36 @@
             SubDirBase=regexprep(SubDir{1},'\..*','');%take the root part of SubDir, before the first dot '.'
     filexml_new=[fullfile(RootPath{1},SubDirBase) '.xml'];
-        save(t,filexml_new)
+       % save(t,filexml_new)
 end
 
 %% main loop on images
 %j1=[];%default
-nbfield2=size(XmlData{1}.Time,2);
+nbfield2=size(XmlData.Time,2)
 for ifile=1:nbfield
     if checkrun
-        update_waitbar(hseries.Waitbar,ifile/nbfield)
-        drawnow
-        stopstate=get(hseries.RUN,'BusyAction');
+        stopstate=get(Param.RUNHandle,'BusyAction');
+        update_waitbar(Param.WaitbarHandle,ifile/nbfield)
     else
         stopstate='queue';
     end
-    if isequal(stopstate,'queue') % enable STOP command
-        filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
-        j1=mod(ifile-1+first_label,nbfield2)+1;
-        i1=floor((ifile-1+first_label)/nbfield2)+1;
-        filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1);
-        try
-            movefile(filename,filename_new);
-            [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
-            if ~s
-                msgbox_uvmat('ERROR',errormsg);
-                return
-            end
-        catch ME
-            msgbox_uvmat('ERROR',ME.message);
+    if ~isequal(stopstate,'queue')% enable STOP command
+        break
+    end
+    filename=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomType{1},i1_series{1}(ifile));
+    j1=mod(ifile-1+first_label,nbfield2)+1;
+    i1=floor((ifile-1+first_label)/nbfield2)+1;
+    filename_new=fullfile_uvmat(RootPath{1},SubDir{1},RootFile{1},FileExt{1},NomTypeNew,i1,[],j1);
+    try
+        movefile(filename,filename_new);
+        [s,errormsg] = fileattrib(filename_new,'-w','a'); %set images to read only '-w' for all users ('a')
+        if ~s
+            msgbox_uvmat('ERROR',errormsg);
             return
         end
-    end
+    catch ME
+        msgbox_uvmat('ERROR',ME.message);
+        return
+    end
+    
 end
 
Index: trunk/src/series/sub_background.m
===================================================================
--- trunk/src/series/sub_background.m	(revision 598)
+++ trunk/src/series/sub_background.m	(revision 599)
@@ -171,11 +171,11 @@
         nbaver_ima=nbaver*step;
     end
-    ParamOut.InputGUI.CheckVolume=strcmp(answer{1},'Yes');
-    ParamOut.InputGUI.SlidingSequenceLength=nbaver_ima;
-    ParamOut.InputGUI.BrightnessRankThreshold=str2num(answer{3});
+    ParamOut.ActionInput.CheckVolume=strcmp(answer{1},'Yes');
+    ParamOut.ActionInput.SlidingSequenceLength=nbaver_ima;
+    ParamOut.ActionInput.BrightnessRankThreshold=str2num(answer{3});
     
     % apply the image rescaling function 'level' (avoid the blinking effects of bright particles)
     answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m after sub_background');
-    ParamOut.InputGUI.CheckLevelTransform=strcmp(answer,'Yes');
+    ParamOut.ActionInput.CheckLevelTransform=strcmp(answer,'Yes');
     return
 end
@@ -190,5 +190,5 @@
 
 %% Input preparation
-nbaver_ima=Param.InputGUI.SlidingSequenceLength;
+nbaver_ima=Param.ActionInput.SlidingSequenceLength;
 NbSlice=Param.IndexRange.NbSlice;
 if ~isequal(NbSlice,1)
@@ -225,10 +225,10 @@
 OutputDir=[Param.OutputSubDir Param.OutputDirExt];
 
-if isequal(Param.InputGUI.CheckVolume,1)
+if isequal(Param.ActionInput.CheckVolume,1)
     step=1;
 else
     step=nbfield_j;%case of bursts: the sliding background is shifted by the length of one burst
 end
-nbaver_ima=Param.InputGUI.SlidingSequenceLength;%number of images for the sliding background
+nbaver_ima=Param.ActionInput.SlidingSequenceLength;%number of images for the sliding background
 nbaver=ceil(nbaver_ima/step);%number of bursts for the sliding background
 if isequal(floor(nbaver/2),nbaver)
@@ -242,5 +242,5 @@
 
 % calculate absolute brightness rank
-rank=floor(Param.InputGUI.BrightnessRankThreshold*nbaver_ima);
+rank=floor(Param.ActionInput.BrightnessRankThreshold*nbaver_ima);
 if rank==0
     rank=1;%rank selected in the sorted image series
@@ -346,5 +346,5 @@
         
         %write result file
-        if Param.InputGUI.CheckLevelTransform
+        if Param.ActionInput.CheckLevelTransform
             C=levels(Acor);
             imwrite(C,newname,'BitDepth',8); % save the new image
@@ -395,5 +395,5 @@
                     newname=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(ifile),[],j1);
                     %write result file
-                    if Param.InputGUI.CheckLevelTransform
+                    if Param.ActionInput.CheckLevelTransform
                         C=levels(Acor);
                         imwrite(C,newname,'BitDepth',8); % save the new image
@@ -430,5 +430,5 @@
         
         %write result file
-        if Param.InputGUI.CheckLevelTransform
+        if Param.ActionInput.CheckLevelTransform
             C=levels(Acor);
             imwrite(C,newname,'BitDepth',8); % save the new image
Index: trunk/src/series/time_series.m
===================================================================
--- trunk/src/series/time_series.m	(revision 598)
+++ trunk/src/series/time_series.m	(revision 599)
@@ -45,13 +45,13 @@
 if isstruct(Param) && isequal(Param.Action.RUN,0)
     ParamOut.AllowInputSort='off';...% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
-    ParamOut.WholeIndexRange='off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
-    ParamOut.NbSlice='on'; ...%nbre of slices ('off' by default)
-    ParamOut.VelType='two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
-    ParamOut.FieldName='two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-    ParamOut.FieldTransform = 'on';...%can use a transform function
-    ParamOut.ProjObject='on';...%can use projection object(option 'off'/'on',
-    ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
-    ParamOut.OutputDirExt='.tseries';%set the output dir extension
-return
+        ParamOut.WholeIndexRange='off';...% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
+        ParamOut.NbSlice='on'; ...%nbre of slices ('off' by default)
+        ParamOut.VelType='two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+        ParamOut.FieldName='two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        ParamOut.FieldTransform = 'on';...%can use a transform function
+        ParamOut.ProjObject='on';...%can use projection object(option 'off'/'on',
+        ParamOut.Mask='off';...%can use mask option   (option 'off'/'on', 'off' by default)
+        ParamOut.OutputDirExt='.tseries';%set the output dir extension
+    return
 end
 
@@ -78,6 +78,6 @@
 % filecell{iview,fileindex}:
 %        iview: line in the table corresponding to a given file series
-%        fileindex: file index within  the file series, 
-% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j 
+%        fileindex: file index within  the file series,
+% i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j
 % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices
 %%%%%%%%%%%%
@@ -90,8 +90,8 @@
 nbfield_i=size(i1_series{1},2); %nb of fields for the i index
 nbfield=nbfield_j*nbfield_i; %total number of fields
-nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices) 
+nbfield_i=floor(nbfield/NbSlice);%total number of  indexes in a slice (adjusted to an integer number of slices)
 nbfield=nbfield_i*NbSlice; %total number of fields after adjustement
 
-%determine the file type on each line from the first input file 
+%determine the file type on each line from the first input file
 ImageTypeOptions={'image','multimage','mmreader','video'};
 NcTypeOptions={'netcdf','civx','civdata'};
@@ -117,5 +117,5 @@
     if diff_time>0
         displ_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun)
-    end   
+    end
     time=time(1,:);% choose the time data from the first sequence
 end
@@ -130,5 +130,5 @@
 
 %%%%%%%%%%%% END STANDARD PART  %%%%%%%%%%%%
- % EDIT FROM HERE
+% EDIT FROM HERE
 
 %% check the validity of  ctinput file types
@@ -137,10 +137,10 @@
 elseif CheckNc{1}
     FileExtOut='.nc';% write result as .nc files for netcdf inputs
-else 
+else
     displ_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun)
     return
 end
 if nbview==2 && ~isequal(CheckImage{1},CheckImage{2})
-        displ_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
+    displ_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun)
     return
 end
@@ -196,227 +196,228 @@
 end
 
-%% LOOP ON SLICES
 nbmissing=0; %number of undetected files
-for i_slice=1:NbSlice
-    index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
-    nbfile=0;
-    nbmissing=0;
-    
-    %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
-    for index=index_slice  
-        if checkrun
-            stopstate=get(Param.RUNHandle,'BusyAction');
-            update_waitbar(Param.WaitbarHandle,index/nbfield)
-        else
-            stopstate='queue';
-        end
-        if isequal(stopstate,'queue')% enable STOP command
-            Data=cell(1,nbview);%initiate the set Data;
-            nbtime=0;
-            dt=[];
-            %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
-            for iview=1:nbview
-                % reading input file(s)
-                [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
-                if ~isempty(errormsg)
-                    errormsg=['time_series / read_field / ' errormsg];
-                    display(errormsg)
-                    break
+% for i_slice=1:NbSlice
+%index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice
+nbfile=0;
+nbmissing=0;
+
+%%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%%
+for index=1:nbfield
+    if checkrun
+        stopstate=get(Param.RUNHandle,'BusyAction');
+        update_waitbar(Param.WaitbarHandle,index/nbfield)
+    else
+        stopstate='queue';
+    end
+    if ~isequal(stopstate,'queue')% enable STOP command
+        break
+    end
+    Data=cell(1,nbview);%initiate the set Data;
+    nbtime=0;
+    dt=[];
+    %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%%
+    for iview=1:nbview
+        % reading input file(s)
+        [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index));
+        if ~isempty(errormsg)
+            errormsg=['time_series / read_field / ' errormsg];
+            display(errormsg)
+            break
+        end
+        if ~isempty(NbSlice_calib)
+            Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
+        end
+    end
+    if isempty(errormsg)
+        Field=Data{1}; % default input field structure
+        % coordinate transform (or other user defined transform)
+        if ~isempty(transform_fct)
+            switch nargin(transform_fct)
+                case 4
+                    if length(Data)==2
+                        Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
+                    else
+                        Field=transform_fct(Data{1},XmlData{1});
+                    end
+                case 3
+                    if length(Data)==2
+                        Field=transform_fct(Data{1},XmlData{1},Data{2});
+                    else
+                        Field=transform_fct(Data{1},XmlData{1});
+                    end
+                case 2
+                    Field=transform_fct(Data{1},XmlData{1});
+                case 1
+                    Field=transform_fct(Data{1});
+            end
+        end
+        
+        % calculate tps coefficients if needed
+        if isfield(Param.ProjObject,'ProjMode')&& strcmp(Param.ProjObject.ProjMode,'interp_tps')
+            Field=tps_coeff_field(Field,check_proj_tps);
+        end
+        
+        %field projection on an object
+        if Param.CheckObject
+            [Field,errormsg]=proj_field(Field,Param.ProjObject);
+            if ~isempty(errormsg)
+                msgbox_uvmat('ERROR',['time_series / proj_field / ' errormsg])
+                return
+            end
+        end
+        nbfile=nbfile+1;
+        
+        % initiate the time series at the first iteration
+        if nbfile==1
+            % stop program if the first field reading is in error
+            if ~isempty(errormsg)
+                displ_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun)
+                return
+            end
+            DataOut=Field;%default
+            DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots
+            nbvar=length(Field.ListVarName);
+            if nbvar==0
+                displ_uvmat('ERROR','no input variable selected',checkrun)
+                return
+            end
+            testsum=2*ones(1,nbvar);%initiate flag for action on each variable
+            if isfield(Field,'VarAttribute') % look for coordinate and flag variables
+                for ivar=1:nbvar
+                    if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
+                        var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
+                        if isequal(var_role,'errorflag')
+                            displ_uvmat('ERROR','do not handle error flags in time series',checkrun)
+                            return
+                        end
+                        if isequal(var_role,'warnflag')
+                            testsum(ivar)=0;  % not recorded variable
+                            eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
+                        end
+                        if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
+                                isequal(var_role,'coord_z')|isequal(var_role,'coord')
+                            testsum(ivar)=1; %constant coordinates, record without time evolution
+                        end
+                    end
+                    % check whether the variable ivar is a dimension variable
+                    DimCell=Field.VarDimName{ivar};
+                    if ischar(DimCell)
+                        DimCell={DimCell};
+                    end
+                    if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
+                        testsum(ivar)=1;
+                    end
                 end
-                if ~isempty(NbSlice_calib)
-                    Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform
+            end
+            for ivar=1:nbvar
+                if testsum(ivar)==2
+                    eval(['DataOut.' Field.ListVarName{ivar} '=[];'])
                 end
             end
-            if isempty(errormsg)
-            Field=Data{1}; % default input field structure
-            % coordinate transform (or other user defined transform)
-            if ~isempty(transform_fct)
-                switch nargin(transform_fct)
-                    case 4
-                        if length(Data)==2
-                            Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2});
-                        else
-                            Field=transform_fct(Data{1},XmlData{1});
+            DataOut.ListVarName=[{'Time'} DataOut.ListVarName];
+        end
+        
+        % add data to the current field
+        for ivar=1:length(Field.ListVarName)
+            VarName=Field.ListVarName{ivar};
+            VarVal=Field.(VarName);
+            if testsum(ivar)==2% test for recorded variable
+                if isempty(errormsg)
+                    if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
+                        if isempty(VarVal)
+                            displ_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(index))],checkrun)
+                            return
                         end
-                    case 3
-                        if length(Data)==2
-                            Field=transform_fct(Data{1},XmlData{1},Data{2});
-                        else
-                            Field=transform_fct(Data{1},XmlData{1});
-                        end
-                    case 2
-                        Field=transform_fct(Data{1},XmlData{1});
-                    case 1
-                        Field=transform_fct(Data{1});
+                        VarVal=mean(VarVal,1);
+                    end
+                    VarVal=shiftdim(VarVal,-1); %shift dimension
+                    DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series
+                else
+                    DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error
                 end
-            end
-            
-            % calculate tps coefficients if needed
-            if isfield(Param.ProjObject,'ProjMode')&& strcmp(Param.ProjObject.ProjMode,'interp_tps')
-                Field=tps_coeff_field(Field,check_proj_tps);
-            end
-            
-            %field projection on an object
-            if Param.CheckObject
-                [Field,errormsg]=proj_field(Field,Param.ProjObject);
-                if ~isempty(errormsg)
-                    msgbox_uvmat('ERROR',['time_series / proj_field / ' errormsg])
+            elseif testsum(ivar)==1% variable representing fixed coordinates
+                VarInit=DataOut.(VarName);
+                if isempty(errormsg) && ~isequal(VarVal,VarInit)
+                    displ_uvmat('ERROR',['time series requires constant coordinates ' VarName],checkrun)
                     return
                 end
             end
-            nbfile=nbfile+1;
-            
-            % initiate the time series at the first iteration
-            if nbfile==1
-                % stop program if the first field reading is in error
-                if ~isempty(errormsg)
-                    displ_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun)
-                    return
-                end
-                DataOut=Field;%default
-                DataOut.NbDim=Field.NbDim+1; %add the time dimension for plots
-                nbvar=length(Field.ListVarName);
-                if nbvar==0
-                    displ_uvmat('ERROR','no input variable selected',checkrun)
-                    return
-                end
-                testsum=2*ones(1,nbvar);%initiate flag for action on each variable
-                if isfield(Field,'VarAttribute') % look for coordinate and flag variables
-                    for ivar=1:nbvar
-                        if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role')
-                            var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable
-                            if isequal(var_role,'errorflag')
-                                displ_uvmat('ERROR','do not handle error flags in time series',checkrun)
-                                return
-                            end
-                            if isequal(var_role,'warnflag')
-                                testsum(ivar)=0;  % not recorded variable
-                                eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable
-                            end
-                            if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|...
-                                    isequal(var_role,'coord_z')|isequal(var_role,'coord')
-                                testsum(ivar)=1; %constant coordinates, record without time evolution
-                            end
-                        end
-                        % check whether the variable ivar is a dimension variable
-                        DimCell=Field.VarDimName{ivar};
-                        if ischar(DimCell)
-                            DimCell={DimCell};
-                        end
-                        if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables
-                            testsum(ivar)=1;
-                        end
-                    end
-                end
-                for ivar=1:nbvar
-                    if testsum(ivar)==2
-                        eval(['DataOut.' Field.ListVarName{ivar} '=[];'])
-                    end
-                end
-                DataOut.ListVarName=[{'Time'} DataOut.ListVarName];
-            end
-            
-            % add data to the current field
-            for ivar=1:length(Field.ListVarName)
-                VarName=Field.ListVarName{ivar};
-                VarVal=Field.(VarName);
-                if testsum(ivar)==2% test for recorded variable
-                    if isempty(errormsg)
-                        if isequal(Param.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
-                            if isempty(VarVal)
-                                displ_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(index))],checkrun)
-                                return
-                            end
-                            VarVal=mean(VarVal,1);
-                        end
-                        VarVal=shiftdim(VarVal,-1); %shift dimension
-                        DataOut.(VarName)=cat(1,DataOut.(VarName),VarVal);%concanete the current field to the time series
-                    else
-                        DataOut.(VarName)=cat(1,DataOut.(VarName),0);% put each variable to 0 in case of input reading error
-                    end
-                elseif testsum(ivar)==1% variable representing fixed coordinates
-                    VarInit=DataOut.(VarName);
-                    if isempty(errormsg) && ~isequal(VarVal,VarInit)
-                        displ_uvmat('ERROR',['time series requires constant coordinates ' VarName],checkrun)
-                        return
-                    end
-                end
-            end
-            
-            % record the time:
-            if isempty(time)% time not set by xml filer(s)
-                if isfield(Data{1},'Time')
-                    DataOut.Time(nbfile,1)=Field.Time;
-                else
-                    DataOut.Time(nbfile,1)=index;%default
-                end
-            else % time from ImaDoc prevails  TODO: correct
-                DataOut.Time(nbfile,1)=time(index);%
-            end
-            
-            % record the number of missing input fields
-            if ~isempty(errormsg)
-                nbmissing=nbmissing+1;
-                display(['index=' num2str(index) ':' errormsg])
-            end
-            end
-        end
-    end
-    %%%%%%% END OF LOOP WITHIN A SLICE
+        end
+        
+        % record the time:
+        if isempty(time)% time not set by xml filer(s)
+            if isfield(Data{1},'Time')
+                DataOut.Time(nbfile,1)=Field.Time;
+            else
+                DataOut.Time(nbfile,1)=index;%default
+            end
+        else % time from ImaDoc prevails  TODO: correct
+            DataOut.Time(nbfile,1)=time(index);%
+        end
+        
+        % record the number of missing input fields
+        if ~isempty(errormsg)
+            nbmissing=nbmissing+1;
+            display(['index=' num2str(index) ':' errormsg])
+        end
+    end
     
-    %remove time for global attributes if exists
-    Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute));
-    if ~isempty(Time_index)
-        DataOut.ListGlobalAttribute(Time_index)=[];
-    end
-    DataOut.Conventions='uvmat';
-    for ivar=1:numel(DataOut.ListVarName)
-        VarName=DataOut.ListVarName{ivar};
-        eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons
-    end
-    
-    % add time dimension
-    for ivar=1:length(Field.ListVarName)
-        DimCell=Field.VarDimName(ivar);
-        if testsum(ivar)==2%variable used as time series
-            DataOut.VarDimName{ivar}=[{'Time'} DimCell];
-        elseif testsum(ivar)==1
-            DataOut.VarDimName{ivar}=DimCell;
-        end
-    end
-    indexremove=find(~testsum);
-    if ~isempty(indexremove)
-        DataOut.ListVarName(1+indexremove)=[];
-        DataOut.VarDimName(indexremove)=[];
-        if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs
-            DataOut.Role(1+indexremove)=[];
-        end
-    end
-    
-    %shift variable attributes
-    if isfield(DataOut,'VarAttribute')
-        DataOut.VarAttribute=[{[]} DataOut.VarAttribute];
-    end
-    DataOut.VarDimName=[{'Time'} DataOut.VarDimName];
-    DataOut.Action=Param.Action;%name of the processing programme
-    test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant)
-    if ~test_time
-        DataOut.Time=1:filecounter;
-    end
-    
-    % display nbmissing
-    if ~isequal(nbmissing,0)
-        displ_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun)
-    end
-    
-    %name of result file
-    OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
-    errormsg=struct2nc(OutputFile,DataOut); %save result file
-    if isempty(errormsg)
-        display([OutputFile ' written'])
-    else
-        displ_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun)
-    end
-end
+end
+%%%%%%% END OF LOOP WITHIN A SLICE
+
+%remove time for global attributes if exists
+Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute));
+if ~isempty(Time_index)
+    DataOut.ListGlobalAttribute(Time_index)=[];
+end
+DataOut.Conventions='uvmat';
+for ivar=1:numel(DataOut.ListVarName)
+    VarName=DataOut.ListVarName{ivar};
+    eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons
+end
+
+% add time dimension
+for ivar=1:length(Field.ListVarName)
+    DimCell=Field.VarDimName(ivar);
+    if testsum(ivar)==2%variable used as time series
+        DataOut.VarDimName{ivar}=[{'Time'} DimCell];
+    elseif testsum(ivar)==1
+        DataOut.VarDimName{ivar}=DimCell;
+    end
+end
+indexremove=find(~testsum);
+if ~isempty(indexremove)
+    DataOut.ListVarName(1+indexremove)=[];
+    DataOut.VarDimName(indexremove)=[];
+    if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs
+        DataOut.Role(1+indexremove)=[];
+    end
+end
+
+%shift variable attributes
+if isfield(DataOut,'VarAttribute')
+    DataOut.VarAttribute=[{[]} DataOut.VarAttribute];
+end
+DataOut.VarDimName=[{'Time'} DataOut.VarDimName];
+DataOut.Action=Param.Action;%name of the processing programme
+test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant)
+if ~test_time
+    DataOut.Time=1:filecounter;
+end
+
+% display nbmissing
+if ~isequal(nbmissing,0)
+    displ_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun)
+end
+
+%name of result file
+OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},FileExtOut,NomTypeOut,i1_series{1}(1),i1_series{1}(end),i_slice,[]);
+errormsg=struct2nc(OutputFile,DataOut); %save result file
+if isempty(errormsg)
+    display([OutputFile ' written'])
+else
+    displ_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun)
+end
+
 
 %% plot the time series (the last one in case of multislices)
@@ -425,5 +426,5 @@
     haxes=axes;
     plot_field(DataOut,haxes)
-       
+    
     %% display the result file using the GUI get_field
     hget_field=findobj(allchild(0),'name','get_field');
Index: trunk/src/uvmat.m
===================================================================
--- trunk/src/uvmat.m	(revision 598)
+++ trunk/src/uvmat.m	(revision 599)
@@ -542,7 +542,7 @@
 end
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
-[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
+[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
 % initiate the input file series and refresh the current field view: 
-update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,1);
+update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,1);
 
 %-----------------------------------------------------------------------
@@ -672,5 +672,5 @@
 % detect the file type, get the movie object if relevant, and look for the corresponding file series:
 % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
-[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
+[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
 
 %% open the file or fill the GUI uvmat according to the detected file type
@@ -2663,5 +2663,6 @@
             plot_handles{2}=guidata(view_field_handle);
             haxes(2)=plot_handles{2}.PlotAxes;
-            PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
+            PlotParam{2}=read_GUI(view_field_handle);
+           % PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
             PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
         end
Index: trunk/src/view_field.m
===================================================================
--- trunk/src/view_field.m	(revision 598)
+++ trunk/src/view_field.m	(revision 599)
@@ -82,4 +82,11 @@
     if isfield(PlotParamOut,'Vectors')
         set(handles.Vectors,'Visible','on')
+    else
+        set(handles.Vectors,'Visible','off')
+    end
+    if isfield(PlotParamOut,'Scalar')
+        set(handles.Scalar,'Visible','on')
+    else
+        set(handles.Scalar,'Visible','off')
     end
     errormsg=fill_GUI(PlotParamOut,hObject);
