Index: /trunk/src/get_field.m
===================================================================
--- /trunk/src/get_field.m	(revision 1071)
+++ /trunk/src/get_field.m	(revision 1072)
@@ -317,5 +317,5 @@
 
 %% set z coordinate menu if relevant
-if Field.MaxDim>=3 && prod(Field.DimValue)<10^8 && ~isempty(ParamIn.Coord_z); % 3D field (with memory content smaller than 400 Mo)
+if Field.MaxDim>=3 && prod(Field.DimValue)<10^8 && ~(isfield(ParamIn,'Coord_z') && isempty(ParamIn.Coord_z)) % 3D field (with memory content smaller than 400 Mo)
     set(handles.Check3D,'Value',1)
 else
Index: /trunk/src/mouse_down.m
===================================================================
--- /trunk/src/mouse_down.m	(revision 1071)
+++ /trunk/src/mouse_down.m	(revision 1072)
@@ -288,5 +288,5 @@
 
 %% selection of an existing projection object (third priority)
-if  test_edit 
+if  test_edit && ~strcmp(get(hcurrentobject,'Type'),'figure')
     testdeform=0;
     if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
@@ -360,9 +360,4 @@
                end
             end
-%             if testdeform==0
-%                 AxeData.Drawing='translate';
-%                 set(AxeData.CurrentObject,'Selected','on')
-%                 set(gcbo,'Pointer','fleur');
-%             end
         else
             if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
@@ -433,12 +428,24 @@
     h_set_object=findobj(allchild(0),'Tag','set_object');
     hh_set_object=guidata(h_set_object);
-    if strcmp(ObjectData.Type,'plane_z')&& ~isempty(ObjectData.Coord)
-        Delta_x=(xy(1,1)-ObjectData.Coord(1,1));%displacement along x
-        Delta_y=(xy(1,2)-ObjectData.Coord(1,2));%displacement along y
-        ObjectData.Angle(1)=(180/pi)*angle(Delta_x+i*Delta_y);
-        ObjectData.Angle(2)=90;       
-        set(hh_set_object.num_Angle_1,'String',num2str(ObjectData.Angle(1)))
-        set(hh_set_object.num_Angle_2,'String',num2str(ObjectData.Angle(2)))
-         drawing_status='off';
+    if strcmp(ObjectData.Type,'plane')
+        if isempty(ObjectData.Coord)||(isfield(ObjectData,'RangeX') && size(ObjectData.RangeX,2)==2)% draw a new plane
+            ObjectData.Coord=xy(1,1:2);% record the coordinates marked by the mouse as origin of the new plane
+            set(hh_set_object.Coord,'Data',ObjectData.Coord);%append the current mouse cordinates in the GUI set_object
+            set(hh_set_object.num_RangeX_2,'String','')
+            set(hh_set_object.num_Angle_1,'String','0')
+            drawing_status='create';
+        else
+            Delta_x=(xy(1,1)-ObjectData.Coord(1,1));%displacement along x
+            Delta_y=(xy(1,2)-ObjectData.Coord(1,2));%displacement along y
+            ObjectData.Angle(1)=(180/pi)*angle(Delta_x+i*Delta_y);
+            ObjectData.Angle(2)=90;
+            ObjectData.RangeX(1)=0;
+            ObjectData.RangeX(2)=abs(Delta_x+i*Delta_y);
+            set(hh_set_object.num_Angle_1,'String',num2str(ObjectData.Angle(1)))
+            set(hh_set_object.num_Angle_2,'String',num2str(ObjectData.Angle(2)))
+            set(hh_set_object.num_RangeX_1,'String',num2str(ObjectData.RangeX(1)))
+            set(hh_set_object.num_RangeX_2,'String',num2str(ObjectData.RangeX(2)))
+            drawing_status='off';
+        end
     else
         ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object
Index: /trunk/src/mouse_motion.m
===================================================================
--- /trunk/src/mouse_motion.m	(revision 1071)
+++ /trunk/src/mouse_motion.m	(revision 1072)
@@ -402,5 +402,5 @@
     if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin)
         switch ObjectData.Type
-            case {'line','polyline','polygon','points','plane_z'}
+            case {'line','polyline','polygon','points'}
                 ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];
                 % ObjectData.Coord(end,:)=xy(1,:);
Index: /trunk/src/mouse_up.m
===================================================================
--- /trunk/src/mouse_up.m	(revision 1071)
+++ /trunk/src/mouse_up.m	(revision 1072)
@@ -95,5 +95,5 @@
     else
         switch ObjectData.Type
-            case {'line','plane_z'}
+            case {'line','plane'}
                 if size(ObjectData.Coord,1)==1 % this is the mouse up for the first point, continue until next click
                     check_multiple=1;
@@ -106,14 +106,14 @@
                     check_multiple=1;% pass to next mous up if width of height=0
                 end
-            case 'plane' %case of 'plane', TODO: NOT ACTIVATED
-                DX=(xy(1,1)-ObjectData.Coord(1,1));
-                DY=(xy(1,2)-ObjectData.Coord(1,2));
-                ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle width
-                if isfield(ObjectData,'RangeX')
-                    XMax=sqrt(DX*DX+DY*DY);
-                    if XMax>max(ObjectData.RangeX)
-                        ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
-                    end
-                end
+%             case 'plane' %case of 'plane', TODO: NOT ACTIVATED
+%                 DX=(xy(1,1)-ObjectData.Coord(1,1));
+%                 DY=(xy(1,2)-ObjectData.Coord(1,2));
+%                 ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle width
+%                 if isfield(ObjectData,'RangeX')
+%                     XMax=sqrt(DX*DX+DY*DY);
+%                     if XMax>max(ObjectData.RangeX)
+%                         ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
+%                     end
+%                 end
             otherwise
                 check_multiple=1;
Index: /trunk/src/proj_field.m
===================================================================
--- /trunk/src/proj_field.m	(revision 1071)
+++ /trunk/src/proj_field.m	(revision 1072)
@@ -999,4 +999,7 @@
     end
     PlaneAngle=(pi/180)*ObjectData.Angle;
+    if PlaneAngle==0
+        PlaneAngle=[0 0];
+    end
     %     om=norm(PlaneAngle);%norm of rotation angle in radians
     %     OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
@@ -1009,9 +1012,9 @@
     %     norm_plane(3)=OmAxis(3)*coeff+cos_om;
     
-    M1=[cos(PlaneAngle(1)) sin(PlaneAngle(1)) 0;-sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1];
+    M1=[cos(PlaneAngle(1)) -sin(PlaneAngle(1)) 0;sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1];
     M=M1;
     if checkM2
