Index: /trunk/src/ListDir.m
===================================================================
--- /trunk/src/ListDir.m	(revision 30)
+++ /trunk/src/ListDir.m	(revision 30)
@@ -0,0 +1,118 @@
+%'ListDir': scan the structure of the directory tree (for dataview.m)
+%------------------------------------------------------------------------
+% function [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in)
+%
+% 
+% OUTPUT:
+% ListDevices: list of Devices 
+% ListRecords: list of records
+% ListXml: list of xml file names
+% List: structure representing the tree structure
+%
+%INPUT
+% CurrentPath: full name (including path) to the input campaign (or subcampaign), we assume that
+%          data are organised as (sub)campaign/Experiment/Device/(Record/)/file .xml
+% ListExperiments: list of experiments to scan (cell of names)
+% ListDevices_in: list of devices to scan (cell of names)
+% ListRecords_in: list of records to scan (cell of names)
+
+function [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices_in,ListRecords_in)
+
+ListRecords={};
+ListDevices={};
+ListXml={};
+irecord_tot=0;
+idevice_tot=0;
+ixml_tot=0;
+for iexp=1:length(ListExperiments) 
+    List.Experiment{iexp}.name=ListExperiments{iexp};
+    hdir=dir(fullfile(CurrentPath,ListExperiments{iexp}));
+    idevice=0;
+    for isub=1:length(hdir)% scan the sub-directories  of the current experiment       
+        if hdir(isub).isdir
+            name=hdir(isub).name;%name of the current device
+            if ~isequal(name(1),'.')% subdirectory of the current experiment
+                [testnew,testselect]=test_select(name,ListDevices,ListDevices_in);
+                if testselect
+                    idevice=idevice+1;
+                    List.Experiment{iexp}.Device{idevice}.name=name;             
+                    if testnew
+                         idevice_tot=idevice_tot+1;
+                         ListDevices{idevice_tot}=name;
+                    end
+                    CurrentDevice=fullfile(CurrentPath,ListExperiments{iexp},name);
+                    hsubxml=dir(fullfile(CurrentDevice,'*.xml'));%look at xml files in the subdirectory of the current device
+                    if isempty(hsubxml) % the subdirectory of the current device contains directories 'Record'' 
+                        hsubdir=dir(fullfile(CurrentPath,ListExperiments{iexp},name));%list what is inside the directory 'Device'   
+                        irecord=0;
+                        for isubsub=1:length(hsubdir)% subdirectories of the current device
+                            if hsubdir(isubsub).isdir                       
+                                RecordName=hsubdir(isubsub).name;  
+                                if ~isequal(RecordName(1),'.')
+                                    [testnew,testselect]=test_select(RecordName,ListRecords,ListRecords_in);
+                                    if testselect
+                                        if testnew
+                                            irecord_tot=irecord_tot+1;
+                                            ListRecords{irecord_tot}=RecordName;
+                                        end
+                                        irecord=irecord+1;
+                                        List.Experiment{iexp}.Device{idevice}.Record{irecord}.name=RecordName;
+                                        hsubsubxml=dir(fullfile(CurrentDevice,RecordName,'*.xml'));%
+                                        for ixml=1:length(hsubsubxml)
+                                            XmlName=hsubsubxml(ixml).name;
+                                            List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}=XmlName;
+                                            testnew=test_select(XmlName,ListXml,{});
+                                            if testnew
+                                                ixml_tot=ixml_tot+1;
+                                                ListXml{ixml_tot}=XmlName;
+                                            end
+                                        end 
+                                    end              
+                                end
+                            end
+                        end
+                    else
+                        for ixml=1:length(hsubxml)
+                            XmlName=hsubxml(ixml).name;
+                            List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}=XmlName;
+                            testnew=test_select(XmlName,ListXml,{});
+                            if testnew
+                                ixml_tot=ixml_tot+1;
+                                ListXml{ixml_tot}=XmlName;
+                            end
+                        end
+                    end
+                end
+            end
+        end
+    end
+end
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% ListDevices: list of devices already scanned
+% ListDevices_in: list of input devices to scan
+function [testnew,testselect]=test_select(name,ListDevices,ListDevices_in)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+if ~isempty(ListDevices_in)
+    testnew=0;
+    testselect=0;
+    for ilist=1:length(ListDevices_in)
+        if isequal(name,ListDevices_in{ilist})
+            testnew=1;
+            testselect=1; 
+            break
+        end
+    end
+else
+    testnew=1; 
+    testselect=1;
+end
+if testnew
+    for ilist=1:length(ListDevices)
+         if isequal(name,ListDevices{ilist})
+              testnew=0;
+              break
+         end
+    end
+end
Index: /trunk/src/imadoc2struct.m
===================================================================
--- /trunk/src/imadoc2struct.m	(revision 20)
+++ /trunk/src/imadoc2struct.m	(revision 30)
@@ -21,16 +21,16 @@
 s.TimeUnit=[]; %default
 s.GeometryCalib=[];
-nom_type_ima=[];%default
-ext_ima=[];%default
+% nom_type_ima=[];%default
+% ext_ima=[];%default
 % abs_time=[];%initiation
 % GeometryCalib.CoordUnit='cm';%default
-mode=[]; %default
-NbSlice=1;%default
-npx=[];%default
-npy=[];%default
+% mode=[]; %default
+% NbSlice=1;%default
+% npx=[];%default
+% npy=[];%default
 % GeometryCalib.Pxcmx=1;
 % GeometryCalib.Pxcmy=1;
 % GeometryCalib=[];
-NbDtj=1;
+% NbDtj=1;
 tsai=[];%default
 % if ~exist('testime','var')
@@ -64,8 +64,8 @@
     end
     s.Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
-    FirstImage=s.Heading.ImageName;
-    if ~isempty(FirstImage)
-        [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage);
-    end
+%     FirstImage=s.Heading.ImageName;
+%     if ~isempty(FirstImage)
+%         [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage);
+%     end
 end
 
@@ -78,13 +78,13 @@
         xindex=findstr(ImageSize,'x');
         if length(xindex)>=2
-            npx=str2num(ImageSize(1:xindex(1)-1));
-            npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
-        end
-    end
-    uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice');
-    if ~isempty(uid_NbSlice)
-        NbSlice=str2num(get(t,children(t,uid_NbSlice),'value'));
-        if isempty(NbSlice),NbSlice=1;end; %default
-    end
+%             npx=str2num(ImageSize(1:xindex(1)-1));
+%             npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
+        end
+    end
+%     uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice');
+%     if ~isempty(uid_NbSlice)
+%         NbSlice=str2num(get(t,children(t,uid_NbSlice),'value'));
+% %         if isempty(NbSlice),NbSlice=1;end; %default
+%     end
     uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
     if ~isempty(uid_TimeUnit)
@@ -94,6 +94,6 @@
     if ~isempty(uid_BurstTiming)
         for k=1:length(uid_BurstTiming)
-            Dtj=[];%default
-            NbDtj=1;%default
+%             Dtj=[];%default
+%             NbDtj=1;%default
             subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
              % reading Dtk
@@ -121,5 +121,5 @@
             % reading Dtk
             Dtk=get_value(subt,'/BurstTiming/Dtk',[]);
-            NbDtk=get_value(subt,'/BurstTiming/NbDtk',1)
+            NbDtk=get_value(subt,'/BurstTiming/NbDtk',1);
             if isempty(Dtk)
                 s.Time=[s.Time;Time_val];
@@ -141,5 +141,5 @@
 if ~isempty(uid_GeometryCalib)
     if length(uid_GeometryCalib)>1
-        error=['More than one GeometryCalib in ' filecivxml];
+        errormsg=['More than one GeometryCalib in ' filecivxml];
         return
     end
@@ -149,5 +149,5 @@
         uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx');
         uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy');
-        if ~isempty(uid_pixcmx) & ~isempty(uid_pixcmy)%NON UTILISE 
+        if ~isempty(uid_pixcmx) && ~isempty(uid_pixcmy)%NON UTILISE 
            pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value'));
             if isempty(pixcmx),pixcmx=1;end; %default
@@ -180,5 +180,5 @@
         uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
         uid_R=find(subt,'/GeometryCalib/R');
-        if ~isempty(uid_focal) & ~isempty(uid_dpx_dpy) & ~isempty(uid_Cx_Cy)
+        if ~isempty(uid_focal) && ~isempty(uid_dpx_dpy) && ~isempty(uid_Cx_Cy)
             tsai.f=str2num(get(subt,children(subt,uid_focal),'value'));
             dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
Index: /trunk/src/nomtype2pair.m
===================================================================
--- /trunk/src/nomtype2pair.m	(revision 20)
+++ /trunk/src/nomtype2pair.m	(revision 30)
@@ -30,8 +30,8 @@
 % Dtj: ~=0 if i index pairs are used
 
-function [nom_type_pair]=nomtype2pair(nom_type,Dti,Dtj);
+function [nom_type_pair]=nomtype2pair(nom_type,Dti,Dtj)
 
 %determine nom_type_nc:
-nom_type_nc=[];%default
+nom_type_pair=[];%default
 switch nom_type
     case {'_i_j'}
