Index: /trunk/src/civ.m
===================================================================
--- /trunk/src/civ.m	(revision 115)
+++ /trunk/src/civ.m	(revision 116)
@@ -770,7 +770,6 @@
 set(handles.RUN, 'Enable','On')
 set(handles.RUN,'BackgroundColor',[1 0 0])
-if isequal(get(handles.BATCH, 'Enable'),'On')
+  set(handles.BATCH,'Enable','On')
     set(handles.BATCH,'BackgroundColor',[1 0 0])
-end
 
 %%%%% store the root input filename for future opening
@@ -2107,5 +2106,6 @@
     s=convert(t);
 end
-if batch
+    test_interp=0;
+    if batch
     if isfield(s,'BatchParam')
         sparam=s.BatchParam;
@@ -2140,5 +2140,5 @@
     end
     %test_interp=get(handles.test_interp,'Value');
-    test_interp=0;
+
     if  isfield(sparam,'PatchBin')
         if ~exist(sparam.PatchBin,'file')
Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m	(revision 115)
+++ /trunk/src/geometry_calib.m	(revision 116)
@@ -71,5 +71,5 @@
 % parameters on the uvmat interface (obtained by 'get_plot_handle.m')
 %------------------------------------------------------------------------
-function geometry_calib_OpeningFcn(hObject, eventdata, handles, handles_uvmat,pos,inputfile)
+function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile,pos)
 %------------------------------------------------------------------------
 % Choose default command line output for geometry_calib
@@ -81,5 +81,5 @@
 
 %set the position of the interface
-if exist('pos','var')& length(pos)>2
+if exist('pos','var')&& length(pos)>2
     pos_gui=get(hObject,'Position');
     pos_gui(1)=pos(1);
@@ -92,13 +92,15 @@
 set(handles.calib_type,'String',{'rescale';'linear';'quadr';'3D_linear';'3D_quadr';'3D_extrinsic'})
 inputxml='';
-if exist('inputfile','var')& ~isempty(inputfile)
+if exist('inputfile','var')&& ~isempty(inputfile)
     struct.XmlInputFile=inputfile;
     set(hObject,'UserData',struct)
     [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile);
-    inputxml=[fullfile(Pathsub,RootFile) '.xml'];
+    if ~strcmp(ext,'.xml')
+        inputfile=[fullfile(Pathsub,RootFile) '.xml']%xml file corresponding to the input file
+    end
 end
 set(handles.ListCoord,'String',{'......'})
-if exist(inputxml,'file')
-    loadfile(handles,inputxml)% load the point coordiantes existing in the xml file
+if exist(inputfile,'file')
+    loadfile(handles,inputfile)% load the point coordiantes existing in the xml file
 end
 set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function
@@ -232,4 +234,7 @@
     set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
     set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
+    UserData=get(handles.geometry_calib,'UserData');
+    UserData.XmlInputFile=outputfile;%save the current xml file name
+    set(handles.geometry_calib,'UserData',UserData)
     uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat, show the image in phys coordinates
     MenuPlot_Callback(hObject, eventdata, handles)
@@ -294,8 +299,8 @@
     %record the points
     GeometryCalib.SourceCalib.PointCoord=Coord;
-    errormsg=update_imadoc(GeometryCalib,outputfile);% introduce the calibration data in the xml file
-    if ~strcmp(errormsg,'')
-        msgbox_uvmat('ERROR',errormsg);
-    end
+%     errormsg=update_imadoc(GeometryCalib,outputfile);% introduce the calibration data in the xml file
+%     if ~strcmp(errormsg,'')
+%         msgbox_uvmat('ERROR',errormsg);
+%     end
 end
 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
@@ -412,12 +417,13 @@
 % y1=XY_mat*a_Y1;
 % err_Y1=max(abs(y1-y_ima));%error
+R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,0];
+norm=abs(det(R));
 GeometryCalib.CalibrationType='linear';
-GeometryCalib.focal=1;
+GeometryCalib.fx_fy=[norm norm];
 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
 R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,0];
