Index: /trunk/src/geometry_calib.m
===================================================================
--- /trunk/src/geometry_calib.m	(revision 696)
+++ /trunk/src/geometry_calib.m	(revision 697)
@@ -848,4 +848,8 @@
 corners_Y=(Coord(end:-1:end-3,5)); 
 
+%%%%%%
+%   corners_X=1000*[1.5415  1.7557 1.7539 1.5415]';
+%   corners_Y=1000*[1.1515 1.1509 1.3645  1.3639]';
+
 %reorder the last two points (the two first in the list) if needed
 angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1)));
@@ -859,5 +863,5 @@
 end
 
-%% initiate the grid
+%% initiate the grid in phys coordinates
 CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
 grid_input=[];%default
@@ -867,4 +871,6 @@
 [T,CalibData.grid,CalibData.grid.CheckWhite]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
 set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
+X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
+Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
 
 %% read the current image, displayed in the GUI uvmat
@@ -873,8 +879,6 @@
 A=UvData.Field.A;%currently displayed image
 npxy=size(A);
-X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
-Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
-
-%calculate transform matrices for plane projection: rectangle assumed to be viewed in perspective
+
+%% calculate transform matrices for plane projection: rectangle assumed to be viewed in perspective
 % reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren
 B = [ X Y ones(size(X)) zeros(4,3)        -X.*corners_X -Y.*corners_X ...
@@ -887,5 +891,5 @@
 C = [l(7:8)' 1];
 
-% transform grid image into 'phys' coordinates 
+%% transform grid image into 'phys' coordinates 
 GeometryCalib.CalibrationType='3D_linear';
 GeometryCalib.fx_fy=[1 1];
@@ -908,7 +912,7 @@
 DataOut=phys(Data,Calib);
 rmpath(fullfile(path_UVMAT,'transform_field'))
-Amod=DataOut.A;% current imgage expressed in 'phys' coord
-Rangx=DataOut.AX;
-Rangy=DataOut.AY;
+Amod=DataOut.A;% current image expressed in 'phys' coord
+Rangx=DataOut.AX;% x coordinates of first and last pixel centres in phys 
+Rangy=DataOut.AY;% y coordinates of first and last pixel centres in phys 
 if CalibData.grid.CheckWhite
     Amod=double(Amod);%case of white grid markers: will look for image maxima
@@ -923,30 +927,19 @@
 ind_range_y=ceil(abs(GeometryCalib.R(2,2)*CalibData.grid.Dy/3));% range of search of image ma around each point obtained by linear interpolation from the marked points
 nbpoints=size(T,1);
-%lokk for image maxima around each expected pgrid point
+TIndex=ones(size(T));% image indices corresponding to point coordinates
+%look for image maxima around each expected grid point
 for ipoint=1:nbpoints
-    i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint));
-    j0=1+round((T(ipoint,2)-Rangy(1))/Dy);%round(Xpx(ipoint));
-    j0min=max(j0-ind_range_y,1);
-    j0max=min(j0+ind_range_y,size(Amod,1));
-    i0min=max(i0-ind_range_x,1);
-    i0max=min(i0+ind_range_x,size(Amod,2));
-    Asub=Amod(j0min:j0max,i0min:i0max);
-  
-
-   
+    i0=1+round((T(ipoint,1)-Rangx(1))/Dx);% x index of the expected point in the phys image Amod
+    j0=1+round((T(ipoint,2)-Rangy(1))/Dy);% y index of the expected point in the phys image Amod
+    j0min=max(j0-ind_range_y,1);% min y index selected for the subimage (cut at the edge to avoid index <1)
+    j0max=min(j0+ind_range_y,size(Amod,1));% max y index selected for the subimage (cut at the edge to avoid index > size)
+    i0min=max(i0-ind_range_x,1);% min x index selected for the subimage (cut at the edge to avoid index <1)
+    i0max=min(i0+ind_range_x,size(Amod,2));% max x index selected for the subimage (cut at the edge to avoid index > size)
+    Asub=Amod(j0min:j0max,i0min:i0max); %subimage used to find brigthness extremum
     x_profile=sum(Asub,1);%profile of subimage summed over y
     y_profile=sum(Asub,2);%profile of subimage summed over x