-        M2=[1 0 0;0 cos(PlaneAngle(2)) sin(PlaneAngle(2));0 -sin(PlaneAngle(2)) cos(PlaneAngle(2))];
-        M=M2*M1;% first rotate in the x,y plane with angle PlaneAngle(1), then slant around the new x axis0 with angle PlaneAngle(2)
+        M2=[1 0 0;0 cos(PlaneAngle(2)) -sin(PlaneAngle(2));0 sin(PlaneAngle(2)) cos(PlaneAngle(2))];
+        M=M1*M2;% first rotate in the x,y plane with angle PlaneAngle(1), then slant around the new x axis0 with angle PlaneAngle(2)
     end
     norm_plane=M*[0 0 1]';
@@ -1038,7 +1041,4 @@
 end
 InterpMesh=min(DX,DY);%mesh used for interpolation in a slanted plane
-% if strcmp(ObjectData.Type,'plane_z')
-%     InterpMesh=10*InterpMesh;%TODO: temporary, to shorten computation
-% end
 
 %% extrema along each axis
@@ -1126,19 +1126,5 @@
 % end
 icell_grid=[];% field cell index which defines the grid
-if ~strcmp(ObjectData.ProjMode,'projection')&& ~strcmp(ObjectData.Type,'plane_z')% TODO:rationalize
-    %% define the new coordinates in case of interpolation on a imposed grid
-    if ~testYMin
-        errormsg='min Y value not defined for the projection grid';return
-    end
-    if ~testYMax
-        errormsg='max Y value not defined for the projection grid';return
-    end
-    if ~testXMin
-        errormsg='min X value not defined for the projection grid';return
-    end
-    if ~testXMax
-        errormsg='max X value not defined for the projection grid';return
-    end
-else
+if strcmp(ObjectData.ProjMode,'projection')
     %% case of a grid requested by the input field
     for icell=1:numel(CellInfo)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates
@@ -1162,5 +1148,5 @@
         end
     end
-    if ~isempty(find(check_grid))% if a grid is requested by the input field
+    if ~isempty(find(check_grid,1))% if a grid is requested by the input field
         if isempty(icell_grid)%  if the grid is not given by cell #icell_grid
             if ~isfield(FieldData,'XMax')
@@ -1169,10 +1155,25 @@
         end
     end
-end
-if ~isempty(find(check_grid))||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used
+else
+    %% define the new coordinates in case of interpolation on a imposed grid
+    if ~testYMin
+        errormsg='min Y value not defined for the projection grid';return% %%%%%%%%%%%%%%%%        A REVOIR
+
+    end
+    if ~testYMax
+        errormsg='max Y value not defined for the projection grid';return
+    end
+    if ~testXMin
+        errormsg='min X value not defined for the projection grid';return
+    end
+    if ~testXMax
+        errormsg='max X value not defined for the projection grid';return
+    end
+end
+if ~isempty(find(check_grid,1))||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used
     if isempty(icell_grid)||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used
         AYName='coord_y';
         AXName='coord_x';
-        if strcmp(ObjectData.ProjMode,'projection')||strcmp(ObjectData.Type,'plane_z')
+        if strcmp(ObjectData.ProjMode,'projection')||strcmp(ObjectData.Type,'plane')
             ProjData.coord_y=[FieldData.YMin FieldData.YMax];%note that if projection is done on a grid, the Min and Max along each direction must have been defined
             ProjData.coord_x=[FieldData.XMin FieldData.XMax];
@@ -1472,5 +1473,5 @@
             end
             
-            if isequal(ProjMode{icell},'projection')% && (~testangle || test90y || test90x)
+            if strcmp(ProjMode{icell},'projection')% && (~testangle || test90y || test90x)
                 if  NbDim==2 && ~testXMin && ~testXMax && ~testYMin && ~testYMax% no range restriction
                     ListVarName=[ListVarName FieldData.ListVarName(VarIndex)];
@@ -1653,5 +1654,5 @@
                         if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
                             VarAttribute{length(ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
-                        end;
+                        end
                         ProjData.(FFName)=isnan(ProjData.(VarName));%detact NaN (points outside the interpolation range)
                         ProjData.(VarName)(ProjData.(FFName))=0; %set to 0 the NaN data
@@ -1661,5 +1662,5 @@
                     VarDimName=[VarDimName {DimCell}];
                     VarAttribute{numel(ListVarName)}.Role='errorflag';
-                elseif ~testangle
+                elseif ~testangle % 3Dcase without change of angle
                     % unstructured z coordinate
                     test_sup=(Coord{1}>=ObjectData.Coord(1,3));
@@ -1683,16 +1684,17 @@
                     % determine the boundaries of the projected field,
                     % first find the 8 summits of the initial volume in the
-                    PlaneAngle=ObjectData.Angle*pi/180;
+                    PlaneAngle=[0 0 0];% default
+                    PlaneAngle(1:numel(ObjectData.Angle))=ObjectData.Angle*pi/180;
                     % new coordinates
                     Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});%initial z coordinates
                     Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)});%initial y coordinates
                     Coord{3}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(3)});%initial x coordinates
-                    summit=zeros(3,8);% initialize summit coordinates
-                    summit(1,1:4)=[Coord{3}(1) Coord{3}(end) Coord{3}(1) Coord{3}(end)];%square
-                    summit(2,1:4)=[Coord{2}(1) Coord{2}(1) Coord{2}(end) Coord{2}(end)];% square at z= Coord{1}(1)
-                    summit(1:2,5:8)=summit(1:2,1:4);
-                    summit(3,:)=[Coord{1}(1)*ones(1,4) Coord{1}(end)*ones(1,4)];
-                    %Mrot_inv=rodrigues(-PlaneAngle);
-                    newsummit=zeros(3,8);% initialize the rotated summit coordinates
+%                     summit=zeros(3,8);% initialize summit coordinates
+%                     summit(1,1:4)=[Coord{3}(1) Coord{3}(end) Coord{3}(1) Coord{3}(end)];%square
+%                     summit(2,1:4)=[Coord{2}(1) Coord{2}(1) Coord{2}(end) Coord{2}(end)];% square at z= Coord{1}(1)
+%                     summit(1:2,5:8)=summit(1:2,1:4);
+%                     summit(3,:)=[Coord{1}(1)*ones(1,4) Coord{1}(end)*ones(1,4)];
+%                     %Mrot_inv=rodrigues(-PlaneAngle);
+%                     newsummit=zeros(3,8);% initialize the rotated summit coordinates
                     ObjectData.Coord=ObjectData.Coord';% set ObjectData.Coord as a vertical vector
                     if size(ObjectData.Coord,1)<3
@@ -1700,17 +1702,20 @@
                     end
                     
