Index: trunk/src/datatree_browser.m
===================================================================
--- trunk/src/datatree_browser.m	(revision 503)
+++ trunk/src/datatree_browser.m	(revision 507)
@@ -22,5 +22,5 @@
 function varargout = datatree_browser(varargin)
 
-% Last Modified by GUIDE v2.5 26-Jul-2012 08:24:26
+% Last Modified by GUIDE v2.5 29-Jul-2012 08:49:20
 
 % Begin initialization code - DO NOT EDIT
@@ -45,5 +45,5 @@
 %------------------------------------------------------------------------
 % --- Executes just before datatree_browser is made visible.
-function datatree_browser_OpeningFcn(hObject, eventdata, handles, projectxml)
+function datatree_browser_OpeningFcn(hObject, eventdata, handles, InputName)
 %------------------------------------------------------------------------
 % Choose default command line output for datatree_browser
@@ -74,58 +74,32 @@
 set(hObject, 'Units', OldUnits);
 
-% % Show a question icon from dialogicons.mat - variables questIconData and questIconMap
-% load dialogicons.mat
-% eval(['IconData=' icontype 'IconData;'])
-% eval(['IconCMap=' icontype 'IconMap;'])
-% questIconMap(256,:) = get(handles.figure1, 'Color');
-% Img=image(IconData, 'Parent', handles.axes1);
-% set(handles.figure1, 'Colormap', IconCMap);
-% set(handles.axes1, ...
-%     'Visible', 'off', ...
-%     'YDir'   , 'reverse'       , ...
-%     'XLim'   , get(Img,'XData'), ...
-%     'YLim'   , get(Img,'YData')  ...
-%     );
-% if exist('GeometryCalib','var')
-%     DataviewData.GeometryCalib=GeometryCalib;
-%     set(hObject,'UserData',DataviewData)
-% end
-% if exist('SubCampaignTst','var') && isequal(SubCampaignTst,'y')
-%    set(handles.SubCampaignTest,'Value',1);
-% end
-if ~isempty(regexp(projectxml,'.project.xml$')) 
-            if exist(regexprep(projectxml,'.project.xml$','.link'),'dir')
-                
-                set(handles.LinkDir,'String',regexprep(projectxml,'.project.xml$','.link'))
-                XmlContent=xml2struct(projectxml);
-                set(handles.SourceDir,'String',XmlContent.SourceDir)
-                set(handles.UpdateLink,'String','UpdateLink')
-%                 datatree_browser(regexprep(fileinput,'.project.xml$','.link'))
-
-        elseif exist(regexprep(projectxml,'.project.xml$',''),'dir')
-                set(handles.SourceDir,'String',regexprep(projectxml,'.project.xml$',''))
+if exist('InputName','var')
+    if isdir(InputName)% opening by uvmat/MenuSetProject
+        set(handles.SourceDir,'String',InputName)% the input directory is considered as a project
+        set(handles.LinkDir,'Visible','off')
+        set(handles.UpdateLink,'String','create_link')
+        set(handles.MarkupDir,'Visible','on')
+
+    else% opening by uvmat/Open
+        InputDir=regexprep(InputName,'.xml$','');
+        if exist(InputDir,'dir')
+            s=xml2struct(InputName);
+            if isfield(s,'SourceDir')
+                set(handles.SourceDir,'String',s.SourceDir)
+                set(handles.LinkDir,'String',InputDir)
+                set(handles.LinkDir,'Visible','on')
+            else
+                set(handles.SourceDir,'String',InputDir)
                 set(handles.LinkDir,'Visible','off')
-                set(handles.UpdateLink,'String','CreateLink')
+                set(handles.MarkupDir,'String','CreateLink')
+            end
         end
-    set(handles.OK,'Visible','on')
-    set(handles.Cancel,'Visible','on')
-    set(handles.figure,'WindowStyle','modal')% Make% Make the GUI modal 
-    drawnow
- uiwait(handles.figure);
-end
-% if exist('RootDir','var') 
-%    set(handles.SourceDir,'String',RootDir);
-% %    set(handles.clean_civ_cmx,'Visible','off')
-%    set(handles.edit_xml,'Visible','off')
-%    set(handles.HELP,'Visible','off')
-%    set(handles.OK,'Visible','on')
-%    set(handles.Cancel,'Visible','on')
-%    set(handles.figure,'WindowStyle','modal')% Make% Make the GUI modal 
-%    set(hObject,'Visible','on')
-%    drawnow
-%    %RootDirectory_Callback(hObject, eventdata, handles)
-%    % UIWAIT makes translate_points wait for user response (see UIRESUME)
-%    uiwait(handles.figure);
-% end
+                FillExperiments(handles)
+        set(handles.OK,'Visible','on')
+        drawnow
+        
+    end
+end
+
 
 %------------------------------------------------------------------------
@@ -135,295 +109,74 @@
 % Get default command line output from handles structure
 varargout{1} = handles.output;
-%delete(handles.figure)
-
-%------------------------------------------------------------------------
-% --- Executes on button press in UpdateLink.
+%delete(handles.datatree_browser)
+
+%------------------------------------------------------------------------
+% --- Executes on button press in MarkupDir: create a xml file to mark SourceDir as project source
+function MarkupDir_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------
+SourceDir=get(handles.SourceDir,'String');
+t=xmltree;
+t=set(t,1,'name','Project');
+try
+save(t,[SourceDir '.xml'])
+catch ME
+    msgbox_uvmat('ERROR',ME.message)
+end
+
+%------------------------------------------------------------------------
+% --- Executes on button press in UpdateLink: create a link dir or update it if it exists
 function UpdateLink_Callback(hObject, eventdata, handles)
 %------------------------------------------------------------------------