Index: /trunk/src/read_geometry_calib.m
===================================================================
--- /trunk/src/read_geometry_calib.m	(revision 30)
+++ /trunk/src/read_geometry_calib.m	(revision 30)
@@ -0,0 +1,51 @@
+%'read_geometry_calib': read data on the GUI geometry_calib
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function data=read_geometry_calib(Coord_cell)
+data_XIma=[];
+data_YIma=[];
+data_XObject=[];
+data_YObject=[];
+data_ZObject=[];
+%Coord=get(handles.ListCoord,'String');
+% XImage=get(handles.XImage,'String');
+% YImage=get(handles.YImage,'String');
+% XObject=get(handles.XObject,'String');
+% YObject=get(handles.YObject,'String');
+% ZObject=get(handles.ZObject,'String');
+% if ischar(Xcolumn)
+%     Xcolumn={Xcolumn};
+% end
+nb_defining_points=length(Coord_cell);
+iline=0;
+for i=1:nb_defining_points
+    coord_str=Coord_cell{i};%character string of line number i
+    k=findstr('|',coord_str);%find separators '|'
+    if length(k)>=4 % test for separators '|'
+        data1=str2num(coord_str(1:k(1)-5));
+        data2=str2num(coord_str(k(1)+5:k(2)-5));
+        data3=str2num(coord_str(k(2)+5:k(3)-5));
+        data4=str2num(coord_str(k(3)+5:k(4)-5));
+        data5=str2num(coord_str(k(4)+5:end));
+        if ~isempty(data1)|~isempty(data2)|~isempty(data3)|~isempty(data4)|~isempty(data5)
+            iline=iline+1;
+            if ~isempty(data1)
+                data.Coord(iline,1)=data1;
+            end    
+            if ~isempty(data2)
+                data.Coord(iline,2)=data2;
+            end
+            if ~isempty(data3)
+                data.Coord(iline,3)=data3;
+            end
+            if ~isempty(data4)
+                data.Coord(iline,4)=data4;
+            end
+            if isempty(data5)
+                data.Coord(iline,5)=0;
+            else
+                data.Coord(iline,5)=data5;
+            end
+        end
+    end
+end
+data.Style='points';
Index: unk/src/read_imadoc.m
===================================================================
--- /trunk/src/read_imadoc.m	(revision 20)
+++ 	(revision )
@@ -1,243 +1,0 @@
-%'read_imadoc': reads the xml file for image documentation, OBSOLETE: replaced by imadoc2struct
-%
-%function [error,Heading,nom_type_ima,ext_ima,abs_time,TimeUnit,mode,NbSlice,npx,npy,GeometryCalib]=read_imadoc(filecivxml,testime) 
-%--------------------------------------------------------
-% OUTPUT:
-%error= 0: all right
-%        2: input file not found
-%        1: input file is not an image documentation file 'ImaDoc'
-%           1.1: 'ImaDoc/Heading' element absent
-%           1.2: 'ImaDoc/Camera' element absent
-%                 1.21: 'ImaDoc/Camera/BurstTiming' absent
-%                     1.211: 'ImaDoc/Camera/BurstTiming/FrameFrequency' absent
-%                     1.212: 'ImaDoc/Camera/BurstTiming/Time' absent
-%
-% INPUT:
-% filecivxml: full name of the xml input file
-% testime=1 read the list of times), =0 (default) do not read it to save computing  time
-%
-%  -- TODO: should be replaced by xml2struct --
-
-function [error,Heading,nom_type_ima,ext_ima,abs_time,TimeUnit,mode,NbSlice,npx,npy,GeometryCalib]=read_imadoc(filecivxml,testime) 
-% global t
-error=0;%default
-Heading=[];%default
-nom_type_ima=[];%default
-ext_ima=[];%default
-abs_time=[];%initiation
-TimeUnit='s'; %default
-% GeometryCalib.CoordUnit='cm';%default
-mode=[]; %default
-NbSlice=1;%default
-npx=[];%default
-npy=[];%default
-% GeometryCalib.Pxcmx=1;
-% GeometryCalib.Pxcmy=1;
-GeometryCalib=[];
-NbDtj=1;
-tsai=[];%default
-if ~exist('testime','var')
-    testime=1;%default
-end
-if exist(filecivxml,'file')~=2, error=2, return;end;%input file does not exist
-filecivxml;
-t=xmltree(filecivxml);
-uid_root=find(t,'/ImaDoc');
-if isempty(uid_root), error=1; return; end;%not an ImaDoc .xml file
-%Heading
-uid_Heading=find(t,'/ImaDoc/Heading');
-if isempty(uid_Heading), 
-    error=1.1;
-else
-    uid_Campaign=find(t,'/ImaDoc/Heading/Campaign');
-    uid_Exp=find(t,'/ImaDoc/Heading/Experiment');
-    uid_Device=find(t,'/ImaDoc/Heading/Device');
-    uid_Record=find(t,'/ImaDoc/Heading/Record');
-    uid_FirstImage=find(t,'/ImaDoc/Heading/ImageName');
-    Heading.Campaign=get(t,children(t,uid_Campaign),'value');
-    Heading.Experiment=get(t,children(t,uid_Exp),'value');
-    Heading.Device=get(t,children(t,uid_Device),'value');
-    if ~isempty(uid_Record)
-        Heading.Record=get(t,children(t,uid_Record),'value');
-    end
-    Heading.ImageName=get(t,children(t,uid_FirstImage),'value');
-    FirstImage=Heading.ImageName;
-    if ~isempty(FirstImage)
-        [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type_ima]=name2display(FirstImage);
-    end
-end
-%Camera   
-uid_Camera=find(t,'/ImaDoc/Camera');
-if isempty(uid_Camera)
-    error=1.2;
-else
-    uid_ImageSize=find(t,'/ImaDoc/Camera/ImageSize');
-    if ~isempty(uid_ImageSize);
-        ImageSize=get(t,children(t,uid_ImageSize),'value');
-        xindex=findstr(ImageSize,'x');
-        if length(xindex)>=2
-            npx=str2num(ImageSize(1:xindex(1)-1));
-            npy=str2num(ImageSize(xindex(1)+1:xindex(2)-1));
-        end
-    end
-    uid_NbSlice=find(t,'/ImaDoc/Camera/NbSlice');
-    if ~isempty(uid_NbSlice)
-        NbSlice=str2num(get(t,children(t,uid_NbSlice),'value'));
-        if isempty(NbSlice),NbSlice=1;end; %default
-    end
-    uid_TimeUnit=find(t,'/ImaDoc/Camera/TimeUnit');
-    if ~isempty(uid_TimeUnit)
-        TimeUnit=get(t,children(t,uid_TimeUnit),'value');
-        if isempty(TimeUnit),TimeUnit='s';end; %default
-    end
-    uid_BurstTiming=find(t,'/ImaDoc/Camera/BurstTiming');
-    if isempty(uid_BurstTiming), error=1.12,return,end;
-    if testime
-        for k=1:length(uid_BurstTiming)
-            Dtj=[];%default
-            NbDtj=1;%default
-            subt=branch(t,uid_BurstTiming(k));%subtree under BurstTiming
-            uid_FrameFrequency=find(subt,'/BurstTiming/FrameFrequency');
-           % if isempty(uid_FrameFrequency), error=1.211,return;
-            if isempty(uid_FrameFrequency),
-                Frequency=1;
-            else
-                Frequency=str2num(get(subt,children(subt,uid_FrameFrequency),'value'));
-            end
-            uid_Dtj=find(subt,'/BurstTiming/Dtj');
-            uid_NbDtj=find(subt,'/BurstTiming/NbDtj');
-            uid_Dti=find(subt,'/BurstTiming/Dti');%new
-            uid_NbDti=find(subt,'/BurstTiming/NbDti');%new
-            if ~isempty(uid_Dtj)
-               Dtj=str2num(get(subt,children(subt,uid_Dtj),'value'));%time intervals in frames
-            end
-            uid_child=children(subt,uid_NbDtj);
-            for ivalue=1:length(uid_child)
-                if isequal(get(subt,uid_child(ivalue),'type'),'chardata')
-                     NbDtj=str2num(get(subt,uid_child(ivalue),'value'));%nbre of intervals Dtj
-               end
-            end
-            if isempty(uid_Dti)|isempty(uid_NbDti)
-               Dti=[]; %default
-            else
-               Dti=str2num(get(subt,children(subt,uid_Dti),'value'));%time intervals in frames
-               uid_child=children(subt,uid_NbDti);
-               for ivalue=1:length(uid_child)
-                  if isequal(get(subt,uid_child(ivalue),'type'),'chardata')
-                     NbDti=str2num(get(subt,uid_child(ivalue),'value'));%nbre of intervals Dti
-                  end
-               end
-            end
-            if ~isempty(Dtj)
-                Dtj=reshape(Dtj'*ones(1,NbDtj),1,length(Dtj)*NbDtj);
-            end
-            Dtj=[0 Dtj];
-            dtunit=Dtj/Frequency;
-            uid_Time=find(subt,'/BurstTiming/Time');
-            if isempty(uid_Time)
-                error=1.212;
-            else
-                nbfield=length(uid_Time);
-               Time=get(subt,children(subt,uid_Time),'value');
-               abstime_read=str2num(char(Time))*ones(1,length(Dtj))+ones(nbfield,1)*cumsum(dtunit);
-               abs_time=[abs_time;abstime_read];
-               if ~isempty(Dti)&size(abs_time,1)==1
-                  abs_time=ones(NbDti+1,1)*abs_time+(Dti/Frequency)*[0:NbDti]'*ones(size(abs_time));
-               end
-            end
-        end
-    end
-end
-% if isempty(abs_time)
-%     abs_time=0;%default
-% end
-%read calibration
-uid_GeometryCalib=find(t,'/ImaDoc/GeometryCalib');
-if ~isempty(uid_GeometryCalib)
-    if length(uid_GeometryCalib)>1
-        errordlg(['More than one GeometryCalib in ' filecivxml])
-        return
-    end
-    subt=branch(t,uid_GeometryCalib);%subtree under GeometryCalib
-    cont=get(subt,1,'contents');
-    if ~isempty(cont)
-        uid_pixcmx=find(subt,'/GeometryCalib/Pxcmx');
-        uid_pixcmy=find(subt,'/GeometryCalib/Pxcmy');
-        if ~isempty(uid_pixcmx) & ~isempty(uid_pixcmy)%NON UTILISE 
-           pixcmx=str2num(get(subt,children(subt,uid_pixcmx),'value'));
-            if isempty(pixcmx),pixcmx=1;end; %default
-            pixcmy=str2num(get(subt,children(subt,uid_pixcmy),'value'));
-            if isempty(pixcmy),pixcmy=1;end; %default
-            tsai.Pxcmx=pixcmx;
-            tsai.Pxcmy=pixcmy;
-        end
-        %default values:
-        tsai.f=1;
-        tsai.dpx=1;
-        tsai.dpy=1;
-        tsai.sx=1;
-        tsai.Cx=0;
-        tsai.Cy=0;
-        tsai.Tz=1;
-        tsai.Tx=0;
-        tsai.Ty=0;
-        tsai.R=[1 0 0; 0 1 0; 0 0 0];
-        tsai.kappa1=0;
-        uid_CoordUnit=find(subt,'/GeometryCalib/CoordUnit');
-        if ~isempty(uid_CoordUnit) 
-            tsai.CoordUnit=get(subt,children(subt,uid_CoordUnit),'value');
-        end
-        uid_focal=find(subt,'/GeometryCalib/focal');
-        uid_dpx_dpy=find(subt,'/GeometryCalib/dpx_dpy');
-        uid_sx=find(subt,'/GeometryCalib/sx');
-        uid_Cx_Cy=find(subt,'/GeometryCalib/Cx_Cy');
-        uid_kappa1=find(subt,'/GeometryCalib/kappa1');
-        uid_Tx_Ty_Tz=find(subt,'/GeometryCalib/Tx_Ty_Tz');
-        uid_R=find(subt,'/GeometryCalib/R');
-        if ~isempty(uid_focal) & ~isempty(uid_dpx_dpy) & ~isempty(uid_Cx_Cy)
-            tsai.f=str2num(get(subt,children(subt,uid_focal),'value'));
-            dpx_dpy=str2num(get(subt,children(subt,uid_dpx_dpy),'value'));
-            tsai.dpx=dpx_dpy(1);
-            tsai.dpy=dpx_dpy(2);
-            if ~isempty(uid_sx)
-               tsai.sx=str2num(get(subt,children(subt,uid_sx),'value')); 
-            end
-            Cx_Cy=str2num(get(subt,children(subt,uid_Cx_Cy),'value'));
-            tsai.Cx=Cx_Cy(1);
-            tsai.Cy=Cx_Cy(2);
-        end
-        if ~isempty(uid_Tx_Ty_Tz) 
-            Tx_Ty_T_char=get(subt,children(subt,uid_Tx_Ty_Tz),'value');
-%             if ~ischar(Tx_Ty_T_char)
-%                 error='multiple values for Tx_Ty_Tz';
-%             else
-                Tx_Ty_Tz=str2num(Tx_Ty_T_char);
-%             end
-            tsai.Tx=Tx_Ty_Tz(1);
-            tsai.Ty=Tx_Ty_Tz(2);
-            tsai.Tz=Tx_Ty_Tz(3);
-        end
-        if ~isempty(uid_R)
-            RR=get(subt,children(subt,uid_R),'value');
-            if length(RR)==3
-                tsai.R=[str2num(RR{1});str2num(RR{2});str2num(RR{3})];
-            end
-        end
-        if ~isempty(uid_kappa1)     
-            tsai.kappa1=str2num(get(subt,children(subt,uid_kappa1),'value'));
-        end
-        %look for laser plane definitions   
-        uid_Angle=find(subt,'/GeometryCalib/PlaneAngle');
-        uid_Pos=find(subt,'/GeometryCalib/PlanePos');
-        if ~isempty(uid_Angle) 
-            tsai.PlaneAngle=str2num(get(subt,children(subt,uid_Angle),'value'));
-        end
-        if ~isempty(uid_Pos)
-            for j=1:length(uid_Pos)
-                tsai.PlanePos(j,:)=str2num(get(subt,children(subt,uid_Pos(j)),'value'));
-            end
-        end
-        GeometryCalib=tsai;
-    end
-end   
-
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m	(revision 20)
+++ /trunk/src/series.m	(revision 30)
@@ -55,5 +55,5 @@
 %--------------------------------------------------------------------------
 function series_OpeningFcn(hObject, eventdata, handles,param)
-
+global nb_builtin
 % Choose default command line output for series
 handles.output = hObject;
@@ -129,13 +129,15 @@
     set(handles.filter2,'Value',param.filter2);
 end
-%set(hObject,'UserData', SeriesData)
 set(hObject,'WindowButtonUpFcn',{@mouse_up_gui,handles}) 
 NomType_Callback(hObject, eventdata, handles)
-%mode_Callback(hObject, eventdata, handles)
 
 %loads the information stored in prefdir to initiate the browser and the list of functions
-menu_str=get(handles.ACTION,'String');%list of functions included in 'series.m'
-menu_str(end)=[];%remove from the list the last option 'more...'
-path_series=which('series');%path of the function 'series'
+menu_str={'check_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
+nb_builtin=numel(menu_str); %number of functions
+ 
+%remove from the list the last option 'more...'
+[path_series,name,ext]=fileparts(which('series'));
+path_series=fullfile(path_series,'/series');%path of the function 'series'
+
 for ilist=1:length(menu_str)
     fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
@@ -151,8 +153,9 @@
              menu_str=[menu_str; {file}];
          end
-         menu_str=[menu_str;{'more...'}];
-         set(handles.ACTION,'String',menu_str)
-    end
-end
+    end
+end
+
+menu_str=[menu_str;{'more...'}];
+set(handles.ACTION,'String',menu_str)
 set(handles.ACTION,'UserData',fct_path)% store the list of path in UserData of ACTION
 
@@ -286,7 +289,5 @@
 function MenuBrowse_insert_Callback(hObject, eventdata, handles)
 
-%hseries=get(handles.browse_root,'parent');
-RootPathCell=get(handles.RootPath,'String');
-% SubDirCell=get(handles.SubDir,'String');  
+RootPathCell=get(handles.RootPath,'String'); 
 RootFileCell=get(handles.RootFile,'String');
 oldfile=''; %default
@@ -392,8 +393,14 @@
 % refresh the GUI data after introduction of a new file series
 function update_file(hObject, eventdata, handles,fileinput,addtest)
-hseries=get(handles.RootPath,'parent');  
+%hseries=get(handles.RootPath,'parent');  
+if ~exist(fileinput,'file')
+    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
+    return
+end
+hseries=handles.figure1;
 % refresh input root name, indices, file extension and nomenclature
 [RootPath,RootFile,field_count,str2,str_a,str_b,FileExt,NomType,SubDir]=name2display(fileinput);
 %check for movie image files
+if ~isempty(FileExt)
 if ~isempty(imformats(FileExt(2:end)))
     imainfo=imfinfo(fileinput);     
@@ -402,4 +409,5 @@
         [RootPath,RootFile]=fileparts(fileinput);
     end
+end
 end
 NcType='none';%default
@@ -486,22 +494,12 @@
 drawnow
 
-% hseries=get(handles.RootFile,'parent');
-% SeriesData=get(hseries,'UserData');%read information set by the browser
-% ext_ima_read=[];
-% field_count=1;%default
-% pxcmx=1;
-% pxcmy=1;
 TimeUnit=''; %default
-% CoordUnit='';%default
 time=[];%default
 GeometryCalib=[];%default
 nb_field=[];%default
 nb_field2=[];%default
-% Heading=[];
-% [PD,Device]=fileparts(RootPathCell{1});
 SeriesData.PathCampaign=get(handles.PathCampaign,'String');
 
 % read timing and total frame number from the current file (movie files) !! may be overrid by xml file
-%icell=length(RootPathCell);
 FileBase=fullfile(RootPath,RootFile);
 
@@ -884,5 +882,6 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 function mode_Callback(hObject, eventdata, handles)
-hseries=get(handles.mode,'parent');
+%hseries=get(handles.mode,'parent');
+hseries=handles.figure1;
 SeriesData=get(hseries,'UserData');
 mode_list=get(handles.mode,'String');
@@ -985,6 +984,6 @@
 %----------------------------------------------------------------
 function find_netcpair_civ(hObject, eventdata, handles,Val)
-hseries=get(handles.list_pair_civ,'parent');
-SeriesData=get(hseries,'UserData'); 
+%hseries=get(handles.list_pair_civ,'parent');
+SeriesData=get(handles.figure1,'UserData'); 
 % NomTypeCell=get(handles.NomType,'String');
 NomTypeCell=SeriesData.NomType;
@@ -1167,5 +1166,5 @@
 SeriesData.displ_num(iview,:)=(displ_num(:,val))';
 SeriesData.ref_time=ref_time;
-set(hseries,'UserData',SeriesData)
+set(handles.figure1,'UserData',SeriesData)
 list_pair_civ_Callback(hObject, eventdata, handles)
 
@@ -1179,6 +1178,6 @@
 Val=get(handles.RootPath,'Value');
 IndexCell=get(handles.NomType,'String');
-hseries=get(handles.list_pair_civ,'parent');
-SeriesData=get(hseries,'UserData');
+%hseries=get(handles.list_pair_civ,'parent');
+SeriesData=get(handles.figure1,'UserData');
 NomType=SeriesData.NomType{Val};
 list_pair=get(handles.list_pair_civ,'String');%get the menu of image pairs
@@ -1241,5 +1240,5 @@
 set(handles.NomType,'String',IndexCell)
 SeriesData.displ_num(Val,:)=displ_num;
-set(hseries,'UserData',SeriesData)
+set(handles.figure1,'UserData',SeriesData)
 % set(handles.NomType,'Value',Val)
 
@@ -1290,6 +1289,6 @@
 %read root name and field type
 set(handles.RUN,'BusyAction','queue');
-hseries=get(handles.RUN,'parent');
-set(0,'CurrentFigure',hseries)
+%hseries=get(handles.RUN,'parent');
+set(0,'CurrentFigure',handles.figure1)
 if isequal(get(handles.GetObject,'Value'),1) 
     Series.GetObject=1;
@@ -1298,5 +1297,5 @@
     Series.GetObject=0;
 end
-SeriesData=get(hseries,'UserData');
+SeriesData=get(handles.figure1,'UserData');
 if isfield(SeriesData,'sethandles')
     if iscell(SeriesData.sethandles)
@@ -1481,11 +1480,19 @@
     end
 end
+% fct_path
+eval(['h_fun=@' action ';'])
+if ~isequal(fct_path,path_series)
+        rmpath(fct_path)% add the prescribed path if not the current one    
+end
+
 Series.Action=action;%name of the processing programme
 set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
 drawnow
 if length(RootPath)>1
-    feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
-else
-    feval(action,num_i1,num_i2,num_j1,num_j2,Series);
+%    feval(action,num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
+    h_fun(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series);
+else
+    h_fun(num_i1,num_i2,num_j1,num_j2,Series);
+%     feval(action,num_i1,num_i2,num_j1,num_j2,Series);
 end
 set(handles.RUN,'BackgroundColor',[1 0 0])
@@ -1518,5 +1525,5 @@
 %----------------------------------------------
 function last_i_Callback(hObject, eventdata, handles)
-    hseries=get(handles.last_i,'parent');
+%     hseries=get(handles.last_i,'parent');
 first_i=str2num(get(handles.first_i,'String'));
 last_i=str2num(get(handles.last_i,'String'));
@@ -1524,5 +1531,5 @@
 set(handles.ref_i,'String', num2str(ref_i))
 ref_i_Callback(hObject, eventdata, handles)
-SeriesData=get(hseries,'UserData');
+SeriesData=get(handles.figure1,'UserData');
 if ~isfield(SeriesData,'Time')
     SeriesData.Time{1}=[];
@@ -1536,5 +1543,5 @@
 %-------------------------------------------------------
 function last_j_Callback(hObject, eventdata, handles)
-    hseries=get(handles.last_i,'parent');
+   % hseries=get(handles.last_i,'parent');
 first_j=str2num(get(handles.first_j,'String'));
 last_j=str2num(get(handles.last_j,'String'));
@@ -1543,5 +1550,5 @@
 
 ref_j_Callback(hObject, eventdata, handles)
-SeriesData=get(hseries,'UserData');
+SeriesData=get(handles.figure1,'UserData');
 if ~isfield(SeriesData,'Time')
     SeriesData.Time{1}=[];
@@ -1557,6 +1564,6 @@
 mode_value=get(handles.mode,'Value');
 mode=mode_list{mode_value};
-hseries=get(handles.ref_i,'parent');
-SeriesData=get(hseries,'UserData');
+%hseries=get(handles.ref_i,'parent');
+SeriesData=get(handles.figure1,'UserData');
 %NomTypeCell=get(handles.NomType,'String');
 NomTypeCell=SeriesData.NomType;
@@ -1578,16 +1585,13 @@
 mode_value=get(handles.mode,'Value');
 mode=mode_list{mode_value};
-hseries=get(handles.ref_i,'parent');
-SeriesData=get(hseries,'UserData');
-%NomTypeCell=get(handles.NomType,'String');
+%hseries=get(handles.ref_i,'parent');
+SeriesData=get(handles.figure1,'UserData');
 NomTypeCell=SeriesData.NomType;
 if ~isempty(NomTypeCell)
-Val=get(handles.NomType,'Value');
-NomType=NomTypeCell{Val};
-% NomType=get(handles.NomType,'String');
+    Val=get(handles.NomType,'Value');
+    NomType=NomTypeCell{Val};
     if isequal(NomType,'_i_j1-j2')|| isequal(NomType,'_i1-i2_j')|| isequal(NomType,'_i1-i2')
         if isequal(mode,'series(Dj)') 
             find_netcpair_civ(hObject, eventdata, handles,Val);% update the menu of pairs depending on the available netcdf files
-%             break
         end
     end
@@ -1597,4 +1601,5 @@
 % --- Executes on selection change in ACTION.
 function ACTION_Callback(hObject, eventdata, handles)
+global nb_builtin
 list_ACTION=get(handles.ACTION,'String');% list menu fields
 index_ACTION=get(handles.ACTION,'Value');% selected string index
@@ -1602,38 +1607,25 @@
 path_series=which('series');%path to series.m
 list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
-nb_builtin=0;
-for ilist=1:length(list_path)
-    if isequal(list_path{ilist},path_series)
-        nb_builtin=nb_builtin+1;
-    else
-        break
-    end
-end
-if nb_builtin==0% the path of series has been changed, reinitialize
-    series_OpeningFcn(hObject, eventdata, handles)
-    return
-end
-
-% add a new function to the menu
+
+% add a new function to the menu if the selected item is 'more...'
 if isequal(ACTION,'more...')
     pathfct=fileparts(path_series);
-    browse_name=fullfile(path_series,'SERIES_FCT');%go to UVMAT/SERIES_FCT by default
-    if length(list_path)>nb_builtin
-        browse_name=list_path{end};% initialize browser with  the path of the last introduced function
-     end 
+%     browse_name=fullfile(path_series,'series');%go to UVMAT/series by default
+%     if length(list_path)>nb_builtin
+%         browse_name=list_path{end};% initialize browser with  the path of the last introduced function
+%      end 
     [FileName, PathName, filterindex] = uigetfile( ...
        {'*.m', ' (*.m)';
         '*.m',  '.m files '; ...
         '*.*', 'All Files (*.*)'}, ...
-        'Pick a file',browse_name);
+        'Pick a file',list_path{end});
     if length(FileName)<2
         return
-    end
-    ext_fct=FileName(end-1:end);
+    end 
+    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
     if ~isequal(ext_fct,'.m')
         msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
         return
     end
-    ACTION=FileName(1:end-2);% ACTION choice updated by the selected item
     
    % insert the choice in the action menu
@@ -1641,5 +1633,5 @@
    index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
    list_path{index_ACTION}=PathName;
-   if length(menu_str)>nb_builtin+5;
+   if length(menu_str)>nb_builtin+5; %nb_builtin=nbre of functions always remaining in the initial menu
        nbremove=length(menu_str)-nb_builtin-5;
        menu_str(nb_builtin+1:end-5)=[];
@@ -1675,12 +1667,12 @@
 %check the current path to the selected function
 PathName=list_path{index_ACTION};%current recorded path
-if ~isequal(path_series,PathName)
-    CurrentPath=fileparts(which(ACTION));
-    if ~isequal(CurrentPath,PathName)&&~isequal(CurrentPath,fullfile(PathName,'private'))
-        addpath(PathName) 
-        errormsg=check_functions;
-        msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
-    end
-end
+% if ~isequal(path_series,PathName)
+%     CurrentPath=fileparts(which(ACTION));
+%     if ~isequal(CurrentPath,PathName)
+%         addpath(PathName) 
+%         errormsg=check_functions;
+%         msgbox_uvmat('CONFIRMATION',[['path ' PathName ' added to the current Matlab pathes'];errormsg])
+%     end
+% end
 set(handles.path,'String',PathName); %show the path to the senlected function
 
@@ -1719,5 +1711,14 @@
 %set the displayed GUI item needed for input parameters
 %list_input=feval(ACTION);% input list asked by the selected function
-varargout=feval(ACTION);% input list asked by the selected function
+if ~isequal(path_series,PathName)
+    addpath(PathName)
+end
+eval(['h_function=@' ACTION ';']);
+if ~isequal(path_series,PathName)
+    rmpath(PathName)
+end
+
+varargout=h_function();
+%varargout=feval(ACTION);% input list asked by the selected function
 Param_list={};
 % RootPath=get(handles.RootPath,'String');
@@ -1851,6 +1852,6 @@
          delete(hget_field)%delete opened versions of get_field
      end
-     hseries=get(handles.FieldMenu,'parent');
-     SeriesData=get(hseries,'UserData');
+     %hseries=get(handles.FieldMenu,'parent');
+     SeriesData=get(handles.figure1,'UserData');
      filename=SeriesData.CurrentInputFile;
      if exist(filename,'file')
@@ -1879,6 +1880,6 @@
          delete(hget_field)
      end
-     hseries=get(handles.FieldMenu,'parent');
-     SeriesData=get(hseries,'UserData');
+     %hseries=get(handles.FieldMenu,'parent');
+     SeriesData=get(handles.figure1,'UserData');
      filename=SeriesData.CurrentInputFile_1;
      if exist(filename,'file')
@@ -1897,1508 +1898,74 @@
 
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %detect the chosen series of files and check their date of modification:
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%INPUT: 
-%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
-%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
-%OTHER INPUTS given by the structure Series
-function GUI_input=check_files(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
-
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-if ~exist('num_i1_cell','var')
-    GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
-        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
-        'RootFile';'on';... %root input file name ('on' by default)
-        'FileExt';'on';... %input file extension ('on' by default)
-        'NomType';'on';...%type of file indexing ('on' by default)
-        'NbSlice';'on'; ...%nbre of slices ('off' by default)
-        %'VelTypeMenu';'on';...% menu for selecting the velocity type (civ1,..) 'off' by default)
-        %'FieldMenu';'on';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-        %'CoordType';'on'...%can use a transform function 'off' by default
-        %'GetObject';'on'...%can use projection object ,'off' by default
-        %'GetMask';'on'...%can use mask option   ,'off' by default
-        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
-               ''};
-    return %exit the function 
-end
-
-%standard parameters for waitbar and STOP action (do not modify)
-hseries=guidata(Series.hseries);%handles of the GUI series
-WaitbarPos=get(hseries.waitbar_frame,'Position');
-
-%%%%%%%%%%%%%%%%%%%%%%%%
-
-% number of slices
-NbSlice=str2num(get(hseries.NbSlice,'String'));
-if isempty(NbSlice)
-    NbSlice=1;
-end
-NbSlice_name=num2str(NbSlice);
-if isequal(NbSlice,[]),NbSlice=1; end; %default
-
-% number of views
-count=0; 
-testcell=iscell(Series.RootFile);
-if ~testcell
-    Series.RootPath={Series.RootPath};
-    Series.RootFile={Series.RootFile};
-    Series.SubDir={Series.SubDir};
-    Series.FileExt={Series.FileExt};
-    Series.NomType={Series.NomType};
-end    
-nbview=length(Series.RootFile);
-for iview=1:nbview
-    filebase=fullfile(Series.RootPath{iview},Series.RootFile{iview});%root file name
-    if testcell
-        num_i1=num_i1_cell{iview}; num_i2=num_i2_cell{iview}; num_j1=num_j1_cell{iview}; num_j2=num_j2_cell{iview};
-    else
-        num_i1=num_i1_cell; num_i2=num_i2_cell; num_j1=num_j1_cell; num_j2=num_j2_cell;
-    end
-    siz=size(num_i1);
-    nbfield2=siz(1); %nb of consecutive fields at each level(burst
-    nbfield=siz(1)*siz(2);
-    nbfield=floor(nbfield/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
-    if isequal(lower(Series.FileExt{iview}),'.avi')
-        info=aviinfo([filebase Series.FileExt{iview}]);
-        message{1}=info.Filename;
-        message{2}=info.FileModDate;
-        message{3}=[num2str(info.FramesPerSecond) ' frames/s '];
-        message{4}=info.ImageType;
-        message{5}=['  compression' info.VideoCompression];
-        message{6}=[ 'quality ' num2str(info.Quality)];   
-        Tabchar=message;
-    else
-        datnum=[];
-        Tabchar={};
-        %LOOP ON SLICES
-        for i_slice=1:NbSlice
-            for ifield=1:nbfield
-                indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
-            end 
-            for index=1:nbfield*nbfield2
-                stopstate=get(hseries.RUN,'BusyAction');
-                if isequal(stopstate,'queue')% enable STOP command
-                    update_waitbar(hseries.waitbar,WaitbarPos,index/(nbfield*nbfield2))
-                    ifile=indselect(index);               
-                    file=...
-                       name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2(ifile),num_j2(ifile),Series.SubDir{iview});                
-                    [Path,Name,ext]=fileparts(file);
-                    detect=exist(file,'file'); % check the existence of the file
-                    if detect==0
-                        count=count+1;
-                        lastfield='not found';
-                    else
-                        datfile=dir(file);
-                        datnum(ifile)=datenum(datfile.date);
-                        filefound(ifile)={datfile.name};
-                        lastfield='';
-                        if isequal(Series.FileExt{iview},'.nc') || isequal(Series.FileExt{iview},'.cdf')
-                            % check the content  netcdf file
-                            Data=nc2struct(file,'ListGlobalAttribute','patch2','fix2','civ2','patch','fix','absolut_time_T0','hart');
-                            if ~isempty(Data.patch2) && isequal(Data.patch2,1) 
-                                lastfield='patch2';
-                            elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
-                                lastfield='fix2';
-                            elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
-                                lastfield='civ2';
-                            elseif ~isempty(Data.patch) && isequal(Data.patch,1);
-                                lastfield='patch1';
-                            elseif ~isempty(Data.fix) && isequal(Data.fix,1);
-                                lastfield='fix1';
-                            elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
-                                lastfield='civ1'; 
-                            end                          
-                        end 
-                    end
-                    Tabchar(1,i_slice)={['slice #' num2str(i_slice)]};
-                    Tabchar(index+1,i_slice)={[file '   ' lastfield]};
-                end
-            end
-        end
-        if isempty(datnum)
-            if NbSlice>1
-                message=['no set of ' num2str(NbSlice) ' (NbSlices) files found'];
-            else
-                 message='no file found';
-            end
-        else
-            datnum=datnum(find(datnum));%keep the non zero values corresponding to existing files
-            [first,ind]=min(datnum);
-            [last,indlast]=max(datnum);
-            message={['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
-                ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
-        end 
-        if ~isempty(Tabchar)
-          Tabchar=reshape(Tabchar,NbSlice*(nbfield*nbfield2+1),1);
-        end
-    end
-    hfig=figure(iview);
-    clf
-    if iview>1
-        pos=get(iview-1,'Position');
-        pos(1)=pos(1)+(iview-1)*pos(1)/nbview;
-        set(hfig,'Position',pos)
-    end
-    set(hfig,'name',['view= ' num2str(iview)])
-   
-    h=uicontrol('Style','listbox', 'Position', [20 20 500 300], 'String', Tabchar, 'Callback', @ncbrowser_uvmat);
-    hh=uicontrol('Style','listbox', 'Position', [20 340 500 40], 'String', message);
-end
-%----------------------------------------------------
-%  determine the list of index pairs of processing file 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
-num_i1=num_i;% set of first image numbers by default
-num_i2=num_i;
-num_j1=num_j;
-num_j2=num_j;
-num_i_out=num_i;
-num_j_out=num_j;
-if isequal (NomType,'_i1-i2_j') |isequal (NomType,'_i1-i2')
-    num_i1_line=num_i+ind_shift(3);% set of first image numbers
-    num_i2_line=num_i+ind_shift(4);
-    % adjust the first and last field number
-        indsel=find(num_i1_line >= 1);
-    num_i_out=num_i(indsel);
-    num_i1_line=num_i1_line(indsel);
-    num_i2_line=num_i2_line(indsel);
-    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
-    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
-    [xx,num_i1]=meshgrid(num_j,num_i1_line);
-    [xx,num_i2]=meshgrid(num_j,num_i2_line);
-elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
-    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
-        num_j1=ind_shift(1)*ones(size(num_i));
-        num_j2=ind_shift(2)*ones(size(num_i));
-    else
-        num_j1_col=num_j+ind_shift(1);% set of first image numbers
-        num_j2_col=num_j+ind_shift(2);
-        % adjust the first field number
-        indsel=find((num_j1_col >= 1));   
-        num_j_out=num_j(indsel);
-        num_j1_col=num_j1_col(indsel);
-        num_j2_col=num_j2_col(indsel);
-        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
-        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
-    end    
-end
-
-
-%----------------------------------------------------------------------
-% --- make average on a series of files
-%----------------------------------------------------------------------
-%INPUT: 
-%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
-%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
-%OTHER INPUTS given by the structure Series
-%  Series.Time: 
-%  Series.GeometryCalib: 
-function GUI_input=aver_stat(num_i1,num_i2,num_j1,num_j2,Series)
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-if ~exist('num_i1','var')
-    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
-        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
-        'RootFile';'on';... %root input file name ('on' by default)
-        'FileExt';'on';... %input file extension ('on' by default)
-        'NomType';'on';...%type of file indexing ('on' by default)
-        'NbSlice';'on'; ...%nbre of slices ('off' by default)
-        'VelTypeMenu';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
-        'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-        'CoordType'; 'on';...%can use a transform function
-        'GetObject';'on';...%can use projection object(option 'off'/'one'/'two',
-        %'GetMask';'on'...%can use mask option   
-        %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter 
-               ''};
-        return
-end
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-hseries=guidata(Series.hseries);%handles of the GUI series
-WaitbarPos=get(hseries.waitbar_frame,'Position');
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%root input file and type
-if ~iscell(Series.RootPath)% case of a single input field series
-    num_i1={num_i1};num_j1={num_j1};num_i2={num_i2};num_j2={num_j2};
-    RootPath={Series.RootPath};
-    RootFile={Series.RootFile};
-    SubDir={Series.SubDir};
-    FileExt={Series.FileExt};
-    NomType={Series.NomType};
-else
-    RootPath=Series.RootPath;
-    RootFile=Series.RootFile;
-    SubDir=Series.SubDir;
-    NomType=Series.NomType;
-    FileExt=Series.FileExt;
-end   
-ext=FileExt{1};
-form=imformats(ext([2:end]));%test valid Matlab image formats
-testima=0;
-if ~isempty(form)||isequal(lower(ext),'.avi')||isequal(lower(ext),'.vol')
-    testima(1)=1;
-end
-if length(FileExt)>=2
-    ext_1=FileExt{2};
-    form=imformats(ext_1([2:end]));%test valid Matlab image formats
-    if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol')
-        testima(2)=1;
-    end
-    if testima(2)~=testima(1)
-        msgbox_uvmat('ERROR','images and netcdf files cannot be compared')
-        return
-    end
-end
-
-%Number of input series: this function  accepts two input file series at most (then it operates on the difference of fields)
-nbview=length(RootPath);
-if nbview>2  
-    RootPath=RootPath(1:2);
-    set(hseries.RootPath,'String',RootPath)
-    SubDir=SubDir(1:2);
-    set(hseries.SubDir,'String',SubDir)
-    RootFile=RootFile(1:2);
-    set(hseries.RootFile,'String',RootFile)
-    NomType=NomType(1:2);
-    FileExt=FileExt(1:2);
-    set(hseries.FileExt,'String',FileExt)
-    nbview=2;
-end
-hhh=which('mmreader');
-for iview=1:nbview
-    test_movie(iview)=0;
-    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
-        if isequal(lower(FileExt{iview}),'.avi')
-            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
-            test_movie(iview)=1;
-        end
-    end 
-end
-
-% number of slices
-NbSlice=str2num(get(hseries.NbSlice,'String'));
-if isempty(NbSlice)
-    NbSlice=1;
-end
-NbSlice_name=num2str(NbSlice);
-
-% Field and velocity type (the same for the two views)
-Field_str=get(hseries.FieldMenu,'String');
-FieldName=[]; %default
-testfield=get(hseries.FieldMenu,'Visible');
-if isequal(testfield,'on')
-    val=get(hseries.FieldMenu,'Value');
-    FieldName=Field_str(val);%the same set of fields for all views
-    if isequal(FieldName,{'get_field...'})
-        hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
-        if length(hget_field)>1
-            delete(hget_field(2:end))
-        elseif isempty(hget_field)
-           filename=...
-                 name_generator(fullfile(RootPath{1},RootFile{1}),num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 
-           get_field(filename);
-           return
-        end
-        %hhget_field=guidata(hget_field);%handles of GUI elements in get_field
-        SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
-    end
-end
-%detect whether the two files are 'images' or 'netcdf'
-testima=0;
-testvol=0;
-testcivx=0;
-testnc=0;
-FileExt=get(hseries.FileExt,'String');
-% test_movie=0;
-for iview=1:nbview
-     ext=FileExt{iview};
-     form=imformats(ext([2:end]));
-     if isequal(lower(ext),'.vol')
-         testvol=testvol+1;
-     elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
-         testima=testima+1;
-     elseif isequal(ext,'.nc')
-         testnc=testnc+1;
-     end
-end
-if testvol
-    msgbox_uvmat('ERROR','volume images not implemented yet')
-    return
-end
-if testnc~=nbview && testima~=nbview && testvol~=nbview
-    msgbox_uvmat('ERROR','compare two image series or two netcdf files with the same fields as input')
-    return
-end
-if ~isequal(FieldName,{'get_field...'})
-    testcivx=testnc;
-end
-
-if testcivx
-    VelType_str=get(hseries.VelTypeMenu,'String');
-    VelType_val=get(hseries.VelTypeMenu,'Value');
-    VelType{1}=VelType_str{VelType_val};
-    if nbview==2
-        VelType_str=get(hseries.VelTypeMenu_1,'String');
-        VelType_val=get(hseries.VelTypeMenu_1,'Value');
-        VelType{2}=VelType_str{VelType_val};
-    end
-end
-
-%Calibration data and timing: read the ImaDoc files
-mode=''; %default
-timecell={};
-itime=0;
-NbSlice_calib={};
-for iview=1:nbview%Loop on views
-    XmlData{iview}=[];%default
-    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
-    if exist([filebase{iview} '.xml'],'file')
-        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
-        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
-        end 
-    elseif exist([filebase{iview} '.civ'],'file')
-        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
-        itime=itime+1;
-        timecell{itime}=time;
-        XmlData{iview}.Time=time;
-        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
-        GeometryCalib.Tx=0;
-        GeometryCalib.Ty=0;
-        GeometryCalib.Tz=1;
-        GeometryCalib.dpx=1;
-        GeometryCalib.dpy=1;
-        GeometryCalib.sx=1;
-        GeometryCalib.Cx=0;
-        GeometryCalib.Cy=0;
-        GeometryCalib.f=1;
-        GeometryCalib.kappa1=0;
-        GeometryCalib.CoordUnit='cm';
-        XmlData{iview}.GeometryCalib=GeometryCalib;
-        if error==1
-            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
-        end
-    end
-end
-
-%check coincidence in time
-multitime=0;
-if length(timecell)==0
-    time=[];
-elseif length(timecell)==1
-    time=timecell{1};
-elseif length(timecell)>1
-    multitime=1;
-    for icell=1:length(timecell)
-        if ~isequal(size(timecell{icell}),size(timecell{1}))
-            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
-            time=timecell{1};
-            multitime=0;
-            break
-        end
-    end
-end
-if multitime
-    for icell=1:length(timecell)
-        time(icell,:,:)=timecell{icell};
-    end
-    diff_time=max(max(diff(time)));
-    if diff_time>0
-        msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
-    end   
-end
-if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 
-    time=[];
-end
-
-% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
-filebasesub=fullfile(RootPath{1},SubDir{1},RootFile{1});
-if isempty(SubDir{1}) % create a subdirectory '/mean'
-    subdir_result='mean';
-%     filebasemean=fullfile(RootPath{1},subdir_result);
-    if ~exist(fullfile(RootPath{1},subdir_result),'dir')
-        dircur=pwd; %record current working directory
-        cd(RootPath{1})% goes to the iamge directory
-        [m1,m2,m3]=mkdir(subdir_result);
-        if ~isequal(m2,'')
-             msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
-        end
-        cd(dircur) %back to the initial working directory
-    end
-    filebase_out=filebase{1}; 
-else
-   subdir_result=SubDir{1};
-   filebase_out=[filebase{1} '_mean'];% output root name obtained by adding the suffix _mean to the input
-end
-%output nomtype (to generalise)
-NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
-    
-if NbSlice==1  
-    filebase_out=[filebasesub '_mean'];
-else
-    filebase_out=[filebasesub '_' NbSlice_name 'mean'];
-    answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
-    if ~isequal(answeryes,'Yes')
-        return
-    end
-end
-
-% coordinate transform or other user defined transform
-Coord_menu=get(hseries.CoordType,'String');
-menu_val=get(hseries.CoordType,'Value');
-usrfct=Coord_menu{menu_val};
-testfct=~isequal(usrfct,'');
-
-%slice loop
-siz=size(num_i1{1});
-lengthtot=siz(1)*siz(2);
-nbfield=floor(lengthtot/(siz(1)*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
-nbfield_slice=nbfield*siz(1);% number of fields per slice
-
-for i_slice=1:NbSlice
-   S=0; %initiate the image sum S 
-   nbfiles=0;
-   nbmissing=0;
-    %averaging loop
-   for ifile=i_slice:NbSlice:lengthtot
-        stopstate=get(hseries.RUN,'BusyAction');
-        if isequal(stopstate,'queue') % enable STOP command
-             update_waitbar(hseries.waitbar,WaitbarPos,ifile/lengthtot)
-             for iview=1:nbview
-                [filename]=...
-                           name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
-                if testima
-                    Data{iview}.ListVarName={'A'};
-                    Data{iview}.AName='image';
-                    if test_movie(iview)
-                        Data{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
-                    else
-                        Data{iview}.A=read_image(filename,NomType{iview},num_i1{iview}(ifile));% read the image, num2 is the counter for avi files 
-                    end
-                    Atype{iview}=class(Data{iview}.A);
-                    Data{iview}.A=double(Data{iview}.A);
-                elseif testcivx
-                    [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
-                else
-                    [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data                
-                    Data{iview}.VarAttribute=SubField.VarAttribute;
-                end 
-                if isfield(Data{iview},'Txt')
-                    msgbox_uvmat('ERROR',['error of input reading: ' Data{iview}.Txt])
-                    return
-                end
-             end   
-             % coordinate transform (or other user defined transform)
-             if ~isequal(Series.CoordType,'')
-                 % z index
-                if ~isempty(NbSlice_calib)
-                    Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform
-                end
-                if nbview==2
-                    [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
-                    if isempty(Data{2})
-                        Data(2)=[];
-                    end
-                else
-                    Data{1}=feval(Series.CoordType,Data{1},XmlData);
-                end
-             end     
-            if testcivx
-                    Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
-            end
-            if length(Data)==2
-                [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
-                if ~isempty(errormsg)
-                    msgbox_uvmat('ERROR',['error in aver_stat/sub_field:' errormsg])
-                    return
-                end
-            else
-                Field=Data{1};
-            end
-            if isfield(Series,'ProjObject')
-                [Field,errormsg]=proj_field(Field,Series.ProjObject);
-                 if ~isempty(errormsg)
-                    msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg])
-                    return
-                end
-             end                                                        
-                nbfiles=nbfiles+1;
-                if nbfiles==1 %first field
-                    time_1=[];
-                    if isfield(Field,'Time')
-                        time_1=Field.Time(1);
-                    end
-                    DataMean=Field;%default
-                else
-                    for ivar=1:length(Field.ListVarName)
-                        VarName=Field.ListVarName{ivar};
-                        eval(['sizmean=size(DataMean.' VarName ');']);
-                        eval(['siz=size(Field.' VarName ');']);
-                        if ~isequal(siz,sizmean)
-                            warndlg_uvmat(['unequal size of input field ' VarName ', need to interpolate on a grid'],'WARNING') 
-                            nbmissing=nbmissing+1;
-                            break
-                        else
-                            eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum 
-                        end
-                    end
-                end
-%             else
-%                 nbmissing=nbmissing+1;
+% %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
+% %%%%%%%%%%%%%%%%%%%%%%% Function independante maintenant
+% %-----------------------------------------------------------------
+% [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1});
+% %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
+% % CellVarIndex=cells of variable index arrays
+% ivar_new=0; % index of the current variable in the projected field
+% icoord=0;
+% for icell=1:length(CellVarIndex)
+%     if NbDim(icell)==1
+%         continue
+%     end
+%     VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
+%     VarType=VarTypeCell{icell};
+%     ivar_X=VarType.coord_x;
+%     ivar_Y=VarType.coord_y;
+%     ivar_FF=VarType.errorflag;
+%     if isempty(ivar_X)
+%         test_grid=1;%test for input data on regular grid (e.g. image)coordinates
+%     else
+%         if length(ivar_Y)~=1
+%                 warndlg_uvmat('y coordinate missing in proj_field.m','ERROR')
+%                 return
+%         end
+%         test_grid=0;
+%     end
+% %    DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
+%     %case of input fields with unstructured coordinates
+%     if ~test_grid
+%         for ivar=VarIndex
+%             VarName=MergeData.ListVarName{ivar};
+%             for iview=1:nbview
+%                 eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName ';'])
 %             end
-        end
-    end %end averaging loop
-    for ivar=1:length(Field.ListVarName)
-        VarName=Field.ListVarName{ivar};
-        eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean
-    end
-    if nbmissing~=0
-        msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
-    end
-    if isempty(time) % time read from files  prevails
-        time_end=[];
-        if isfield(Field,'Time')
-            time_end=Field.Time(1);%last time read
-            if ~isempty(time_1)
-                DataMean.Time=time_1;
-                DataMean.Time_end=time_end;
-            end
-        end
-    else  % time from ImaDoc prevails
-        DataMean.Time=time(1,num_i1{1}(1),num_j1{1}(1));
-        DataMean.Time_end=time(end,num_i1{end}(end),num_j1{end}(end));
-    end
-    
-    %writing the result file
-   if testima   
-       if NbSlice==1
-        [filemean]=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.png',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end));
-       else % label the file number by the slice # for simplicity
-          [filemean]=name_generator(filebase_out,i_slice,1,'.png','_i');
-       end
-        if exist(filemean,'file')
-            backupfile=filemean;
-            testexist=2;
-            while testexist==2
-                backupfile=[backupfile(1:end-4) '~.png'];
-                testexist=exist(backupfile,'file');
-            end
-            [success,message]=copyfile(filemean,backupfile);%make backup
-            if ~isequal(success,1)
-                msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])
-                return
-            end
-        end
-        if isequal(Atype{1},'uint16')
-            imwrite(uint16(DataMean.A),filemean,'BitDepth',16);
-        else
-            imwrite(uint8(DataMean.A),filemean,'BitDepth',8);
-        end
-        display([filemean ' written']);
-    else %determine global attributes
-        DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Series.Action}];
-        ActionKey='Action';
-        while isfield(DataMean,ActionKey)
-            ActionKey=[ActionKey '_1'];
-        end
-        eval(['DataMean.' ActionKey '=Series.Action;'])
-        DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {ActionKey}];
-        if isfield(DataMean,'Time')
-            DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {'Time','Time_end'}];
-        end  
-        if NbSlice==1
-          filemean=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.nc',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end));
-        else % label the file number by the slice # for simplicity
-          [filemean]=name_generator(filebase_out,i_slice,1,'.nc','_i');
-        end
-        if exist(filemean,'file')
-            backupfile=filemean;
-            testexist=2;
-            while testexist==2
-                backupfile=[backupfile(1:end-3) '~.nc'];
-                testexist=exist(backupfile,'file');
-            end
-            [success,message]=copyfile(filemean,backupfile);%make backup
-            if ~isequal(success,1)
-                msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])
-                display(['previous file result ' filemean ' already exists, problem in backup'])
-                return
-            end
-        end
-        errormsg=struct2nc(filemean,DataMean); %save result file
-        if isempty(errormsg)
-            display([filemean ' written']);
-        else
-            msgbox_uvmat('ERROR',['error in writting result file: ' errormsg])
-            display(errormsg)
-        end
-   end
-end
-hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
-delete(hget_field)
-'TEST'
-uvmat(filemean)
-
-
-% %----------------------------------------------------------------------
-% % --makes a time averaged velocity field 
-% %----------------------------------------------------------------------
-% function aver_vel(num_i1,num_i2,num_j1,num_j2,Series)
-%                           %handles of the GUI series
-%   
-% hseries=guidata(Series.hseries);%handles of the GUI series
-% WaitbarPos=get(hseries.waitbar_frame,'Position');
-% Field_list=get(hseries.FieldMenu,'String');
-% val=get(hseries.FieldMenu,'Value');
-% FieldName=Field_list{val(1)};
-% set(hseries.FieldMenu,'Value',val(1))% select only one input field
-% if isequal(FieldName,'get_field...')
-%     hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
-% end
-% %root input file and type
-% RootPath=get(hseries.RootPath,'String');
-% SubDir=get(hseries.SubDir,'String');
-% RootFile=get(hseries.RootFile,'String');
-% %NomType=get(hseries.NomType,'String');
-% NomType=Series.NomType;
-% FileExt=get(hseries.FileExt,'String');
-% ext=FileExt{1};     
-% VelType_str=get(hseries.VelTypeMenu,'String');
-% VelType_val=get(hseries.VelTypeMenu,'Value');
-% VelType{1}=VelType_str{VelType_val};
-% 
-% time=0; %default
-% % number of slices
-% NbSlice=str2num(get(hseries.NbSlice,'String'));
-% if isempty(NbSlice)
-%     NbSlice=1;
-% end
-% NbSlice_name=num2str(NbSlice);
-% filebase=fullfile(RootPath{1},RootFile{1});
-% Calib=[];
-% if exist([filebase '.xml'],'file')
-%     %[error,Heading,nom_type_read,ext_ima_read,time_imadoc,TimeUnit,mode,NbSlice,npx,npy,Calib]=read_imadoc([filebase '.xml']);
-%     [XmlData,warntext]=imadoc2struct([filebase '.xml']);
-% end
-% if NbSlice==1
-%    filebase_mean=[filebase '_mean']; %root name for the result
-% else
-%    filebase_mean=[filebase '_' NbSlice_name 'mean']; %root name for the results
-%    answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_mean ' ...']});
-%     if ~isequal(answeryes,'Yes')
-%     return
+%         end
+%     %case of fields defined on a structured  grid 
+%     else  
+% %        DimValue=MergeData.DimValue(DimIndices);%set of dimension values
+%         testFF=0;
+%         for iview=2:nbview
+% %             if ~isequal(DimValue,Data{iview}.DimValue(DimIndices))
+% %                 MergeData.Txt='ERROR: attempt at merging structured fields with different sizes';
+% %                 return
+% %             end
+%             for ivar=VarIndex
+%                 VarName=MergeData.ListVarName{ivar};
+%                 if isfield(MergeData,'VarAttribute')
+%                     if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
+%                         testFF=1;
+%                     end
+%                 end
+%                 eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';'])
+%             end
+%         end
+%         if testFF
+%             nbaver=nbview-MergeData.FF;
+%             indgood=find(nbaver>0);
+%             for ivar=VarIndex
+%                 VarName=MergeData.ListVarName{ivar};
+%                 eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);'])
+%             end 
+%         else
+%             for ivar=VarIndex
+%                 VarName=MergeData.ListVarName{ivar};
+%                 eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;'])
+%             end    
+%         end
 %     end
 % end