-    %%%%
-%     if ipoint==5
-%                 figure(10)
-%   imagesc(Asub)
-%     figure(11)
-%     plot(x_profile,'r')
-%     hold on
-%     plot(y_profile,'b')
-%     end
-    %%%%
-    [tild,ind_x_max]=max(x_profile);
-    [tild,ind_y_max]=max(y_profile);
+
+    [tild,ind_x_max]=max(x_profile);% index of max for the x profile
+    [tild,ind_y_max]=max(y_profile);% index of max for the y profile
     %sub-pixel improvement using moments
     x_shift=0;
@@ -960,9 +953,21 @@
         y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop);
     end
-    Delta(ipoint,1)=(i0min+ind_x_max-1+x_shift-i0)*Dx;%shift from the initial guess
-    Delta(ipoint,2)=(j0min+ind_y_max-1+y_shift-j0)*Dy;
-end
-Tmod=T(:,(1:2))+Delta;% 'phys' coordinates of the detected points 
-Tmod(:,2)=flipdim(Tmod(:,2),1);% inverse the order of y coordinates
+        %%%%
+%     if ipoint==9
+%                 figure(11)
+%   imagesc(Asub)
+%     figure(12)
+%     plot(x_profile,'r')
+%     hold on
+%     plot(y_profile,'b')
+%     grid on
+%     end
+    %%%%
+    TIndex(ipoint,1)=(i0min+ind_x_max-1+x_shift);% x position of the maximum (in index of Amod)
+    TIndex(ipoint,2)=(j0min+ind_y_max-1+y_shift);% y position of the maximum (in index of Amod)
+end
+Tmod(:,1)=(TIndex(:,1)-1)*Dx+Rangx(1);
+Tmod(:,2)=(TIndex(:,2)-1)*Dy+Rangy(1);
+%Tmod=T(:,(1:2))+Delta;% 'phys' coordinates of the detected points 
 [Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2));% image coordinates of the detected points
 Coord=[T Xpx Ypx zeros(size(T,1),1)];
@@ -970,4 +975,11 @@
 PLOT_Callback(hObject, eventdata, handles)
 set(handles.APPLY,'BackgroundColor',[1 0 1])
+
+% figure(10)
+% hold off
+% imagesc(Rangx,Rangy,Amod)
+% hold on
+% plot(Tmod(:,1),Tmod(:,2),'+')
+
 
 %-----------------------------------------------------------------------
Index: /trunk/src/xml2struct.m
===================================================================
--- /trunk/src/xml2struct.m	(revision 696)
+++ /trunk/src/xml2struct.m	(revision 697)
@@ -60,5 +60,4 @@
         end
     case 'char' 
-        out=ss; %reproduce the input string
         % try to convert to number if the char does not correspond to a function (otherwise str2num calls this function as it uses 'eval')
         if ~isempty(regexp(ss,'^(-*\d+\.*\d*\ *)+$')) || ~isempty(regexp(ss,'\d+e(-|+)\d+')) % if the string corresponds to a set of numbers (with possible sign and decimal, or scientific notation) separated by blanks
@@ -68,6 +67,7 @@
             if ~isempty(sep_ind)
                 sep_ind=[-2 sep_ind length(ss)+1];
+                out={};
                 for icolumn=1:length(sep_ind)-1
-                    out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1);
+                    out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1);% get info between separators as a cell array
                 end
             else
@@ -76,5 +76,5 @@
         end
     case 'cell'
-        out=[];%default
+        out={};%default
         check_numeric=zeros(size(ss));
         for ilist=1:numel(ss)
