Index: trunk/src/geometry_calib.m
===================================================================
--- trunk/src/geometry_calib.m	(revision 121)
+++ trunk/src/geometry_calib.m	(revision 128)
@@ -54,5 +54,5 @@
                    'gui_LayoutFcn',  [] , ...
                    'gui_Callback',   []);
-if nargin && ischar(varargin{1})
+if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
     gui_State.gui_Callback = str2func(varargin{1});
 end
@@ -95,6 +95,5 @@
 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);
+    [Pathsub,RootFile,field_count,str2,str_a,str_b,ext]=name2display(inputfile);
     if ~strcmp(ext,'.xml')
         inputfile=[fullfile(Pathsub,RootFile) '.xml'];%xml file corresponding to the input file
@@ -103,6 +102,10 @@
 set(handles.ListCoord,'String',{'......'})
 if exist(inputfile,'file')
-    loadfile(handles,inputfile)% load the point coordiantes existing in the xml file
-end
+    Heading=loadfile(handles,inputfile);% load the point coordiantes existing in the xml file
+end
+if isfield(Heading,'Campaign')&& ischar(Heading.Campaign)
+    struct.Campaign=Heading.Campaign;
+end
+set(hObject,'UserData',struct)
 set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function
 
@@ -213,4 +216,6 @@
     ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
     ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
+
+%% record the calibration parameters and display the current image of uvmat in the new phys coordinates
 if strcmp(answer,'Yes')
     if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
@@ -219,5 +224,5 @@
             Z_plane=0; %default
         else
-            Z_plane=str2num(answer_1);
+            Z_plane=str2double(answer_1);
         end
         GeometryCalib.NbSlice=1;
@@ -228,4 +233,5 @@
         msgbox_uvmat('ERROR',errormsg);
     end
+    
     %display image with new calibration in the currently opened uvmat interface
     hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers
@@ -251,12 +257,11 @@
 %------------------------------------------------------------------
 % --- Executes on button press in calibrate_lin.
+
 function REPLICATE_Callback(hObject, eventdata, handles)
-% %%%%%%Todo: correct on the model of APPLY_Callback%%%%%%%%%%
-%------------------------------------------------------------------------
-calib_cell=get(handles.calib_type,'String');
-val=get(handles.calib_type,'Value');
-Coord_cell=get(handles.ListCoord,'String');
-Object=read_geometry_calib(Coord_cell);
-GeometryCalib=feval(['calib_' calib_cell{val}],Object.Coord,handles);
+%------------------------------------------------------------------------
+
+%% Apply calibration
+calib_cell=get(handles.calib_type,'String'); %#ok<NASGU>
+val=get(handles.calib_type,'Value'); %#ok<NASGU>
 
 %read the current calibration points
@@ -288,5 +293,5 @@
     [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima));
     [EM,ind_dim]=max(GeometryCalib.ErrorMax);
-    index=index(ind_dim);
+%     index=index(ind_dim);
     %set the Z position of the reference plane used for calibration
     Z_plane=[];
@@ -295,5 +300,5 @@
     end
     answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane)); 
-    Z_plane=str2num(answer_1);
+    Z_plane=str2double(answer_1);
     GeometryCalib.NbSlice=1;
     GeometryCalib.SliceCoord=[0 0 Z_plane];
@@ -304,9 +309,7 @@
     %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
-end
+end
+
+%% display calibration paprameters
 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
 
@@ -319,24 +322,5 @@
 set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4))
 
-% indicate the plane of the calibration grid if defined
-% huvmat=findobj(allchild(0),'Name','uvmat');
-% hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
-% RootPath='';
-% RootFile='';
-% if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile)
-%     testhandle=1;
-%     RootPath=get(hhuvmat.RootPath,'String');
-%     RootFile=get(hhuvmat.RootFile,'String');
-%     filebase=fullfile(RootPath,RootFile);
-%     outputfile=[filebase '.xml'];
-% else
-%     question={'save the calibration data and point coordinates in'};
-%     def={fullfile(RootPath,['ObjectCalib.xml'])};
-%     options.Resize='on';
-%     answer=inputdlg(question,'save average in a new file',1,def,options);
-%     outputfile=answer{1};
-% end
-
-%open and read the dataview GUI
+%% open the GUI dataview 
 h_dataview=findobj(allchild(0),'name','dataview');
 if ~isempty(h_dataview)