-% siz=size(num_i1);
-% nbfield2=siz(1); %nb of consecutive fields at each level(burst)
-% lengthtot=siz(1)*siz(2);
-% nbfield=floor(lengthtot/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
-% nbfield_slice=nbfield*nbfield2;% number of fields per slice
-% %projection object
-% GridX=[];
-% GridY=[];
-% if isfield(Series,'sethandles')
-%         Series.ProjObject=read_set_object(Series.sethandles);
-%         if isfield(Series.ProjObject,'Style')
-%             answeryes=questdlg({['statistics on field series projected on ' Series.ProjObject.Style]});
-%             if ~isequal(answeryes,'Yes')
-%                 return
-%             end
-%         end
-% end
-% 
-% %LOOP ON SLICES
-% for i_slice=1:NbSlice
-%     %select the series of image indices at the level islice
-%     for ifield=1:nbfield
-%         indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
-%     end  
-%     %name of result file
-%     [filemean,idetect]=...
-%                name_generator(filebase_mean,num_i1(i_slice),num_j1(1),Series.FileExt{1},'_i1-i2_j1-j2',1,num_i2(i_slice+nbfield_slice*NbSlice-1),num_j2(end),Series.SubDir{1});
-% 
-%     % field=get(handles.civ1,'UserData');%read current selected field type (civ1,civ2...)
-%     itime=0;
-%      dt=[];
-%      %LOOP ON FIELDS IN  A SLICE
-%      test_interpolate=0;%default
-%     for index=1:nbfield*nbfield2
-%             ifile=indselect(index);
-%         stopstate=get(hseries.RUN,'BusyAction');
-%         if isequal(stopstate,'queue')% enable STOP command
-%             update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield*nbfield2))
-%             %name of the current file
-%             [filename,idetect]=name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{1},Series.NomType{1},1,num_i2(ifile),num_j2(ifile),Series.SubDir{1});
-%             %read input file
-%             itime=itime+1;
-%             if isequal(FieldName,'get_field...')
-%                 hhget_field=guidata(hget_field);%handles of GUI elements in get_field
-%                 hObject=0;
-%                 eventdata=0;
-%                 SubField=get_field('read_var_names',hObject,eventdata,hhget_field); %read the names of the variables to plot in the get_field GUI 
-%                 [Data,var_detect]=nc2struct(filename,SubField.ListVarName); %read input data   
-%                 time(itime)=itime;
-%                 dt=1; 
-%                 Calib_read=[];
-%             else
-%                 [nb_coord,nb_dim,Civ,CivStage,timeread,Data,VelTypeOut,Calib_read]=read_ncfield(filename,VelType{1});%reading the first file
-%                  time(itime)=timeread;
-%                 if isequal(Civ,1)
-%                     Data.CoordType='px';%test for pixel coordinates
-%                     if isequal(itime,1)
-%                         dt=Data.dt;
-%                     elseif ~isequal(Data.dt,dt)
-%                         warndlg_uvmat('series with non constant dt, need phys coordinates','ERROR')
-%                         return
-%                     end
-%                 end 
-%             end
-%             %increment the detected fields, skip the others
-%             if idetect==0
-%                 warndlg_uvmat(['input file ' filename ' not found'],'ERROR')
-%                 %A FAIRE STOCKER LE RESULT ACTUEL S'IL EXISTE
-%             end
-% %             itime=itime+1;
-% %             time(itime)=timeread;
-%        
-%             %coordinate transform
-%             if isempty(Calib)
-%                 Calib=Calib_read;%use Calib from xml file in priority, then Calib from the current file
-%             end
-%             if ~isequal(Series.CoordType,'')
-%                 Data=feval(Series.CoordType,Data,Calib);
-%             end
-%             %projection on object if defined
-%             if isfield(Series,'ProjObject');
-%                 Data=proj_field(Data,Series.ProjObject);
-%                 if isequal(itime,1)%use the positions on the first field for the whole series, ou utiliser grille
-%                     if isfield(Data,'Txt')%display error message
-%                         warndlg(Data.Txt,'ERROR')
-%                         return
-%                     end
-%                 end
-%             else%remove false vectors and interpolate on the positions of the first field
-%                 Data=document_field(Data);
-%                 Data.Style='plane';
-%             end 
-%     %%%%%%%%% initiate the average at the first iteration: check list and structure of variables
-%             if ifile==i_slice%first field in the slice
-%                 testfalse=0;
-%                 ListIndex={};
-%                 testnewcell=1;
-%                 %group the variables (fields of 'Data') in cells of variables with the same dimensions
-%                 [DimVarIndex,CellVarIndex]=find_field_indices(Data);
-%                 VarIndex=CellVarIndex{1}; % ONLY THE FIRST VAR GROUP IS AVERAGED
-%                 DimIndex=Data.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)         
-%                 MeanData=Data;%transfer heading
-%                 MeanData.Time=[time(1) time(end)];
-%                 MeanData.Action=Series.Action;%name of the processing programme
-%                 MeanData.ListDimName=Data.ListDimName(DimIndex);%name of dimension 
-%                 MeanData.DimValue=Data.DimValue(DimIndex);%values of dimension (nbre of vectors)
-%                 MeanData.ListVarName=Data.ListVarName;
-%                 MeanData.VarDimIndex=Data.VarDimIndex;
-%                 MeanData.ListVarAttribute={'Role'};%list of variable attribute names A FAIRE: transferer les autres attributs
-%                 testsum=ones(size(VarIndex));
-%                 indexfalse=0;
-%                 CoordName={};
-%                 indexremove=[];
-%                 if isfield(Data,'Role') % look for coordinate and flag variables    
-%                     for ivar=1:length(VarIndex)
-%                         VarName=Data.ListVarName{VarIndex(ivar)};
-%                         var_role=Data.Role{VarIndex(ivar)};%'role' of the variable
-%                         MeanData.Role{ivar}=var_role; 
-%                         if isequal(var_role,'falseflag')
-%                             indexfalse=ivar; %test for false flag 
-%                             indexremove=ivar;
-%                             FFName=VarName;
-%                             testsum(ivar)=0;
-%                             eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable                      
-%                         end
-%                         if isequal(var_role,'warnflag')                        
-%                             testsum(ivar)=0; %do not sum warn flag 
-%                             eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
-%                             indexremove=[indexremove ivar];
-%                         end                  
-%                         if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|isequal(var_role,'coord_z')
-%                             eval(['MeanData.' VarName '=Data.' VarName ';']);
-%                             testsum(ivar)=0;
-%                             eval(['CoordName=[CoordName ''' VarName '''];']);
-%                         end
-%                         if testsum(ivar)~=0
-%                            eval(['MeanData.' VarName '=zeros(size(Data.' VarName '));']);%initialise sum
-%                         end
-%                     end
-%                 end
-%                 findsum=find(testsum);
-%                 VarIndexSum=VarIndex(findsum);%indices of variables to sum (not coordinates nor flags)
-%                 if length(CoordName)==0 
-%                     if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates, prepare histograms
-%                          for ilist=1:length(VarIndexSum)
-%                             VarName=Data.ListVarName{VarIndexSum(ilist)};
-%                             eval(['MeanData=rmfield(MeanData,''' VarName ''');']);%remove variable
-%                             indexremove=[indexremove ilist];
-%                             eval(['[MeanData.' VarName 'hist,MeanData.' VarName 'val]=hist(Data.' VarName ',100);']);%make histo
-%                             eval(['sizhist=size(MeanData.' VarName 'hist);'])
-%                             if sizhist(1)==1
-%                                 eval(['MeanData.' VarName 'hist=MeanData.' VarName 'hist'';'])
-%                             end
-%                             eval(['maxval=max(MeanData.' VarName 'val);']);
-%                             eval(['minval=min(MeanData.' VarName 'val);']);
-%                             dC(ilist)=(maxval-minval)/100;%size of the histogram bin    
-%                          end
-%                     else
-% %                         icoord=0;
-% %                         for ilist=1:length(DimVarIndex)  
-% %                             VarDim=Data.ListVarName{DimVarIndex(ilist)};
-% %                             icoord=icoord+1;
-% %                             % eval(['Coord{' num2str(icord) '}=[' CoordName ''' VarName ''']']);
-% %                              %eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']);
-% %                         end
-%                     end
-%                 end
-%                 if ~isempty(indexremove)
-%                     MeanData.ListVarName(VarIndex(indexremove))=[];
-%                     MeanData.VarDimIndex(VarIndex(indexremove))=[];
-%                     if isfield(MeanData,'Role')%generaliser aus autres attributs
-%                         MeanData.Role(VarIndex(indexremove))=[];
-%                     end
-%                 end
-%                % END OF INITIALISATION
-% 
-%             end
-%        
-%          % A FAIRE: regular grid if coord_x undefined
-%             if indexfalse~=0 %suppress false data
-%                  eval(['testexist=isfield(Data,''' FFName ''');'])
-%                 if testexist
-%                     eval(['indsel=find(Data.' FFName '==0);']);
-%                     for icoord=1:length(CoordName)
-%                         eval(['Data.' CoordName{icoord} '=Data.' CoordName{icoord} '(indsel);']);
-%                     end
-%                 end
-%             end
-%             for ilist=1:length(VarIndexSum)
-%                 VarName=Data.ListVarName{VarIndexSum(ilist)};
-%                 if indexfalse~=0 & testexist
-%                     eval(['Data.' VarName '=Data.' VarName '(indsel);']);
-%                 end
-%                 if length(CoordName)==0%no variable use dfor unstructured coordinates
-%                     if isempty(DimVarIndex)|isequal(DimVarIndex,0)% no coordinate variable for structured coordinates
-% %                         %update histogram with the current field #ifile
-%                         str_left=['[MeanData.' VarName 'val,MeanData.' VarName 'hist]='];
-%                         str_right=['hist_update(MeanData.' VarName 'val,MeanData.' VarName 'hist,Data.' VarName ',dC(ilist));']; 
-%                         eval([str_left str_right]);%update global histo
-%                     else
-%                        %INTERPOLER
-%                             
-%                         eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum%CAS x,y change
-%                     end
-%                 else   
-%                     if length(CoordName)==2
-%                         eval(['test_interp= ~isequal(Data.' CoordName{1} ',MeanData.' CoordName{1} ...
-%                             ')|~isequal(Data.' CoordName{2} ',MeanData.' CoordName{2} ');'])
-%                         if test_interp
-%                             eval(['Data.' VarName '=griddata_uvmat(Data.' CoordName{1} ',Data.' CoordName{2}...
-%                                 ',Data.' VarName ',MeanData.' CoordName{1} ',MeanData.' CoordName{2} ');']);
-%                             test_interpolate=1;
-%                         end
-%                     end 
-%                     eval(['MeanData.' VarName '=MeanData.' VarName '+Data.' VarName ';']);%increment sum
-%                 end
-%             end
-%         end
-%     end
-%     if length(CoordName)~=0 | ~isequal(DimVarIndex,0)% no coordinate variable for structured coordinates
-%         for ilist=1:length(VarIndexSum)  
-%             VarName=Data.ListVarName{VarIndexSum(ilist)};
-%             eval(['MeanData.' VarName '=MeanData.' VarName '/itime;']);%normalize sum by the number of fields
-%         end
-%     else
-%         MeanData.NbDim=1;
-%         MeanData.ListDimName={};
-%         MeanData.DimValue=[];
-%         for ilist=1:length(VarIndexSum)  
-%             VarName=Data.ListVarName{VarIndexSum(ilist)};
-%             MeanData.ListVarName=[MeanData.ListVarName {[VarName 'val']} {[VarName 'hist']}];
-%             MeanData.VarDimIndex=[MeanData.VarDimIndex {[ilist]} {[ilist]}];
-%             MeanData.ListDimName=[MeanData.ListDimName {[VarName 'val']}];
-%             eval(['MeanData.DimValue=[MeanData.DimValue length(MeanData.' VarName 'val)];']);
-%         end   
-%     end
-%     figure
-%     haxes=axes;
-%     plot_field(MeanData,haxes)%plot the resulting average
-%     % change variable names for consitency with civ1 data (need to generalize these programs)
-%     if length(MeanData.ListVarName) >= 4 & isequal(MeanData.ListVarName(1:4), {'X'  'Y'  'U'  'V'})
-%        MeanData.ListGlobalAttribute={'nb_coord','nb_dim','dt','absolut_time_T0','pixcmx','pixcmy','hart','civ','fix'};
-%        MeanData.nb_coord=2;
-%        MeanData.nb_dim=2;
-%        MeanData.dt=1;
-%        MeanData.absolut_time_T0=0;
-%        MeanData.pixcmx=1; %pix per cm (1 by default)
-%        MeanData.pixcmy=1; %pix per cm (1 by default)
-%        MeanData.hart=0;
-%        if isequal(Data.CoordType,'px')
-%          MeanData.civ=1;
-%       else
-%          MeanData.civ=0;
-%        end
-%       MeanData.fix=0;
-%         MeanData.ListVarName(1:4)={'vec_X'  'vec_Y'  'vec_U'  'vec_V'};
-%         MeanData.vec_X=MeanData.X;
-%         MeanData.vec_Y=MeanData.Y;
-%         MeanData.vec_U=MeanData.U;
-%         MeanData.vec_V=MeanData.V;
-%     end
-%     error=struct2nc(filemean,MeanData); %save result file
-%     if isequal(error,0)
-%         if test_interpolate
-%             'fields interpolated to the positions of the first one'
-%         end
-%         [filemean ' written']
-%     else
-%         warndlg_uvmat(error,'ERROR')
-%     end
-% end
-
-%----------------------------------------------------------------------
-% --project fields on a projection object (e. g. a regular grid), possibly
-% merge several fields
-%----------------------------------------------------------------------
-%INPUT: 
-%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
-%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
-%OTHER INPUTS given by the structure Series
-function GUI_input=merge_proj(num_i1,num_i2,num_j1,num_j2,Series);
-
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-if ~exist('num_i1','var')
-    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
-        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
-        'RootFile';'on';... %root input file name ('on' by default)
-        'FileExt';'on';... %input file extension ('on' by default)
-        'NomType';'on';...%type of file indexing ('on' by default)
-        'NbSlice';'on'; ...%nbre of slices ('off' by default)
-        'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
-        'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-        'CoordType';'on';...%can use a transform function 'off' by default
-        'GetObject';'on';...%can use projection object ,'off' by default
-        %'GetMask';'on'...%can use mask option   ,'off' by default
-        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
-               ''};
-    return %exit the function 
-end
-
-%-------------------------------------------------
-hseries=guidata(Series.hseries);%handles of the GUI series
-WaitbarPos=get(hseries.waitbar_frame,'Position'); %positiopn of waitbar frame
-%-------------------------------------------------
-
-%numbers of view fields (nbre of inputs in RootPath)
-testcell=iscell(Series.RootFile);
-if ~testcell
-    Series.RootPath={Series.RootPath};
-    Series.RootFile={Series.RootFile};
-    Series.SubDir={Series.SubDir};
-    Series.FileExt={Series.FileExt};
-    Series.NomType={Series.NomType};
-    num_i1={num_i1};
-    num_i2={num_i2};
-    num_j1={num_j1};
-    num_j2={num_j2};
-end 
-nbview=length(Series.RootFile);%number of views (file series to merge)
-nbfield=size(num_i1{1},1)*size(num_i1{1},2);%number of fields in the time series
-transform=Series.CoordType; %  field transform function
-hhh=which('mmreader');
-for iview=1:nbview
-    test_movie(iview)=0;
-    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
-        if isequal(lower(FileExt{iview}),'.avi')
-            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
-            test_movie(iview)=1;
-        end
-    end 
-end
-
-%Calibration data and timing: read the ImaDoc files
-mode=''; %default
-timecell={};
-itime=0;
-NbSlice_calib={}; %test for z index 
-for iview=1:nbview%Loop on views
-    XmlData{iview}=[];%default
-    filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview});
-    if exist([filebase{iview} '.xml'],'file')
-        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
-        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);
-            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
-                msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
-            end
-        end    
-    elseif exist([filebase{iview} '.civ'],'file')
-        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
-        itime=itime+1;
-        timecell{itime}=time;
-        XmlData{iview}.Time=time;
-        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
-        GeometryCalib.Tx=0;
-        GeometryCalib.Ty=0;
-        GeometryCalib.Tz=1;
-        GeometryCalib.dpx=1;
-        GeometryCalib.dpy=1;
-        GeometryCalib.sx=1;
-        GeometryCalib.Cx=0;
-        GeometryCalib.Cy=0;
-        GeometryCalib.f=1;
-        GeometryCalib.kappa1=0;
-        GeometryCalib.CoordUnit='cm';
-        XmlData{iview}.GeometryCalib=GeometryCalib;
-        if error==1
-            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
-        end
-    end
-end
-
-%check coincidence in time
-multitime=0;
-if length(timecell)==0
-    time=[];
-elseif length(timecell)==1
-    time=timecell{1};
-elseif length(timecell)>1
-    multitime=1;
-    for icell=1:length(timecell)
-        if ~isequal(size(timecell{icell}),size(timecell{1}))
-            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
-            time=timecell{1};
-            multitime=0;
-            break
-        end
-    end
-end
-if multitime
-    for icell=1:length(timecell)
-        time(icell,:,:)=timecell{icell};
-    end
-    diff_time=max(max(diff(time)));
-    if diff_time>0
-        msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
-    end   
-end
-if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 
-    time=[];
-end
-
-% Field and velocity type (the same for all views)
-Field_str=get(hseries.FieldMenu,'String');
-val=get(hseries.FieldMenu,'Value');
-FieldName=Field_str(val);%the same set of fields for all views
-VelType_str=get(hseries.VelTypeMenu,'String');
-VelType_val=get(hseries.VelTypeMenu,'Value');
-VelType=VelType_str{VelType_val}; %the same for all views
-if isequal(FieldName,'get_field...')
-    hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
-   % hhget_field=guidata(hget_field);%handles of GUI elements in get_field
-    SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI
-%     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
-%         list_transform=get(hhget_field.menu_coord,'String');
-%         val_list=get(hhget_field.menu_coord,'Value');
-%         transform=list_transform{val_list};
-%     end
-end
-%detect whether all the files are 'images' or 'netcdf'
-testima=0;
-testvol=0;
-testcivx=0;
-testnc=0;
-FileExt=get(hseries.FileExt,'String');
-for iview=1:nbview
-     ext=FileExt{iview};
-     form=imformats(ext([2:end]));
-     if isequal(lower(ext),'.vol')
-         testvol=testvol+1;
-     elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
-         testima=testima+1;
-     elseif isequal(ext,'.nc')
-         testnc=testnc+1;
-     end
-end
-if testvol
-    msgbox_uvmat('ERROR','volume images not implemented yet')
-    return
-end
-if testnc~=nbview && testima~=nbview && testvol~=nbview
-    msgbox_uvmat('ERROR','need a set of images or a set of netcdf files with the same fields as input')
-    return
-end
-if ~isequal(FieldName,'get_field...')
-    testcivx=testnc;
-end
-%name of output files and directory:
-% res_subdir=fullfile(Series.RootPath{1},[Series.SubDir{1} '_STAT']);
-ProjectDir=fileparts(fileparts(Series.RootPath{1}));% preoject directory (GERK)
-prompt={['result directory (in' ProjectDir ')']};
-RootPath=get(hseries.RootPath,'String');
-SubDir=get(hseries.SubDir,'String');
-if isequal(length(RootPath),1)
-    fulldir=RootPath{1};
-    subdir='GRID';
-    res_subdir=fullfile(fulldir,subdir);
-else
-    def={fullfile(ProjectDir,'0_RESULTS')};
-    dlgTitle='result directory';
-    lineNo=1;
-    answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def);
-    fulldir=answer{1};
-    subdir=[];
-    dirlist=sort(Series.RootFile);
-    for iview=1:nbview
-        if ~isempty(subdir)
-            subdir=[subdir '-'];
-        end
-        subdir=[subdir dirlist{iview}];
-    end  
-    res_subdir=fullfile(fulldir,subdir);
-end
-ext=FileExt{1};
-if ~exist(fulldir,'dir')
-    msgbox_uvmat('ERROR',['directory ' fulldir ' needs to be created'])
-    return
-end
-if ~exist(res_subdir,'dir')
-    dircur=pwd;
-    cd(fulldir)
-    error=mkdir(subdir);
-    cd(dircur)
-end
-filebasesub=fullfile(res_subdir,Series.RootFile{1});
-filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files
-
-%projection object
-if isfield(Series,'sethandles')
-    if ishandle(Series.sethandles.set_object)
-        Series.ProjObject=read_set_object(Series.sethandles);
-        if ~isfield(Series.ProjObject,'Style')
-            msgbox_uvmat('ERROR','Undefined projection object style')
-            return
-        end
-        if ~isequal(Series.ProjObject.Style,'plane')
-            msgbox_uvmat('ERROR','The projection object must be a plane')
-            return
-        end
-    end
-end
-
-    %MAIN LOOP
-for ifile=1:nbfield                
-    stopstate=get(hseries.RUN,'BusyAction');
-    if isequal(stopstate,'queue')% enable STOP command from the 'series' interface
-         update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
-         Amerge=0;
-         
-         %----------LOOP ON VIEWS----------------------
-        nbtime=0;
-        for iview=1:nbview
-            %name of the current file
-            filename=name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
-            if ~exist(filename,'file')
-                msgbox_uvmat('ERROR',['missing input file' filename])
-                break
-            end
-
-            %reading the current file
-            if testima
-                if test_movie(iview)
-                    Field{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
-                else
-                    Field{iview}.A=read_image(filename,Series.NomType{iview},num_i1{iview}(ifile)); 
-                end % TODO: introduce ListVarName
-                npxy=size(Field{iview}.A);
-                Field{iview}.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
-                Field{iview}.AY=[npxy(1)-0.5 0.5];
-                Field{iview}.CoordType='px'; 
-                Field{iview}.AName='image';
-            else
-                if testcivx
-                    [Field{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
-                else
-                    [Field{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data                
-                    Field{iview}.VarAttribute=SubField.VarAttribute;
-                end
-                if isfield(Field{iview},'Time')
-                    timeread(iview)=Field{iview}.Time;
-                    nbtime=nbtime+1;
-                end
-            end
-            % coord transform
-            % z index
-            if ~isempty(NbSlice_calib)
-                Field{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
-            end
-            if ~isequal(transform,'')
-                Field{iview}=feval(Series.CoordType,Field{iview},XmlData{iview});%transform to phys if requested
-            end
-            if testcivx
-                    Field{iview}=calc_field(FieldName,Field{iview});
-            end
-
-            %projection on object (gridded plane)
-            if isfield(Series,'ProjObject')
-                Field{iview}=proj_field(Field{iview},Series.ProjObject);
-            end
-        end    
-        
-         %----------END LOOP ON VIEWS----------------------
-         
-        %merge the nbview fields
-        MergeData=merge_field(Field);
-        if isfield(MergeData,'Txt')
-            msgbox_uvmat('ERROR',MergeData.Txt)
-            return
-        end
-        
-        % generating the name of the merged field
-        mergename=name_generator(filebase_merge,num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile));
-        
-        % time:
-        time_i=0;%default
-        if isempty(time)% time from ImaDoc prevails
-            time_i=sum(timeread)/nbtime;
-        else
-            time_i=(time(iview,num_i1{iview}(ifile),num_j1{iview}(ifile))+time(iview,num_i2{iview}(ifile),num_j2{iview}(ifile)))/2;
-        end
-        
-        % recording the merged field
-        if testima    %in case of input images an image is produced   
-            if isa(MergeData.A,'uint8')
-                bitdepth=8;
-            elseif isa(MergeData.A,'uint16')
-                bitdepth=16;
-            end
-            imwrite(MergeData.A,mergename,'BitDepth',bitdepth); 
-            %write xml calibration file
-            siz=size(MergeData.A);
-            npy=siz(1);
-            npx=siz(2);
-            if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
-                Rangx=MergeData.VarAttribute{1}.Coord_2;
-                Rangy=MergeData.VarAttribute{1}.Coord_1;
-            elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
-                Rangx=[MergeData.AX(1) MergeData.AX(end)];
-                Rangy=[MergeData.AY(1) MergeData.AY(end)];
-            else
-                Rangx=[0.5 npx-0.5];
-                Rangy=[npy-0.5 0.5];%default
-            end
-            pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
-            pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
-            T_x=-pxcmx*Rangx(1)+0.5;
-            T_y=-pxcmy*Rangy(2)+0.5;
-            GeometryCal.focal=1;
-            GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
-            GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
-            ImaDoc.GeometryCalib=GeometryCal;
-            t=struct2xml(ImaDoc);
-            t=set(t,1,'name','ImaDoc');
-            save(t,[filebase_merge '.xml'])     
-            display([filebase_merge '.xml saved'])
-        else
-            MergeData.ListGlobalAttribute={'Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'};        
-            MergeData.nb_coord=2;
-            MergeData.nb_dim=2;
-            MergeData.dt=1;
-            MergeData.Time=time_i;
-            error=struct2nc(mergename,MergeData); %save result file
-            if isempty(error)
-                display(['output file ' mergename ' written'])
-            else
-                display(error)
-            end
-        end
-    end
-end
-
-%--------------------------------------------------------------------------   
-function MergeData=merge_field(Data)
-% initiate Matlab  structure for physical field
-if isempty(Data)||~iscell(Data)
-    MergeData=[];
-    return
-end
-MergeData=Data{1};%default
-error=0;
-nbview=length(Data);
-if nbview==1
-    return
-end
-for iview=1:nbview
-    if ~isequal(MergeData.ListDimName,Data{iview}.ListDimName)
-        error=1;
-    end
-    if ~isequal(MergeData.ListVarName,Data{iview}.ListVarName)
-        error=1;
-    end
-%      if ~isequal(MergeData.VarDimIndex,Data{iview}.VarDimIndex)
-%         error=1;
-%      end
-end
-if error
-    MergeData.Txt='ERROR: attempt at merging fields of incompatible type';
-    return
-end
-%group the variables (fields of 'FieldData') in cells of variables with the same dimensions
-%-----------------------------------------------------------------
-[CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1});
-%LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
-% CellVarIndex=cells of variable index arrays
-ivar_new=0; % index of the current variable in the projected field
-icoord=0;
-for icell=1:length(CellVarIndex)
-    if NbDim(icell)==1
-        continue
-    end
-    VarIndex=CellVarIndex{icell};%  indices of the selected variables in the list FieldData.ListVarName
-    VarType=VarTypeCell{icell};
-    ivar_X=VarType.coord_x;
-    ivar_Y=VarType.coord_y;
-    ivar_FF=VarType.errorflag;
-    if isempty(ivar_X)
-        test_grid=1;%test for input data on regular grid (e.g. image)coordinates
-    else
-        if length(ivar_Y)~=1
-                warndlg_uvmat('y coordinate missing in proj_field.m','ERROR')
-                return
-        end
-        test_grid=0;
-    end
-%    DimIndices=Data{1}.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
-    %case of input fields with unstructured coordinates
-    if ~test_grid
-        for ivar=VarIndex
-            VarName=MergeData.ListVarName{ivar};
-            for iview=1:nbview
-                eval(['MergeData.' VarName '=[MergeData.' VarName '; Data{iview}.' VarName ';'])
-            end
-        end
-    %case of fields defined on a structured  grid 
-    else  
-%        DimValue=MergeData.DimValue(DimIndices);%set of dimension values
-        testFF=0;
-        for iview=2:nbview
-%             if ~isequal(DimValue,Data{iview}.DimValue(DimIndices))
-%                 MergeData.Txt='ERROR: attempt at merging structured fields with different sizes';
-%                 return
-%             end
-            for ivar=VarIndex
-                VarName=MergeData.ListVarName{ivar};
-                if isfield(MergeData,'VarAttribute')
-                    if length(MergeData.VarAttribute)>=ivar && isfield(MergeData.VarAttribute{ivar},'Role') && isequal(MergeData.VarAttribute{ivar}.Role,'errorflag')
-                        testFF=1;
-                    end
-                end
-                eval(['MergeData.' VarName '=MergeData.' VarName '+ Data{iview}.' VarName ';'])
-            end
-        end
-        if testFF
-            nbaver=nbview-MergeData.FF;
-            indgood=find(nbaver>0);
-            for ivar=VarIndex
-                VarName=MergeData.ListVarName{ivar};
-                eval(['MergeData.' VarName '(indgood)=double(MergeData.' VarName '(indgood))./nbaver(indgood);'])
-            end 
-        else
-            for ivar=VarIndex
-                VarName=MergeData.ListVarName{ivar};
-                eval(['MergeData.' VarName '=double(MergeData.' VarName ')./nbview;'])
-            end    
-        end
-    end
-end
-    
-    
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %detect the chosen series of files and check their date of modification:
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%INPUT: 
-%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
-%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
-%OTHER INPUTS given by the structure Series
-function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
-
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-if ~exist('num_i1','var')
-    GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
-        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
-        %'RootFile';'on';... %root input file name ('on' by default)
-        %'FileExt';'on';... %input file extension ('on' by default)
-        %'NomType';'on';...%type of file indexing ('on' by default)
-        %'NbSlice';'on'; ...%nbre of slices ('off' by default)
-        %'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
-        %'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-        %'CoordType';'on'...%can use a transform function 'off' by default
-        %'GetObject';'on'...%can use projection object ,'off' by default
-        %'GetMask';'on'...%can use mask option   ,'off' by default
-        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
-               ''};
-    return %exit the function 
-end
-%---------------------------------------------------------
-hseries=guidata(Series.hseries);%handles of the GUI series
-WaitbarPos=get(hseries.waitbar_frame,'Position');
-
-%%%%%%%%%%%%%%%%%%%%%%%%
-message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
-answer=msgbox_uvmat('INPUT_Y-N',message);
-if ~isequal(answer,'Yes')
-    return
-end
-nbdelete=0;
-testcell=iscell(Series.RootFile);
-if ~testcell
-    Series.RootPath={Series.RootPath};
-    Series.RootFile={Series.RootFile};
-    Series.SubDir={Series.SubDir};
-    Series.FileExt={Series.FileExt};
-    Series.NomType={Series.NomType};
-end 
-for iview=1:length(Series.RootFile)
-    hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files
-    for ilist=1:length(hdir)
-        update_waitbar(hseries.waitbar,WaitbarPos,ilist/length(hdir))
-        FileName=hdir(ilist).name;
-        [dd,ff,Ext]=fileparts(FileName);
-        if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
-            delete(fullfile(Series.RootPath{iview},Series.SubDir{iview},FileName))
-            nbdelete=nbdelete+1;
-        end
-    end
-end
-msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx'])
-
-
-
-
+%     
 
 %-----------------------------
@@ -3607,724 +2174,5 @@
 
 
-%----------------------------------------------------------------------
-% --- make a time series analysis
-%----------------------------------------------------------------------
-%INPUT: 
-%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
-%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
-%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
-%OTHER INPUTS given by the structure Series
-function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series) 
-
-%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
-if ~exist('num_i1','var')
-    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
-        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
-        'RootFile';'on';... %root input file name ('on' by default)
-        'FileExt';'on';... %input file extension ('on' by default)
-        'NomType';'on';...%type of file indexing ('on' by default)
-        'NbSlice';'on'; ...%nbre of slices ('off' by default)
-        'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
-        'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
-        'CoordType';'on';...%can use a transform function 'off' by default
-        'GetObject';'on';...%can use projection object ,'off' by default
-        %'GetMask';'on'...%can use mask option   ,'off' by default
-        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
-               ''};
-    return %exit the function 
-end
-
-%------------------------------------------------------
-hseries=guidata(Series.hseries);%handles in the GUI series
-WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame
-
-%projection object
-test_object=get(hseries.GetObject,'Value');
-if test_object%isfield(Series,'sethandles')
-    Series.ProjObject=read_set_object(Series.sethandles);
-    %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
-    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' Series.ProjObject.Style]);
-    if ~isequal(answeryes,'Yes')
-        return
-    end
-else
-    msgbox_uvmat('ERROR','a projection object is needed');
-    return
-end
-
-% root names
-if iscell(Series.RootPath)
-    RootPath=Series.RootPath;
-    RootFile=Series.RootFile;
-    SubDir=Series.SubDir;
-    FileExt=Series.FileExt;
-    NomType=Series.NomType;
-else
-    RootPath={Series.RootPath};
-    RootFile={Series.RootFile};
-    SubDir={Series.SubDir};
-    FileExt={Series.FileExt};
-    NomType={Series.NomType};
-    num_i1={num_i1};
-    num_i2={num_i2};
-    num_j1={num_j1};
-    num_j2={num_j2};
-end
-ext=FileExt{1};
-form=imformats(ext([2:end]));%test valid Matlab image formats
-testima=0;
-if ~isempty(form)||isequal(lower(ext),'.avi')
-    testima=1;
-end
-nbview=length(RootPath);%number of series (1 or 2)
-nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series
-
-%Number of input series: this function  accepts only a single input file series 
-nbview=length(RootPath);
-if nbview==2
-    %TODO: choose between difference and two series
-elseif nbview>2  % TODO: make multiple series
-%     RootPath=RootPath(1:2);
-%     set(hseries.RootPath,'String',RootPath)
-%     SubDir=SubDir(1:2);
-%     set(hseries.SubDir,'String',SubDir)
-%     RootFile=RootFile(1:2);
-%     set(hseries.RootFile,'String',RootFile)
-%     NomType=NomType(1:2);
-%     %set(hseries.NomType,'String',NomType)
-%     FileExt=FileExt(1:2);
-%     set(hseries.FileExt,'String',FileExt)
-%     nbview=2;
-end
-hhh=which('mmreader');
-for iview=1:nbview
-    test_movie(iview)=0;
-    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
-        if isequal(lower(FileExt{iview}),'.avi')
-            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
-            test_movie(iview)=1;
-        end
-    end 
-end
-filebase{1}=fullfile(RootPath{1},RootFile{1});
-
-% number of slices
-NbSlice=str2num(get(hseries.NbSlice,'String'));
-if isempty(NbSlice)
-    NbSlice=1;
-end
-NbSlice_name=num2str(NbSlice);
-
-% Field and velocity type (the same for the two views)
-if isfield(Series,'Field')
-    FieldName=Series.Field;%the same set of fields for all views
-else
-    FieldName={''};
-end
-if isequal(FieldName,{'get_field...'})
-    hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
-    if numel(hget_field)>1
-        delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld
-    elseif isempty(hget_field)
-       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 
-       idetect(iview)=exist(filename,'file');
-       hget_field=get_field(filename);
-       return
-    end
-    %hhget_field=guidata(hget_field);%handles of GUI elements in get_field
-    SubField=read_get_field(hget_field) %read the names of the variables to plot in the get_field GUI
-    if isempty(SubField)
-        delete(hget_field)
-       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
-        hget_field=get_field(filename);
-        SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
-    end
-%     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
-%         list_transform=get(hhget_field.menu_coord,'String');
-%         val_list=get(hhget_field.menu_coord,'Value');
-%         transform=list_transform{val_list};
-%     end
-end
-
-%detect whether the two files are 'images' or 'netcdf'
-testima=0;
-testvol=0;
-testcivx=0;
-testnc=0;
-FileExt=get(hseries.FileExt,'String');
-for iview=1:nbview
-     ext=FileExt{iview};
-     form=imformats(ext([2:end]));
-     if isequal(lower(ext),'.vol')
-         testvol=testvol+1;
-     elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
-         testima=testima+1;
-     elseif isequal(ext,'.nc')
-         testnc=testnc+1;
-     end
-end
-if testvol
-    msgbox_uvmat('ERROR','volume images not implemented yet')
-    return
-end
-if testnc~=nbview && testima~=nbview && testvol~=nbview
-    msgbox_uvmat('need a set of images or a set of netcdf files with the same fields as input','ERROR')
-    return
-end
-if ~isequal(FieldName,{'get_field...'})
-    testcivx=testnc;
-end
-
-% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
-filebasesub=fullfile(RootPath{1},RootFile{1});
-if NbSlice==1
-    filebase_out=[filebasesub '_time'];
-else
-    filebase_out=[filebasesub '_' NbSlice_name 'mtim'];
-    increment=num_i1{1}(2)-num_i1{1}(1);
-    if ~isequal(increment,1) % if an increment is set
-        answeryes=msgbox_uvmat('INPUT_Y-N',['will take time series in ' num2str(NbSlice) 'slices with increment = ' num2str(increment) '!']); 
-    else    
-        answeryes=msgbox_uvmat('INPUT_Y-N',{['will take time series in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
-    end
-    if ~isequal(answeryes,'Yes')
-        return
-    end
-end
-VelType_str=get(hseries.VelTypeMenu,'String');
-VelType_val=get(hseries.VelTypeMenu,'Value');
-VelType{1}=VelType_str{VelType_val};
-if nbview==2
-    VelType_str=get(hseries.VelTypeMenu_1,'String');
-    VelType_val=get(hseries.VelTypeMenu_1,'Value');
-    VelType{2}=VelType_str{VelType_val};
-end
-
-%Calibration data and timing: read the ImaDoc files
-mode=''; %default
-timecell={};
-XmlData={};
-itime=0;
-NbSlice_calib={};
-for iview=1:nbview%Loop on views
-    XmlData{iview}=[];%default
-    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
-    if exist([filebase{iview} '.xml'],'file')
-        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
-        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 field series');
-            end
-        end 
-    elseif exist([filebase{iview} '.civ'],'file')
-        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
-        itime=itime+1;
-        timecell{itime}=time;
-        XmlData{iview}.Time=time;
-        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
-        GeometryCalib.Tx=0;
-        GeometryCalib.Ty=0;
-        GeometryCalib.Tz=1;
-        GeometryCalib.dpx=1;
-        GeometryCalib.dpy=1;
-        GeometryCalib.sx=1;
-        GeometryCalib.Cx=0;
-        GeometryCalib.Cy=0;
-        GeometryCalib.f=1;
-        GeometryCalib.kappa1=0;
-        GeometryCalib.CoordUnit='cm';
-        XmlData{iview}.GeometryCalib=GeometryCalib;
-        if error==1
-            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
-        end
-    end
-end
-
-%check coincidence in time
-multitime=0;
-if length(timecell)==0
-    time=[];
-elseif length(timecell)==1
-    time=timecell{1};
-elseif length(timecell)>1
-    multitime=1;
-    for icell=1:length(timecell)
-        if ~isequal(size(timecell{icell}),size(timecell{1}))
-            warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING')
-            time=timecell{1};
-            multitime=0;
-            break
-        end
-    end
-end
-if multitime
-    for icell=1:length(timecell)
-        time(icell,:,:)=timecell{icell};
-    end
-    diff_time=max(max(diff(time)));
-    if diff_time>0
-        warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING')
-    end   
-end
-if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 
-    time=[];
-end
-
-% image or scalar processing programme set by user
-Coord_menu=get(hseries.CoordType,'String');
-menu_val=get(hseries.CoordType,'Value');
-usrfct=Coord_menu{menu_val};
-testfct=~isequal(usrfct,'');
-
-% to update:
-VelType_str=get(hseries.VelTypeMenu,'String');
-VelType_val=get(hseries.VelTypeMenu,'Value');
-VelType{1}=VelType_str{VelType_val};
-if nbview==2
-    VelType_str=get(hseries.VelTypeMenu_1,'String');
-    VelType_val=get(hseries.VelTypeMenu_1,'Value');
-    VelType{2}=VelType_str{VelType_val};
-end
-
-%LOOP ON SLICES
-for i_slice=1:NbSlice
-     dt=[];
-     nbmissing=0; %number of undetected files
-     nbfiles=0;
-    %%%%%%%%%%%%%%%%%%%%%%%%%%%%LOOP ON FIELDS IN  A SLICE
-    for ifile=i_slice:NbSlice:nbfield  
-        stopstate=get(hseries.RUN,'BusyAction');
-        if isequal(stopstate,'queue')% enable STOP command
-             update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) 
-             for iview=1:nbview
-                filename=...
-                           name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview}); 
-                idetect(iview)=exist(filename,'file');
-                Data{iview}=[]; %default      
-                if testima                  
-                    Data{iview}.ListVarName={'A'};
-                    Data{iview}.AName='image';
-                    if test_movie(iview)
-                        A=read(MovieObject{iview},num_i1{iview}(ifile));
-                    else
-                        A=double(read_image(filename,NomType{iview},num_i1{iview}(ifile)));% read the image, num2 is the counter for avi files 
-                    end
-                    Data{iview}.ListVarName={'coord_y','coord_x','A'}; % 
-                    npy=size(A,1);
-                    npx=size(A,2);
-                    nbcolor=size(A,3);
-                    if nbcolor==3
-                         Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x','rgb'}};
-                    else
-                         Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'}};
-                    end  
-                    Data{iview}.coord_y=[npy-0.5 0.5];
-                    Data{iview}.coord_x=[0.5 npx-0.5];
-                    Data{iview}.A=A;
-                    Data{iview}.CoordType='px';
-                elseif testcivx
-                    [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
-                else
-                    [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data                
-                    Data{iview}.VarAttribute=SubField.VarAttribute;
-                end
-                if ~isempty(NbSlice_calib)  % z index
-                    Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
-                end
-             end
-            % geometry transform or other user defined transform
-            if ~isequal(Series.CoordType,'')           
-                if nbview==2
-                    [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
-                    if isempty(Data{2})
-                        Data(2)=[];
-                    end
-                else
-                    Data{1}=feval(Series.CoordType,Data{1},XmlData{1});
-                end
-            end
-            if testcivx
-                    Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
-            end
-            if length(Data)==2
-                [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
-                if ~isempty(errormsg)
-                    msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg])
-                    return
-                end
-            else
-                Field=Data{1};
-            end
-            if isfield(Series,'ProjObject')
-                Series.ProjObject
-                [Field,errormsg]=proj_field(Field,Series.ProjObject);
-                if ~isempty(errormsg)
-                    msgbox_uvmat('ERROR',['error in time_series/proj_field:' errormsg])
-                    return
-                end
-            end
-            if min(idetect)>=1% the input file(s) have been detected          
-                nbfiles=nbfiles+1;
-                if nbfiles==1 %first field: initiate the time series
-                    RecordData=Field;%default
-                    RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots         
-                    nbvar=length(Field.ListVarName);
-                    if nbvar==0
-                        msgbox_uvmat('ERROR','no input variable selected in get_field')
-                        return
-                    end
-                    testsum=2*ones(1,nbvar);%initiate flag for action on each variable
-                    indexfalse=0;
-                    CoordName={};
-                    indexremove=[];
-                    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')
-                                    msgbox_uvmat('ERROR','do not handle error flags in time series')
-                                    return                                               
-                                end
-                                if isequal(var_role,'warnflag')                        
-                                    testsum(ivar)=0;  % not recorded variable 
-                                    eval(['RecordData=rmfield(RecordData,''' 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
-                                % check whether the variable ivar is a dimension variable
-                                %index=Field.VarDimIndex{ivar};%dimension indices of the variable #ivar
-                                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
-                    end
-                    for ivar=1:nbvar
-                        if testsum(ivar)==2                     
-                            eval(['RecordData.' Field.ListVarName{ivar} '=[];'])
-                        end
-                    end
-                    RecordData.ListVarName=[{'Time'} RecordData.ListVarName];
-                end
-                for ivar=1:length(Field.ListVarName)
-                    VarName=Field.ListVarName{ivar};
-                    eval(['VarVal=Field.' VarName ';']);
-                    if testsum(ivar)==2% test for recorded variable 
-                        eval(['VarVal=Field.' VarName ';']);
-                        if isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
-                            if isempty(VarVal)
-                                msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
-                                return                             
-                            end
-                            VarVal=mean(VarVal,1);
-                        end
-                        VarVal=shiftdim(VarVal,-1); %shift dimension 
-                        eval(['RecordData.' VarName '=cat(1,RecordData.' VarName ',VarVal);']);%concanete the current field to the time series    
-                    elseif testsum(ivar)==1% variable representing fixed coordinates
-                        eval(['VarInit=RecordData.' VarName ';']);
-                        if ~isequal(VarVal,VarInit)
-                            msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName])
-                            return
-                        end
-                    end                 
-                end
-                % time:
-                if isempty(time)% time read in ncfiles
-                   if isfield(Field,'Time')
-                       RecordData.Time(nbfiles,1)=Field.Time;
-                   else
-                       RecordData.Time(nbfiles,1)=nbfiles;%default
-                   end
-                else % time from ImaDoc prevails
-                    RecordData.Time(nbfiles,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
-                end
-            else
-                nbmissing=nbmissing+1;
-            end
-        end
-    end
-    %remove time for global attributes if exists
-    for iattr=1:numel(RecordData.ListGlobalAttribute) 
-        if strcmp(RecordData.ListGlobalAttribute{iattr},'Time')
-            RecordData.ListGlobalAttribute(iattr)=[];
-            break
-        end
-    end
-    for ivar=1:numel(RecordData.ListVarName)
-        VarName=RecordData.ListVarName{ivar};
-        eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons
-    end
-        % add time dimension and update VarDimIndex:
-   %if ~isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
-        for ivar=1:length(Field.ListVarName)
-%              vardimindex=Field.VarDimIndex{ivar};% array of dimension indices for variable VarIndex(ivar)
-             DimCell=Field.VarDimName(ivar);
-             if testsum(ivar)==2%variable used as time series
-%                  RecordData.VarDimIndex{ivar}=[1 vardimindex+1];
-                  RecordData.VarDimName{ivar}=[{'Time'} DimCell];
-             elseif testsum(ivar)==1
-%                  RecordData.VarDimIndex{ivar}=[vardimindex+1];
-                 RecordData.VarDimName{ivar}=DimCell;
-             end
-        end
-   % end
-    indexremove=find(~testsum);
-    if ~isempty(indexremove)
-        RecordData.ListVarName(1+indexremove)=[];
-        RecordData.VarDimName(indexremove)=[];
-        if isfield(RecordData,'Role')&~isempty(RecordData.Role{1})%generaliser aus autres attributs
-            RecordData.Role(1+indexremove)=[];
-        end
-    end
-    %RecordData.VarDimIndex=[{[1]} RecordData.VarDimIndex]; %time dimension
-    %shift variable attributes
-    if isfield(RecordData,'VarAttribute')
-        RecordData.VarAttribute=[{[]} RecordData.VarAttribute];
-    end 
-    RecordData.VarDimName=[{'Time'} RecordData.VarDimName];
-    RecordData.Action=Series.Action;%name of the processing programme
-    %name of result file
-    [filemean]=...
-               name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),SubDir{1});
-    errormsg=struct2nc(filemean,RecordData); %save result file
-    if isempty(errormsg)
-        display([filemean ' written'])
-    else
-        msgbox_uvmat('ERROR',['error in Series/struct2nc' errormsg])
-    end
-end
-figure
-haxes=axes;
-
-plot_field(RecordData,haxes)
-hget_field=findobj(allchild(0),'name','get_field');
-if ~isempty(hget_field)
-    delete(hget_field)
-end
-get_field(filemean,RecordData)
-    
-%-----------------------------------------------------------------------
-% --- Executes on selection change in CoordType.
-function CoordType_Callback(hObject, eventdata, handles)
-menu_str=get(handles.CoordType,'String');
-ind_coord=get(handles.CoordType,'Value');
-coord_option=menu_str{ind_coord};
-if isequal(coord_option,'more...'); 
-    fct_name='';
-    if exist('./TMP/current_usr_fct.mat','file')% if a file is found
-        h=load('./TMP/current_usr_fct.mat');
-        if isfield(h,'fct_name'); 
-            fct_name=h.fct_name;
-        end
-    end
-    prompt = {'Enter the name of the transform function'};
-    dlg_title = 'user defined transform';
-    num_lines= 1;
-    [FileName, PathName, filterindex] = uigetfile( ...
-       {'*.m', ' (*.m)';
-        '*.m',  '.m files '; ...
-        '*.*', 'All Files (*.*)'}, ...
-        'Pick a file', fct_name);
-    fct_name=fullfile(PathName,FileName);
-    addpath(PathName);%add the path to the selected fct
-    [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
-    if ~exist(fct_name,'file')
-           warndlg(['image procesing fct ' fct_name ' not found'])
-    else
-        transform=FileName(1:end-2);% 
-        update_menu(handles.CoordType,transform)%add the selected fct to the menu
-  %      set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu 
-      %save ('./TMP/current_usr_fct.mat','fct_name');
-    end   
-end
-ind_coord=get(handles.CoordType,'Value');   
-
-%---------------------------------------------------------------------
-% --- Executes on selection change in ProjObject.
-function ProjObject_Callback(hObject, eventdata, handles)
-
-list_object=get(handles.ProjObject,'String');
-index=get(handles.ProjObject,'Value');
-hseries=get(handles.ProjObject,'Parent');
-SeriesData=get(hseries,'UserData');
-Obj=SeriesData.ProjObject{index};
-[SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index});
-set(hseries,'UserData',SeriesData);
-
-%-------------------------------------------------------------
-%generates a series of file names with reference numbers between range1 and
-%range2 with increment incr. The reference number num_ref is the image number at the middle of the
-%image pair. The set of first numbers num1 of the image pairs is also
-%given as output
-%------------------------------------------------------
-function [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(filebase,subdir,mode,first_i,incr_i,last_i,first_j,incr_j,last_j)
-[Path,Name]=fileparts(filebase);
-filebasesub=fullfile(Path,subdir,Name);
-filecell={};%default
-num_i1=[];
-num_i2=[];
-num_j1=[];
-num_j2=[];
-ind0_i=first_i:incr_i:last_i;
-nbcolumn=length(ind0_i);
-ind0_j=first_j:incr_j:last_j;
-nbline=length(ind0_j);
-if isequal(mode,'#_ab')
-    dirpair=dir([filebasesub '*_*.nc']);
-elseif isequal(mode,'bursts')|isequal(mode,'series(Dj)')  
-    dirpair=dir([filebasesub '_*_*-*.nc']);
-elseif isequal(mode,'series(Di)')
-    dirpair=dir([filebasesub '_*-*_*.nc']);
-else
-    errordlg('option *|* not yet implemented')
-    return
-end
-if isempty(dirpair)
-        errordlg('no pair detected in the selected range')
-        return
-end
-    %ind0_i=first_i:incr_i:last_i;
-    %nbcolumn=length(ind0_i);
-    %dirpair=dir([filebasesub '_*_*-*.nc']);
-if isequal(mode,'bursts')|isequal(mode,'#_ab')
-    icount=0;
-    for ifile=1:length(dirpair)
-        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
-        
-%         if isempty(str2num(str_1))
-%             dirpair(ifile).name
-%         end
-        num1_r=str2num(str_1);
-        if isequal(RootFile,Name) & ~isempty(num1_r)   
-            num_i1(ifile)=num1_r;
-            num_a(ifile)=stra2num(str_a);
-            num_b(ifile)=stra2num(str_b);
-%             icount=icount+1;
-        end      
-    end
-    length(dirpair)
-%     num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
-    test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
-    ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices 
-    select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
-    ind_i=ind_i(select);%set of selected indices ind_i
-    [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
-    select=select(indsort);
-    num_i1=num_i1(select);
-    num_a=num_a(select);
-    num_b=num_b(select);
-    dirpair=dirpair(select);
-    [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn); 
-    ind_i(ind_remove)=[];
-    num_a(ind_remove)=[];
-    num_b(ind_remove)=[];
-    num_j1=zeros(1,nbcolumn);%default
-    num_j2=num_j1;
-    num_j1(ind_i)=num_a;
-    num_j2(ind_i)=num_b;
-    num_i1=first_i:incr_i:last_i;
-    num_i2=num_i1;
-    nbmissing=nbcolumn-length(ind_i);
-
-elseif isequal(mode,'series(Di)') 
-    %ind0_i=first_i:incr_i:last_i;
-    %nbcolumn=length(ind0_i);
-    %ind0_j=first_j:incr_j:last_j;
-    %nbline=length(ind0_j);
-    %dirpair=dir([filebasesub '_*-*_*.nc']);
-    for ifile=1:length(dirpair)
-        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
-        num_i1_r(ifile)=str2num(str_1);
-        num_i2_r(ifile)=str2num(str_2);
-        num_j(ifile)=str2num(str_a);
-    end
-    num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
-    test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
-    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices 
-    ind_j=((num_j-first_j)/incr_j)+1;
-    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
-    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
-    ind_ij=ind_ij(select);%set of selected indices ind_ij
-    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij 
-    select=select(indsort);
-    num_i1_r=num_i1_r(select);
-    num_i2_r=num_i2_r(select);
-%     num_j=num_j(select);
-    dirpair=dirpair(select);
-    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
-    ind_ij(ind_remove)=[];
-    num_i1_r(ind_remove)=[];
-    num_i2_r(ind_remove)=[];
-    num_i1=zeros(1,nbline*nbcolumn);%default
-    num_i2=num_i1;
-    num_i1(ind_ij)=num_i1_r;
-    num_j2(ind_ij)=num_i2_r;
-    num_i1=reshape(num_i1,nbline,nbcolumn);
-    num_i2=reshape(num_i2,nbline,nbcolumn);
-    num_j1=meshgrid(ind0_i,ind0_j);
-    num_j2=num_j1;
-    nbmissing=nbline*nbcolumn-length(ind_ij);
-elseif isequal(mode,'series(Dj)')
- %   ind0_i=first_i:incr_i:last_i;
- %   nbcolumn=length(ind0_i);
- %   ind0_j=first_j:incr_j:last_j;
-  %  nbline=length(ind0_j);
-  %  dirpair=dir([filebasesub '_*_*-*.nc']);
-    for ifile=1:length(dirpair)
-        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
-        num_i(ifile)=str2num(str_1);
-        num_a(ifile)=str2num(str_a);
-        num_b(ifile)=str2num(str_b);
-    end
-    num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
-    test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
-    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices 
-    ind_j=((num_j-first_j)/incr_j)+1;
-    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
-    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
-    ind_ij=ind_ij(select);%set of selected indices ind_ij
-    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij 
-    select=select(indsort);
-    num_i=num_i(select);
-    num_a=num_a(select);
-    num_b=num_b(select);
-    dirpair=dirpair(select);
-    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
-    ind_ij(ind_remove)=[];
-    num_a(ind_remove)=[];
-    num_b(ind_remove)=[];
-    num_j1=zeros(1,nbline*nbcolumn);%default
-    num_j2=num_j1;
-    num_j1(ind_ij)=num_a;
-    num_j2(ind_ij)=num_b;
-    num_j1=reshape(num_j1,nbline,nbcolumn);
-    num_j2=reshape(num_j2,nbline,nbcolumn);
-    num_i1=meshgrid(ind0_i,ind0_j);
-    num_i2=num_i1;
-    nbmissing=nbline*nbcolumn-length(ind_ij);
-%     for i=1:length(indsel);%A SUPPRIMER ULTERIEUREMENT
-%         if indsel(i)==0
-%             filecell{i}='';
-%         else
-%             Name=dirpair(indsel(i)).name;
-%             filecell{i}=fullfile(Path,subdir,Name);
-%         end
-%     end
-%else
-%    errordlg('option *|* not yet implemented')
-%    return
-end
+
 
 %%%%%%%%%%%%%
@@ -4399,6 +2247,5 @@
             last_j2 =last_j +ind_shift(2);
             siz=size(SeriesData.Time{1});
-            if first_i1>=1 && first_j1
-                >=1 && siz(1)>=last_i2 && siz(2)>=last_j2
+            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
                 time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
                 time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
Index: /trunk/src/series/aver_stat.m
===================================================================
--- /trunk/src/series/aver_stat.m	(revision 30)
+++ /trunk/src/series/aver_stat.m	(revision 30)
@@ -0,0 +1,461 @@
+function GUI_input=aver_stat(num_i1,num_i2,num_j1,num_j2,Series)
+%----------------------------------------------------------------------
+% --- make average on a series of files
+%----------------------------------------------------------------------
+%INPUT: 
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+%  Series.Time: 
+%  Series.GeometryCalib:%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+        'RootFile';'on';... %root input file name ('on' by default)
+        'FileExt';'on';... %input file extension ('on' by default)
+        'NomType';'on';...%type of file indexing ('on' by default)
+        'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        'VelTypeMenu';'two';...% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
+        'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        'CoordType'; 'on';...%can use a transform function
+        'GetObject';'on';...%can use projection object(option 'off'/'one'/'two',
+        %'GetMask';'on'...%can use mask option   
+        %'PARAMETER'; %options: name of the user defined parameter',repeat a line for each parameter 
+               ''};
+        return
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%root input file and type
+if ~iscell(Series.RootPath)% case of a single input field series
+    num_i1={num_i1};num_j1={num_j1};num_i2={num_i2};num_j2={num_j2};
+    RootPath={Series.RootPath};
+    RootFile={Series.RootFile};
+    SubDir={Series.SubDir};
+    FileExt={Series.FileExt};
+    NomType={Series.NomType};
+else
+    RootPath=Series.RootPath;
+    RootFile=Series.RootFile;
+    SubDir=Series.SubDir;
+    NomType=Series.NomType;
+    FileExt=Series.FileExt;
+end   
+ext=FileExt{1};
+form=imformats(ext([2:end]));%test valid Matlab image formats
+testima=0;
+if ~isempty(form)||isequal(lower(ext),'.avi')||isequal(lower(ext),'.vol')
+    testima(1)=1;
+end
+if length(FileExt)>=2
+    ext_1=FileExt{2};
+    form=imformats(ext_1([2:end]));%test valid Matlab image formats
+    if ~isempty(form)||isequal(lower(ext_1),'.avi')||isequal(lower(ext_1),'.vol')
+        testima(2)=1;
+    end
+    if testima(2)~=testima(1)
+        msgbox_uvmat('ERROR','images and netcdf files cannot be compared')
+        return
+    end
+end
+
+%Number of input series: this function  accepts two input file series at most (then it operates on the difference of fields)
+nbview=length(RootPath);
+if nbview>2  
+    RootPath=RootPath(1:2);
+    set(hseries.RootPath,'String',RootPath)
+    SubDir=SubDir(1:2);
+    set(hseries.SubDir,'String',SubDir)
+    RootFile=RootFile(1:2);
+    set(hseries.RootFile,'String',RootFile)
+    NomType=NomType(1:2);
+    FileExt=FileExt(1:2);
+    set(hseries.FileExt,'String',FileExt)
+    nbview=2;
+end
+hhh=which('mmreader');
+for iview=1:nbview
+    test_movie(iview)=0;
+    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
+        if isequal(lower(FileExt{iview}),'.avi')
+            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
+            test_movie(iview)=1;
+        end
+    end 
+end
+
+% number of slices
+NbSlice=str2num(get(hseries.NbSlice,'String'));
+if isempty(NbSlice)
+    NbSlice=1;
+end
+NbSlice_name=num2str(NbSlice);
+
+% Field and velocity type (the same for the two views)
+Field_str=get(hseries.FieldMenu,'String');
+FieldName=[]; %default
+testfield=get(hseries.FieldMenu,'Visible');
+if isequal(testfield,'on')
+    val=get(hseries.FieldMenu,'Value');
+    FieldName=Field_str(val);%the same set of fields for all views
+    if isequal(FieldName,{'get_field...'})
+        hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
+        if length(hget_field)>1
+            delete(hget_field(2:end))
+        elseif isempty(hget_field)
+           filename=...
+                 name_generator(fullfile(RootPath{1},RootFile{1}),num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 
+           get_field(filename);
+           return
+        end
+        %hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+        SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
+    end
+end
+%detect whether the two files are 'images' or 'netcdf'
+testima=0;
+testvol=0;
+testcivx=0;
+testnc=0;
+FileExt=get(hseries.FileExt,'String');
+% test_movie=0;
+for iview=1:nbview
+     ext=FileExt{iview};
+     form=imformats(ext([2:end]));
+     if isequal(lower(ext),'.vol')
+         testvol=testvol+1;
+     elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
+         testima=testima+1;
+     elseif isequal(ext,'.nc')
+         testnc=testnc+1;
+     end
+end
+if testvol
+    msgbox_uvmat('ERROR','volume images not implemented yet')
+    return
+end
+if testnc~=nbview && testima~=nbview && testvol~=nbview
+    msgbox_uvmat('ERROR','compare two image series or two netcdf files with the same fields as input')
+    return
+end
+if ~isequal(FieldName,{'get_field...'})
+    testcivx=testnc;
+end
+
+if testcivx
+    VelType_str=get(hseries.VelTypeMenu,'String');
+    VelType_val=get(hseries.VelTypeMenu,'Value');
+    VelType{1}=VelType_str{VelType_val};
+    if nbview==2
+        VelType_str=get(hseries.VelTypeMenu_1,'String');
+        VelType_val=get(hseries.VelTypeMenu_1,'Value');
+        VelType{2}=VelType_str{VelType_val};
+    end
+end
+
+%Calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={};
+for iview=1:nbview%Loop on views
+    XmlData{iview}=[];%default
+    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
+    if exist([filebase{iview} '.xml'],'file')
+        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
+        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
+        end 
+    elseif exist([filebase{iview} '.civ'],'file')
+        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+        itime=itime+1;
+        timecell{itime}=time;
+        XmlData{iview}.Time=time;
+        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+        GeometryCalib.Tx=0;
+        GeometryCalib.Ty=0;
+        GeometryCalib.Tz=1;
+        GeometryCalib.dpx=1;
+        GeometryCalib.dpy=1;
+        GeometryCalib.sx=1;
+        GeometryCalib.Cx=0;
+        GeometryCalib.Cy=0;
+        GeometryCalib.f=1;
+        GeometryCalib.kappa1=0;
+        GeometryCalib.CoordUnit='cm';
+        XmlData{iview}.GeometryCalib=GeometryCalib;
+        if error==1
+            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+        end
+    end
+end
+
+%check coincidence in time
+multitime=0;
+if length(timecell)==0
+    time=[];
+elseif length(timecell)==1
+    time=timecell{1};
+elseif length(timecell)>1
+    multitime=1;
+    for icell=1:length(timecell)
+        if ~isequal(size(timecell{icell}),size(timecell{1}))
+            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
+            time=timecell{1};
+            multitime=0;
+            break
+        end
+    end
+end
+if multitime
+    for icell=1:length(timecell)
+        time(icell,:,:)=timecell{icell};
+    end
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
+    end   
+end
+if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 
+    time=[];
+end
+
+% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
+subdir_result='aver_stat';
+% filebasesub=fullfile(RootPath{1},subdir_result,RootFile{1});
+% if isempty(SubDir{1}) % create a subdirectory '/aver_stat'
+%     subdir_result='aver_stat';
+%     filebasemean=fullfile(RootPath{1},subdir_result);
+if ~exist(fullfile(RootPath{1},subdir_result),'dir')
+    dircur=pwd; %record current working directory
+    cd(RootPath{1})% goes to the iamge directory
+    [m1,m2,m3]=mkdir(subdir_result);
+    if ~isequal(m2,'')
+         msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation
+    end
+    cd(dircur) %back to the initial working directory
+end
+filebase_out=filebase{1}; 
+% else
+%    subdir_result=SubDir{1};
+%    filebase_out=[filebase{1} '_mean'];% output root name obtained by adding the suffix _mean to the input
+% end
+%output nomtype (to generalise)
+NomTypeOut=nomtype2pair(NomType{1},num_i2{end}(end)-num_i1{1}(1),num_j2{end}(end)-num_j1{1}(1));
+    
+% if NbSlice==1  
+%     filebase_out=[filebasesub '_mean'];
+% else
+%     filebase_out=[filebasesub '_' NbSlice_name 'mean'];
+%     answeryes=questdlg({['will make average in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
+%     if ~isequal(answeryes,'Yes')
+%         return
+%     end
+% end
+
+% coordinate transform or other user defined transform
+Coord_menu=get(hseries.CoordType,'String');
+menu_val=get(hseries.CoordType,'Value');
+usrfct=Coord_menu{menu_val};
+testfct=~isequal(usrfct,'');
+
+%slice loop
+siz=size(num_i1{1});
+lengthtot=siz(1)*siz(2);
+nbfield=floor(lengthtot/(siz(1)*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
+nbfield_slice=nbfield*siz(1);% number of fields per slice
+
+for i_slice=1:NbSlice
+   S=0; %initiate the image sum S 
+   nbfiles=0;
+   nbmissing=0;
+    %averaging loop
+   for ifile=i_slice:NbSlice:lengthtot
+        stopstate=get(hseries.RUN,'BusyAction');
+        if isequal(stopstate,'queue') % enable STOP command
+             update_waitbar(hseries.waitbar,WaitbarPos,ifile/lengthtot)
+             for iview=1:nbview
+                [filename]=...
+                           name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
+                if testima
+                    Data{iview}.ListVarName={'A'};
+                    Data{iview}.AName='image';
+                    if test_movie(iview)
+                        Data{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
+                    else
+                        Data{iview}.A=read_image(filename,NomType{iview},num_i1{iview}(ifile));% read the image, num2 is the counter for avi files 
+                    end
+                    Atype{iview}=class(Data{iview}.A);
+                    Data{iview}.A=double(Data{iview}.A);
+                elseif testcivx
+                    [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
+                else
+                    [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data                
+                    Data{iview}.VarAttribute=SubField.VarAttribute;
+                end 
+                if isfield(Data{iview},'Txt')
+                    msgbox_uvmat('ERROR',['error of input reading: ' Data{iview}.Txt])
+                    return
+                end
+             end   
+             % coordinate transform (or other user defined transform)
+             if ~isequal(Series.CoordType,'')
+                 % z index
+                if ~isempty(NbSlice_calib)
+                    Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;%Zindex for phys transform
+                end
+                if nbview==2
+                    [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
+                    if isempty(Data{2})
+                        Data(2)=[];
+                    end
+                else
+                    Data{1}=feval(Series.CoordType,Data{1},XmlData);
+                end
+             end     
+            if testcivx
+                    Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
+            end
+            if length(Data)==2
+                [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
+                if ~isempty(errormsg)
+                    msgbox_uvmat('ERROR',['error in aver_stat/sub_field:' errormsg])
+                    return
+                end
+            else
+                Field=Data{1};
+            end
+            if isfield(Series,'ProjObject')
+                [Field,errormsg]=proj_field(Field,Series.ProjObject);
+                 if ~isempty(errormsg)
+                    msgbox_uvmat('ERROR',['error in aver_stat/proj_field:' errormsg])
+                    return
+                end
+             end                                                        
+                nbfiles=nbfiles+1;
+                if nbfiles==1 %first field
+                    time_1=[];
+                    if isfield(Field,'Time')
+                        time_1=Field.Time(1);
+                    end
+                    DataMean=Field;%default
+                else
+                    for ivar=1:length(Field.ListVarName)
+                        VarName=Field.ListVarName{ivar};
+                        eval(['sizmean=size(DataMean.' VarName ');']);
+                        eval(['siz=size(Field.' VarName ');']);
+                        if ~isequal(siz,sizmean)
+                            warndlg_uvmat(['unequal size of input field ' VarName ', need to interpolate on a grid'],'WARNING') 
+                            nbmissing=nbmissing+1;
+                            break
+                        else
+                            eval(['DataMean.' VarName '=DataMean.' VarName '+ Field.' VarName ';']); % update the sum 
+                        end
+                    end
+                end
+%             else
+%                 nbmissing=nbmissing+1;
+%             end
+        end
+    end %end averaging loop
+    for ivar=1:length(Field.ListVarName)
+        VarName=Field.ListVarName{ivar};
+        eval(['DataMean.' VarName '=DataMean.' VarName '/nbfiles;']); % normalize the mean
+    end
+    if nbmissing~=0
+        msgbox_uvmat('WARNING',[num2str(nbmissing) ' input files are missing or skipted'])
+    end
+    if isempty(time) % time read from files  prevails
+        time_end=[];
+        if isfield(Field,'Time')
+            time_end=Field.Time(1);%last time read
+            if ~isempty(time_1)
+                DataMean.Time=time_1;
+                DataMean.Time_end=time_end;
+            end
+        end
+    else  % time from ImaDoc prevails
+        DataMean.Time=time(1,num_i1{1}(1),num_j1{1}(1));
+        DataMean.Time_end=time(end,num_i1{end}(end),num_j1{end}(end));
+    end
+    
+    %writing the result file
+   if testima   
+%        if NbSlice==1
+        [filemean]=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.png',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end),subdir_result);
+%        else % label the file number by the slice # for simplicity
+%           [filemean]=name_generator(filebase_out,i_slice,1,'.png','_i');
+%        end
+        if exist(filemean,'file')
+            backupfile=filemean;
+            testexist=2;
+            while testexist==2
+                backupfile=[backupfile(1:end-4) '~.png'];
+                testexist=exist(backupfile,'file');
+            end
+            [success,message]=copyfile(filemean,backupfile);%make backup
+            if ~isequal(success,1)
+                msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])
+                return
+            end
+        end
+        if isequal(Atype{1},'uint16')
+            imwrite(uint16(DataMean.A),filemean,'BitDepth',16);
+        else
+            imwrite(uint8(DataMean.A),filemean,'BitDepth',8);
+        end
+        display([filemean ' written']);
+    else %determine global attributes
+        DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {Series.Action}];
+        ActionKey='Action';
+        while isfield(DataMean,ActionKey)
+            ActionKey=[ActionKey '_1'];
+        end
+        eval(['DataMean.' ActionKey '=Series.Action;'])
+        DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {ActionKey}];
+        if isfield(DataMean,'Time')
+            DataMean.ListGlobalAttribute=[DataMean.ListGlobalAttribute {'Time','Time_end'}];
+        end  
+%         if NbSlice==1
+          filemean=name_generator(filebase_out,num_i1{1}(1),num_j1{1}(1),'.nc',NomTypeOut,1,num_i2{end}(end),num_j2{end}(end),subdir_result);
+%         else % label the file number by the slice # for simplicity
+%           [filemean]=name_generator(filebase_out,i_slice,1,'.nc','_i');
+%         end
+        if exist(filemean,'file')
+            backupfile=filemean;
+            testexist=2;
+            while testexist==2
+                backupfile=[backupfile(1:end-3) '~.nc'];
+                testexist=exist(backupfile,'file');
+            end
+            [success,message]=copyfile(filemean,backupfile);%make backup
+            if ~isequal(success,1)
+                msgbox_uvmat('ERROR',['previous file result ' filemean ' already exists, problem in backup'])
+                display(['previous file result ' filemean ' already exists, problem in backup'])
+                return
+            end
+        end
+        errormsg=struct2nc(filemean,DataMean); %save result file
+        if isempty(errormsg)
+            display([filemean ' written']);
+        else
+            msgbox_uvmat('ERROR',['error in writting result file: ' errormsg])
+            display(errormsg)
+        end
+   end
+end
+hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
+delete(hget_field)
+uvmat(filemean)
Index: /trunk/src/series/check_files.m
===================================================================
--- /trunk/src/series/check_files.m	(revision 30)
+++ /trunk/src/series/check_files.m	(revision 30)
@@ -0,0 +1,189 @@
+function GUI_input=check_files(num_i1_cell,num_i2_cell,num_j1_cell,num_j2_cell,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %detect the chosen series of files and check their date of modification:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%INPUT: 
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+
+%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1_cell','var')
+    GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+        'RootFile';'on';... %root input file name ('on' by default)
+        'FileExt';'on';... %input file extension ('on' by default)
+        'NomType';'on';...%type of file indexing ('on' by default)
+        'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        %'VelTypeMenu';'on';...% menu for selecting the velocity type (civ1,..) 'off' by default)
+        %'FieldMenu';'on';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        %'CoordType';'on'...%can use a transform function 'off' by default
+        %'GetObject';'on'...%can use projection object ,'off' by default
+        %'GetMask';'on'...%can use mask option   ,'off' by default
+        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
+               ''};
+    return %exit the function 
+end
+
+%standard parameters for waitbar and STOP action (do not modify)
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+
+% number of slices
+NbSlice=str2num(get(hseries.NbSlice,'String'));
+if isempty(NbSlice)
+    NbSlice=1;
+end
+NbSlice_name=num2str(NbSlice);
+if isequal(NbSlice,[]),NbSlice=1; end; %default
+
+% number of views
+count=0; 
+testcell=iscell(Series.RootFile);
+if ~testcell
+    Series.RootPath={Series.RootPath};
+    Series.RootFile={Series.RootFile};
+    Series.SubDir={Series.SubDir};
+    Series.FileExt={Series.FileExt};
+    Series.NomType={Series.NomType};
+end    
+nbview=length(Series.RootFile);
+for iview=1:nbview
+    filebase=fullfile(Series.RootPath{iview},Series.RootFile{iview});%root file name
+    if testcell
+        num_i1=num_i1_cell{iview}; num_i2=num_i2_cell{iview}; num_j1=num_j1_cell{iview}; num_j2=num_j2_cell{iview};
+    else
+        num_i1=num_i1_cell; num_i2=num_i2_cell; num_j1=num_j1_cell; num_j2=num_j2_cell;
+    end
+    siz=size(num_i1);
+    nbfield2=siz(1); %nb of consecutive fields at each level(burst
+    nbfield=siz(1)*siz(2);
+    nbfield=floor(nbfield/(nbfield2*NbSlice));%total number of i indexes (adjusted to an integer number of slices)
+    if isequal(lower(Series.FileExt{iview}),'.avi')
+        info=aviinfo([filebase Series.FileExt{iview}]);
+        message{1}=info.Filename;
+        message{2}=info.FileModDate;
+        message{3}=[num2str(info.FramesPerSecond) ' frames/s '];
+        message{4}=info.ImageType;
+        message{5}=['  compression' info.VideoCompression];
+        message{6}=[ 'quality ' num2str(info.Quality)];   
+        Tabchar=message;
+    else
+        datnum=[];
+        Tabchar={};
+        %LOOP ON SLICES
+        for i_slice=1:NbSlice
+            for ifield=1:nbfield
+                indselect(:,ifield)=((ifield-1)*NbSlice+(i_slice-1))*nbfield2+[1:nbfield2]';%selected indices on the list of files of a slice
+            end 
+            for index=1:nbfield*nbfield2
+                stopstate=get(hseries.RUN,'BusyAction');
+                if isequal(stopstate,'queue')% enable STOP command
+                    update_waitbar(hseries.waitbar,WaitbarPos,index/(nbfield*nbfield2))
+                    ifile=indselect(index);               
+                    file=...
+                       name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2(ifile),num_j2(ifile),Series.SubDir{iview});                
+                    [Path,Name,ext]=fileparts(file);
+                    detect=exist(file,'file'); % check the existence of the file
+                    if detect==0
+                        count=count+1;
+                        lastfield='not found';
+                    else
+                        datfile=dir(file);
+                        datnum(ifile)=datenum(datfile.date);
+                        filefound(ifile)={datfile.name};
+                        lastfield='';
+                        if isequal(Series.FileExt{iview},'.nc') || isequal(Series.FileExt{iview},'.cdf')
+                            % check the content  netcdf file
+                            Data=nc2struct(file,'ListGlobalAttribute','patch2','fix2','civ2','patch','fix','absolut_time_T0','hart');
+                            if ~isempty(Data.patch2) && isequal(Data.patch2,1) 
+                                lastfield='patch2';
+                            elseif ~isempty(Data.fix2) && isequal(Data.fix2,1)
+                                lastfield='fix2';
+                            elseif ~isempty(Data.civ2) && isequal(Data.civ2,1);
+                                lastfield='civ2';
+                            elseif ~isempty(Data.patch) && isequal(Data.patch,1);
+                                lastfield='patch1';
+                            elseif ~isempty(Data.fix) && isequal(Data.fix,1);
+                                lastfield='fix1';
+                            elseif ~isempty(Data.absolut_time_T0) && ~isempty(Data.hart)
+                                lastfield='civ1'; 
+                            end                          
+                        end 
+                    end
+                    Tabchar(1,i_slice)={['slice #' num2str(i_slice)]};
+                    Tabchar(index+1,i_slice)={[file '   ' lastfield]};
+                end
+            end
+        end
+        if isempty(datnum)
+            if NbSlice>1
+                message=['no set of ' num2str(NbSlice) ' (NbSlices) files found'];
+            else
+                 message='no file found';
+            end
+        else
+            datnum=datnum(find(datnum));%keep the non zero values corresponding to existing files
+            [first,ind]=min(datnum);
+            [last,indlast]=max(datnum);
+            message={['oldest modification:  ' cell2mat(filefound(ind)) ' : ' datestr(first)];...
+                ['latest modification:  ' cell2mat(filefound(indlast)) ' : ' datestr(last)]};
+        end 
+        if ~isempty(Tabchar)
+          Tabchar=reshape(Tabchar,NbSlice*(nbfield*nbfield2+1),1);
+        end
+    end
+    hfig=figure(iview);
+    clf
+    if iview>1
+        pos=get(iview-1,'Position');
+        pos(1)=pos(1)+(iview-1)*pos(1)/nbview;
+        set(hfig,'Position',pos)
+    end
+    set(hfig,'name',['view= ' num2str(iview)])
+   
+    h=uicontrol('Style','listbox', 'Position', [20 20 500 300], 'String', Tabchar, 'Callback', @ncbrowser_uvmat);
+    hh=uicontrol('Style','listbox', 'Position', [20 340 500 40], 'String', message);
+end
+%----------------------------------------------------
+%  determine the list of index pairs of processing file 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
+num_i1=num_i;% set of first image numbers by default
+num_i2=num_i;
+num_j1=num_j;
+num_j2=num_j;
+num_i_out=num_i;
+num_j_out=num_j;
+if isequal (NomType,'_i1-i2_j') |isequal (NomType,'_i1-i2')
+    num_i1_line=num_i+ind_shift(3);% set of first image numbers
+    num_i2_line=num_i+ind_shift(4);
+    % adjust the first and last field number
+        indsel=find(num_i1_line >= 1);
+    num_i_out=num_i(indsel);
+    num_i1_line=num_i1_line(indsel);
+    num_i2_line=num_i2_line(indsel);
+    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
+    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
+    [xx,num_i1]=meshgrid(num_j,num_i1_line);
+    [xx,num_i2]=meshgrid(num_j,num_i2_line);
+elseif isequal (NomType,'_i_j1-j2') || isequal (NomType,'#_ab')
+    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
+        num_j1=ind_shift(1)*ones(size(num_i));
+        num_j2=ind_shift(2)*ones(size(num_i));
+    else
+        num_j1_col=num_j+ind_shift(1);% set of first image numbers
+        num_j2_col=num_j+ind_shift(2);
+        % adjust the first field number
+        indsel=find((num_j1_col >= 1));   
+        num_j_out=num_j(indsel);
+        num_j1_col=num_j1_col(indsel);
+        num_j2_col=num_j2_col(indsel);
+        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
+        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
+    end    
+end
Index: /trunk/src/series/clean_civ_cmx.m
===================================================================
--- /trunk/src/series/clean_civ_cmx.m	(revision 30)
+++ /trunk/src/series/clean_civ_cmx.m	(revision 30)
@@ -0,0 +1,63 @@
+function GUI_input=clean_civ_cmx(num_i1,num_i2,num_j1,num_j2,Series) %(filecell,filecell_1,num_i,num_j,vel_type,field,param);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ %detect the chosen series of files and check their date of modification:
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%INPUT: 
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+
+%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+    GUI_input={'RootPath';'many';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+        %'RootFile';'on';... %root input file name ('on' by default)
+        %'FileExt';'on';... %input file extension ('on' by default)
+        %'NomType';'on';...%type of file indexing ('on' by default)
+        %'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        %'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
+        %'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        %'CoordType';'on'...%can use a transform function 'off' by default
+        %'GetObject';'on'...%can use projection object ,'off' by default
+        %'GetMask';'on'...%can use mask option   ,'off' by default
+        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
+               ''};
+    return %exit the function 
+end
+%---------------------------------------------------------
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
+answer=msgbox_uvmat('INPUT_Y-N',message);
+if ~isequal(answer,'Yes')
+    return
+end
+nbdelete=0;
+testcell=iscell(Series.RootFile);
+if ~testcell
+    Series.RootPath={Series.RootPath};
+    Series.RootFile={Series.RootFile};
+    Series.SubDir={Series.SubDir};
+    Series.FileExt={Series.FileExt};
+    Series.NomType={Series.NomType};
+end 
+for iview=1:length(Series.RootFile)
+    hdir=dir(fullfile(Series.RootPath{iview},Series.SubDir{iview}));%list files
+    for ilist=1:length(hdir)
+        update_waitbar(hseries.waitbar,WaitbarPos,ilist/length(hdir))
+        FileName=hdir(ilist).name;
+        [dd,ff,Ext]=fileparts(FileName);
+        if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
+            delete(fullfile(Series.RootPath{iview},Series.SubDir{iview},FileName))
+            nbdelete=nbdelete+1;
+        end
+    end
+end
+msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete) ' files deleted by clean_civ_cmx'])
+
+
+
Index: /trunk/src/series/merge_proj.m
===================================================================
--- /trunk/src/series/merge_proj.m	(revision 30)
+++ /trunk/src/series/merge_proj.m	(revision 30)
@@ -0,0 +1,383 @@
+function GUI_input=merge_proj(num_i1,num_i2,num_j1,num_j2,Series);
+
+%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+        'RootFile';'on';... %root input file name ('on' by default)
+        'FileExt';'on';... %input file extension ('on' by default)
+        'NomType';'on';...%type of file indexing ('on' by default)
+        'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        'VelTypeMenu';'one';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
+        'FieldMenu';'one';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        'CoordType';'on';...%can use a transform function 'off' by default
+        'GetObject';'on';...%can use projection object ,'off' by default
+        %'GetMask';'on'...%can use mask option   ,'off' by default
+        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
+               ''};
+    return %exit the function 
+end
+
+%-------------------------------------------------
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position'); %positiopn of waitbar frame
+%-------------------------------------------------
+
+%numbers of view fields (nbre of inputs in RootPath)
+testcell=iscell(Series.RootFile);
+if ~testcell
+    Series.RootPath={Series.RootPath};
+    Series.RootFile={Series.RootFile};
+    Series.SubDir={Series.SubDir};
+    Series.FileExt={Series.FileExt};
+    Series.NomType={Series.NomType};
+    num_i1={num_i1};
+    num_i2={num_i2};
+    num_j1={num_j1};
+    num_j2={num_j2};
+end 
+nbview=length(Series.RootFile);%number of views (file series to merge)
+nbfield=size(num_i1{1},1)*size(num_i1{1},2);%number of fields in the time series
+transform=Series.CoordType; %  field transform function
+hhh=which('mmreader');
+for iview=1:nbview
+    test_movie(iview)=0;
+    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
+        if isequal(lower(FileExt{iview}),'.avi')
+            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
+            test_movie(iview)=1;
+        end
+    end 
+end
+
+%Calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+itime=0;
+NbSlice_calib={}; %test for z index 
+for iview=1:nbview%Loop on views
+    XmlData{iview}=[];%default
+    filebase{iview}=fullfile(Series.RootPath{iview},Series.RootFile{iview});
+    if exist([filebase{iview} '.xml'],'file')
+        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
+        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);
+            if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
+                msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
+            end
+        end    
+    elseif exist([filebase{iview} '.civ'],'file')
+        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+        itime=itime+1;
+        timecell{itime}=time;
+        XmlData{iview}.Time=time;
+        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+        GeometryCalib.Tx=0;
+        GeometryCalib.Ty=0;
+        GeometryCalib.Tz=1;
+        GeometryCalib.dpx=1;
+        GeometryCalib.dpy=1;
+        GeometryCalib.sx=1;
+        GeometryCalib.Cx=0;
+        GeometryCalib.Cy=0;
+        GeometryCalib.f=1;
+        GeometryCalib.kappa1=0;
+        GeometryCalib.CoordUnit='cm';
+        XmlData{iview}.GeometryCalib=GeometryCalib;
+        if error==1
+            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+        end
+    end
+end
+
+%check coincidence in time
+multitime=0;
+if length(timecell)==0
+    time=[];
+elseif length(timecell)==1
+    time=timecell{1};
+elseif length(timecell)>1
+    multitime=1;
+    for icell=1:length(timecell)
+        if ~isequal(size(timecell{icell}),size(timecell{1}))
+            msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used')
+            time=timecell{1};
+            multitime=0;
+            break
+        end
+    end
+end
+if multitime
+    for icell=1:length(timecell)
+        time(icell,:,:)=timecell{icell};
+    end
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)])
+    end   
+end
+if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 
+    time=[];
+end
+
+% Field and velocity type (the same for all views)
+Field_str=get(hseries.FieldMenu,'String');
+val=get(hseries.FieldMenu,'Value');
+FieldName=Field_str(val);%the same set of fields for all views
+VelType_str=get(hseries.VelTypeMenu,'String');
+VelType_val=get(hseries.VelTypeMenu,'Value');
+VelType=VelType_str{VelType_val}; %the same for all views
+if isequal(FieldName,'get_field...')
+    hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI
+   % hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+    SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI
+%     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
+%         list_transform=get(hhget_field.menu_coord,'String');
+%         val_list=get(hhget_field.menu_coord,'Value');
+%         transform=list_transform{val_list};
+%     end
+end
+%detect whether all the files are 'images' or 'netcdf'
+testima=0;
+testvol=0;
+testcivx=0;
+testnc=0;
+FileExt=get(hseries.FileExt,'String');
+for iview=1:nbview
+     ext=FileExt{iview};
+     form=imformats(ext([2:end]));
+     if isequal(lower(ext),'.vol')
+         testvol=testvol+1;
+     elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
+         testima=testima+1;
+     elseif isequal(ext,'.nc')
+         testnc=testnc+1;
+     end
+end
+if testvol
+    msgbox_uvmat('ERROR','volume images not implemented yet')
+    return
+end
+if testnc~=nbview && testima~=nbview && testvol~=nbview
+    msgbox_uvmat('ERROR','need a set of images or a set of netcdf files with the same fields as input')
+    return
+end
+if ~isequal(FieldName,'get_field...')
+    testcivx=testnc;
+end
+%name of output files and directory:
+% res_subdir=fullfile(Series.RootPath{1},[Series.SubDir{1} '_STAT']);
+ProjectDir=fileparts(fileparts(Series.RootPath{1}));% preoject directory (GERK)
+prompt={['result directory (in' ProjectDir ')']};
+RootPath=get(hseries.RootPath,'String');
+SubDir=get(hseries.SubDir,'String');
+if isequal(length(RootPath),1)
+    fulldir=RootPath{1};
+    subdir='GRID';
+    res_subdir=fullfile(fulldir,subdir);
+else
+    def={fullfile(ProjectDir,'0_RESULTS')};
+    dlgTitle='result directory';
+    lineNo=1;
+    answer=msgbox_uvmat('INPUT_TXT',dlgTitle,def);
+    fulldir=answer{1};
+    subdir=[];
+    dirlist=sort(Series.RootFile);
+    for iview=1:nbview
+        if ~isempty(subdir)
+            subdir=[subdir '-'];
+        end
+        subdir=[subdir dirlist{iview}];
+    end  
+    res_subdir=fullfile(fulldir,subdir);
+end
+ext=FileExt{1};
+if ~exist(fulldir,'dir')
+    msgbox_uvmat('ERROR',['directory ' fulldir ' needs to be created'])
+    return
+end
+if ~exist(res_subdir,'dir')
+    dircur=pwd;
+    cd(fulldir)
+    error=mkdir(subdir);
+    cd(dircur)
+end
+filebasesub=fullfile(res_subdir,Series.RootFile{1});
+filebase_merge=fullfile(res_subdir,'merged');%root name for the merged files
+
+%projection object
+if isfield(Series,'sethandles')
+    if ishandle(Series.sethandles.set_object)
+        Series.ProjObject=read_set_object(Series.sethandles);
+        if ~isfield(Series.ProjObject,'Style')
+            msgbox_uvmat('ERROR','Undefined projection object style')
+            return
+        end
+        if ~isequal(Series.ProjObject.Style,'plane')
+            msgbox_uvmat('ERROR','The projection object must be a plane')
+            return
+        end
+    end
+end
+
+    %MAIN LOOP
+for ifile=1:nbfield                
+    stopstate=get(hseries.RUN,'BusyAction');
+    if isequal(stopstate,'queue')% enable STOP command from the 'series' interface
+         update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield)
+         Amerge=0;
+         
+         %----------LOOP ON VIEWS----------------------
+        nbtime=0;
+        for iview=1:nbview
+            %name of the current file
+            filename=name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview});
+            if ~exist(filename,'file')
+                msgbox_uvmat('ERROR',['missing input file' filename])
+                break
+            end
+
+            %reading the current file
+            if testima
+                if test_movie(iview)
+                    Field{iview}.A=read(MovieObject{iview},num_i1{iview}(ifile));
+                else
+                    Field{iview}.A=read_image(filename,Series.NomType{iview},num_i1{iview}(ifile)); 
+                end % TODO: introduce ListVarName
+                npxy=size(Field{iview}.A);
+                Field{iview}.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers
+                Field{iview}.AY=[npxy(1)-0.5 0.5];
+                Field{iview}.CoordType='px'; 
+                Field{iview}.AName='image';
+            else
+                if testcivx
+                    [Field{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
+                else
+                    [Field{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data                
+                    Field{iview}.VarAttribute=SubField.VarAttribute;
+                end
+                if isfield(Field{iview},'Time')
+                    timeread(iview)=Field{iview}.Time;
+                    nbtime=nbtime+1;
+                end
+            end
+            % coord transform
+            % z index
+            if ~isempty(NbSlice_calib)
+                Field{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
+            end
+            if ~isequal(transform,'')
+                Field{iview}=feval(Series.CoordType,Field{iview},XmlData{iview});%transform to phys if requested
+            end
+            if testcivx
+                    Field{iview}=calc_field(FieldName,Field{iview});
+            end
+
+            %projection on object (gridded plane)
+            if isfield(Series,'ProjObject')
+                Field{iview}=proj_field(Field{iview},Series.ProjObject);
+            end
+        end    
+        
+         %----------END LOOP ON VIEWS----------------------
+         
+        %merge the nbview fields
+        MergeData=merge_field(Field);
+        if isfield(MergeData,'Txt')
+            msgbox_uvmat('ERROR',MergeData.Txt)
+            return
+        end
+        
+        % generating the name of the merged field
+        mergename=name_generator(filebase_merge,num_i1{iview}(ifile),num_j1{iview}(ifile),Series.FileExt{iview},Series.NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile));
+        
+        % time:
+        time_i=0;%default
+        if isempty(time)% time from ImaDoc prevails
+            time_i=sum(timeread)/nbtime;
+        else
+            time_i=(time(iview,num_i1{iview}(ifile),num_j1{iview}(ifile))+time(iview,num_i2{iview}(ifile),num_j2{iview}(ifile)))/2;
+        end
+        
+        % recording the merged field
+        if testima    %in case of input images an image is produced   
+            if isa(MergeData.A,'uint8')
+                bitdepth=8;
+            elseif isa(MergeData.A,'uint16')
+                bitdepth=16;
+            end
+            imwrite(MergeData.A,mergename,'BitDepth',bitdepth); 
+            %write xml calibration file
+            siz=size(MergeData.A);
+            npy=siz(1);
+            npx=siz(2);
+            if isfield(MergeData,'VarAttribute')&&isfield(MergeData.VarAttribute{1},'Coord_2')&&isfield(MergeData.VarAttribute{1},'Coord_1')
+                Rangx=MergeData.VarAttribute{1}.Coord_2;
+                Rangy=MergeData.VarAttribute{1}.Coord_1;
+            elseif isfield(MergeData,'AX')&& isfield(MergeData,'AY')
+                Rangx=[MergeData.AX(1) MergeData.AX(end)];
+                Rangy=[MergeData.AY(1) MergeData.AY(end)];
+            else
+                Rangx=[0.5 npx-0.5];
+                Rangy=[npy-0.5 0.5];%default
+            end
+            pxcmx=(npx-1)/(Rangx(2)-Rangx(1));
+            pxcmy=(npy-1)/(Rangy(1)-Rangy(2));
+            T_x=-pxcmx*Rangx(1)+0.5;
+            T_y=-pxcmy*Rangy(2)+0.5;
+            GeometryCal.focal=1;
+            GeometryCal.R=[pxcmx,0,0;0,pxcmy,0;0,0,1];
+            GeometryCal.Tx_Ty_Tz=[T_x T_y 1];
+            ImaDoc.GeometryCalib=GeometryCal;
+            t=struct2xml(ImaDoc);
+            t=set(t,1,'name','ImaDoc');
+            save(t,[filebase_merge '.xml'])     
+            display([filebase_merge '.xml saved'])
+        else
+            MergeData.ListGlobalAttribute={'Project','InputFile_1','InputFile_end','nb_coord','nb_dim','dt','Time','civ'};        
+            MergeData.nb_coord=2;
+            MergeData.nb_dim=2;
+            MergeData.dt=1;
+            MergeData.Time=time_i;
+            error=struct2nc(mergename,MergeData); %save result file
+            if isempty(error)
+                display(['output file ' mergename ' written'])
+            else
+                display(error)
+            end
+        end
+    end
+end
+
+%--------------------------------------------------------------------------   
+function MergeData=merge_field(Data)
+% initiate Matlab  structure for physical field
+if isempty(Data)||~iscell(Data)
+    MergeData=[];
+    return
+end
+MergeData=Data{1};%default
+error=0;
+nbview=length(Data);
+if nbview==1
+    return
+end
+for iview=1:nbview
+    if ~isequal(MergeData.ListDimName,Data{iview}.ListDimName)
+        error=1;
+    end
+    if ~isequal(MergeData.ListVarName,Data{iview}.ListVarName)
+        error=1;
+    end
+%      if ~isequal(MergeData.VarDimIndex,Data{iview}.VarDimIndex)
+%         error=1;
+%      end
+end
+if error
+    MergeData.Txt='ERROR: attempt at merging fields of incompatible type';
+    return
+end
Index: /trunk/src/series/sub_background.m
===================================================================
--- /trunk/src/series/sub_background.m	(revision 30)
+++ /trunk/src/series/sub_background.m	(revision 30)
@@ -0,0 +1,301 @@
+%----------------------------------------------------------------------
+% --- substract background to the images: rank the images by luminosity at each point and substracts to the images
+%----------------------------------------------------------------------
+% Method: 
+    %calculate the background image by sorting the luminosity of each point
+    % over a sliding sub-sequence of 'nbaver_ima' images. 
+    % The luminosity value of rank 'rank' is selected as the
+    % 'background'. rank=nbimages/2 gives the median value.  Smaller values are appropriate
+    % for a dense set of particles. The extrem value rank=1 gives the true minimum
+    % luminosity, but it can be polluted by noise. 
+% Organization of image indices:
+    % The program is working on a series of images, labelled by two indices i and j, given 
+    % by the input matlab vectors num_i1 and num_j1 respectively. In the list, j is the fastest increasing index.
+    % The processing can be done in slices (number nbslice), with bursts of
+    % nbfield2 successive images for a given slice (mode 'multilevel')
+    % In the mode 'volume', nbfield2=1 (1 image at each level), and
+    % nbslice=
+%INPUT:
+% num_i1: matrix of image indices i
+% num_j1: matrix of image indices j, must be the same size as num_i1
+% num_i2 and num_j2: not used for a function acting on images
+% Series: matlab structure containing parameters, as defined by the interface UVMAT/series
+%       Series.RootPath: path to the image series
+%       Series.RootFile: root file name
+%       Series.FileExt: image file extension 
+%       Series.NomType: nomenclature type for file indexing
+%       Series.NbSlice: %number of slices defined on the interface
+
+function GUI_input=sub_background (num_i1,num_i2,num_j1,num_j2,Series)
+
+%------------------------------------------------------------------------
+%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+    GUI_input={'RootPath';'on';...
+        'SubDir';'off';... % subdirectory of derived files (PIV fields), ('on' by default)
+        'RootFile';'on';... %root input file name ('on' by default)
+        'FileExt';'on';... %inputf file extension ('on' by default)
+        'NomType';'on';...%type of file indexing ('on' by default)
+        'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        %'VelTypeMenu';'on';...% menu for selecting the velocity type (civ1,..)('off' by default)
+        %'FieldMenu';'on';...% menu for selecting the velocity field (s) in the input file ('off' by default)
+        %'VelTypeMenu_1';'on';...% menu for selecting the velocity type (civ1,..)('off' by default)
+        %'FieldMenu_1';'on';...% menu for selecting the velocity field (s) in the input file ('off' by default)
+        %'CoordType';...%can use a transform function
+        %'GetObject';...;%can use projection object
+        %'GetMask';...;%can use mask option  
+        'PARAMETER';'NbSliding';...
+        'PARAMETER';'VolumeScan';...
+        'PARAMETER';'RankBrightness';...
+               ''};
+    return %exit the function 
+end
+
+%----------------------------------------------------------------
+% initiate the waitbar
+hseries=guidata(Series.hseries);%handles of the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position');
+%-----------------------------------------------------------------
+if iscell(Series.RootPath)
+    wardlg_uvmat('This function use only one input file series','ERROR')
+end
+
+nbslice_i=Series.NbSlice; %number of slices 
+siz=size(num_i1);
+nbaver_init=23;%approximate number of images used for the sliding background: to be adjusted later to include an integer number of bursts
+
+%adjust the proposed number of images in the sliding average to include an integer number of bursts
+if siz(2)~=1
+    nbaver=floor(nbaver_init/siz(1)); % number of bursts used for the sliding background, 
+    if isequal(floor(nbaver/2),nbaver)
+        nbaver=nbaver+1;%put the number of burst to an odd number (so the middle burst is defined)
+    end
+    nbaver_init=nbaver*siz(1);%propose by default an integer number of bursts
+end
+
+filebase=fullfile(Series.RootPath,Series.RootFile);
+dir_images=Series.RootPath;
+nom_type=Series.NomType;
+
+%create dir of the new images
+[dir_images,namebase]=fileparts(filebase);
+[path,subdir_ima]=fileparts(dir_images);
+curdir=pwd;
+cd(path);
+mkdir([subdir_ima '_b']);
+cd(curdir);
+filebase_b=fullfile(path,[subdir_ima '_b'],namebase);
+
+prompt = {'Number of images for the sliding background';'The number of positions (laser slices)';'volume scan mode (Yes/No)';...
+        'the luminosity rank chosen to define the background (0.1=for dense particle seeding, 0.5 (median) for sparse particles'};
+dlg_title = ['get (slice by slice) a sliding background and substract to each image, result in subdir ' subdir_ima '_b'];
+num_lines= 3;
+def     = { num2str(nbaver_init);num2str(nbslice_i);'No';'0.1'};
+answer = inputdlg(prompt,dlg_title,num_lines,def);
+set(hseries.ParamVal,'String',answer([1 [3:4]]))
+set(hseries.ParamVal,'Visible','on')
+
+nbaver_ima=str2num(answer{1});%number of images for the sliding background
+nbaver=ceil(nbaver_ima/siz(1))%number of bursts for the sliding background
+if isequal(floor(nbaver/2),nbaver)
+   nbaver=nbaver+1%put the number of burst to an odd number (so the middle burst is defined)
+end
+% if isequal(nbaver,round(nbaver))
+step=siz(1);%case of bursts: the sliding background is shifted by one burst 
+% else
+%    step=1;
+% end
+vol_test=answer{3};
+if isequal(vol_test,'Yes')
+    nbfield2=1;%case of volume: no consecutive series at a given level
+    nbslice_i=siz(1);%number of slices 
+else
+    nbfield2=siz(1); %nb of consecutive images at each level(burst)
+    if siz(2)>1
+       nbslice_i=str2num(answer{2})/(num_i1(1,2)-num_i1(1,1));% number of slices
+    else
+        nbslice_i=1;
+    end
+    if ~isequal(floor(nbslice_i),nbslice_i)
+        warndlg_uvmat('the number of slices must be a multiple of the i increment','ERROR')
+        return
+    end
+end
+% nbaver=floor(nbaver_init/nbfield2); % number of bursts used for the sliding background, 
+% if isequal(floor(nbaver/2),nbaver)
+%     nbaver=nbaver+1;%put the number of burst to an odd number 
+% end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%nbaver_ima=nbaver*nbfield2;% adjust the number of sliding images A  REMETRE
+% if ~isequal(nbaver_ima,nbaver_init)
+%     hwarn=warndlg(['number of images in the sliding average adjusted to ' num2str(nbaver_ima)]);
+%     set(hwarn,'Units','normalized')
+%     set(hwarn,'Position',[0.3 0.3 0.4 0.1])
+% end
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+rank=floor(str2num(answer{4})*nbaver_ima);
+if rank==0
+    rank=1;%rank selected in the sorted image series
+end
+lengthtot=siz(1)*siz(2);
+nbfield=floor(lengthtot/(nbfield2*nbslice_i));%total number of i indexes (adjusted to an integer number of slices)
+nbfield_slice=nbfield*nbfield2;% number of fields per slice
+% test_plot=isequal(answer{5},'Yes'); %=1 to display background images
+if nbaver_ima > nbfield*nbfield2
+    errordlg('number of images in a slice smaller than the proposed number of images for the sliding average')
+    return
+end
+nbfirst=(ceil(nbaver/2))*step;
+if nbfirst>nbaver_ima
+    nbfirst=ceil(nbaver_ima/2)
+    step=1;
+    nbaver=nbaver_ima;
+end
+
+%copy the xml file
+if exist([filebase '.xml'],'file')
+    copyfile([filebase '.xml'],[filebase_b '.xml']);% copy the .civ file
+    t=xmltree([filebase_b '.xml']);
+    
+    %update information on the first image name in the series
+    uid_Heading=find(t,'ImaDoc/Heading');
+    if isempty(uid_Heading)
+        [t,uid_Heading]=add(t,1,'element','Heading');
+    end   
+    uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
+    ImageName=name_generator(filebase_b,num_i1(1),num_j1(1),'.png',Series.NomType);
+    [pth,ImageName]=fileparts(ImageName);
+    ImageName=[ImageName '.png']
+    if isempty(uid_ImageName)
+       [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
+    end
+    uid_value=children(t,uid_ImageName);
+    if isempty(uid_value)
+        t=add(t,uid_ImageName,'chardata',ImageName)%indicate  name of the first image, with ;png extension
+    else
+        t=set(t,uid_value(1),'value',ImageName)%indicate  name of the first image, with ;png extension
+    end  
+
+    %add information about image transform
+    [t,new_uid]=add(t,1,'element','ImageTransform');
+    [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
+    [t]=add(t,NameFunction_uid,'chardata','sub_background');      
+    [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
+    [t]=add(t,new_uid,'chardata',num2str(nbslice_i));
+    [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
+    [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
+    [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
+    [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images 
+    save(t,[filebase_b '.xml'])
+elseif exist([filebase '.civ'],'file')
+    copyfile([filebase '.civ'],[filebase_b '.civ']);% copy the .civ file
+end
+%copy the mask
+if exist([filebase '_1mask_1'],'file')
+     copyfile([filebase '_1mask_1'],[filebase_b '_1mask_1']);% copy the mask file
+end
+
+%MAIN LOOP ON SLICES
+for islice=1:nbslice_i
+    %select the series of image indices at the level islice
+    for ifield=1:nbfield
+        for iburst=1:nbfield2
+            indselect(iburst,ifield)=((ifield-1)*nbslice_i+(islice-1))*nbfield2+iburst;
+        end
+    end  
+    %read the first series of nbaver_ima images and sort by luminosity at each pixel
+    for ifield = 1:nbaver_ima
+              ifile=indselect(ifield);
+                [filename,idetect]=...
+           name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt,Series.NomType);
+               Aread=imread(filename);
+               size(Aread)
+               if size(Aread,3)>1 %(color images)
+                   Aread=sum(Aread,3); %sum over color components
+               end
+                Ak(:,:,ifield)=Aread;           
+    end
+    Asort=sort(Ak,3);%sort the luminosity of images at each point
+    B=Asort(:,:,rank);%background image
+% 
+%     namemean=name_generator([filebase '_back'],islice,[],'.png','_i');% makes the file name
+%     imwrite(B,namemean,'BitDepth',16); % save the first background image
+%     ['background image for slice ' num2str(islice) ' saved in ' namemean]
+    %substract the background from each of the first images and save the new images
+%     for ifield=1:floor(nbaver_ima/2)+1 
+    'first background image will be substracted'
+
+    for ifield=1:nbfirst
+            Acor=double(Ak(:,:,ifield))-double(B);%substract background to the current image
+            Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
+            C=uint16(Acor);% set to integer 16 bits
+            ifile=indselect(ifield);
+            newname=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',nom_type)% makes the new file name
+            imwrite(C,newname,'BitDepth',16); % save the new image
+    end
+    %repeat the operation on a sliding series of nbaver*nbfield2 images
+    'sliding background image will be substracted'
+    if nbfield_slice > nbaver_ima
+%         for ifield = floor(nbaver_ima/2)+2:step:nbfield_slice-floor(nbaver_ima/2)
+        for ifield = step*ceil(nbaver/2)+1:step:nbfield_slice-step*floor(nbaver/2)
+            stopstate=get(hseries.RUN,'BusyAction');
+            if isequal(stopstate,'queue')% enable STOP command
+%                 waitbarpos(4)=((ifield+(islice-1)*nbfield_slice)/(nbfield_slice*nbslice_i))*Series.WaitbarPos(4);
+%                 waitbarpos(2)=Series.WaitbarPos(4)+Series.WaitbarPos(2)-waitbarpos(4);
+%                 set(hwaitbar,'Position',waitbarpos)
+%                 drawnow
+                update_waitbar(hseries.waitbar,WaitbarPos,(ifield+(islice-1)*nbfield_slice)/(nbfield_slice*nbslice_i))
+                (ifield+(islice-1)*nbfield_slice)/(nbfield_slice*nbslice_i)
+                Ak(:,:,[1:nbaver_ima-step])=Ak(:,:,[1+step:nbaver_ima]);% shift the current image series by one burst (step)
+                %incorporate next burst in the current image series
+                for iburst=1:step
+                    ifile=indselect(ifield+step*floor(nbaver/2)+iburst-1);
+                    [filename,idetect]=...
+                       name_generator(filebase,num_i1(ifile),num_j1(ifile),Series.FileExt,Series.NomType);
+                    Aread=imread(filename);
+                    if size(Aread,3)>1 %(color images)
+                       Aread=sum(Aread,3); %sum over color components
+                    end
+                    Ak(:,:,nbaver_ima-step+iburst)=Aread;
+                end
+                Asort=sort(Ak,3);%sort the new current image series by luminosity
+                B=Asort(:,:,rank);%current background image
+                for iburst=1:step
+%                     Acor=double(Ak(:,:,floor(nbaver_ima/2)+iburst-1))-double(B);
+                    index=step*floor(nbaver/2)+iburst;
+                    Acor=double(Ak(:,:,index))-double(B);
+                    Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
+                    C=uint16(Acor);
+                    ifile=indselect(ifield+iburst-1);
+                    [newname]=...
+                       name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',Series.NomType)
+%                     newname=name_generator(filebase_b,num_i1(indselect(ifield+iburst-1)),num_j1(indselect(ifield+iburst-1)),'.png',nom_type)% makes the new file name
+                    imwrite(C,newname,'BitDepth',16); % save the new image
+                end  
+            else
+                return
+            end
+        end
+    end
+
+%substract the background from the last images
+%     for ifield=nbfield_slice-floor(nbaver_ima/2)+1:nbfield_slice
+     'last background image will be substracted'
+     ifield=nbfield_slice-(step*ceil(nbaver/2))+1:nbfield_slice;
+    for ifield=nbfield_slice-(step*floor(nbaver/2))+1:nbfield_slice  
+        index=ifield-nbfield_slice+step*(2*floor(nbaver/2)+1);
+        Acor=double(Ak(:,:,index))-double(B);
+        Acor=(Acor>0).*Acor; % put to 0 the negative elements in Acor
+        C=uint16(Acor);
+        ifile=indselect(ifield);
+        newname=name_generator(filebase_b,num_i1(ifile),num_j1(ifile),'.png',nom_type)% makes the new file name
+        imwrite(C,newname,'BitDepth',16); % save the new image
+    end
+end
+
+%finish the waitbar
+update_waitbar(hseries.waitbar,WaitbarPos,1)
+
+
+    
+    
Index: /trunk/src/series/time_series.m
===================================================================
--- /trunk/src/series/time_series.m	(revision 30)
+++ /trunk/src/series/time_series.m	(revision 30)
@@ -0,0 +1,720 @@
+function GUI_input=time_series(num_i1,num_i2,num_j1,num_j2,Series) 
+%----------------------------------------------------------------------
+% --- make a time series analysis
+%----------------------------------------------------------------------
+%INPUT: 
+%num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_i2: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ)
+%num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ )
+%num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ)
+%OTHER INPUTS given by the structure Series
+
+%requests for the visibility of input windows in the GUI series  (activated directly by the selection in the menu ACTION)
+if ~exist('num_i1','var')
+    GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one')
+        'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default)
+        'RootFile';'on';... %root input file name ('on' by default)
+        'FileExt';'on';... %input file extension ('on' by default)
+        'NomType';'on';...%type of file indexing ('on' by default)
+        'NbSlice';'on'; ...%nbre of slices ('off' by default)
+        'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default)
+        'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
+        'CoordType';'on';...%can use a transform function 'off' by default
+        'GetObject';'on';...%can use projection object ,'off' by default
+        %'GetMask';'on'...%can use mask option   ,'off' by default
+        %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter 
+               ''};
+    return %exit the function 
+end
+
+%------------------------------------------------------
+hseries=guidata(Series.hseries);%handles in the GUI series
+WaitbarPos=get(hseries.waitbar_frame,'Position'); %position of the waitbar frame
+
+%projection object
+test_object=get(hseries.GetObject,'Value');
+if test_object%isfield(Series,'sethandles')
+    Series.ProjObject=read_set_object(Series.sethandles);
+    %answeryes=questdlg({['field series projected on ' Series.ProjObject.Style]});
+    answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' Series.ProjObject.Style]);
+    if ~isequal(answeryes,'Yes')
+        return
+    end
+else
+    msgbox_uvmat('ERROR','a projection object is needed');
+    return
+end
+
+% root names
+if iscell(Series.RootPath)
+    RootPath=Series.RootPath;
+    RootFile=Series.RootFile;
+    SubDir=Series.SubDir;
+    FileExt=Series.FileExt;
+    NomType=Series.NomType;
+else
+    RootPath={Series.RootPath};
+    RootFile={Series.RootFile};
+    SubDir={Series.SubDir};
+    FileExt={Series.FileExt};
+    NomType={Series.NomType};
+    num_i1={num_i1};
+    num_i2={num_i2};
+    num_j1={num_j1};
+    num_j2={num_j2};
+end
+ext=FileExt{1};
+form=imformats(ext([2:end]));%test valid Matlab image formats
+testima=0;
+if ~isempty(form)||isequal(lower(ext),'.avi')
+    testima=1;
+end
+nbview=length(RootPath);%number of series (1 or 2)
+nbfield=size(num_i1{1},1)*size(num_i1{1},2); %number of fields in the time series
+
+%Number of input series: this function  accepts only a single input file series 
+nbview=length(RootPath);
+if nbview==2
+    %TODO: choose between difference and two series
+elseif nbview>2  % TODO: make multiple series
+%     RootPath=RootPath(1:2);
+%     set(hseries.RootPath,'String',RootPath)
+%     SubDir=SubDir(1:2);
+%     set(hseries.SubDir,'String',SubDir)
+%     RootFile=RootFile(1:2);
+%     set(hseries.RootFile,'String',RootFile)
+%     NomType=NomType(1:2);
+%     %set(hseries.NomType,'String',NomType)
+%     FileExt=FileExt(1:2);
+%     set(hseries.FileExt,'String',FileExt)
+%     nbview=2;
+end
+hhh=which('mmreader');
+for iview=1:nbview
+    test_movie(iview)=0;
+    if ~isequal(hhh,'')&& mmreader.isPlatformSupported()
+        if isequal(lower(FileExt{iview}),'.avi')
+            MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}]));
+            test_movie(iview)=1;
+        end
+    end 
+end
+filebase{1}=fullfile(RootPath{1},RootFile{1});
+
+% number of slices
+NbSlice=str2num(get(hseries.NbSlice,'String'));
+if isempty(NbSlice)
+    NbSlice=1;
+end
+NbSlice_name=num2str(NbSlice);
+
+% Field and velocity type (the same for the two views)
+if isfield(Series,'Field')
+    FieldName=Series.Field;%the same set of fields for all views
+else
+    FieldName={''};
+end
+if isequal(FieldName,{'get_field...'})
+    hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI
+    if numel(hget_field)>1
+        delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld
+    elseif isempty(hget_field)
+       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1}); 
+       idetect(iview)=exist(filename,'file');
+       hget_field=get_field(filename);
+       return
+    end
+    %hhget_field=guidata(hget_field);%handles of GUI elements in get_field
+    SubField=read_get_field(hget_field) %read the names of the variables to plot in the get_field GUI
+    if isempty(SubField)
+        delete(hget_field)
+       filename=name_generator(filebase{1},num_i1{1}(1),num_j1{1}(1),FileExt{1},NomType{1},1,num_i2{1}(1),num_j2{1}(1),SubDir{1});
+        hget_field=get_field(filename);
+        SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI
+    end
+%     if isequal(get(hhget_field.menu_coord,'Visible'),'on')
+%         list_transform=get(hhget_field.menu_coord,'String');
+%         val_list=get(hhget_field.menu_coord,'Value');
+%         transform=list_transform{val_list};
+%     end
+end
+
+%detect whether the two files are 'images' or 'netcdf'
+testima=0;
+testvol=0;
+testcivx=0;
+testnc=0;
+FileExt=get(hseries.FileExt,'String');
+for iview=1:nbview
+     ext=FileExt{iview};
+     form=imformats(ext([2:end]));
+     if isequal(lower(ext),'.vol')
+         testvol=testvol+1;
+     elseif ~isempty(form)||isequal(lower(ext),'.avi')% if the extension corresponds to an image format recognized by Matlab
+         testima=testima+1;
+     elseif isequal(ext,'.nc')
+         testnc=testnc+1;
+     end
+end
+if testvol
+    msgbox_uvmat('ERROR','volume images not implemented yet')
+    return
+end
+if testnc~=nbview && testima~=nbview && testvol~=nbview
+    msgbox_uvmat('need a set of images or a set of netcdf files with the same fields as input','ERROR')
+    return
+end
+if ~isequal(FieldName,{'get_field...'})
+    testcivx=testnc;
+end
+
+% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES)
+filebasesub=fullfile(RootPath{1},RootFile{1});
+if NbSlice==1
+    filebase_out=[filebasesub '_time'];
+else
+    filebase_out=[filebasesub '_' NbSlice_name 'mtim'];
+    increment=num_i1{1}(2)-num_i1{1}(1);
+    if ~isequal(increment,1) % if an increment is set
+        answeryes=msgbox_uvmat('INPUT_Y-N',['will take time series in ' num2str(NbSlice) 'slices with increment = ' num2str(increment) '!']); 
+    else    
+        answeryes=msgbox_uvmat('INPUT_Y-N',{['will take time series in ' num2str(NbSlice) ' slices'];['results stored as files ' filebase_out ' ...']});
+    end
+    if ~isequal(answeryes,'Yes')
+        return
+    end
+end
+VelType_str=get(hseries.VelTypeMenu,'String');
+VelType_val=get(hseries.VelTypeMenu,'Value');
+VelType{1}=VelType_str{VelType_val};
+if nbview==2
+    VelType_str=get(hseries.VelTypeMenu_1,'String');
+    VelType_val=get(hseries.VelTypeMenu_1,'Value');
+    VelType{2}=VelType_str{VelType_val};
+end
+
+%Calibration data and timing: read the ImaDoc files
+mode=''; %default
+timecell={};
+XmlData={};
+itime=0;
+NbSlice_calib={};
+for iview=1:nbview%Loop on views
+    XmlData{iview}=[];%default
+    filebase{iview}=fullfile(RootPath{iview},RootFile{iview});
+    if exist([filebase{iview} '.xml'],'file')
+        [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); 
+        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 field series');
+            end
+        end 
+    elseif exist([filebase{iview} '.civ'],'file')
+        [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']);
+        itime=itime+1;
+        timecell{itime}=time;
+        XmlData{iview}.Time=time;
+        GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0];
+        GeometryCalib.Tx=0;
+        GeometryCalib.Ty=0;
+        GeometryCalib.Tz=1;
+        GeometryCalib.dpx=1;
+        GeometryCalib.dpy=1;
+        GeometryCalib.sx=1;
+        GeometryCalib.Cx=0;
+        GeometryCalib.Cy=0;
+        GeometryCalib.f=1;
+        GeometryCalib.kappa1=0;
+        GeometryCalib.CoordUnit='cm';
+        XmlData{iview}.GeometryCalib=GeometryCalib;
+        if error==1
+            msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file');
+        end
+    end
+end
+
+%check coincidence in time
+multitime=0;
+if length(timecell)==0
+    time=[];
+elseif length(timecell)==1
+    time=timecell{1};
+elseif length(timecell)>1
+    multitime=1;
+    for icell=1:length(timecell)
+        if ~isequal(size(timecell{icell}),size(timecell{1}))
+            warndlg_uvmat('inconsistent time array dimensions in ImaDoc fields, the time for the first series is used','WARNING')
+            time=timecell{1};
+            multitime=0;
+            break
+        end
+    end
+end
+if multitime
+    for icell=1:length(timecell)
+        time(icell,:,:)=timecell{icell};
+    end
+    diff_time=max(max(diff(time)));
+    if diff_time>0
+        warndlg_uvmat(['times of series differ by more than ' num2str(diff_time)],'WARNING')
+    end   
+end
+if size(time,2) < num_i2{1}(end) || size(time,3) < num_j2{1}(end)% ime array absent or too short in ImaDoc xml file' 
+    time=[];
+end
+
+% image or scalar processing programme set by user
+Coord_menu=get(hseries.CoordType,'String');
+menu_val=get(hseries.CoordType,'Value');
+usrfct=Coord_menu{menu_val};
+testfct=~isequal(usrfct,'');
+
+% to update:
+VelType_str=get(hseries.VelTypeMenu,'String');
+VelType_val=get(hseries.VelTypeMenu,'Value');
+VelType{1}=VelType_str{VelType_val};
+if nbview==2
+    VelType_str=get(hseries.VelTypeMenu_1,'String');
+    VelType_val=get(hseries.VelTypeMenu_1,'Value');
+    VelType{2}=VelType_str{VelType_val};
+end
+
+%LOOP ON SLICES
+for i_slice=1:NbSlice
+     dt=[];
+     nbmissing=0; %number of undetected files
+     nbfiles=0;
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%LOOP ON FIELDS IN  A SLICE
+    for ifile=i_slice:NbSlice:nbfield  
+        stopstate=get(hseries.RUN,'BusyAction');
+        if isequal(stopstate,'queue')% enable STOP command
+             update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) 
+             for iview=1:nbview
+                filename=...
+                           name_generator(filebase{iview},num_i1{iview}(ifile),num_j1{iview}(ifile),FileExt{iview},NomType{iview},1,num_i2{iview}(ifile),num_j2{iview}(ifile),SubDir{iview}); 
+                idetect(iview)=exist(filename,'file');
+                Data{iview}=[]; %default      
+                if testima                  
+                    Data{iview}.ListVarName={'A'};
+                    Data{iview}.AName='image';
+                    if test_movie(iview)
+                        A=read(MovieObject{iview},num_i1{iview}(ifile));
+                    else
+                        A=double(read_image(filename,NomType{iview},num_i1{iview}(ifile)));% read the image, num2 is the counter for avi files 
+                    end
+                    Data{iview}.ListVarName={'coord_y','coord_x','A'}; % 
+                    npy=size(A,1);
+                    npx=size(A,2);
+                    nbcolor=size(A,3);
+                    if nbcolor==3
+                         Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x','rgb'}};
+                    else
+                         Data{iview}.VarDimName={'coord_y','coord_x',{'coord_y','coord_x'}};
+                    end  
+                    Data{iview}.coord_y=[npy-0.5 0.5];
+                    Data{iview}.coord_x=[0.5 npx-0.5];
+                    Data{iview}.A=A;
+                    Data{iview}.CoordType='px';
+                elseif testcivx
+                    [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType);
+                else
+                    [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data                
+                    Data{iview}.VarAttribute=SubField.VarAttribute;
+                end
+                if ~isempty(NbSlice_calib)  % z index
+                    Data{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
+                end
+             end
+            % geometry transform or other user defined transform
+            if ~isequal(Series.CoordType,'')           
+                if nbview==2
+                    [Data{1},Data{2}]=feval(Series.CoordType,Data{1},XmlData{1},Data{2},XmlData{2});
+                    if isempty(Data{2})
+                        Data(2)=[];
+                    end
+                else
+                    Data{1}=feval(Series.CoordType,Data{1},XmlData{1});
+                end
+            end
+            if testcivx
+                    Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..)
+            end
+            if length(Data)==2
+                [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields
+                if ~isempty(errormsg)
+                    msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg])
+                    return
+                end
+            else
+                Field=Data{1};
+            end
+            if isfield(Series,'ProjObject')
+                Series.ProjObject
+                [Field,errormsg]=proj_field(Field,Series.ProjObject);
+                if ~isempty(errormsg)
+                    msgbox_uvmat('ERROR',['error in time_series/proj_field:' errormsg])
+                    return
+                end
+            end
+            if min(idetect)>=1% the input file(s) have been detected          
+                nbfiles=nbfiles+1;
+                if nbfiles==1 %first field: initiate the time series
+                    RecordData=Field;%default
+                    RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots         
+                    nbvar=length(Field.ListVarName);
+                    if nbvar==0
+                        msgbox_uvmat('ERROR','no input variable selected in get_field')
+                        return
+                    end
+                    testsum=2*ones(1,nbvar);%initiate flag for action on each variable
+                    indexfalse=0;
+                    CoordName={};
+                    indexremove=[];
+                    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')
+                                    msgbox_uvmat('ERROR','do not handle error flags in time series')
+                                    return                                               
+                                end
+                                if isequal(var_role,'warnflag')                        
+                                    testsum(ivar)=0;  % not recorded variable 
+                                    eval(['RecordData=rmfield(RecordData,''' 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
+                                % check whether the variable ivar is a dimension variable
+                                %index=Field.VarDimIndex{ivar};%dimension indices of the variable #ivar
+                                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
+                    end
+                    for ivar=1:nbvar
+                        if testsum(ivar)==2                     
+                            eval(['RecordData.' Field.ListVarName{ivar} '=[];'])
+                        end
+                    end
+                    RecordData.ListVarName=[{'Time'} RecordData.ListVarName];
+                end
+                for ivar=1:length(Field.ListVarName)
+                    VarName=Field.ListVarName{ivar};
+                    eval(['VarVal=Field.' VarName ';']);
+                    if testsum(ivar)==2% test for recorded variable 
+                        eval(['VarVal=Field.' VarName ';']);
+                        if isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
+                            if isempty(VarVal)
+                                msgbox_uvmat('ERROR',['empty result at frame index ' num2str(num_i1{iview}(ifile))])
+                                return                             
+                            end
+                            VarVal=mean(VarVal,1);
+                        end
+                        VarVal=shiftdim(VarVal,-1); %shift dimension 
+                        eval(['RecordData.' VarName '=cat(1,RecordData.' VarName ',VarVal);']);%concanete the current field to the time series    
+                    elseif testsum(ivar)==1% variable representing fixed coordinates
+                        eval(['VarInit=RecordData.' VarName ';']);
+                        if ~isequal(VarVal,VarInit)
+                            msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName])
+                            return
+                        end
+                    end                 
+                end
+                % time:
+                if isempty(time)% time read in ncfiles
+                   if isfield(Field,'Time')
+                       RecordData.Time(nbfiles,1)=Field.Time;
+                   else
+                       RecordData.Time(nbfiles,1)=nbfiles;%default
+                   end
+                else % time from ImaDoc prevails
+                    RecordData.Time(nbfiles,1)=(time(1,num_i1{1}(ifile),num_j1{1}(ifile))+time(end,num_i2{end}(ifile),num_j2{end}(ifile)))/2;
+                end
+            else
+                nbmissing=nbmissing+1;
+            end
+        end
+    end
+    %remove time for global attributes if exists
+    for iattr=1:numel(RecordData.ListGlobalAttribute) 
+        if strcmp(RecordData.ListGlobalAttribute{iattr},'Time')
+            RecordData.ListGlobalAttribute(iattr)=[];
+            break
+        end
+    end
+    for ivar=1:numel(RecordData.ListVarName)
+        VarName=RecordData.ListVarName{ivar};
+        eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons
+    end
+        % add time dimension and update VarDimIndex:
+   %if ~isequal(Series.ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode
+        for ivar=1:length(Field.ListVarName)
+%              vardimindex=Field.VarDimIndex{ivar};% array of dimension indices for variable VarIndex(ivar)
+             DimCell=Field.VarDimName(ivar);
+             if testsum(ivar)==2%variable used as time series
+%                  RecordData.VarDimIndex{ivar}=[1 vardimindex+1];
+                  RecordData.VarDimName{ivar}=[{'Time'} DimCell];
+             elseif testsum(ivar)==1
+%                  RecordData.VarDimIndex{ivar}=[vardimindex+1];
+                 RecordData.VarDimName{ivar}=DimCell;
+             end
+        end
+   % end
+    indexremove=find(~testsum);
+    if ~isempty(indexremove)
+        RecordData.ListVarName(1+indexremove)=[];
+        RecordData.VarDimName(indexremove)=[];
+        if isfield(RecordData,'Role')&~isempty(RecordData.Role{1})%generaliser aus autres attributs
+            RecordData.Role(1+indexremove)=[];
+        end
+    end
+    %RecordData.VarDimIndex=[{[1]} RecordData.VarDimIndex]; %time dimension
+    %shift variable attributes
+    if isfield(RecordData,'VarAttribute')
+        RecordData.VarAttribute=[{[]} RecordData.VarAttribute];
+    end 
+    RecordData.VarDimName=[{'Time'} RecordData.VarDimName];
+    RecordData.Action=Series.Action;%name of the processing programme
+    %name of result file
+    [filemean]=...
+               name_generator(filebase_out,num_i1{1}(i_slice),num_j1{1}(i_slice),'.nc','_i1-i2_j1-j2',1,num_i2{end}(ifile),num_j2{end}(ifile),SubDir{1});
+    errormsg=struct2nc(filemean,RecordData); %save result file
+    if isempty(errormsg)
+        display([filemean ' written'])
+    else
+        msgbox_uvmat('ERROR',['error in Series/struct2nc' errormsg])
+    end
+end
+figure
+haxes=axes;
+
+plot_field(RecordData,haxes)
+hget_field=findobj(allchild(0),'name','get_field');
+if ~isempty(hget_field)
+    delete(hget_field)
+end
+get_field(filemean,RecordData)
+    
+%-----------------------------------------------------------------------
+% --- Executes on selection change in CoordType.
+function CoordType_Callback(hObject, eventdata, handles)
+menu_str=get(handles.CoordType,'String');
+ind_coord=get(handles.CoordType,'Value');
+coord_option=menu_str{ind_coord};
+if isequal(coord_option,'more...'); 
+    fct_name='';
+    if exist('./TMP/current_usr_fct.mat','file')% if a file is found
+        h=load('./TMP/current_usr_fct.mat');
+        if isfield(h,'fct_name'); 
+            fct_name=h.fct_name;
+        end
+    end
+    prompt = {'Enter the name of the transform function'};
+    dlg_title = 'user defined transform';
+    num_lines= 1;
+    [FileName, PathName, filterindex] = uigetfile( ...
+       {'*.m', ' (*.m)';
+        '*.m',  '.m files '; ...
+        '*.*', 'All Files (*.*)'}, ...
+        'Pick a file', fct_name);
+    fct_name=fullfile(PathName,FileName);
+    addpath(PathName);%add the path to the selected fct
+    [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER
+    if ~exist(fct_name,'file')
+           warndlg(['image procesing fct ' fct_name ' not found'])
+    else
+        transform=FileName(1:end-2);% 
+        update_menu(handles.CoordType,transform)%add the selected fct to the menu
+  %      set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu 
+      %save ('./TMP/current_usr_fct.mat','fct_name');
+    end   
+end
+ind_coord=get(handles.CoordType,'Value');   
+
+%---------------------------------------------------------------------
+% --- Executes on selection change in ProjObject.
+function ProjObject_Callback(hObject, eventdata, handles)
+
+list_object=get(handles.ProjObject,'String');
+index=get(handles.ProjObject,'Value');
+hseries=get(handles.ProjObject,'Parent');
+SeriesData=get(hseries,'UserData');
+Obj=SeriesData.ProjObject{index};
+[SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index});
+set(hseries,'UserData',SeriesData);
+
+%-------------------------------------------------------------
+%generates a series of file names with reference numbers between range1 and
+%range2 with increment incr. The reference number num_ref is the image number at the middle of the
+%image pair. The set of first numbers num1 of the image pairs is also
+%given as output
+%------------------------------------------------------
+function [num_i1,num_i2,num_j1,num_j2,nbmissing]=netseries_generator(filebase,subdir,mode,first_i,incr_i,last_i,first_j,incr_j,last_j)
+[Path,Name]=fileparts(filebase);
+filebasesub=fullfile(Path,subdir,Name);
+filecell={};%default
+num_i1=[];
+num_i2=[];
+num_j1=[];
+num_j2=[];
+ind0_i=first_i:incr_i:last_i;
+nbcolumn=length(ind0_i);
+ind0_j=first_j:incr_j:last_j;
+nbline=length(ind0_j);
+if isequal(mode,'#_ab')
+    dirpair=dir([filebasesub '*_*.nc']);
+elseif isequal(mode,'bursts')|isequal(mode,'series(Dj)')  
+    dirpair=dir([filebasesub '_*_*-*.nc']);
+elseif isequal(mode,'series(Di)')
+    dirpair=dir([filebasesub '_*-*_*.nc']);
+else
+    errordlg('option *|* not yet implemented')
+    return
+end
+if isempty(dirpair)
+        errordlg('no pair detected in the selected range')
+        return
+end
+    %ind0_i=first_i:incr_i:last_i;
+    %nbcolumn=length(ind0_i);
+    %dirpair=dir([filebasesub '_*_*-*.nc']);
+if isequal(mode,'bursts')|isequal(mode,'#_ab')
+    icount=0;
+    for ifile=1:length(dirpair)
+        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
+        
+%         if isempty(str2num(str_1))
+%             dirpair(ifile).name
+%         end
+        num1_r=str2num(str_1);
+        if isequal(RootFile,Name) & ~isempty(num1_r)   
+            num_i1(ifile)=num1_r;
+            num_a(ifile)=stra2num(str_a);
+            num_b(ifile)=stra2num(str_b);
+%             icount=icount+1;
+        end      
+    end
+    length(dirpair)
+%     num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
+    test_range= (num_i1 >=first_i)&(num_i1<= last_i);% =1 when both numbers are in the range
+    ind_i=((num_i1-first_i)/incr_i)+1;%indices i in the list of prescribed file indices 
+    select=find(test_range &(floor(ind_i)==ind_i));%selected indices of num_i1 in the file directory
+    ind_i=ind_i(select);%set of selected indices ind_i
+    [ind_i,indsort]=sort(ind_i);%sorted list of ind_i
+    select=select(indsort);
+    num_i1=num_i1(select);
+    num_a=num_a(select);
+    num_b=num_b(select);
+    dirpair=dirpair(select);
+    [ind_remove]=find_pairs(dirpair,ind_i,nbcolumn); 
+    ind_i(ind_remove)=[];
+    num_a(ind_remove)=[];
+    num_b(ind_remove)=[];
+    num_j1=zeros(1,nbcolumn);%default
+    num_j2=num_j1;
+    num_j1(ind_i)=num_a;
+    num_j2(ind_i)=num_b;
+    num_i1=first_i:incr_i:last_i;
+    num_i2=num_i1;
+    nbmissing=nbcolumn-length(ind_i);
+
+elseif isequal(mode,'series(Di)') 
+    %ind0_i=first_i:incr_i:last_i;
+    %nbcolumn=length(ind0_i);
+    %ind0_j=first_j:incr_j:last_j;
+    %nbline=length(ind0_j);
+    %dirpair=dir([filebasesub '_*-*_*.nc']);
+    for ifile=1:length(dirpair)
+        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
+        num_i1_r(ifile)=str2num(str_1);
+        num_i2_r(ifile)=str2num(str_2);
+        num_j(ifile)=str2num(str_a);
+    end
+    num_i=floor((num_i1_r+num_i2_r)/2); %list of reference indices of the detected files
+    test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
+    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices 
+    ind_j=((num_j-first_j)/incr_j)+1;
+    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
+    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
+    ind_ij=ind_ij(select);%set of selected indices ind_ij
+    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij 
+    select=select(indsort);
+    num_i1_r=num_i1_r(select);
+    num_i2_r=num_i2_r(select);
+%     num_j=num_j(select);
+    dirpair=dirpair(select);
+    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
+    ind_ij(ind_remove)=[];
+    num_i1_r(ind_remove)=[];
+    num_i2_r(ind_remove)=[];
+    num_i1=zeros(1,nbline*nbcolumn);%default
+    num_i2=num_i1;
+    num_i1(ind_ij)=num_i1_r;
+    num_j2(ind_ij)=num_i2_r;
+    num_i1=reshape(num_i1,nbline,nbcolumn);
+    num_i2=reshape(num_i2,nbline,nbcolumn);
+    num_j1=meshgrid(ind0_i,ind0_j);
+    num_j2=num_j1;
+    nbmissing=nbline*nbcolumn-length(ind_ij);
+elseif isequal(mode,'series(Dj)')
+ %   ind0_i=first_i:incr_i:last_i;
+ %   nbcolumn=length(ind0_i);
+ %   ind0_j=first_j:incr_j:last_j;
+  %  nbline=length(ind0_j);
+  %  dirpair=dir([filebasesub '_*_*-*.nc']);
+    for ifile=1:length(dirpair)
+        [RootPath,RootFile,str_1,str_2,str_a,str_b,ext,nom_type]=name2display(dirpair(ifile).name);
+        num_i(ifile)=str2num(str_1);
+        num_a(ifile)=str2num(str_a);
+        num_b(ifile)=str2num(str_b);
+    end
+    num_j=floor((num_a+num_b)/2); %list of reference indices of the detected files
+    test_range= (num_i >=first_i)&(num_i<= last_i)&(num_j >=first_j)&(num_j<= last_j);% =1 when both numbers are in the range
+    ind_i=((num_i-first_i)/incr_i)+1;%indices i and j in the list of prescribed file indices 
+    ind_j=((num_j-first_j)/incr_j)+1;
+    ind_ij=ind_j+nbline*(ind_i-1);%indices in the reshhaped series of prescribed file indices
+    select=find(test_range &(floor(ind_i)==ind_i)&(floor(ind_j)==ind_j));%selected indices in the file directory
+    ind_ij=ind_ij(select);%set of selected indices ind_ij
+    [ind_ij,indsort]=sort(ind_ij);%sorted list of ind_ij 
+    select=select(indsort);
+    num_i=num_i(select);
+    num_a=num_a(select);
+    num_b=num_b(select);
+    dirpair=dirpair(select);
+    [ind_remove]=find_pairs(dirpair,ind_ij,nbcolumn*nbline) ;
+    ind_ij(ind_remove)=[];
+    num_a(ind_remove)=[];
+    num_b(ind_remove)=[];
+    num_j1=zeros(1,nbline*nbcolumn);%default
+    num_j2=num_j1;
+    num_j1(ind_ij)=num_a;
+    num_j2(ind_ij)=num_b;
+    num_j1=reshape(num_j1,nbline,nbcolumn);
+    num_j2=reshape(num_j2,nbline,nbcolumn);
+    num_i1=meshgrid(ind0_i,ind0_j);
+    num_i2=num_i1;
+    nbmissing=nbline*nbcolumn-length(ind_ij);
+%     for i=1:length(indsel);%A SUPPRIMER ULTERIEUREMENT
+%         if indsel(i)==0
+%             filecell{i}='';
+%         else
+%             Name=dirpair(indsel(i)).name;
+%             filecell{i}=fullfile(Path,subdir,Name);
+%         end
+%     end
+%else
+%    errordlg('option *|* not yet implemented')
+%    return
+end
Index: /trunk/src/update_imadoc.m
===================================================================
--- /trunk/src/update_imadoc.m	(revision 20)
+++ /trunk/src/update_imadoc.m	(revision 30)
@@ -10,4 +10,5 @@
 testappend=0;
 if exist(outputfile,'file');%=1 if the output file already exists, 0 else  
+    testappend=1;
     t=xmltree(outputfile); %read the file
     backupfile=outputfile;
@@ -28,11 +29,4 @@
         [t,uid_calib]=add(t,1,'element','GeometryCalib');
     else %if GeometryCalib already exists, delete its content
-%         backupfile=outputfile;
-%         testexist=2;
-%         while testexist==2
-%            backupfile=[backupfile '~'];
-%            testexist=exist(backupfile,'file');
-%         end
-%         [success,message]=copyfile(outputfile,backupfile);%make backup
         if isequal(success,1)
             delete(outputfile)
@@ -42,5 +36,4 @@
         uid_child=children(t,uid_calib);
         t=delete(t,uid_child);
-        testappend=1;
     end
 end
@@ -49,5 +42,4 @@
     t=set(t,1,'name','ImaDoc');
     [t,uid_calib]=add(t,1,'element','GeometryCalib');
-%     t=struct2xml(GeometryCalib,t,uid_calib);
 end
 t=struct2xml(GeometryCalib,t,uid_calib); 
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 20)
+++ /trunk/src/uvmat.m	(revision 30)
@@ -325,5 +325,12 @@
 else
    if ishandle(handles.UVMAT_title)