-                    M1=[cos(PlaneAngle(1)) sin(PlaneAngle(1)) 0;-sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1];
-                    M2=[1 0 0;0 cos(PlaneAngle(2)) sin(PlaneAngle(2));0 -sin(PlaneAngle(2)) cos(PlaneAngle(2))];
-                    M=M2*M1;
+%                     M1=[cos(PlaneAngle(1)) sin(PlaneAngle(1)) 0;-sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1];
+%                     M2=[1 0 0;0 cos(PlaneAngle(2)) sin(PlaneAngle(2));0 -sin(PlaneAngle(2)) cos(PlaneAngle(2))];
+%                     M=M1*M2;
                     M_inv=inv(M);
                     
-                    for isummit=1:8% TODO: introduce a function for rotation of n points (to use also for scattered data)
-                        newsummit(:,isummit)=M*(summit(:,isummit)-(ObjectData.Coord));
-                    end
-                    coord_x_proj=min(newsummit(1,:)):InterpMesh: max(newsummit(1,:));% set of coordinqtes in the projection plane
-                    coord_y_proj=min(newsummit(2,:)):InterpMesh: max(newsummit(2,:));
-                    coord_z_proj=-width:width;
+%                     for isummit=1:8% TODO: introduce a function for rotation of n points (to use also for scattered data)
+%                         newsummit(:,isummit)=M*(summit(:,isummit)-(ObjectData.Coord));
+%                     end
+%                     coord_x_proj=min(newsummit(1,:)):InterpMesh: max(newsummit(1,:));% set of coordinqtes in the projection plane
+%                     coord_y_proj=min(newsummit(2,:)):InterpMesh: max(newsummit(2,:));
+%                     coord_z_proj=-width:width;
+                    coord_x_proj=ObjectData.RangeX(1):InterpMesh:ObjectData.RangeX(2);% set of coordinqtes in the projection plane
+                     coord_y_proj=ObjectData.RangeY(1):InterpMesh:ObjectData.RangeY(2);
+                    coord_z_proj=-floor(ObjectData.RangeInterp/InterpMesh):InterpMesh:floor(ObjectData.RangeInterp/InterpMesh);
                     %Mrot=rodrigues(PlaneAngle);% inverse rotation matrix
-                    Origin=M_inv*[coord_x_proj(1);coord_y_proj(1);coord_z_proj(1)]+ObjectData.Coord;
+                    %Origin=M_inv*[coord_x_proj(1);coord_y_proj(1);coord_z_proj(1)]+ObjectData.Coord;
                     npx=numel(coord_x_proj);
                     npy=numel(coord_y_proj);
@@ -1722,5 +1727,9 @@
                     iX=[coord_x_proj(end)-coord_x_proj(1);0;0]/(npx-1);
                     iY=[0;coord_y_proj(end)-coord_y_proj(1);0]/(npy-1);
+                    if npz==1
+                        iZ=[0;0;0];
+                    else
                     iZ=[0;0;coord_z_proj(end)-coord_z_proj(1)]/(npz-1);
+                    end
                     %                     iX(1:2)=[cosphi -sinphi;sinphi cosphi]*iX(1:2);
                     %                     iY(1:2)=[-cosphi -sinphi;sinphi cosphi]*iY(1:2);
@@ -1731,4 +1740,5 @@
                     
                     [Grid_x,Grid_y,Grid_z]=meshgrid(0:npx-1,0:npy-1,0:npz-1);
+                    %[Grid_x,Grid_y,Grid_z]=meshgrid(0:npz-1,0:npy-1,0:npx-1);
                     if ismatrix(Grid_x)% add a singleton in case of a single z value
                         Grid_x=shiftdim(Grid_x,-1);
@@ -1736,8 +1746,8 @@
                         Grid_z=shiftdim(Grid_z,-1);
                     end
-                    XI=Origin(1)+ix(1)*Grid_x+iy(1)*Grid_y+iz(1)*Grid_z;
-                    YI=Origin(2)+ix(2)*Grid_x+iy(2)*Grid_y+iz(2)*Grid_z;
-                    ZI=Origin(3)+ix(3)*Grid_x+iy(3)*Grid_y+iz(3)*Grid_z;
-                    [X,Y,Z]=meshgrid(Coord{3},Coord{2},Coord{1});% mesh in the initial coordinates
+                    XI=ObjectData.Coord(1)+ix(1)*Grid_x+iy(1)*Grid_y+iz(1)*Grid_z;
+                    YI=ObjectData.Coord(2)+ix(2)*Grid_x+iy(2)*Grid_y+iz(2)*Grid_z;
+                    ZI=ObjectData.Coord(3)+ix(3)*Grid_x+iy(3)*Grid_y+iz(3)*Grid_z;
+                  %  [X,Y,Z]=meshgrid(Coord{3},Coord{2},Coord{1});% grid of initial coordinates
                     for ivar=VarIndex
                         VarName=FieldData.ListVarName{ivar};