-InputString=get(handles.UpdateLink,'String')
-switch InputString
-    case 'CreateLink'
-        CurrentDir=fileparts(get(handles.SourceDir,'String'));
-        if ~exist(CurrentDir,'dir')
-            CurrentDir='';
-        end
-        SourceDir=uigetdir(CurrentDir,'pick up the source project directory'); %file browser
-        if isequal(SourceDir,0)
-            return
-        else
-            set(handles.SourceDir,'String',SourceDir)
-        end
-        drawnow
-        [SourcePath,ProjectName]=fileparts(SourceDir);
-        MirrorRoot=uigetdir(CurrentDir,'path to the link directory'); %file browser
-        if isempty(MirrorRoot)
-            return
-        else
-            MirrorDir=fullfile(MirrorRoot,[ProjectName '.link']);
-        end
-        if ~exist(MirrorDir,'dir')
-            mkdir(MirrorDir)
-        end
-        MirrorDoc.SourceDir=SourceDir;
-        t=struct2xml(MirrorDoc);
-        set(t,1,'name','DataTree');
-        save(t,fullfile(MirrorDir,[ProjectName '.xml']))
-        set(handles.LinkDir,'String',MirrorDir)
-        
-        %update_link(SourceDir,LinkDir)
-        SourceDir_Callback([],[], handles)
-    case 'UpDateLink'
-        %      MirrorDir=get(handles.LinkDir,'String');
-        % menu={'*.xml', ' (*.xml)';
-        %     '*.xml',  '.xml files '; ...
-        %     '*.*',  'All Files (*.*)'};
-        % [MirrorXml, PathName] = uigetfile( menu, 'Pick the head xml file in the link directory',MirrorDir);
-        [MirrorXml, PathName]=fileparts(get(handles.LinkDir,'String'));
-        %set(handles.LinkDir,'String',fullfile(PathName,regexprep(MirrorXml,'.xml$','.link')))
-        LinkDir_Callback(hObject, eventdata, handles)
-end
-
-% RootDirectory_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-% --- Executes on button press in open_SubCampaign.
-function UpdateMirror_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-% MirrorDir=get(handles.LinkDir,'String');
-% menu={'*.xml', ' (*.xml)';
-%     '*.xml',  '.xml files '; ...
-%     '*.*',  'All Files (*.*)'};
-% [MirrorXml, PathName] = uigetfile( menu, 'Pick the head xml file in the link directory',MirrorDir);
-% set(handles.LinkDir,'String',fullfile(PathName,regexprep(MirrorXml,'.xml$','.link')))
-% MirrorDir_Callback(hObject, eventdata, handles)
-
-
-%------------------------------------------------------------------------
-function LinkDir_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------   
-MirrorDir=get(handles.LinkDir,'String');
-[tild,MirrorName]=fileparts(MirrorDir);
-s=xml2struct(fullfile(MirrorDir,[MirrorName '.xml']));
-set(handles.SourceDir,'String',s.SourceDir)
-SourceDir_Callback([],[], handles)
-%update_link(s.SourceDir, LinkDir)
-
-
-% %------------------------------------------------------------------------
-% function update_link(SourceDir,LinkDir,handles)
-% %------------------------------------------------------------------------
-% SourceDir_Callback([],[], handles)
-
-%------------------------------------------------------------------------
-function SourceDir_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-set(handles.SourceDir,'BackgroundColor',[1 1 0])
-drawnow
+[SourcePath,ProjectName]=fileparts(get(handles.SourceDir,'String'));
+LinkDir=get(handles.LinkDir,'String');
+if isempty(LinkDir)||strcmp(get(handles.LinkDir,'Visible'),'off')
+    LinkRoot=uigetdir(LinkDir,'pick up the path to the link directory'); %file browser
+    if isempty(LinkRoot),return,end
+    LinkDir=fullfile(LinkRoot,[ProjectName '.link']);
+    set(handles.LinkDir,'Visible','on')
+    set(handles.LinkDir,'String',LinkDir)
+end
+
+if ~exist(LinkDir,'dir')
+    try
+        mkdir(LinkDir)
+    catch ME
+        msgbox_uvmat('ERROR',ME.message)
+    end
+end
+LinkDirXml=fullfile(fileparts(LinkDir),[ProjectName '.link.xml']);
+if ~exist(LinkDirXml,'file')
+    LinkDoc.SourceDir=get(handles.SourceDir,'String');
+    t=struct2xml(LinkDoc);
+    t=set(t,1,'name','Project');
+    save(t,LinkDirXml)
+    set(handles.UpdateLink,'String','update_link')
+end
+
+FillExperiments(handles)
+
+%------------------------------------------------------------------------
+% --- Fill the column 'Experiments' with the list of detected directries
+function FillExperiments(handles)
+%------------------------------------------------------------------------    
 SourceDir=get(handles.SourceDir,'String');