@@ -344,47 +328,64 @@
 end
 CalibData=get(handles.geometry_calib,'UserData');%read the calibration image source on the interface userdata
-
+InputFile='';
 if isfield(CalibData,'XmlInputFile')
-    XmlInput=fileparts(CalibData.XmlInputFile);
-    [XmlInput,filename,ext]=fileparts(XmlInput);
+    InputDir=fileparts(CalibData.XmlInputFile);
+    [InputDir,DirName]=fileparts(InputDir);
 end
 SubCampaignTest='n'; %default
-testinput=0;
-if isfield(CalibData,'Heading')
-    Heading=CalibData.Heading;
-    if isfield(Heading,'Record') && isequal([filename ext],Heading.Record)
-        [XmlInput,filename,ext]=fileparts(XmlInput);
-    end
-    if isfield(Heading,'Device') && isequal([filename ext],Heading.Device)
-        [XmlInput,filename,ext]=fileparts(XmlInput);
-        Device=Heading.Device;
-    end
-    if isfield(Heading,'Experiment') && isequal([filename ext],Heading.Experiment)
-        [PP,filename,ext]=fileparts(XmlInput);
-    end
-    testinput=0;
-    if isfield(Heading,'SubCampaign') && isequal([filename ext],Heading.SubCampaign)
-        SubCampaignTest='y';
-        testinput=1;
-    elseif isfield(Heading,'Campaign') && isequal([filename ext],Heading.Campaign)
-        testinput=1;
-    end 
-end
-if ~testinput
-    filename='PROJETS';%default
-    if isfield(CalibData,'XmlInputFile')
-         [pp,filename]=fileparts(CalibData.XmlInputFile);
-    end
-    while ~isequal(filename,'PROJETS') && numel(filename)>1
-        filename_1=filename;
-        pp_1=pp;
-        [pp,filename]=fileparts(pp);
-    end
-    XmlInput=fullfile(pp_1,filename_1);
-    testinput=1;
-end
-if testinput
-    outcome=dataview(XmlInput,SubCampaignTest,GeometryCalib);
-end
+testup=0;
+if isfield(CalibData,'SubCampaign')
+    SubCampaignTest='y';
+    dir_ref=CalibData.SubCampaign;
+    testup=1;
+elseif isfield(CalibData,'Campaign')
+    dir_ref=CalibData.Campaign;
+    testup=1;
+end
+while testup
+    [InputDir,DirName]=fileparts(InputDir);
+    if strcmp(DirName,dir_ref)
+        break
+    end
+end
+InputDir=fullfile(InputDir,DirName);
+answer=msgbox_uvmat('INPUT_TXT','Campaign ?',InputDir); 
+if strcmp(answer,'Cancel')
+    return
+end
+
+dataview(answer,SubCampaignTest,GeometryCalib);
+        
+%     if isfield(Heading,'Device') && isequal([filename ext],Heading.Device)
+%         [XmlInput,filename,ext]=fileparts(XmlInput);
+%         Device=Heading.Device;
+%     end
+%     if isfield(Heading,'Experiment') && isequal([filename ext],Heading.Experiment)
+%         [PP,filename,ext]=fileparts(XmlInput);
+%     end
+%     testinput=0;
+%     if isfield(Heading,'SubCampaign') && isequal([filename ext],Heading.SubCampaign)
+%         SubCampaignTest='y';
+%         testinput=1;
+%     elseif isfield(Heading,'Campaign') && isequal([filename ext],Heading.Campaign)
+%         testinput=1;
+% %     end 
+% end
+% if ~testinput
+%     filename='PROJETS';%default
+%     if isfield(CalibData,'XmlInputFile')
+%          [pp,filename]=fileparts(CalibData.XmlInputFile);
+%     end
+%     while ~isequal(filename,'PROJETS') && numel(filename)>1
+%         filename_1=filename;
+%         pp_1=pp;
+%         [pp,filename]=fileparts(pp);
+%     end
+%     XmlInput=fullfile(pp_1,filename_1);
+%     testinput=1;
+% end
+% if testinput
+%     outcome=dataview(XmlInput,SubCampaignTest,GeometryCalib);
+% end
 
 %------------------------------------------------------------------------