@@ -1745,9 +1755,11 @@
                         VarDimName=[VarDimName {{'coord_y','coord_x'}}];
                         VarAttribute{length(ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
-                        FieldData.(VarName)=permute(FieldData.(VarName),[2 3 1]);
+                        FieldData.(VarName)=permute(FieldData.(VarName),[2 3 1]); %coordinate permutation needed to use interp3
+                        indexnan=isnan(FieldData.(VarName));
+                        FieldData.(VarName)(indexnan)=0;%set to zero the undefined values
                         ProjData.coord_x=coord_x_proj;
                         ProjData.coord_y=coord_y_proj;
-                        ProjData.(VarName)=interp3(X,Y,Z,double(FieldData.(VarName)),XI,YI,ZI,'*linear');
-                        ProjData.(VarName)=nanmean(ProjData.(VarName),3);
+                        ProjData.(VarName)=interp3(Coord{3},Coord{2},Coord{1},double(FieldData.(VarName)),ZI,YI,XI,'*linear');
+                        ProjData.(VarName)=nanmean(ProjData.(VarName),1);
                         ProjData.(VarName)=squeeze(ProjData.(VarName));
                     end
Index: /trunk/src/series.m
===================================================================
--- /trunk/src/series.m	(revision 1071)
+++ /trunk/src/series.m	(revision 1072)
@@ -1452,4 +1452,7 @@
     Param.TransformInput=SeriesData.TransformInput;
 end
+if isfield(SeriesData,'ProjObject')
+    Param.ProjObject=SeriesData.ProjObject;
+end
 if ~isfield(SeriesData,'i1_series')
     errormsg='The input field series needs to be refreshed: press REFRESH';
@@ -1602,43 +1605,47 @@
 NbExp=1;% initiate the number of experiments set by the GUI browse_data, =1 otherwise
 if get(handles.Replicate,'Value')
-    set(handles.Replicate,'BackgroundColor',[1 1 0])%paint Relicate button in yellow
     hh=findobj(allchild(0),'Tag','browse_data');
-    BrowseData=guidata(hh);
-    SourceDir=get(BrowseData.SourceDir,'String');
-    ListExp=get(BrowseData.ListExperiments,'String');
-    ExpIndices=get(BrowseData.ListExperiments,'Value');
-    ListExp=ListExp(ExpIndices);
-    ListDevices=get(BrowseData.ListDevices,'String');
-    DeviceIndices=get(BrowseData.ListDevices,'Value');
-    ListDevices=ListDevices(DeviceIndices);
-    ListDataSeries=get(BrowseData.DataSeries,'String');
-    DataSeriesIndices=get(BrowseData.DataSeries,'Value');
-    ListDataSeries=ListDataSeries(DataSeriesIndices);
-    NbExp=0; % counter of the number of experiments set by the GUI browse_data
-    for iexp=1:numel(ListExp)
-        if ~isempty(regexp(ListExp{iexp},'^\+/'))% if it is a folder
-            if strcmp(get(BrowseData.DataSeries,'enable'),'off');%case of a multiple input line for series
-                NbExp=NbExp+1;
-                ExpIndex{NbExp}=iexp;
-                for idevice=1:numel(ListDevices)
-                    lpath= fullfile(SourceDir,regexprep(ListExp{iexp},'^\+/',''),...
-                        regexprep(ListDevices{idevice},'^\+/',''));
-                    ldir=regexprep(ListDataSeries{idevice},'^\+/','');
-                    ListPath{idevice,NbExp}=lpath;
-                    ListSubdir{idevice,NbExp}=ldir;
-                end
-            else
-                for idevice=1:numel(ListDevices)
-                    if ~isempty(regexp(ListDevices{idevice},'^\+/'))% if it is a folder
-                        for isubdir=1:numel(ListDataSeries)
-                            if ~isempty(regexp(ListDataSeries{isubdir},'^\+/'))% if it is a folder
-                                lpath= fullfile(SourceDir,regexprep(ListExp{iexp},'^\+/',''),...
-                                    regexprep(ListDevices{idevice},'^\+/',''));
-                                ldir= regexprep(ListDataSeries{isubdir},'^\+/','');
-                                if exist(fullfile(lpath,ldir),'dir')
-                                    NbExp=NbExp+1;
-                                    ExpIndex{NbExp}=iexp;
-                                    ListPath{NbExp}=lpath;
-                                    ListSubdir{NbExp}=ldir;
+    if isempty(hh)
+        set(handles.Replicate,'Value',0)
+    else
+        set(handles.Replicate,'BackgroundColor',[1 1 0])%paint Relicate button in yellow
+        BrowseData=guidata(hh);
+        SourceDir=get(BrowseData.SourceDir,'String');
+        ListExp=get(BrowseData.ListExperiments,'String');
+        ExpIndices=get(BrowseData.ListExperiments,'Value');
+        ListExp=ListExp(ExpIndices);
+        ListDevices=get(BrowseData.ListDevices,'String');
+        DeviceIndices=get(BrowseData.ListDevices,'Value');
+        ListDevices=ListDevices(DeviceIndices);
+        ListDataSeries=get(BrowseData.DataSeries,'String');
+        DataSeriesIndices=get(BrowseData.DataSeries,'Value');
+        ListDataSeries=ListDataSeries(DataSeriesIndices);
+        NbExp=0; % counter of the number of experiments set by the GUI browse_data
+        for iexp=1:numel(ListExp)
+            if ~isempty(regexp(ListExp{iexp},'^\+/'))% if it is a folder
+                if strcmp(get(BrowseData.DataSeries,'enable'),'off');%case of a multiple input line for series
+                    NbExp=NbExp+1;
+                    ExpIndex{NbExp}=iexp;
+                    for idevice=1:numel(ListDevices)
+                        lpath= fullfile(SourceDir,regexprep(ListExp{iexp},'^\+/',''),...
+                            regexprep(ListDevices{idevice},'^\+/',''));
+                        ldir=regexprep(ListDataSeries{idevice},'^\+/','');
+                        ListPath{idevice,NbExp}=lpath;
+                        ListSubdir{idevice,NbExp}=ldir;
+                    end
+                else
+                    for idevice=1:numel(ListDevices)
+                        if ~isempty(regexp(ListDevices{idevice},'^\+/'))% if it is a folder
+                            for isubdir=1:numel(ListDataSeries)
+                                if ~isempty(regexp(ListDataSeries{isubdir},'^\+/'))% if it is a folder
+                                    lpath= fullfile(SourceDir,regexprep(ListExp{iexp},'^\+/',''),...
+                                        regexprep(ListDevices{idevice},'^\+/',''));
+                                    ldir= regexprep(ListDataSeries{isubdir},'^\+/','');
+                                    if exist(fullfile(lpath,ldir),'dir')
+                                        NbExp=NbExp+1;
+                                        ExpIndex{NbExp}=iexp;
+                                        ListPath{NbExp}=lpath;
+                                        ListSubdir{NbExp}=ldir;
+                                    end
                                 end
                             end
@@ -1648,8 +1655,8 @@
             end
         end
-    end
-    answer=msgbox_uvmat('INPUT_Y-N-Cancel',['replicate the processing on ' num2str(NbExp) ' data series']);
-    if strcmp(answer,'Cancel')||strcmp(answer,'No')
-        return
+        answer=msgbox_uvmat('INPUT_Y-N-Cancel',['replicate the processing on ' num2str(NbExp) ' data series']);
+        if strcmp(answer,'Cancel')||strcmp(answer,'No')
+            return
+        end
     end
 end
@@ -1678,5 +1685,5 @@
     Param.IndexRange.last_i=str2num(get(handles.num_last_i,'String'));
     
-    %% create the output data directory if needed, after chcking its existence
+    %% create the output data directory if needed, after checking its existence
     OutputDir='';
     answer='';
@@ -2654,5 +2661,5 @@
     ProjObjectVisible='off';
 end
-set(handles.ProjObject,'Visible',ProjObjectVisible)
+set(handles.ProjObjectName,'Visible',ProjObjectVisible)
 set(handles.DeleteObject,'Visible',ProjObjectVisible)
 set(handles.ViewObject,'Visible',ProjObjectVisible)
@@ -3074,5 +3081,5 @@
         end
         ProjObject=read_GUI(hset_object);
-        set(handles.ProjObject,'String',ProjObject.Name); % display the object name
+        set(handles.ProjObjectName,'String',ProjObject.Name); % display the object name
         SeriesData=get(handles.series,'UserData');
         SeriesData.ProjObject=ProjObject;
@@ -3082,5 +3089,5 @@
     set(handles.DeleteObject,'Visible','on');
     set(handles.ViewObject,'Visible','on');
-    set(handles.ProjObject,'Visible','on');
+    set(handles.ProjObjectName,'Visible','on');
 else
     set(handles.EditObject,'Visible','off');
@@ -3090,5 +3097,5 @@
         set(handles.ViewObject,'Value',0);
     end
-    set(handles.ProjObject,'Visible','off');
+    set(handles.ProjObjectName,'Visible','off');
 end
 
@@ -3131,6 +3138,6 @@
 SeriesData.ProjObject=[];
 set(handles.series,'UserData',SeriesData)
-set(handles.ProjObject,'String','')
-set(handles.ProjObject,'Visible','off')
+set(handles.ProjObjectName,'String','')
+set(handles.ProjObjectName,'Visible','off')
 set(handles.CheckObject,'Value',0)
 set(handles.ViewObject,'Visible','off')
@@ -3389,11 +3396,11 @@
 set(handles.series,'UserData',SeriesData)
 if isfield(Param,'CheckObject') && isequal(Param.CheckObject,1)
-    set(handles.ProjObject,'String',Param.ProjObject.Name)
+    set(handles.ProjObjectName,'String',Param.ProjObject.Name)
     set(handles.ViewObject,'Visible','on')
     set(handles.EditObject,'Visible','on')
     set(handles.DeleteObject,'Visible','on')
 else     
-    set(handles.ProjObject,'String','')
-    set(handles.ProjObject,'Visible','off')
+    set(handles.ProjObjectName,'String','')
+    set(handles.ProjObjectName,'Visible','off')
     set(handles.ViewObject,'Visible','off')
     set(handles.EditObject,'Visible','off')
@@ -3874,2 +3881,5 @@
     end
 end
+
+
+
Index: /trunk/src/set_object.m
===================================================================
--- /trunk/src/set_object.m	(revision 1071)
+++ /trunk/src/set_object.m	(revision 1072)
@@ -100,9 +100,9 @@
 
 % fill the interface as set in the input data:
-if exist('data','var') 
+if exist('data','var')
     if isfield(data,'Coord')
         set(handles.Coord,'Data',data.Coord)
         if size(data.Coord,2)==3
-        set(handles.z_slider,'Visible','on')
+            set(handles.z_slider,'Visible','on')
         end
     else
@@ -114,5 +114,5 @@
     if isfield(data,'ProjModeMenu')
         set(handles.ProjMode,'UserData',data.ProjModeMenu)% data.ProjModeMenu as default menu (used in Type_Callback)
-    end      
+    end
     errormsg=fill_GUI(data,handles.set_object);
     if ~isempty(errormsg)
@@ -120,5 +120,5 @@
         return
     end
-    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type   
+    Type_Callback(hObject, eventdata, handles)% update the GUI set_object depending on the object type
     set(handles.REFRESH,'BackgroundColor',[1 0 0])
     if isfield(data,'RangeZ')
@@ -151,5 +151,5 @@
         set(handles.num_RangeY_1,'String',num2str(min(data.RangeY),3))
     end
-    if isfield(data,'RangeZ')&& ~strcmp(data.Type,'plane_z')%TODO: generalise
+    if isfield(data,'RangeZ')%&& ~strcmp(data.Type,'plane_z')%TODO: generalise
         if ischar(data.RangeZ)
             data.RangeZ=str2num(data.RangeZ);
@@ -159,17 +159,16 @@
             set(handles.num_RangeZ_1,'String',num2str(min(data.RangeZ),3))
         end
-    end  
+    end
     if ~isfield(data,'Angle')
         data.Angle=[0 0];
     end
-%     if isfield(data,'Angle') && isequal(numel(data.Angle),3)
-         set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
-%          set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
-%         set(handles.num_Angle_3,'String',num2str(data.Angle(3)))
-%     end
+    set(handles.num_Angle_1,'String',num2str(data.Angle(1)))
+    if numel(data.Angle)==2
+        set(handles.num_Angle_2,'Visible','on')
+        set(handles.num_Angle_2,'String',num2str(data.Angle(2)))
+    end
 end
 set(get(handles.set_object,'children'),'enable','off')
 set(handles.SAVE,'enable','on')
-% set(handles.REFRESH,'enable','off') 
 
 
@@ -245,5 +244,7 @@
         end
     case {'rectangle','ellipse','plane','volume'}
+        if ~isempty(Coord)
         Coord=Coord(1,:);
+        end
 end
 set(handles.Coord,'Data',Coord)
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 1071)
+++ /trunk/src/uvmat.m	(revision 1072)
@@ -1007,8 +1007,15 @@
                 data.RangeY=UvData.Field.CoordMesh;
             case 'plane_z'
+                data.Type='plane';
+                if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
+                    data.RangeY=[UvData.Field.ZMin UvData.Field.ZMax];
+                else
+                    msgbox_uvmat('ERROR','The input field is not 3D: no vertical plane projection')
+                    return
+                end
                 data.Angle=[0 90];
                 data.DX=UvData.Field.CoordMesh;
                 data.DY=UvData.Field.CoordMesh;
-                data.RangeZ=UvData.Field.CoordMesh;
+                data.RangeZ=UvData.Field.CoordMesh;      
                 data.Coord=[];
             otherwise
@@ -1021,5 +1028,8 @@
     end
 end
-
+hset_object=findobj(allchild(0),'Tag','set_object');
+if ~isempty(hset_object)
+    delete(hset_object)%delete existing GUI set_object
+end
 hset_object=set_object(data,handles);% call the GUI set_object
 hchild=get(hset_object,'children');
@@ -1438,6 +1448,6 @@
 end
 if numel(find(select_line))<2
-    msgbox_uvmat('ERROR',{'light rays must be defined by at least two lines created by Projection object/line in the menu bar'; ...
-    'use a third line to get a reference luminosity profile accross the illumination beam'});
+    msgbox_uvmat('ERROR',{'lines must be defined by Projection object in the upper menu bar: ';'1-two lines following the illumination rays'; ...
+    '2-a reference line near the fluid boundary receiving the illumination beam';'a mask polygon to select the area in which the exponential decay is fitted'});
     return
 else
@@ -1457,9 +1467,16 @@
     blackoffset=XmlData.LIFCalib.BlackOffset ;% image value for black background, to be determined by taking images with a cover on the objective lens
 end
-answer=msgbox_uvmat('INPUT_TXT','camera offset value in the absence of illumination:', num2str(blackoffset));
+
+prompt = {'offset luminosity value in the absence of illumination';'smoothing length for the reference line (in pixels)'};
+    dlg_title = 'set the parameters for LIF';
+    num_lines= 2;
+    def     = { '0';'20'};
+    answer = inputdlg(prompt,dlg_title,num_lines,def);
+
 if strcmp(answer,'Cancel')
     return
 else
-    XmlData.LIFCalib.BlackOffset=str2num(answer) ;% image value for black background, to be determined by taking images with a cover on the objective lens
+    XmlData.LIFCalib.BlackOffset=str2num(answer{1}) ;% image value for black background, to be determined by taking images with a cover on the objective lens
+    XmlData.LIFCalib.SmoothingLength=str2num(answer{2}) ;% smoothing length used for the reference line
 end
 
@@ -1491,4 +1508,5 @@
 
 %% use the third line for reference luminosity, renormalize the image intensity along each ray to get a uniform brightness along this line
+%UvData.Field.CoordMesh
 if numel(find(select_line))==3
     x_ref=linspace(LineData{3}.Coord(1,1),LineData{3}.Coord(2,1),10);
@@ -1508,5 +1526,5 @@
     line_nan= isnan(dist_source);
     dist_source_pixel(line_nan)=1;
-    width=20; %number of pixels used for reference
+    width=XmlData.LIFCalib.SmoothingLength; %number of pixels used for reference
     DataPol.A=double(DataPol.A)-XmlData.LIFCalib.BlackOffset;% black background substracted
     Anorm=zeros(size(DataPol.A));
@@ -1516,4 +1534,7 @@
     end
     lum(line_nan)=NaN;
+    XmlData.LIFCalib.RefLineAzimuth=DataPol.Coord_y;
+    XmlData.LIFCalib.RefLineRadius=dist_source;
+    XmlData.LIFCalib.RefLineLum=lum;
     figure(11)
     plot(1:size(DataPol.A,1),lum)
@@ -1554,10 +1575,10 @@
     [XLine,YLine] = pol2cart(ThetaLine,RLine);
     XLine=XLine+x0;
-    YLine=YLine+y0;  
+    YLine=YLine+y0;
     if ~isempty(index_mask)
         ind_good=inpolygon(XLine,YLine,MaskData.Coord(:,1),MaskData.Coord(:,2));
         if numel(find(ind_good))>100
-        ALine=ALine(ind_good);
-        RLine=RLine(ind_good);
+            ALine=ALine(ind_good);
+            RLine=RLine(ind_good);
         else
             continue
@@ -1565,5 +1586,5 @@
     end
     p = polyfit(RLine,ALine,1);
-        gamma_coeff(iY)=-p(1);
+    gamma_coeff(iY)=-p(1);
 end
 
@@ -1578,7 +1599,10 @@
 ylabel('decay coeff(m-1)')
 
+%% keep the average of gamma_coeff
+XmlData.LIFCalib.DecayRate=mean(gamma_coeff(gamma_coeff>0));
+
 %% record the calibration data in the xml file
 XmlFileName=find_imadoc(get(handles.RootPath,'String'),get(handles.SubDir,'String'),get(handles.RootFile,'String'),get(handles.FileExt,'String'));
-answer=msgbox_uvmat('INPUT_Y-N','save the illumination origin in the current xml file?');
+answer=msgbox_uvmat('INPUT_Y-N','save the LIF parameters in the current xml file?');
 if strcmp(answer,'Yes')
     t=xmltree(XmlFileName); %read the file
@@ -1605,31 +1629,59 @@
     end
     uid_origin=find(t,'ImaDoc/LIFCalib/LightOrigin');
-    if ~isempty(uid_origin)  %if GeometryCalib does not already exists, create it
-         t=delete(t,uid_origin);
+    if ~isempty(uid_origin)  %if LightOrigin already exists, delete it
+        t=delete(t,uid_origin);
     end
     uid_line=find(t,'ImaDoc/LIFCalib/Ray1Coord');
-    if ~isempty(uid_line)  %if GeometryCalib does not already exists, create it
-         t=delete(t,uid_line);
-    end
-       uid_line=find(t,'ImaDoc/LIFCalib/Ray2Coord');
-    if ~isempty(uid_line)  %if GeometryCalib does not already exists, create it
-         t=delete(t,uid_line);
-    end
-       uid_mask=find(t,'ImaDoc/LIFCalib/MaskPolygonCoord');
-    if ~isempty(uid_mask)  %if GeometryCalib does not already exists, create it
-         t=delete(t,uid_mask);
-    end
-     uid_BlackOffset=find(t,'ImaDoc/LIFCalib/BlackOffset');
-    if ~isempty(uid_BlackOffset)  %if GeometryCalib does not already exists, create it
-         t=delete(t,uid_BlackOffset);
-    end
+    if ~isempty(uid_line)  %if Ray1Coord already exists, delete it
+        t=delete(t,uid_line);
+    end
+    uid_line=find(t,'ImaDoc/LIFCalib/Ray2Coord');
+    if ~isempty(uid_line)  %if Ray2Coord already exists, delete it
+        t=delete(t,uid_line);
+    end
+    uid_line=find(t,'ImaDoc/LIFCalib/RefLineCoord');
+    if ~isempty(uid_line)  %if RefLineCoord already exists, delete it
+        t=delete(t,uid_line);
+    end
+    uid_mask=find(t,'ImaDoc/LIFCalib/MaskPolygonCoord');
+    if ~isempty(uid_mask) %if MaskPolygonCoord already exists, delete it
+        t=delete(t,uid_mask);
+    end
+    uid_BlackOffset=find(t,'ImaDoc/LIFCalib/BlackOffset');
+    if ~isempty(uid_BlackOffset)  %if BlackOffset already exists, delete it
+        t=delete(t,uid_BlackOffset);
+    end
+    uid_DecayRate=find(t,'ImaDoc/LIFCalib/DecayRate');
+    if ~isempty(uid_DecayRate)  %if DecayRate already exists, delete it
+        t=delete(t,uid_DecayRate);
+    end
+    uid_RefLineRadius=find(t,'ImaDoc/LIFCalib/RefLineRadius');
+    if ~isempty(uid_RefLineRadius)  %if RefLineLum already exists, delete it
+        t=delete(t,uid_RefLineRadius);
+    end
+    uid_RefLineLum=find(t,'ImaDoc/LIFCalib/RefLineLum');
+    if ~isempty(uid_RefLineLum)  %if RefLineLum already exists, delete it
+        t=delete(t,uid_RefLineLum);
+    end
+    uid_RefLineAzimuth=find(t,'ImaDoc/LIFCalib/RefLineAzimuth');
+    if ~isempty(uid_RefLineAzimuth)  %if RefLineLum already exists, delete it
+        t=delete(t,uid_RefLineAzimuth);
+    end
+    
     % save the LIF calibration data
     t=struct2xml(XmlData.LIFCalib,t,uid_illumination);
     save(t,XmlFileName);
-end
-
-
-
-
+    
+    % display the concentration in uvmat
+    InputFileREFRESH_Callback(hObject, eventdata, handles);% refresh the current xml file to apply 'ima2concentration'
+    transform_list=get(handles.TransformName,'String');
+    ichoice=find(strcmp('ima2concentration',transform_list),1);%look for the selected fct in the existing menu
+    if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it)
+        transform_list=transform_list(1:end-1);
+        ichoice=numel(transform_list)-1;
+    end
+    set(handles.TransformName,'Value',ichoice)
+    TransformName_Callback(hObject, eventdata, handles)
+end
 
 
@@ -3149,156 +3201,12 @@
     set(handles.Dt_txt,'String','')% the time interval indication is suppressed
     return