-MirrorDir=get(handles.LinkDir,'String');
-ExpName={''};
-if exist(SourceDir,'dir')
-    hdir=dir(SourceDir); %list files and dirs
-    idir=0;
-    for ilist=1:length(hdir)
-        if hdir(ilist).isdir
-            dirname=hdir(ilist).name;
-            if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
-                idir=idir+1;
-                ExpName{idir}=hdir(ilist).name;
-                link=fullfile(MirrorDir,ExpName{idir})
+LinkDir='';
+if strcmp(get(handles.LinkDir,'Visible'),'on')
+    LinkDir=get(handles.LinkDir,'String');
+end
+
+hdir=dir(SourceDir); %list files and dirs
+idir=0;
+ExpName=cell(length(hdir),1);
+for ilist=1:length(hdir)
+    if hdir(ilist).isdir
+        dirname=hdir(ilist).name;
+        if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')% do not list directories beginning by '0'
+            idir=idir+1;
+            ExpName{idir}=hdir(ilist).name;
+            if ~isempty(LinkDir)
+                link=fullfile(LinkDir,ExpName{idir});
                 if ~exist(link,'dir')
-                   mkdir(link)
-                end
-            end
-            % look for the list of 'devices'
-        else
-            %warning for isolated files
-        end
-    end
-    set(handles.ListExperiments,'String',[{'*'};ExpName'])
-    set(handles.ListExperiments,'Value',1)
-    ListExperiments_Callback(hObject, eventdata, handles)
-else
-    msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory'])
-end
-set(handles.SourceDir,'BackgroundColor',[1 1 1])
-
-
-%------------------------------------------------------------------------
-% --- Executes on selection change in ListExperiments.
- function ListExperiments_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-SourcePath=get(handles.SourceDir,'String');
-MirrorPath=get(handles.LinkDir,'String');
-ListExperiments=get(handles.ListExperiments,'String');
-ListDevices={};
-list_val=get(handles.ListExperiments,'Value');
-if isequal(list_val(1),1)
-    ListExperiments=ListExperiments(2:end); %choose all experiments
-    testList=1;
-    set(handles.ListExperiments,'Value',1)
-else
-    ListExperiments=ListExperiments(list_val);%choose selected experiments
-    testList=0;
-end
-for iexp=1:numel(ListExperiments)
-    hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and dirs
-    idir=0;
-    for ilist=1:length(hdir)
-         if ~isequal(hdir(ilist).name(1),'.')
-        source=fullfile(SourcePath,ListExperiments{iexp},hdir(ilist).name);
-        link=fullfile(MirrorPath,ListExperiments{iexp},hdir(ilist).name);
-        if ~exist(link)
-            system(['ln -s ' source ' ' link])
-        end
-        check_list=strcmp(hdir(ilist).name,ListDevices);
-        if isempty(find(check_list))
-            ListDevices=[ListDevices;hdir(ilist).name];
-        end    
-         end
-    end
-end
-set(handles.ListDevices,'String',ListDevices)
-%         if hdir(ilist).isdir
-%             dirname=hdir(ilist).name;
-%             if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
-%                 idir=idir+1;
-%                 ExpName{idir}=hdir(ilist).name;
-%                 link=fullfile(LinkDir,ExpName{idir});
-%                 if ~exist(link,'dir')
-%                    mkdir(link)
-%                 end
-%             end
-%             % look for the list of 'devices'
-%         else
-%             %warning for isolated files
-%         end
-%     end
-%     set(handles.ListExperiments,'String',[{'*'};ExpName'])
-%     set(handles.ListExperiments,'Value',1)
-%     ListExperiments_Callback(hObject, eventdata, handles)
-    
-    
-% set(handles.ListDevices,'Value',1)
-% set(handles.ListRecords,'Value',1)
-% set(handles.ListXml,'Value',1)
-% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,{},{});
-% set(handles.ListRecords,'String',[{'*'};ListRecords'])
-% set(handles.ListDevices,'String',[{'*'};ListDevices'])
-% set(handles.ListXml,'String',[{'*'};ListXml'])
-% if testList
-%     DataviewData=get(handles.figure,'UserData');
-%     DataviewData.List=List;
-%     set(handles.figure,'UserData',DataviewData)
-% end
-% set(handles.CampaignDoc,'Visible','on')
-% set(handles.edit_xml,'Visible','on')
-
-%------------------------------------------------------------------------
-% --- Executes on button press in update_headings.
-function ListDevices_Callback(hObject, eventdata, handles)
-CurrentPath=get(handles.SourceDir,'String');
-ListExperiments=get(handles.ListExperiments,'String');
-list_val=get(handles.ListExperiments,'Value');
-if isequal(list_val,1)
-    ListExperiments=ListExperiments(2:end);
-else
-    ListExperiments=ListExperiments(list_val);
-end
-set(handles.ListRecords,'Value',1)
-set(handles.ListXml,'Value',1)
-ListDevices=get(handles.ListDevices,'String');
-list_val=get(handles.ListDevices,'Value');
-if isequal(list_val,1)
-    ListDevices=ListDevices(2:end);
-else
-    ListDevices=ListDevices(list_val);
-end
-[ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
-set(handles.ListRecords,'String',[{'*'};ListRecords'])
-set(handles.ListXml,'String',[{'*'};ListXml'])
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-
-%------------------------------------------------------------------------
-% --- Executes on selection change in ListRecords.
-function ListRecords_Callback(hObject, eventdata, handles)
-Value=get(handles.ListRecords,'Value');
-if isequal(Value(1),1)
-    set(handles.ListRecords,'Value',1);
-end
-
-%------------------------------------------------------------------------
-% --- Executes on button press in CampaignDoc.
-function CampaignDoc_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------   
-answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file')
-if ~isequal(answer{1},'OK')
-    return
-end
-set(handles.ListExperiments,'Value',1)
-ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
-DataviewData=get(handles.figure,'UserData');
-List=DataviewData.List;
-Currentpath=get(handles.SourceDir,'String');
-[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
-Campaign=[Campaign DirExt];
-t=xmltree;
-t=set(t,1,'name','CampaignDoc');
-t = attributes(t,'add',1,'source','directory');
-SubCampaignTest=get(handles.SubCampaignTest,'Value');
-root_uid=1;
-if SubCampaignTest
-    %TO DO open an exoiting xml doc
-    [t,root_uid]=add(t,1,'element','SubCampaign');
-    t =attributes(t,'add',root_uid,'DirName',Campaign);
-end
-for iexp=1:length(List.Experiment)
-    set(handles.ListExperiments,'Value',iexp+1)
-    drawnow
-    test_mod=0;
-    [t,uid_exp]=add(t,root_uid,'element','Experiment');
-    t = attributes(t,'add',uid_exp,'i',num2str(iexp));
-    ExpName=List.Experiment{iexp}.name;
-    t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
-   
-    if isfield(List.Experiment{iexp},'Device')
-        for idevice=1:length(List.Experiment{iexp}.Device)
-            [t,uid_device]=add(t,uid_exp,'element','Device');
-            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
-            t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
-            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
-                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
-                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
-                    [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
-                    if test
-                        [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
-                    end
-                    if isequal(Title,'ImaDoc')
-                        [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
-                        t = attributes(t,'add',uid_xml,'source','file');
-                        [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                    
-                    end
-                end
-             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
-                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
-                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
-                    [t,uid_record]=add(t,uid_device,'element','Record');
-                    t = attributes(t,'add',uid_record,'DirName',RecordName);
-                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
-                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
-                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
-                            [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
-                            if test
-                                [FileName ' , Heading updated']
-                            end
-                            [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
-                            t = attributes(t,'add',uid_xml,'source','file');
-                            [t]=add(t,uid_xml,'chardata',FileName);
-                        end
-                    end
+                    mkdir(link)% create the directory containing links
                 end
             end
@@ -431,177 +184,359 @@
     end
 end
+set(handles.ListExperiments,'String',[{'*'};ExpName(1:idir)])
 set(handles.ListExperiments,'Value',1)
-outputdir=get(handles.SourceDir,'String');
-[path,dirname]=fileparts(outputdir);
-outputfile=fullfile(outputdir,[dirname '.xml']);
-%campaigndoc(t);
-save(t,outputfile)
-
-%------------------------------------------------------------------------
-% --- Executes on button press in CampaignDoc.
-function edit_xml_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-CurrentPath=get(handles.SourceDir,'String');
-%[CurrentPath,Name,Ext]=fileparts(CurrentDir);
+ListExperiments_Callback([],[], handles)
+
+
+%------------------------------------------------------------------------
+% --- Executes on selection change in ListExperiments.
+ function ListExperiments_Callback(hObject,eventdata,handles)
+%------------------------------------------------------------------------
+SourcePath=get(handles.SourceDir,'String');
+MirrorPath='';
+if strcmp(get(handles.LinkDir,'Visible'),'on')
+MirrorPath=get(handles.LinkDir,'String');
+end
 ListExperiments=get(handles.ListExperiments,'String');
-Value=get(handles.ListExperiments,'Value');
-if ~isequal(Value,1)
-    ListExperiments=ListExperiments(Value);
-end
-ListDevices=get(handles.ListDevices,'String');
-Value=get(handles.ListDevices,'Value');
-if ~isequal(Value,1)
-    ListDevices=ListDevices(Value);
-end
-ListRecords=get(handles.ListRecords,'String');
-Value=get(handles.ListRecords,'Value');
-if ~isequal(Value,1)
-    ListRecords=ListRecords(Value);
-end
-[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
-ListXml=get(handles.ListXml,'String');
-Value=get(handles.ListXml,'Value');
-set(handles.ListXml,'Value',Value(1));
-if isequal(Value(1),1)
-    msgbox_uvmat('ERROR','an xml file needs to be selected')
-   return
+if isequal(get(handles.ListExperiments,'Value'),1)
+    ListExperiments=ListExperiments(2:end); %choose all experiments
 else
-    XmlName=ListXml{Value(1)};
-end
-for iexp=1:length(List.Experiment)
-    ExpName=List.Experiment{iexp}.name;
-    if isfield(List.Experiment{iexp},'Device')
-        for idevice=1:length(List.Experiment{iexp}.Device)
-            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
-            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
-                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
-                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
-                    if isequal(FileName,XmlName)
-                        editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
-                        return
-                    end
+    ListExperiments=ListExperiments(get(handles.ListExperiments,'Value'));
+end
+ListDevices={};
+
+for iexp=1:numel(ListExperiments)
+    hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and dirs
+    for ilist=1:length(hdir)
+        Device=hdir(ilist).name;
+        if ~isequal(Device(1),'.')
+            if ~isempty(MirrorPath)% we list the links to the data directories of files
+                link=fullfile(MirrorPath,ListExperiments{iexp},Device);
+                if ~exist(link)
+                    source=fullfile(SourcePath,ListExperiments{iexp},Device);
+                    system(['ln -s ' source ' ' link])%TODO translate for DOS
                 end
-             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
-                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
-                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
-                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
-                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
-                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
-                            if isequal(FileName,XmlName)
-                                editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
-                                return
-                            end                          
-                        end
-                    end
-                end
+                Device=['@' Device];
+            end
+            if hdir(ilist).isdir
+                Device=[Device '/'];
+            end
+            check_list=strcmp(Device,ListDevices);
+            if isempty(find(check_list))
+                ListDevices=[ListDevices;Device];
             end
         end
     end
 end
-
-
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% CurrentPath/Campaign: root directory 
-function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
-
- %Shema for Heading:
-%  Campaign             
-%  (SubCampaign)
-% Experiment
-%  Device
-%  (Record)
-%  ImageName
-%  DateExp
-%                 old: %Project: suppressed ( changed to Campaign)
-                       %Exp: suppressed (changed to experiment)
-                       %ImaNames: changed to ImageName
-if exist('Record','var') && ~isempty(Record)
-    xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname);  
-    testrecord=1;
-else
-    xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname); 
-    testrecord=0;
-end
-if ~exist('testSubCampaign','var')
-    testSubCampaign=0;
-end
-if testSubCampaign
-   SubCampaign=Campaign;
-   [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
-   Campaign=[Campaign DirExt];
-end
-test_mod=0; %test for the modification of the xml file
-t_device=xmltree(xmlfullname);
-Title=get(t_device,1,'name');
-uid_child=children(t_device,1);
-Heading_old=[];
-uidheading=0;
-for ilist=1:length(uid_child)
-    name=get(t_device,uid_child(ilist),'name');
-    if isequal(name,'Heading')
-        uidheading=uid_child(ilist);
+set(handles.ListDevices,'String',ListDevices)
+
+
+%------------------------------------------------------------------------
+% --- Executes on selection in column ListDevices
+function ListDevices_Callback(hObject, eventdata, handles)
+%------------------------------------------------------------------------    
+list_val=get(handles.ListExperiments,'Value');
+if numel(list_val)~=1
+    msgbox_uvmat('ERROR','select a single experiment')
+    return
+end
+ListExperiments=get(handles.ListExperiments,'String');
+Experiment=ListExperiments{list_val};
+RootPath='';
+if strcmp(get(handles.LinkDir,'Visible'),'on')
+    RootPath=get(handles.LinkDir,'String');
+end
+if isempty(RootPath)
+RootPath=get(handles.SourceDir,'String');
+end
+ListDevices=get(handles.ListDevices,'String');
+Device=ListDevices{get(handles.ListDevices,'Value')};
+Device=regexprep(Device,'^@','');
+if strcmp(Device(end),'/')
+    DataDir=fullfile(RootPath,Experiment,Device(1:end-1));
+    DirList=dir(DataDir);
+    for ilist=1:numel(DirList)
+        [tild,tild,FileExt]=fileparts(DirList(ilist).name);
+        FileExt=regexprep(FileExt,'^.','');
+        if ~isempty(FileExt) && (~isempty(imformats(FileExt))||strcmp(lower(FileExt),'avi')||strcmp(lower(FileExt),'nc'))
+            uvmat(fullfile(DataDir,DirList(ilist).name))
+            return
+        end
     end
 end
-if uidheading
-    subt=branch(t_device,uidheading);
-    Heading_old=convert(subt);
-else
-   return % do not edit xml files without element 'Heading'
-end
-if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
-    test_mod=1;
-end
-Heading.Campaign=Campaign;
-if testSubCampaign
-    if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
-        test_mod=1;
-    end
-    Heading.SubCampaign=SubCampaign;
-end
-if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
-    test_mod=1;
-end
-Heading.Experiment=Experiment;
-if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
-    test_mod=1;
-end
-Heading.Device=Device;
-if testrecord
-    if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
-        test_mod=1;
-    end
-    Heading.Record=Record;
-end
-if isfield(Heading_old,'ImaNames')
-    test_mod=1;
-    if  ~isempty(Heading_old.ImaNames)
-        Heading.ImageName=Heading_old.ImaNames;
-    end
-end
-if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
-    Heading.ImageName=Heading_old.ImageName;
-end
-if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
-    Heading.DateExp=Heading_old.DateExp;
-end
-if test_mod && uidheading
-     uid_child=children(t_device,uidheading);
-     t_device=delete(t_device,uid_child);
-    t_device=struct2xml(Heading,t_device,uidheading);
-    backupfile=xmlfullname;
-    testexist=2;
-    while testexist==2
-       backupfile=[backupfile '~'];
-       testexist=exist(backupfile,'file');
-    end
-    [success,message]=copyfile(xmlfullname,backupfile);%make backup
-    if isequal(success,1)
-        delete(xmlfullname)
-    else
-        return
-    end
-    save(t_device,xmlfullname)
-end
+% 
+% set(handles.ListRecords,'Value',1)
+% set(handles.ListXml,'Value',1)
+% ListDevices=get(handles.ListDevices,'String');
+% list_val=get(handles.ListDevices,'Value');
+% if isequal(list_val,1)
+%     ListDevices=ListDevices(2:end);
+% else
+%     ListDevices=ListDevices(list_val);
+% end
+% [ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
+% set(handles.ListRecords,'String',[{'*'};ListRecords'])
+% set(handles.ListXml,'String',[{'*'};ListXml'])
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+
+% %------------------------------------------------------------------------
+% % --- Executes on selection change in ListRecords.
+% function ListRecords_Callback(hObject, eventdata, handles)
+% Value=get(handles.ListRecords,'Value');
+% if isequal(Value(1),1)
+%     set(handles.ListRecords,'Value',1);
+% end
+
+% %------------------------------------------------------------------------
+% % --- Executes on button press in CampaignDoc.
+% function CampaignDoc_Callback(hObject, eventdata, handles)
+% %------------------------------------------------------------------------   
+% answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file')
+% if ~isequal(answer{1},'OK')
+%     return
+% end
+% set(handles.ListExperiments,'Value',1)
+% ListExperiments_Callback(handles)%update the overview of the experiment directories
+% DataviewData=get(handles.datatree_browser,'UserData');
+% List=DataviewData.List;
+% Currentpath=get(handles.SourceDir,'String');
+% [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
+% Campaign=[Campaign DirExt];
+% t=xmltree;
+% t=set(t,1,'name','CampaignDoc');
+% t = attributes(t,'add',1,'source','directory');
+% SubCampaignTest=get(handles.SubCampaignTest,'Value');
+% root_uid=1;
+% if SubCampaignTest
+%     %TO DO open an exoiting xml doc
+%     [t,root_uid]=add(t,1,'element','SubCampaign');
+%     t =attributes(t,'add',root_uid,'DirName',Campaign);
+% end
+% for iexp=1:length(List.Experiment)
+%     set(handles.ListExperiments,'Value',iexp+1)
+%     drawnow
+%     test_mod=0;
+%     [t,uid_exp]=add(t,root_uid,'element','Experiment');
+%     t = attributes(t,'add',uid_exp,'i',num2str(iexp));
+%     ExpName=List.Experiment{iexp}.name;
+%     t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
+%    
+%     if isfield(List.Experiment{iexp},'Device')
+%         for idevice=1:length(List.Experiment{iexp}.Device)
+%             [t,uid_device]=add(t,uid_exp,'element','Device');
+%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
+%             t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
+%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
+%                     [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
+%                     if test
+%                         [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
+%                     end
+%                     if isequal(Title,'ImaDoc')
+%                         [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
+%                         t = attributes(t,'add',uid_xml,'source','file');
+%                         [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                    
+%                     end
+%                 end
+%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+%                     [t,uid_record]=add(t,uid_device,'element','Record');
+%                     t = attributes(t,'add',uid_record,'DirName',RecordName);
+%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+%                             [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
+%                             if test
+%                                 [FileName ' , Heading updated']
+%                             end
+%                             [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
+%                             t = attributes(t,'add',uid_xml,'source','file');
+%                             [t]=add(t,uid_xml,'chardata',FileName);
+%                         end
+%                     end
+%                 end
+%             end
+%         end
+%     end
+% end
+% set(handles.ListExperiments,'Value',1)
+% outputdir=get(handles.SourceDir,'String');
+% [path,dirname]=fileparts(outputdir);
+% outputfile=fullfile(outputdir,[dirname '.xml']);
+% %campaigndoc(t);
+% save(t,outputfile)
+% 
+% %------------------------------------------------------------------------
+% % --- Executes on button press in CampaignDoc.
+% function edit_xml_Callback(hObject, eventdata, handles)
+% %------------------------------------------------------------------------
+% CurrentPath=get(handles.SourceDir,'String');
+% %[CurrentPath,Name,Ext]=fileparts(CurrentDir);
+% ListExperiments=get(handles.ListExperiments,'String');
+% Value=get(handles.ListExperiments,'Value');
+% if ~isequal(Value,1)
+%     ListExperiments=ListExperiments(Value);
+% end
+% ListDevices=get(handles.ListDevices,'String');
+% Value=get(handles.ListDevices,'Value');
+% if ~isequal(Value,1)
+%     ListDevices=ListDevices(Value);
+% end
+% ListRecords=get(handles.ListRecords,'String');
+% Value=get(handles.ListRecords,'Value');
+% if ~isequal(Value,1)
+%     ListRecords=ListRecords(Value);
+% end
+% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
+% ListXml=get(handles.ListXml,'String');
+% Value=get(handles.ListXml,'Value');
+% set(handles.ListXml,'Value',Value(1));
+% if isequal(Value(1),1)
+%     msgbox_uvmat('ERROR','an xml file needs to be selected')
+%    return
+% else
+%     XmlName=ListXml{Value(1)};
+% end
+% for iexp=1:length(List.Experiment)
+%     ExpName=List.Experiment{iexp}.name;
+%     if isfield(List.Experiment{iexp},'Device')
+%         for idevice=1:length(List.Experiment{iexp}.Device)
+%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
+%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
+%                     if isequal(FileName,XmlName)
+%                         editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
+%                         return
+%                     end
+%                 end
+%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+%                             if isequal(FileName,XmlName)
+%                                 editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
+%                                 return
+%                             end                          
+%                         end
+%                     end
+%                 end
+%             end
+%         end
+%     end
+% end
+
+
+% 
+% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% % CurrentPath/Campaign: root directory 
+% function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
+% 
+%  %Shema for Heading:
+% %  Campaign             
+% %  (SubCampaign)
+% % Experiment
+% %  Device
+% %  (Record)
+% %  ImageName
+% %  DateExp
+% %                 old: %Project: suppressed ( changed to Campaign)
+%                        %Exp: suppressed (changed to experiment)
+%                        %ImaNames: changed to ImageName
+% if exist('Record','var') && ~isempty(Record)
+%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname);  
+%     testrecord=1;
+% else
+%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname); 
+%     testrecord=0;
+% end
+% if ~exist('testSubCampaign','var')
+%     testSubCampaign=0;
+% end
+% if testSubCampaign
+%    SubCampaign=Campaign;
+%    [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
+%    Campaign=[Campaign DirExt];
+% end
+% test_mod=0; %test for the modification of the xml file
+% t_device=xmltree(xmlfullname);
+% Title=get(t_device,1,'name');
+% uid_child=children(t_device,1);
+% Heading_old=[];
+% uidheading=0;
+% for ilist=1:length(uid_child)
+%     name=get(t_device,uid_child(ilist),'name');
+%     if isequal(name,'Heading')
+%         uidheading=uid_child(ilist);
+%     end
+% end
+% if uidheading
+%     subt=branch(t_device,uidheading);
+%     Heading_old=convert(subt);
+% else
+%    return % do not edit xml files without element 'Heading'
+% end
+% if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
+%     test_mod=1;
+% end
+% Heading.Campaign=Campaign;
+% if testSubCampaign
+%     if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
+%         test_mod=1;
+%     end
+%     Heading.SubCampaign=SubCampaign;
+% end
+% if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
+%     test_mod=1;
+% end
+% Heading.Experiment=Experiment;
+% if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
+%     test_mod=1;
+% end
+% Heading.Device=Device;
+% if testrecord
+%     if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
+%         test_mod=1;
+%     end
+%     Heading.Record=Record;
+% end
+% if isfield(Heading_old,'ImaNames')
+%     test_mod=1;
+%     if  ~isempty(Heading_old.ImaNames)
+%         Heading.ImageName=Heading_old.ImaNames;
+%     end
+% end
+% if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
+%     Heading.ImageName=Heading_old.ImageName;
+% end
+% if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
+%     Heading.DateExp=Heading_old.DateExp;
+% end
+% if test_mod && uidheading
+%      uid_child=children(t_device,uidheading);
+%      t_device=delete(t_device,uid_child);
+%     t_device=struct2xml(Heading,t_device,uidheading);
+%     backupfile=xmlfullname;
+%     testexist=2;
+%     while testexist==2
+%        backupfile=[backupfile '~'];
+%        testexist=exist(backupfile,'file');
+%     end
+%     [success,message]=copyfile(xmlfullname,backupfile);%make backup
+%     if isequal(success,1)
+%         delete(xmlfullname)
+%     else
+%         return
+%     end
+%     save(t_device,xmlfullname)
+% end
 
 %------------------------------------------------------------------------
@@ -616,12 +551,12 @@
 end
 
-
-
-% --- Executes on selection change in ListXml.
-function ListXml_Callback(hObject, eventdata, handles)
-Value=get(handles.ListXml,'Value');
-if isequal(Value(1),1)
-    set(handles.ListXml,'Value',1);
-end
+% 
+% 
+% % --- Executes on selection change in ListXml.
+% function ListXml_Callback(hObject, eventdata, handles)
+% Value=get(handles.ListXml,'Value');
+% if isequal(Value(1),1)
+%     set(handles.ListXml,'Value',1);
+% end
 
 
@@ -634,6 +569,6 @@
 end
 set(handles.ListExperiments,'Value',1)
-ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
-DataviewData=get(handles.figure,'UserData')
+ListDataDir(hObject, eventdata, handles)%update the overview of the experiment directories
+DataviewData=get(handles.datatree_browser,'UserData')
 List=DataviewData.List;
 Currentpath=get(handles.SourceDir,'String');
@@ -688,90 +623,90 @@
 set(handles.ListExperiments,'Value',1)
 
-
-% --- Executes on button press in OK.
-function OK_Callback(hObject, eventdata, handles)
-%------------------------------------------------------------------------
-CurrentPath=get(handles.SourceDir,'String');
-ListExperiments=get(handles.ListExperiments,'String');
-IndicesExp=get(handles.ListExperiments,'Value');
-if ~isequal(IndicesExp,1)
-    ListExperiments=ListExperiments(IndicesExp);
-end
-ListDevices=get(handles.ListDevices,'String');
-Value=get(handles.ListDevices,'Value');
-if isequal(Value,1)
-    msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated')
-    return
-else 
-    ListDevices=ListDevices(Value);
-end
-ListRecords=get(handles.ListRecords,'String');
-Value=get(handles.ListRecords,'Value');
-if ~isequal(Value,1)
-    ListRecords=ListRecords(Value);
-end
-[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
-ListXml=get(handles.ListXml,'String');
-Value=get(handles.ListXml,'Value');
-if isequal(Value,1)
-    msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit')
-    return
-else
-    ListXml=ListXml(Value);
-end
-
-%update all the selected xml files
-DataviewData=get(handles.figure,'UserData');
-% answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' ...
-%     DataviewData.GeometryCalib.CalibrationType ' calibration data'])
-% if ~isequal(answer,'Yes')
+% 
+% % --- Executes on button press in OK.
+% function OK_Callback(hObject, eventdata, handles)
+% %------------------------------------------------------------------------
+% CurrentPath=get(handles.SourceDir,'String');
+% ListExperiments=get(handles.ListExperiments,'String');
+% IndicesExp=get(handles.ListExperiments,'Value');
+% if ~isequal(IndicesExp,1)
+%     ListExperiments=ListExperiments(IndicesExp);
+% end
+% ListDevices=get(handles.ListDevices,'String');
+% Value=get(handles.ListDevices,'Value');
+% if isequal(Value,1)
+%     msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated')
 %     return
-% end
-%List.Experiment{1}.Device{1}
-%List.Experiment{2}.Device{1}
-for iexp=1:length(List.Experiment)
-    ExpName=List.Experiment{iexp}.name;
-    set(handles.ListExperiments,'Value',IndicesExp(iexp));
-    if isfield(List.Experiment{iexp},'Device')
-        for idevice=1:length(List.Experiment{iexp}.Device)
-            DeviceName=List.Experiment{iexp}.Device{idevice}.name;      
-            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
-                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
-                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
-                    for ilistxml=1:length(ListXml)
-                        if isequal(FileName,ListXml{ilistxml})
-                            set(handles.ListXml,'Value',Value(ilistxml))
-                            drawnow
-                            xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
-                            update_imadoc(DataviewData.GeometryCalib,xmlfullname)
-                            display([xmlfullname ' updated'])
-                            break
-                        end
-                    end
-                end
-             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
-                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
-                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
-                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
-                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
-                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
-                            for ilistxml=1:length(ListXml)
-                                if isequal(FileName,ListXml{ilistxml})
-                                    set(handles.ListXml,'Value',Value(ilistxml))
-                                    drawnow
-                                    xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
-                                    update_imadoc(DataviewData.GeometryCalib,xmlfullname)
-                                    display([xmlfullname ' updated'])
-                                    break
-                                end
-                            end
-                        end
-                    end
-                end
-            end
-        end
-    end
-end
-set(handles.ListXml,'Value',Value)   
+% else 
+%     ListDevices=ListDevices(Value);
+% end
+% ListRecords=get(handles.ListRecords,'String');
+% Value=get(handles.ListRecords,'Value');
+% if ~isequal(Value,1)
+%     ListRecords=ListRecords(Value);
+% end
+% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
+% ListXml=get(handles.ListXml,'String');
+% Value=get(handles.ListXml,'Value');
+% if isequal(Value,1)
+%     msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit')
+%     return
+% else
+%     ListXml=ListXml(Value);
+% end
+% 
+% %update all the selected xml files
+% DataviewData=get(handles.datatree_browser,'UserData');
+% % answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' ...
+% %     DataviewData.GeometryCalib.CalibrationType ' calibration data'])
+% % if ~isequal(answer,'Yes')
+% %     return
+% % end
+% %List.Experiment{1}.Device{1}
+% %List.Experiment{2}.Device{1}
+% for iexp=1:length(List.Experiment)
+%     ExpName=List.Experiment{iexp}.name;
+%     set(handles.ListExperiments,'Value',IndicesExp(iexp));
+%     if isfield(List.Experiment{iexp},'Device')
+%         for idevice=1:length(List.Experiment{iexp}.Device)
+%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;      
+%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
+%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
+%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
+%                     for ilistxml=1:length(ListXml)
+%                         if isequal(FileName,ListXml{ilistxml})
+%                             set(handles.ListXml,'Value',Value(ilistxml))
+%                             drawnow
+%                             xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
+%                             update_imadoc(DataviewData.GeometryCalib,xmlfullname)
+%                             display([xmlfullname ' updated'])
+%                             break
+%                         end
+%                     end
+%                 end
+%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
+%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
+%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
+%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
+%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
+%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
+%                             for ilistxml=1:length(ListXml)
+%                                 if isequal(FileName,ListXml{ilistxml})
+%                                     set(handles.ListXml,'Value',Value(ilistxml))
+%                                     drawnow
+%                                     xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
+%                                     update_imadoc(DataviewData.GeometryCalib,xmlfullname)
+%                                     display([xmlfullname ' updated'])
+%                                     break
+%                                 end
+%                             end
+%                         end
+%                     end
+%                 end
+%             end
+%         end
+%     end
+% end
+% set(handles.ListXml,'Value',Value)   
 %     
 %     
@@ -817,36 +752,21 @@
 handles.output ='OK, Calibration replicated';
 guidata(hObject, handles);% Update handles structure
-uiresume(handles.figure);
-
-% --- Executes on button press in Cancel.
-function Cancel_Callback(hObject, eventdata, handles)
-handles.output = get(hObject,'String');
-guidata(hObject, handles); % Update handles structure
-% Use UIRESUME instead of delete because the OutputFcn needs
-uiresume(handles.figure);
-
-% --- Executes when user attempts to close figure.
-function figure_CloseRequestFcn(hObject, eventdata, handles)
-% if isequal(get(handles.figure, 'waitstatus'), 'waiting')
+uiresume(handles.datatree_browser);
+% 
+% % --- Executes on button press in Cancel.
+% function Cancel_Callback(hObject, eventdata, handles)
+% handles.output = get(hObject,'String');
+% guidata(hObject, handles); % Update handles structure
+% % Use UIRESUME instead of delete because the OutputFcn needs
+% uiresume(handles.datatree_browser);
+
+% --- Executes when user attempts to close datatree_browser.
+function datatree_browser_CloseRequestFcn(hObject, eventdata, handles)
+% if isequal(get(handles.datatree_browser, 'waitstatus'), 'waiting')
 %     % The GUI is still in UIWAIT, us UIRESUME
-%     uiresume(handles.figure);
+%     uiresume(handles.datatree_browser);
 % else
 %     % The GUI is no longer waiting, just close it
-%     delete(handles.figure);
-% end
-
-% --- Executes on key press over figure1 with no controls selected.
-function figure_KeyPressFcn(hObject, eventdata, handles)
-% Check for "enter" or "escape"
-if isequal(get(hObject,'CurrentKey'),'escape')
-    % User said no by hitting escape
-    handles.output = 'Cancel';
-    
-    % Update handles structure
-    guidata(hObject, handles);
-    
-    uiresume(handles.figure);
-end
-if isequal(get(hObject,'CurrentKey'),'return')
-    uiresume(handles.figure);
-end 
+%     delete(handles.datatree_browser);
+% end
+delete(hObject)