@@ -434,5 +435,5 @@
 R=[R;[0 0]];
 GeometryCalib.R=[R [0;0;1]];
-GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0]
+GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0];
 %------------------------------------------------------------------------
 % determine the tsai parameters for a view normal to the grid plane
@@ -700,5 +701,5 @@
 
 %--------------------------------------------------------------------------
-function GeometryCalib=calib_tsai(Coord,handles)% old version using gauthier's bianry ccal_fo
+function GeometryCalib=calib_tsai(Coord,handles)% OBSOLETE: old version using gauthier's bianry ccal_fo
 % NOT USED
 %------------------------------------------------------------------------
@@ -811,6 +812,6 @@
 huvmat=findobj(allchild(0),'Name','uvmat');
 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat
-RootPath='';
-RootFile='';
+% RootPath='';
+% RootFile='';
 if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
     testhandle=1;
@@ -830,5 +831,5 @@
         listfile={outputfile};
     else
-        listfile=[listfile;{outputfile}]%update the list of coord files
+        listfile=[listfile;{outputfile}];%update the list of coord files
     end
     set(handles.coord_files,'string',listfile);
@@ -901,5 +902,5 @@
 end
 coord_str=Coord_cell{val};
-k=findstr('|',coord_str);
+k=findstr(' | ',coord_str);
 if isempty(k)%last line '.....' selected
     if ~isempty(hhh)
@@ -1000,7 +1001,7 @@
 %------------------------------------------------------------------------
 huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle
-UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
+%UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface
 hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat
-hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
+%hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat
 h_menu_coord=findobj(huvmat,'Tag','transform_fct');
 menu=get(h_menu_coord,'String');
@@ -1079,5 +1080,5 @@
 
 %size(data.Coord,1)
-Tabchar=cell2tab(Coord,'    |    ');
+Tabchar=cell2tab(Coord,' | ');
 Tabchar=[Tabchar ;{'......'}];
 set(handles.ListCoord,'String',Tabchar)
@@ -1236,5 +1237,5 @@
      Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digits
 end
-Tabchar=cell2tab(Coord(end:-1:1,:),'    |    ');
+Tabchar=cell2tab(Coord(end:-1:1,:),' | ');
 Tabchar=[Tabchar ;{'......'}];
 set(handles.ListCoord,'Value',1)
@@ -1266,5 +1267,5 @@
    end
 end
-Tabchar=cell2tab(Coord,'    |    ');
+Tabchar=cell2tab(Coord,' | ');
 Tabchar=[Tabchar; {'.....'}];
 %set(handles.ListCoord,'Value',1)
@@ -1310,5 +1311,5 @@
    end
 end
-Tabchar=cell2tab(Coord,'    |    ');
+Tabchar=cell2tab(Coord,'| ');
 Tabchar=[Tabchar;{'......'}];
 set(handles.ListCoord,'Value',1)
@@ -1460,5 +1461,5 @@
 end
 CoordCell=reshape(CoordCell,[],5);
-Tabchar=cell2tab(CoordCell,'    |    ');%transform cells into table ready for display
+Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
 Tabchar=[Tabchar;{'......'}];
 set(handles.ListCoord,'Value',1)
@@ -1541,7 +1542,16 @@
 
 % -----------------------------------------------------------------------
-function loadfile(handles,fileinput)
-%------------------------------------------------------------------------
+function Heading=loadfile(handles,fileinput)
+%------------------------------------------------------------------------
+Heading=[];%default
 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
+if ~isempty(errormsg)
+    msgbox_uvmat('ERROR',['Error for reading ' fileinput ': '  errormsg])
+    return
+end
+if ~isempty(s.Heading)
+    Heading=s.Heading;
+end
+    
 GeometryCalib=s.GeometryCalib;
 fx=1;fy=1;Cx=0;Cy=0;kc=0; %default
@@ -1585,5 +1595,5 @@
     end
     CoordCell=reshape(CoordCell,[],5);
-    Tabchar=cell2tab(CoordCell,'    |    ');%transform cells into table ready for display
+    Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display
     MenuPlot_Callback(handles.geometry_calib, [], handles)
 end