-        set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; 'version 2.2.beta';date_str};errormsg]);
+       fid=fopen('revision.log')
+       if fid
+        a=textscan(fid,'%s%s%s',1,'HeaderLines',1,'Delimiter','|');
+        set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; ['at revision ' a{1}{1}]};a{3}{1};errormsg]);
+        fclose(fid);
+       else
+           set(handles.UVMAT_title,'String',[{'Copyright Joel Sommeria, 2008, Coriolis/ LEGI / CNRS-UJF-INPG';'GNU General Public License'; path_to_uvmat; 'version 2.2.beta';date_str};errormsg]);
+       end
    end
 end
@@ -470,10 +477,25 @@
 %----------------------------------------------------------------
 function display_file_name(hObject, eventdata, handles,fileinput)
+if ~exist(fileinput,'file')
+    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
+    return
+end
 [RootPath,RootFile,i1,i2,str_a,str_b,ext,NomType,SubDir]=name2display(fileinput);
-form=imformats(ext(2:end));%test valid Matlab image formats
-if ~isempty(form)
-    ext_test='.image';
-    imainfo=imfinfo(fileinput);  
-    if length(imainfo) >1 %case of image with multiple frames
+ext_test=''; %default
+if ~isempty(ext) 
+    form=imformats(ext(2:end));%test valid Matlab image formats
+    if ~isempty(form)
+        ext_test='.image';
+        imainfo=imfinfo(fileinput);  
+        if length(imainfo) >1 %case of image with multiple frames
+            i1='1'; % set the frame counter to 1 by default
+            i2='';
+            str_a='';
+            str_b='';
+            NomType='*'; %indicate a set of indexed frames within a single file
+            [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
+        end
+    elseif isequal(lower(ext),'.avi')
+        ext_test='.image';
         i1='1'; % set the frame counter to 1 by default
         i2='';
@@ -482,15 +504,7 @@
         NomType='*'; %indicate a set of indexed frames within a single file
         [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
-    end
-elseif isequal(lower(ext),'.avi')
-    ext_test='.image';
-    i1='1'; % set the frame counter to 1 by default
-    i2='';
-    str_a='';
-    str_b='';
-    NomType='*'; %indicate a set of indexed frames within a single file
-    [RootPath,RootFile]=fileparts(fileinput); %include the indices in the root file
-else
-    ext_test=lower(ext);
+    else
+        ext_test=lower(ext);
+    end
 end
 switch ext_test