-norm=det(R);
-GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) norm]; 
+GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) 1]; 
 GeometryCalib.R=R/norm;
-
+GeometryCalib.omc=(180/pi)*[acos(R(1,1)) 0 0];
 %------------------------------------------------------------------------
 % determine the tsai parameters for a view normal to the grid plane
@@ -600,9 +606,9 @@
 path_uvmat=which('geometry_calib');% check the path detected for source file uvmat
 path_UVMAT=fileparts(path_uvmat); %path to UVMAT
-x_1=Coord(:,4:5)';
-X_1=Coord(:,1:3)';
+x_1=double(Coord(:,4:5)');%image coordiantes
+X_1=double(Coord(:,1:3)');% phys coordinates
 huvmat=findobj(allchild(0),'Tag','uvmat');
 hhuvmat=guidata(huvmat);
-ny=str2num(get(hhuvmat.npy,'String'));
+ny=str2double(get(hhuvmat.npy,'String'));
 x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
 n_ima=1;
@@ -615,5 +621,5 @@
 fct_path=fullfile(path_UVMAT,'toolbox_calib');
 addpath(fct_path)
-Cx_Cy=ny-(GeometryCalib.Cx_Cy)';%reverse Cx_Cy(2) for calibration (inversion of px ordinate)
+GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%reverse Cx_Cy(2) for calibration (inversion of px ordinate)
 % [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,...
 %     [Calib.f Calib.f*Calib.sx]',...
@@ -621,10 +627,6 @@
 %     [-Calib.kappa1*Calib.f^2 0 0 0 0]);
 [omc,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,...
-    (GeometryCalib.fx_fy)',...
-    Cx_Cy,[GeometryCalib.kc 0 0 0 0]);
-%get the euler angles ???
+    (GeometryCalib.fx_fy)',GeometryCalib.Cx_Cy',[GeometryCalib.kc 0 0 0 0]);
 rmpath(fct_path);
-
-std(ex')
 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
 GeometryCalib.Tx_Ty_Tz=Tc1';
@@ -633,7 +635,8 @@
 GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
 GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
-%GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
+GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
 GeometryCalib.omc=(180/pi)*omc';
 %GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward
+
 
 
@@ -993,7 +996,7 @@
 % --------------------------------------------------------------------
 function MenuHelp_Callback(hObject, eventdata, handles)
-path_to_uvmat=which ('uvmat');% check the path of uvmat
+path_to_uvmat=which('uvmat');% check the path of uvmat
 pathelp=fileparts(path_to_uvmat);
-    helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
+helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
 if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
 else
@@ -1409,5 +1412,5 @@
 GeometryCalib=s.GeometryCalib;
 %GeometryCalib=load_calib(hObject, eventdata, handles)
-calib=reshape(GeometryCalib.PointCoord',[],1);
+calib=reshape(GeometryCalib.PointCoord,[],1);
 for ilist=1:numel(calib)
     CoordCell{ilist}=num2str(calib(ilist));
@@ -1474,5 +1477,5 @@
 fileinput=[];%default
 oldfile=''; %default
-UserData=get(handles.geometry_calib,'UserData')
+UserData=get(handles.geometry_calib,'UserData');
 if isfield(UserData,'XmlInputFile')
     oldfile=UserData.XmlInputFile;
@@ -1497,6 +1500,7 @@
 function loadfile(handles,fileinput)
 %------------------------------------------------------------------------
-[s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
-GeometryCalib=s.GeometryCalib
+fileinput
+[s,errormsg]=imadoc2struct(fileinput,'GeometryCalib')
+GeometryCalib=s.GeometryCalib;
 fx=1;fy=1;Cx=0;Cy=0;kc=0; %default
 %     Tabchar={};
@@ -1534,5 +1538,5 @@
         set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
     end
-    calib=reshape(GeometryCalib.PointCoord',[],1);
+    calib=reshape(GeometryCalib.PointCoord,[],1);
     for ilist=1:numel(calib)
         CoordCell{ilist}=num2str(calib(ilist));
Index: /trunk/src/griddata_uvmat.m
===================================================================
--- /trunk/src/griddata_uvmat.m	(revision 115)
+++ /trunk/src/griddata_uvmat.m	(revision 116)
@@ -2,8 +2,7 @@
 %adapt the input of the matlab function griddata to the appropriate version of Matlab
 function ZI = griddata_uvmat(X,Y,Z,XI,YI)
-whos X Y Z XI YI
 txt=ver;
 Release=txt(1).Release;
-relnumb=str2num(Release(3:4))
+relnumb=str2num(Release(3:4));
 if relnumb >= 20
     ZI=griddata(double(X),double(Y),double(Z),double(XI),double(YI),'linear',{'QJ'});
Index: /trunk/src/imadoc2struct.m
===================================================================
--- /trunk/src/imadoc2struct.m	(revision 115)
+++ /trunk/src/imadoc2struct.m	(revision 116)
@@ -217,4 +217,5 @@
         if strcmp(option,'GeometryCalib')
             tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);%time in TimeUnit
+            size(tsai.PointCoord)
         end
         s.GeometryCalib=tsai;
@@ -228,9 +229,9 @@
 val=default;
 uid=find(t,label);%find the element iud(s)
-if ~isempty(uid)
-   uid_child=children(t,uid);
+if ~isempty(uid) %if the element named label exists
+   uid_child=children(t,uid);%find the children 
    if ~isempty(uid_child)
-       data=get(t,uid_child,'type');
-       if iscell(data)
+       data=get(t,uid_child,'type');%get the type of child
+       if iscell(data)% case of multiple element
            for icell=1:numel(data)
                val_read=str2num(get(t,uid_child(icell),'value'));
@@ -239,6 +240,6 @@
                end
            end
-           val=val';
-       else
+%           val=val';
+       else % case of unique element value
            val_read=str2num(get(t,uid_child,'value'));
            if ~isempty(val_read)
Index: /trunk/src/series/merge_proj.m
===================================================================
--- /trunk/src/series/merge_proj.m	(revision 115)
+++ /trunk/src/series/merge_proj.m	(revision 116)
@@ -23,4 +23,6 @@
 WaitbarPos=get(hseries.waitbar_frame,'Position'); %positiopn of waitbar frame
 %-------------------------------------------------
+
+
 
 %projection object
@@ -229,7 +231,12 @@
 if ~exist(res_subdir,'dir')
     dircur=pwd;
-    cd(fulldir)
-    error=mkdir(subdir);
-    cd(dircur)
+    cd(fulldir);
+    succeed=mkdir(subdir);
+    if succeed
+    cd(dircur);
+    else
+    msgbox_uvmat('ERROR',['Cannot create directory ' fulldir])
+    return
+    end        
 end
 filebasesub=fullfile(res_subdir,Series.RootFile{1});
@@ -286,9 +293,13 @@
             % coord transform
             % z index
+      
             if ~isempty(NbSlice_calib)
-                Field{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1;
-            end
+                Field{iview}.ZIndex=mod(num_i1{iview}(ifile)-1,NbSlice_calib{1})+1
+            end
+%              Field{iview}.ZIndex=1;
             if ~isempty(transform_fct)
-                Field{iview}=transform_fct(Field{iview},XmlData{iview});%transform to phys if requested
+                XmlData{iview}.GeometryCalib
+                Field{iview}=transform_fct(Field{iview},XmlData{iview});                
+                %transform to phys if requested
             end
             if testcivx
@@ -301,5 +312,4 @@
             end
         end    
-        
          %----------END LOOP ON VIEWS----------------------
          
@@ -376,5 +386,5 @@
             %MergeData.dt=1;
             MergeData.Time=time_i;
-            error=struct2nc(mergename,MergeData); %save result file
+            error=struct2nc(mergename,MergeData);%save result file
             if isempty(error)
                 display(['output file ' mergename ' written'])
Index: /trunk/src/transform_field/phys.m
===================================================================
--- /trunk/src/transform_field/phys.m	(revision 115)
+++ /trunk/src/transform_field/phys.m	(revision 116)
@@ -58,8 +58,8 @@
 end
 %transform of X,Y coordinates for vector fields
-if isfield(Data,'ZIndex')&&~isempty(Data.ZIndex)
+if isfield(Data,'ZIndex')&&~isempty(Data.ZIndex)&&~isnan(Data.ZIndex)
     ZIndex=Data.ZIndex;
 else
-    ZIndex=0;
+    ZIndex=1;
 end
 if test_1
@@ -111,6 +111,6 @@
     DataOut.TimeUnit='s';
     %transform of X,Y coordinates for vector fields
-    if isfield(Data,'ZIndex') && ~isempty(Data.ZIndex)
-        Z=Data.ZIndex;
+    if isfield(Data,'ZIndex') && ~isempty(Data.ZIndex)&&~isnan(Data.ZIndex)
+        Z=Data.ZIndex
     else
         Z=0;
@@ -153,11 +153,18 @@
 end
 
-
 %%%%%%%%%%%%%%%%%%%%
 function [A_out,Rangx,Rangy]=phys_Ima(A,CalibIn,ZIndex)
+
+if ndims(A)==3
+    A=mean(A,3);
+end
+
+
 xcorner=[];
 ycorner=[];
 npx=[];
 npy=[];
+dx=ones(1,length(A));
+dy=ones(1,length(A));
 for icell=1:length(A)
     siz=size(A{icell});
@@ -165,5 +172,5 @@
     npy=[npy siz(1)];
     Calib=CalibIn{icell};
-    xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordiantes of corners
+    xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordinates of corners
     yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5];
     [xcorner_new,ycorner_new]=phys_XYZ(Calib,xima,yima,ZIndex);%corresponding physical coordinates
@@ -177,5 +184,5 @@
 Rangy(2)=min(ycorner);
 Rangy(1)=max(ycorner);
-test_multi=(max(npx)~=min(npx)) | (max(npy)~=min(npy)); 
+test_multi=(max(npx)~=min(npx)) || (max(npy)~=min(npy)); %different image lengths
 npX=1+round((Rangx(2)-Rangx(1))/min(dx));% nbre of pixels in the new image (use the finest resolution min(dx) in the set of images)
 npY=1+round((Rangy(1)-Rangy(2))/min(dy));
@@ -187,6 +194,5 @@
 for icell=1:length(A) 
     Calib=CalibIn{icell};
-    if (isfield(Calib,'R') && ~isequal(Calib.R(2,1),0) && ~isequal(Calib.R(1,2),0)) ||...
-        ((isfield(Calib,'kappa1')&& ~isequal(Calib.kappa1,0))) || test_multi || ~isequal(Calib,CalibIn{1})
+    if isfield(Calib,'R') || isfield(Calib,'kc')|| test_multi ||~isequal(Calib,CalibIn{1})% the image needs to be interpolated to the new coordinates
         zphys=0; %default
         if isfield(Calib,'SliceCoord') %.Z= index of plane
@@ -227,14 +233,14 @@
             A_out{icell}=uint16(A_out{icell});
         end
-    else%
-        
+    else%      
         A_out{icell}=A{icell};%no transform
         Rangx=[0.5 npx-0.5];%image coordiantes of corners
         Rangy=[npy-0.5 0.5];
-        [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[ZIndex ZIndex]);%case of translations without rotation and quadratic deformation
-        [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[ZIndex ZIndex]);
-    end
-end
-
+        [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],ZIndex);%case of translations without rotation and quadratic deformation
+        [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,ZIndex);
+    end
+end
+
+%------------------------------------------------------------------------
 %'phys_XYZ':transforms image (px) to real world (phys) coordinates using geometric calibration parameters
 % function [Xphys,Yphys]=phys_XYZ(Calib,X,Y,Z)
@@ -245,13 +251,10 @@
 %Z: index of plane
 function [Xphys,Yphys,Zphys]=phys_XYZ(Calib,X,Y,Z)
-if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'SliceCoord')&length(Calib.SliceCoord)>=Z
+%------------------------------------------------------------------------
+if exist('Z','var')&& isequal(Z,round(Z))&& Z>0 && isfield(Calib,'SliceCoord')&&length(Calib.SliceCoord)>=Z
     Zindex=Z;
     Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE
 else
-%     if exist('Z','var')
-%         Zphys=Z;
-%     else
-        Zphys=0;
-%     end
+    Zphys=0;
 end
 if ~exist('X','var')||~exist('Y','var')
@@ -260,12 +263,27 @@
     return
 end
-Xphys=X;%default
-Yphys=Y;
-%image transform
+%coordinate transform
+if ~isfield(Calib,'fx_fy')
+     Calib.fx_fy=[1 1];
+end
+if ~isfield(Calib,'Tx_Ty_Tz')
+     Calib.Tx_Ty_Tz=[0 0 1];
+end
+if ~isfield(Calib,'Cx_Cy')
+     Calib.Cx_Cy=[0 0];
+end
+if ~isfield(Calib,'kc')
+     Calib.kc=0;
+end
 if isfield(Calib,'R')
     R=(Calib.R)';
+    Tx=Calib.Tx_Ty_Tz(1);
+    Ty=Calib.Tx_Ty_Tz(2);
+    Tz=Calib.Tx_Ty_Tz(3);
+    f=Calib.fx_fy(1);%dpy=1; sx=1
+    dpx=Calib.fx_fy(2)/Calib.fx_fy(1);
     Dx=R(5)*R(7)-R(4)*R(8);
     Dy=R(1)*R(8)-R(2)*R(7);
-    D0=Calib.f*(R(2)*R(4)-R(1)*R(5));
+    D0=f*(R(2)*R(4)-R(1)*R(5));
     Z11=R(6)*R(8)-R(5)*R(9);
     Z12=R(2)*R(9)-R(3)*R(8);  
@@ -274,20 +292,37 @@
     Zx0=R(3)*R(5)-R(2)*R(6);
     Zy0=R(1)*R(6)-R(3)*R(4);
-    A11=R(8)*Calib.Ty-R(5)*Calib.Tz+Z11*Zphys;
-    A12=R(2)*Calib.Tz-R(8)*Calib.Tx+Z12*Zphys;
-    A21=-R(7)*Calib.Ty+R(4)*Calib.Tz+Z21*Zphys;
-    A22=-R(1)*Calib.Tz+R(7)*Calib.Tx+Z11*Zphys;
-    X0=Calib.f*(R(5)*Calib.Tx-R(2)*Calib.Ty+Zx0*Zphys);
-    Y0=Calib.f*(-R(4)*Calib.Tx+R(1)*Calib.Ty+Zy0*Zphys);
+    A11=R(8)*Ty-R(5)*Tz+Z11*Zphys;
+    A12=R(2)*Tz-R(8)*Tx+Z12*Zphys;
+    A21=-R(7)*Ty+R(4)*Tz+Z21*Zphys;
+    A22=-R(1)*Tz+R(7)*Tx+Z22*Zphys;
+    X0=f*(R(5)*Tx-R(2)*Ty+Zx0*Zphys);
+    Y0=f*(-R(4)*Tx+R(1)*Ty+Zy0*Zphys);
         %px to camera:
-    Xd=(Calib.dpx/Calib.sx)*(X-Calib.Cx); % sensor coordinates
-    Yd=Calib.dpy*(Y-Calib.Cy);
-    dist_fact=1+Calib.kappa1*(Xd.*Xd+Yd.*Yd); %distortion factor
-    Xu=dist_fact.*Xd;%undistorted sensor coordinates
-    Yu=dist_fact.*Yd;
+    Xd=dpx*(X-Calib.Cx_Cy(1)); % sensor coordinates
+    Yd=(Y-Calib.Cx_Cy(2));
+    dist_fact=1+Calib.kc*(Xd.*Xd+Yd.*Yd)/(f*f); %distortion factor
+    Xu=Xd./dist_fact;%undistorted sensor coordinates
+    Yu=Yd./dist_fact;
     denom=Dx*Xu+Dy*Yu+D0;
     % denom2=denom.*denom;
     Xphys=(A11.*Xu+A12.*Yu+X0)./denom;%world coordinates
     Yphys=(A21.*Xu+A22.*Yu+Y0)./denom;
+%     Xd=(X-Calib.Cx_Cy(1))/Calib.fx_fy(1); % sensor coordinates
+%     Yd=(Y-Calib.Cx_Cy(2))/Calib.fx_fy(2);
+%     dist_fact=1+Calib.kc*(Xd.*Xd+Yd.*Yd); %distortion factor
+%     Xu=Xd./dist_fact;%undistorted sensor coordinates
+%     Yu=Yd./dist_fact;
+%     A11=R(7)*Xu-R(1);
+%     A12=R(8)*Xu-R(2);
+%     A21=R(7)*Yu-R(4);
+%     A22=R(8)*Yu-R(5);
+%     B1=(R(3)-R(9)*Xu)*Zphys-Tz*Xu+Tx;
+%     B2=(R(6)-R(9)*Yu)*Zphys-Tz*Yu+Ty;
+%     deter=A12.*A21-A11.*A22;
+%     Xphys=(A21.*B1-A11.*B2)./deter;
+%     Yphys=(-A22.*B1+A12.*B2)./deter;
+else
+    Xphys=-Calib.Tx_Ty_Tz(1)+X/Calib.fx_fy(1);
+    Yphys=-Calib.Tx_Ty_Tz(2)+Y/Calib.fx_fy(2);
 end
 
Index: /trunk/src/transform_field/px.m
===================================================================
--- /trunk/src/transform_field/px.m	(revision 115)
+++ /trunk/src/transform_field/px.m	(revision 116)
@@ -18,5 +18,5 @@
 %      DataIn.A, AX, AY : image or scalar input -> EMPTY  CORRESPONDING OUTPUT (A REVOIR)
 %      Other fields in DataIn: copied to DataOut without modification
-% Calib: structure containing the calibration parameters (Tsai) or containing a subtree Calib.GeometryCalib with these parameters
+% Calib: structure containing the  substructure Calib.GeometryCalib with the calibration parameters
 %
 % call the function  px_XYZ (case of images) for pointwise coordinate transforms
@@ -36,5 +36,8 @@
     DataOut=px_1(Data,CalibData.GeometryCalib);
 end
-if exist('Data_1','var')
+if isfield(DataOut,'Z')
+    DataOut=rmfield(DataOut,'Z');
+end
+if exist('Data_1','var')% if there is a second input field, it is also transformed
     if ~(exist('CalibData_1','var') && isfield(CalibData_1,'GeometryCalib'))
         DataOut_1=Data_1;
@@ -42,5 +45,8 @@
         DataOut_1=px_1(Data_1,CalibData_1.GeometryCalib);
     end
-else
+    if isfield(DataOut_1,'Z')
+        DataOut_1=rmfield(DataOut_1,'Z');
+    end
+else % no second input field then empty second output field
     DataOut_1=[];
 end
@@ -52,9 +58,9 @@
 
 %Act only if .CoordType=phys, and Calib defined
-if isfield(Data,'CoordType')& isequal(Data.CoordType,'phys')& ~isempty(Calib)
+if isfield(Data,'CoordType')&& isequal(Data.CoordType,'phys')&& ~isempty(Calib)
     DataOut.CoordType='px'; %put flag for pixel coordinates
     DataOut.CoordUnit='px';
     %transform of X,Y coordinates
-    if isfield(Data,'Z')&~isempty(Data.Z)
+    if isfield(Data,'Z')&&~isempty(Data.Z)
         Z=Data.Z;
     else
@@ -97,41 +103,41 @@
 % [Zphys]: corresponding array of z physical coordinates (0 by default)
 
-
-function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
-X=[];%default
-Y=[];
-% if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
-%     Zindex=Z;
-%     planepos=Calib.PlanePos{Zindex};
-%     zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
-% else
-%     zphys=0;
+% 
+% function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys)
+% X=[];%default
+% Y=[];
+% % if exist('Z','var')& isequal(Z,round(Z))& Z>0 & isfield(Calib,'PlanePos')&length(Calib.PlanePos)>=Z
+% %     Zindex=Z;
+% %     planepos=Calib.PlanePos{Zindex};
+% %     zphys=planepos(3);%A GENERALISER CAS AVEC ANGLE
+% % else
+% %     zphys=0;
+% % end
+% if ~exist('Zphys','var')
+%     Zphys=0;
 % end
-if ~exist('Zphys','var')
-    Zphys=0;
-end
-
-%%%%%%%%%%%%%
-if isfield(Calib,'R')
-    R=(Calib.R)';
-    xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx;
-    yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty;
-    zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz;
-%undistorted image coordinates
-    Xu=Calib.f*xc./zc;
-    Yu=Calib.f*yc./zc;
-%distorted image coordinates
-    distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
-% distortion=1;
-    Xd=Xu./distortion;
-    Yd=Yu./distortion;
-%pixel coordinates
-    X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
-    Y=Yd/Calib.dpy+Calib.Cy;
-
-elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib  
-        X=Xphys*Calib.Pxcmx;
-        Y=Yphys*Calib.Pxcmy;
-end
+% 
+% %%%%%%%%%%%%%
+% if isfield(Calib,'R')
+%     R=(Calib.R)';
+%     xc=R(1)*Xphys+R(2)*Yphys+R(3)*Zphys+Calib.Tx;
+%     yc=R(4)*Xphys+R(5)*Yphys+R(6)*Zphys+Calib.Ty;
+%     zc=R(7)*Xphys+R(8)*Yphys+R(9)*Zphys+Calib.Tz;
+% %undistorted image coordinates
+%     Xu=Calib.f*xc./zc;
+%     Yu=Calib.f*yc./zc;
+% %distorted image coordinates
+%     distortion=(Calib.kappa1)*(Xu.*Xu+Yu.*Yu)+1; %A REVOIR
+% % distortion=1;
+%     Xd=Xu./distortion;
+%     Yd=Yu./distortion;
+% %pixel coordinates
+%     X=Xd*Calib.sx/Calib.dpx+Calib.Cx;
+%     Y=Yd/Calib.dpy+Calib.Cy;
+% 
+% elseif isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib  
+%         X=Xphys*Calib.Pxcmx;
+%         Y=Yphys*Calib.Pxcmy;
+% end
 
 
Index: /trunk/src/uvmat.m
===================================================================
--- /trunk/src/uvmat.m	(revision 115)
+++ /trunk/src/uvmat.m	(revision 116)
@@ -744,4 +744,16 @@
     set(handles.view_xml,'BackgroundColor',[1 1 1])
     drawnow
+    if isfield(XmlData, 'GeometryCalib') && ~isempty(XmlData.GeometryCalib)
+        hgeometry_calib=findobj('tag','geometry_calib');
+        if ~isempty(hgeometry_calib)
+            GUserData=get(hgeometry_calib,'UserData');
+            if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,filexml))
+                answer=msgbox_uvmat('INPUT_Y-N','replace the display of geometry_calib with the new input data?');
+                if strcmp(answer,'Yes')
+                    geometry_calib(filexml);%diplay the new calibration points and parameters in geometry_calib
+                end
+            end
+        end
+    end  
 elseif exist(fileciv,'file')% if .civ file found 
     [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
@@ -4565,5 +4577,5 @@
 pos(2)=pos(2)-0.02;
 [FileName,RootPath,FileBase,FileIndices,FileExt,SubDir]=read_file_boxes(handles);
-[UvData.hset_object,UvData.sethandles]=geometry_calib(handles,pos,FileName);% call the set_object interface	
+[UvData.hset_object,UvData.sethandles]=geometry_calib(FileName,pos);% call the geometry_calib interface	
 pos_uvmat=get(handles.uvmat,'Position');
 
Index: /trunk/src/view_field.m
===================================================================
--- /trunk/src/view_field.m	(revision 115)
+++ /trunk/src/view_field.m	(revision 116)
@@ -605,4 +605,5 @@
 %-------------------------------------------------------
 function decimate4_Callback(hObject, eventdata, handles)
+'TEST'
 update_plot(handles)
 