-end
-
-%% check the input file indexing:
-[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
-NomType=get(handles.NomType,'String');
-if ~isempty(find(regexp(NomType,'-')))
-    msgbox_uvmat('ERROR','The movie pair requires file series with a single index on the first input line')
-    return
-end
-filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
-
-set(handles.movie_pair,'BusyAction','queue')%
-set(handles.CheckFixPair,'Value',1)% impose fixed pair (needed for function runpm)
-set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
-set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
-drawnow
-% list_fields=get(handles.FieldName,'String');% list menu fields
-% index_fields=get(handles.FieldName,'Value');% selected string index
-% FieldName=list_fields{index_fields}; % selected field
-
-
-% if isequal(FieldName,'image')
-%     index=1;
-
-% else
-%     list_fields=get(handles.FieldName_1,'String');% list menu fields
-%     index_fields=get(handles.FieldName_1,'Value');% selected string index
-%     FieldName=list_fields{index_fields}; % selected field
-%     if isequal(FieldName,'image')
-%         index=2;
-%         [RootPath,SubDir,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles);% get info from the second input line
-%     else
-%         msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
-%         set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
-%         set(handles.movie_pair,'Value',0)
-%         return
-%     end
-% end
-num_i1=str2num(get(handles.i1,'String'));
-num_j1=stra2num(get(handles.j1,'String'));
-num_i2=str2num(get(handles.i2,'String'));
-num_j2=stra2num(get(handles.j2,'String'));
-
-%% determine the name 'imaname_1' of the second file in the pair
-imaname_1='';
-if isempty(num_j2)% no second j index indicated
-    if isempty(num_i2)
-        if strcmp(get(handles.j2,'Visible'),'on') %if the j box is visible
-            imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1,[],num_j1+1);
-        end
-        if exist(imaname_1,'file')
-            num_j2=num_j1+1;% look by default for the next j index as the second file
-            set(handles.j2,'String',num2stra(num_j2,NomType));
-        else
-            imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1+1,[],num_j1);
-            if exist(imaname_1,'file')
-                num_i2=num_i1+1;
-                set(handles.i2,'String',num2str(num_i2));
-            else
-                msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
-                set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
-                set(handles.movie_pair,'Value',0)
-                return
-            end
-        end
-    else
-        num_j2=num_j1;%repeat the index i1 by default
-    end
-end
-if isempty(num_i2)
-    num_i2=num_i1;%repeat the index i1 by default
-end
-if isempty(num_j1)
-    num_j1=1;
-end
-if isempty(num_j2)
-    num_j2=num_j1;%repeat the index i1 by default
-end
-imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i2,[],num_j2);
-if strcmp(NomType,'*')
-    num_frame=num_i2;
-else
-    num_frame=num_j2;
-end
-if ~exist(imaname_1,'file')
-      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
-      set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
-       set(handles.movie_pair,'Value',0)
-      return
-end
-
-%% display the first field in the pair (including possibly a background field from second line input filename_1)
-filename_1='';%default
-FileIndex_1='';
-if get(handles.SubField,'Value')
-    [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
-    filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
-end
-% num_i1=stra2num(get(handles.i1,'String'));
-% num_i2=stra2num(get(handles.i2,'String'));
-% num_j1=stra2num(get(handles.j1,'String'));
-% num_j2=stra2num(get(handles.j2,'String'));
-[tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
-if isempty(j1_1)% case of movies, the index is not given by file index
-    j1_1=num_j1;
-end
-
-errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
-
-if isempty(errormsg)
-    set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
-else
-     msgbox_uvmat('ERROR',errormsg);
-     set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
-end
-UvData=get(handles.uvmat,'UserData');
-Field_a=UvData.Field;% movie on the field defined by the second input line
-
-%% display time interval for the image pair
-if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'Time')...
-        && size(UvData.XmlData{1}.Time,1)>=num_i2+1 && size(UvData.XmlData{1}.Time,2)>=num_j2+1
-    dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
-    if  isfield(UvData,'TimeUnit')
-        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
-    else
-        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
-    end
-else
-    set(handles.Dt_txt,'String','')
-end
-
-%% read the second field
-if isempty(UvData.MovieObject)
-    [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileInfo{index}.FileType,[],num_frame);
-else
-    [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileInfo{1}.FileType,UvData.MovieObject{1},num_frame);
-end
-if ~isempty(errormsg)
-    msgbox_uvmat('ERROR',['Error in reading second image: ' errormsg])
-    return
-end
-
-%% apply phys or other transform on the two input fields
-transform=get(handles.TransformPath,'UserData');
-if  ~isempty(transform)
-    if isfield(UvData,'XmlData') && ~isempty(UvData.XmlData) %use geometry calib recorded from the ImaDoc xml file as first priority
-        if nargin(transform)>=2
-            Field_b=transform(Field_b,UvData.XmlData{1});
-        else
-            Field_b=transform(Field_b);
-        end
-    end
+else
+    set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
+    drawnow
+end
+
+increment=str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
+if isnan(increment)% case of free increment: move to next available field index
+    increment='+';
 end
 
@@ -3308,9 +3216,17 @@
 set(handles.speed,'Visible','on')
 set(handles.speed_txt,'Visible','on')
+set(handles.movie_pair,'BusyAction','queue')
 while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue') % enable STOP command
     % read and plot the series of images in non erase mode
-    set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields
+    errormsg=runpm(hObject,eventdata,handles,increment);
+    if ~isempty(errormsg)
+        msgbox_uvmat('ERROR',errormsg);
+    end
+    
+    %     set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields
     pause(1.02-get(handles.speed,'Value'));% wait for next image
-    set(hima,'CData',Field_a.A);
+    errormsg=runpm(hObject,eventdata,handles,-increment);
+    
+    %     set(hima,'CData',Field_a.A);
     pause(1.02-get(handles.speed,'Value'));% wait for next image
 end
@@ -3318,4 +3234,165 @@
 set(handles.movie_pair,'Value',0)
 set(handles.Dt_txt,'String','')
+
+
+
+
+set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back in red
+
+% 
+% set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
+% drawnow
+% increment=-str2double(get(handles.num_IndexIncrement,'String')); %get the field increment d
+% if isnan(increment)% case of free increment: move to previous available field index
+%     increment='-';
+% end
+% errormsg=runpm(hObject,eventdata,handles,increment);
+% if ~isempty(errormsg)
+%     msgbox_uvmat('ERROR',errormsg);
+% end
+% set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back in red
+% 
+% %% check the input file indexing:
+% [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
+% NomType=get(handles.NomType,'String');
+% if ~isempty(find(regexp(NomType,'-')))
+%     msgbox_uvmat('ERROR','The movie pair requires file series with a single index on the first input line')
+%     return
+% end
+% filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% build the input file name (first line)
+% 
+% set(handles.movie_pair,'BusyAction','queue')%
+% set(handles.CheckFixPair,'Value',1)% impose fixed pair (needed for function runpm)
+% set(handles.REFRESH,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
+% set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow to indicate its activity
+% drawnow
+% 
+% num_i1=str2num(get(handles.i1,'String'));
+% num_j1=stra2num(get(handles.j1,'String'));
+% num_i2=str2num(get(handles.i2,'String'));
+% num_j2=stra2num(get(handles.j2,'String'));
+% 
+% %% determine the name 'imaname_1' of the second file in the pair
+% imaname_1='';
+% if isempty(num_j2)% no second j index indicated
+%     if isempty(num_i2)
+%         if strcmp(get(handles.j2,'Visible'),'on') %if the j box is visible
+%             imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1,[],num_j1+1);
+%         end
+%         if exist(imaname_1,'file')
+%             num_j2=num_j1+1;% look by default for the next j index as the second file
+%             set(handles.j2,'String',num2stra(num_j2,NomType));
+%         else
+%             imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i1+1,[],num_j1);
+%             if exist(imaname_1,'file')
+%                 num_i2=num_i1+1;
+%                 set(handles.i2,'String',num2str(num_i2));
+%             else
+%                 msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
+%                 set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
+%                 set(handles.movie_pair,'Value',0)
+%                 return
+%             end
+%         end
+%     else
+%         num_j2=num_j1;%repeat the index i1 by default
+%     end
+% end
+% if isempty(num_i2)
+%     num_i2=num_i1;%repeat the index i1 by default
+% end
+% if isempty(num_j1)
+%     num_j1=1;
+% end
+% if isempty(num_j2)
+%     num_j2=num_j1;%repeat the index i1 by default
+% end
+% imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,num_i2,[],num_j2);
+% if strcmp(NomType,'*')
+%     num_frame=num_i2;
+% else
+%     num_frame=num_j2;
+% end
+% if ~exist(imaname_1,'file')
+%       msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
+%       set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
+%        set(handles.movie_pair,'Value',0)
+%       return
+% end
+% 
+% %% display the first field in the pair (including possibly a background field from second line input filename_1)
+% filename_1='';%default
+% FileIndex_1='';
+% if get(handles.SubField,'Value')
+%     [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
+%     filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
+% end
+% [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);% get the indices of the second series from the string FileIndex_1
+% if isempty(j1_1)% case of movies, the index is not given by file index
+%     j1_1=num_j1;
+% end
+% 
+% errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
+% 
+% if isempty(errormsg)
+%     set(handles.REFRESH,'BackgroundColor',[1 0 0])% set button color to red, update successfull
+% else
+%      msgbox_uvmat('ERROR',errormsg);
+%      set(handles.REFRESH,'BackgroundColor',[1 0 1])% keep button color magenta, input not succesfull
+% end
+% UvData=get(handles.uvmat,'UserData');
+% Field_a=UvData.Field;% movie on the field defined by the second input line
+% 
+% %% display time interval for the image pair
+% if isfield(UvData,'XmlData')&&isfield(UvData.XmlData{1},'Time')...
+%         && size(UvData.XmlData{1}.Time,1)>=num_i2+1 && size(UvData.XmlData{1}.Time,2)>=num_j2+1
+%     dt=(UvData.XmlData{1}.Time(num_i2+1,num_j2+1)-UvData.XmlData{1}.Time(num_i1+1,num_j1+1));
+%     if  isfield(UvData,'TimeUnit')
+%         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' UvData.TimeUnit] )
+%     else
+%         set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
+%     end
+% else
+%     set(handles.Dt_txt,'String','')
+% end
+% 
+% %% read the second field
+% if isempty(UvData.MovieObject)
+%     [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileInfo{index}.FileType,[],num_frame);
+% else
+%     [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileInfo{1}.FileType,UvData.MovieObject{1},num_frame);
+% end
+% if ~isempty(errormsg)
+%     msgbox_uvmat('ERROR',['Error in reading second image: ' errormsg])
+%     return
+% end
+% 
+% %% apply phys or other transform on the two input fields
+% transform=get(handles.TransformPath,'UserData');
+% if  ~isempty(transform)
+%     if isfield(UvData,'XmlData') && ~isempty(UvData.XmlData) %use geometry calib recorded from the ImaDoc xml file as first priority
+%         if nargin(transform)>=2
+%             Field_b=transform(Field_b,UvData.XmlData{1});
+%         else
+%             Field_b=transform(Field_b);
+%         end
+%     end
+% end
+% 
+% %% make movie until movie speed is set to 0 or STOP is activated
+% hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER)
+% set(handles.STOP,'Visible','on')
+% set(handles.speed,'Visible','on')
+% set(handles.speed_txt,'Visible','on')
+% while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue') % enable STOP command
+%     % read and plot the series of images in non erase mode
+%     set(hima,'CData',Field_b.A); %TODO: generalise to other kinds of fields
+%     pause(1.02-get(handles.speed,'Value'));% wait for next image
+%     set(hima,'CData',Field_a.A);
+%     pause(1.02-get(handles.speed,'Value'));% wait for next image
+% end
+% set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
+% set(handles.movie_pair,'Value',0)
+% set(handles.Dt_txt,'String','')
 
 %------------------------------------------------------------------------
@@ -5925,4 +6002,6 @@
         set(hhset_object.SAVE,'Enable','on')
     end
+else
+    delete(hset_object)
 end
 
