source: trunk/src/datatree_browser.m @ 534

Last change on this file since 534 was 508, checked in by sommeria, 12 years ago

various improvements

File size: 32.0 KB
Line 
1%'datatree_browser': function for scanning directories in a campaign
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI datatree_browser.fig
5
6%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
7%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
8%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
9%     This file is part of the toolbox UVMAT.
10%
11%     UVMAT is free software; you can redistribute it and/or modify
12%     it under the terms of the GNU General Public License as published by
13%     the Free Software Foundation; either version 2 of the License, or
14%     (at your option) any later version.
15%
16%     UVMAT is distributed in the hope that it will be useful,
17%     but WITHOUT ANY WARRANTY; without even the implied warranty of
18%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
20%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21
22function varargout = datatree_browser(varargin)
23
24% Last Modified by GUIDE v2.5 29-Jul-2012 08:49:20
25
26% Begin initialization code - DO NOT EDIT
27gui_Singleton = 1;
28gui_State = struct('gui_Name',       mfilename, ...
29                   'gui_Singleton',  gui_Singleton, ...
30                   'gui_OpeningFcn', @datatree_browser_OpeningFcn, ...
31                   'gui_OutputFcn',  @datatree_browser_OutputFcn, ...
32                   'gui_LayoutFcn',  [] , ...
33                   'gui_Callback',   []);
34if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))             
35    gui_State.gui_Callback = str2func(varargin{1});
36end
37
38if nargout
39    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
40else
41    gui_mainfcn(gui_State, varargin{:});
42end
43% End initialization code - DO NOT EDIT
44
45%------------------------------------------------------------------------
46% --- Executes just before datatree_browser is made visible.
47function datatree_browser_OpeningFcn(hObject, eventdata, handles, InputName)
48%------------------------------------------------------------------------
49% Choose default command line output for datatree_browser
50handles.output = 'Cancel';
51
52% Update handles structure
53guidata(hObject, handles);
54testCancel=1;
55testinputstring=0;
56icontype='quest';%default question icon (text input asked)
57
58% Determine the position of the dialog - centered on the screen
59FigPos=get(0,'DefaultFigurePosition');
60OldUnits = get(hObject, 'Units');
61set(hObject, 'Units', 'pixels');
62OldPos = get(hObject,'Position');
63FigWidth = OldPos(3);
64FigHeight = OldPos(4);
65ScreenUnits=get(0,'Units');
66set(0,'Units','pixels');
67ScreenSize=get(0,'ScreenSize');
68set(0,'Units',ScreenUnits);
69
70FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
71FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
72FigPos(3:4)=[FigWidth FigHeight];
73set(hObject, 'Position', FigPos);
74set(hObject, 'Units', OldUnits);
75
76if exist('InputName','var')
77    if isdir(InputName)% opening by uvmat/MenuSetProject
78        set(handles.SourceDir,'String',InputName)% the input directory is considered as a project
79        set(handles.LinkDir,'Visible','off')
80        set(handles.UpdateLink,'String','create_link')
81        set(handles.MarkupDir,'Visible','on')
82       
83    else% opening by uvmat/Open
84        InputDir=regexprep(InputName,'.xml$','');
85        if exist(InputDir,'dir')
86            s=xml2struct(InputName);
87            if isfield(s,'SourceDir')
88                set(handles.SourceDir,'String',s.SourceDir)
89                set(handles.LinkDir,'String',InputDir)
90                set(handles.LinkDir,'Visible','on')
91            else
92                set(handles.SourceDir,'String',InputDir)
93                set(handles.LinkDir,'Visible','off')
94                set(handles.MarkupDir,'String','CreateLink')
95            end
96        end     
97    end
98    FillExperiments(handles)
99    set(handles.OK,'Visible','on')
100    drawnow
101end
102
103
104%------------------------------------------------------------------------
105% --- Outputs from this function are returned to the command line.
106function varargout = datatree_browser_OutputFcn(hObject, eventdata, handles)
107%------------------------------------------------------------------------
108% Get default command line output from handles structure
109varargout{1} = handles.output;
110%delete(handles.datatree_browser)
111
112%------------------------------------------------------------------------
113% --- Executes on button press in MarkupDir: create a xml file to mark SourceDir as project source
114function MarkupDir_Callback(hObject, eventdata, handles)
115%------------------------------------------------------------------------
116SourceDir=get(handles.SourceDir,'String');
117t=xmltree;
118t=set(t,1,'name','Project');
119try
120save(t,[SourceDir '.xml'])
121catch ME
122    msgbox_uvmat('ERROR',ME.message)
123end
124
125%------------------------------------------------------------------------
126% --- Executes on button press in UpdateLink: create a link dir or update it if it exists
127function UpdateLink_Callback(hObject, eventdata, handles)
128%------------------------------------------------------------------------
129[SourcePath,ProjectName]=fileparts(get(handles.SourceDir,'String'));
130LinkDir=get(handles.LinkDir,'String');
131if isempty(LinkDir)||strcmp(get(handles.LinkDir,'Visible'),'off')
132    LinkRoot=uigetdir(LinkDir,'pick up the path to the link directory'); %file browser
133    if isempty(LinkRoot),return,end
134    LinkDir=fullfile(LinkRoot,[ProjectName '.link']);
135    set(handles.LinkDir,'Visible','on')
136    set(handles.LinkDir,'String',LinkDir)
137end
138
139if ~exist(LinkDir,'dir')
140    try
141        mkdir(LinkDir)
142    catch ME
143        msgbox_uvmat('ERROR',ME.message)
144    end
145end
146LinkDirXml=fullfile(fileparts(LinkDir),[ProjectName '.link.xml']);
147if ~exist(LinkDirXml,'file')
148    LinkDoc.SourceDir=get(handles.SourceDir,'String');
149    t=struct2xml(LinkDoc);
150    t=set(t,1,'name','Project');
151    save(t,LinkDirXml)
152    set(handles.UpdateLink,'String','update_link')
153end
154
155FillExperiments(handles)
156
157%------------------------------------------------------------------------
158% --- Fill the column 'Experiments' with the list of detected directries
159function FillExperiments(handles)
160%------------------------------------------------------------------------   
161SourceDir=get(handles.SourceDir,'String');
162LinkDir='';
163if strcmp(get(handles.LinkDir,'Visible'),'on')
164    LinkDir=get(handles.LinkDir,'String');
165end
166
167hdir=dir(SourceDir); %list files and dirs
168idir=0;
169ExpName=cell(length(hdir),1);
170for ilist=1:length(hdir)
171    if hdir(ilist).isdir
172        dirname=hdir(ilist).name;
173        if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')% do not list directories beginning by '0'
174            idir=idir+1;
175            ExpName{idir}=hdir(ilist).name;
176            if ~isempty(LinkDir)
177                link=fullfile(LinkDir,ExpName{idir});
178                if ~exist(link,'dir')
179                    mkdir(link)% create the directory containing links
180                end
181            end
182        end
183    end
184end
185set(handles.ListExperiments,'String',[{'*'};ExpName(1:idir)])
186set(handles.ListExperiments,'Value',1)
187ListExperiments_Callback([],[], handles)
188
189
190%------------------------------------------------------------------------
191% --- Executes on selection change in ListExperiments.
192 function ListExperiments_Callback(hObject,eventdata,handles)
193%------------------------------------------------------------------------
194SourcePath=get(handles.SourceDir,'String');
195MirrorPath='';
196if strcmp(get(handles.LinkDir,'Visible'),'on')
197    MirrorPath=get(handles.LinkDir,'String');
198end
199ListExperiments=get(handles.ListExperiments,'String');
200if isequal(get(handles.ListExperiments,'Value'),1)
201    ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' has been selected
202else
203    ListExperiments=ListExperiments(get(handles.ListExperiments,'Value'));
204end
205ListDevices={};
206
207%% loop on the list of selected experiments
208for iexp=1:numel(ListExperiments)
209   
210    % update the directory of the sources and update the links in the case of a link dir
211    hdir=dir(fullfile(SourcePath,ListExperiments{iexp})); %list files and folders in the source
212    for ilist=1:length(hdir)
213        Device=hdir(ilist).name;
214        if ~isequal(Device(1),'.')
215            if ~isempty(MirrorPath)% we list the links to the data directories of files
216                link=fullfile(MirrorPath,ListExperiments{iexp},Device);
217                if ~exist(link)% create a link if it does not exist
218                    source=fullfile(SourcePath,ListExperiments{iexp},Device);
219                    system(['ln -s ' source ' ' link])%TODO translate for DOS
220                end
221                Device=['@' Device];
222            end
223            if hdir(ilist).isdir
224                Device=[Device '/'];
225            end
226            check_list=strcmp(Device,ListDevices);
227            if isempty(find(check_list))
228                ListDevices=[ListDevices;Device];
229            end
230        end
231    end
232   
233    % check for dir and files in the link dir which do not exist in the source dir
234    if ~isempty(MirrorPath)
235        hdir=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and folders in the link dir
236        for ilist=1:length(hdir)
237            Device=hdir(ilist).name;
238            if ~isequal(Device(1),'.')
239                if hdir(ilist).isdir
240                    Device=[Device '/'];
241                end
242                check_list=strcmp(Device,ListDevices) | strcmp(['@' Device],ListDevices);
243                if isempty(find(check_list))
244                    ListDevices=[ListDevices;Device];
245                end
246            end
247        end
248    end
249end
250
251%% display the updated list, keeping track of the previously selected item
252PreviousList=get(handles.ListDevices,'String');
253NewValue=[];
254if ~isempty(PreviousList)&&iscell(PreviousList)
255    PreviousDevice=PreviousList{get(handles.ListDevices,'Value')};
256    NewValue=find(strcmp(PreviousDevice,ListDevices));
257end
258if isempty(NewValue)
259    NewValue=1;
260end
261set(handles.ListDevices,'Value',NewValue)
262set(handles.ListDevices,'String',ListDevices)
263
264
265%------------------------------------------------------------------------
266% --- Executes on selection in column ListDevices
267function ListDevices_Callback(hObject, eventdata, handles)
268%------------------------------------------------------------------------   
269list_val=get(handles.ListExperiments,'Value');
270if isequal(list_val,1) || numel(list_val)~=1
271    msgbox_uvmat('ERROR','select a single experiment in the column ''Experiments''')
272    return
273end
274ListExperiments=get(handles.ListExperiments,'String');
275Experiment=ListExperiments{list_val};
276RootPath='';
277if strcmp(get(handles.LinkDir,'Visible'),'on')
278    RootPath=get(handles.LinkDir,'String');
279end
280if isempty(RootPath)
281RootPath=get(handles.SourceDir,'String');
282end
283ListDevices=get(handles.ListDevices,'String');
284Device=ListDevices{get(handles.ListDevices,'Value')};
285Device=regexprep(Device,'^@','');
286
287%% open the selected file
288% case of a directory, open a file inside
289if strcmp(Device(end),'/')
290    DataDir=fullfile(RootPath,Experiment,Device(1:end-1));
291    DirList=dir(DataDir);
292    for ilist=1:numel(DirList)
293        if ~DirList(ilist).isdir
294            [tild,tild,FileExt]=fileparts(DirList(ilist).name);
295            FileExt=regexprep(FileExt,'^.','');
296            if ~isempty(FileExt) && (~isempty(imformats(FileExt))||strcmp(lower(FileExt),'avi')||strcmp(lower(FileExt),'nc'))
297                uvmat(fullfile(DataDir,DirList(ilist).name))
298                return
299            end
300        end
301    end
302    % open browser if no valid input file has been detected
303    [FileName, PathName] = uigetfile( ...
304            { '*.*', 'All Files (*.*)'}, ...
305            'Pick a mask file *.png',DataDir);
306    if ~isempty(FileName)
307        uvmat(fullfile(PathName,FileName));
308        return
309    end
310else %case of a file
311    uvmat(fullfile(RootPath,Experiment,Device))
312    return
313end
314
315
316
317%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318
319
320
321% %------------------------------------------------------------------------
322% % --- Executes on selection change in ListRecords.
323% function ListRecords_Callback(hObject, eventdata, handles)
324% Value=get(handles.ListRecords,'Value');
325% if isequal(Value(1),1)
326%     set(handles.ListRecords,'Value',1);
327% end
328
329% %------------------------------------------------------------------------
330% % --- Executes on button press in CampaignDoc.
331% function CampaignDoc_Callback(hObject, eventdata, handles)
332% %------------------------------------------------------------------------   
333% 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')
334% if ~isequal(answer{1},'OK')
335%     return
336% end
337% set(handles.ListExperiments,'Value',1)
338% ListExperiments_Callback(handles)%update the overview of the experiment directories
339% DataviewData=get(handles.datatree_browser,'UserData');
340% List=DataviewData.List;
341% Currentpath=get(handles.SourceDir,'String');
342% [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
343% Campaign=[Campaign DirExt];
344% t=xmltree;
345% t=set(t,1,'name','CampaignDoc');
346% t = attributes(t,'add',1,'source','directory');
347% SubCampaignTest=get(handles.SubCampaignTest,'Value');
348% root_uid=1;
349% if SubCampaignTest
350%     %TO DO open an exoiting xml doc
351%     [t,root_uid]=add(t,1,'element','SubCampaign');
352%     t =attributes(t,'add',root_uid,'DirName',Campaign);
353% end
354% for iexp=1:length(List.Experiment)
355%     set(handles.ListExperiments,'Value',iexp+1)
356%     drawnow
357%     test_mod=0;
358%     [t,uid_exp]=add(t,root_uid,'element','Experiment');
359%     t = attributes(t,'add',uid_exp,'i',num2str(iexp));
360%     ExpName=List.Experiment{iexp}.name;
361%     t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
362%   
363%     if isfield(List.Experiment{iexp},'Device')
364%         for idevice=1:length(List.Experiment{iexp}.Device)
365%             [t,uid_device]=add(t,uid_exp,'element','Device');
366%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
367%             t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
368%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
369%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
370%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
371%                     [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
372%                     if test
373%                         [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
374%                     end
375%                     if isequal(Title,'ImaDoc')
376%                         [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
377%                         t = attributes(t,'add',uid_xml,'source','file');
378%                         [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                   
379%                     end
380%                 end
381%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
382%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
383%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
384%                     [t,uid_record]=add(t,uid_device,'element','Record');
385%                     t = attributes(t,'add',uid_record,'DirName',RecordName);
386%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
387%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
388%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
389%                             [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
390%                             if test
391%                                 [FileName ' , Heading updated']
392%                             end
393%                             [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
394%                             t = attributes(t,'add',uid_xml,'source','file');
395%                             [t]=add(t,uid_xml,'chardata',FileName);
396%                         end
397%                     end
398%                 end
399%             end
400%         end
401%     end
402% end
403% set(handles.ListExperiments,'Value',1)
404% outputdir=get(handles.SourceDir,'String');
405% [path,dirname]=fileparts(outputdir);
406% outputfile=fullfile(outputdir,[dirname '.xml']);
407% %campaigndoc(t);
408% save(t,outputfile)
409%
410% %------------------------------------------------------------------------
411% % --- Executes on button press in CampaignDoc.
412% function edit_xml_Callback(hObject, eventdata, handles)
413% %------------------------------------------------------------------------
414% CurrentPath=get(handles.SourceDir,'String');
415% %[CurrentPath,Name,Ext]=fileparts(CurrentDir);
416% ListExperiments=get(handles.ListExperiments,'String');
417% Value=get(handles.ListExperiments,'Value');
418% if ~isequal(Value,1)
419%     ListExperiments=ListExperiments(Value);
420% end
421% ListDevices=get(handles.ListDevices,'String');
422% Value=get(handles.ListDevices,'Value');
423% if ~isequal(Value,1)
424%     ListDevices=ListDevices(Value);
425% end
426% ListRecords=get(handles.ListRecords,'String');
427% Value=get(handles.ListRecords,'Value');
428% if ~isequal(Value,1)
429%     ListRecords=ListRecords(Value);
430% end
431% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
432% ListXml=get(handles.ListXml,'String');
433% Value=get(handles.ListXml,'Value');
434% set(handles.ListXml,'Value',Value(1));
435% if isequal(Value(1),1)
436%     msgbox_uvmat('ERROR','an xml file needs to be selected')
437%    return
438% else
439%     XmlName=ListXml{Value(1)};
440% end
441% for iexp=1:length(List.Experiment)
442%     ExpName=List.Experiment{iexp}.name;
443%     if isfield(List.Experiment{iexp},'Device')
444%         for idevice=1:length(List.Experiment{iexp}.Device)
445%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
446%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
447%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
448%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
449%                     if isequal(FileName,XmlName)
450%                         editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
451%                         return
452%                     end
453%                 end
454%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
455%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
456%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
457%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
458%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
459%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
460%                             if isequal(FileName,XmlName)
461%                                 editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
462%                                 return
463%                             end                         
464%                         end
465%                     end
466%                 end
467%             end
468%         end
469%     end
470% end
471
472
473%
474% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
475% % CurrentPath/Campaign: root directory
476% function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
477%
478%  %Shema for Heading:
479% %  Campaign             
480% %  (SubCampaign)
481% % Experiment
482% %  Device
483% %  (Record)
484% %  ImageName
485% %  DateExp
486% %                 old: %Project: suppressed ( changed to Campaign)
487%                        %Exp: suppressed (changed to experiment)
488%                        %ImaNames: changed to ImageName
489% if exist('Record','var') && ~isempty(Record)
490%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname); 
491%     testrecord=1;
492% else
493%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname);
494%     testrecord=0;
495% end
496% if ~exist('testSubCampaign','var')
497%     testSubCampaign=0;
498% end
499% if testSubCampaign
500%    SubCampaign=Campaign;
501%    [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
502%    Campaign=[Campaign DirExt];
503% end
504% test_mod=0; %test for the modification of the xml file
505% t_device=xmltree(xmlfullname);
506% Title=get(t_device,1,'name');
507% uid_child=children(t_device,1);
508% Heading_old=[];
509% uidheading=0;
510% for ilist=1:length(uid_child)
511%     name=get(t_device,uid_child(ilist),'name');
512%     if isequal(name,'Heading')
513%         uidheading=uid_child(ilist);
514%     end
515% end
516% if uidheading
517%     subt=branch(t_device,uidheading);
518%     Heading_old=convert(subt);
519% else
520%    return % do not edit xml files without element 'Heading'
521% end
522% if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
523%     test_mod=1;
524% end
525% Heading.Campaign=Campaign;
526% if testSubCampaign
527%     if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
528%         test_mod=1;
529%     end
530%     Heading.SubCampaign=SubCampaign;
531% end
532% if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
533%     test_mod=1;
534% end
535% Heading.Experiment=Experiment;
536% if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
537%     test_mod=1;
538% end
539% Heading.Device=Device;
540% if testrecord
541%     if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
542%         test_mod=1;
543%     end
544%     Heading.Record=Record;
545% end
546% if isfield(Heading_old,'ImaNames')
547%     test_mod=1;
548%     if  ~isempty(Heading_old.ImaNames)
549%         Heading.ImageName=Heading_old.ImaNames;
550%     end
551% end
552% if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
553%     Heading.ImageName=Heading_old.ImageName;
554% end
555% if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
556%     Heading.DateExp=Heading_old.DateExp;
557% end
558% if test_mod && uidheading
559%      uid_child=children(t_device,uidheading);
560%      t_device=delete(t_device,uid_child);
561%     t_device=struct2xml(Heading,t_device,uidheading);
562%     backupfile=xmlfullname;
563%     testexist=2;
564%     while testexist==2
565%        backupfile=[backupfile '~'];
566%        testexist=exist(backupfile,'file');
567%     end
568%     [success,message]=copyfile(xmlfullname,backupfile);%make backup
569%     if isequal(success,1)
570%         delete(xmlfullname)
571%     else
572%         return
573%     end
574%     save(t_device,xmlfullname)
575% end
576
577%------------------------------------------------------------------------
578% --- Executes on button press in HELP.
579function HELP_Callback(hObject, eventdata, handles)
580path_to_uvmat=which ('uvmat')% check the path of uvmat
581pathelp=fileparts(path_to_uvmat);
582helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
583if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
584else
585web([helpfile '#dataview'])   
586end
587
588%
589%
590% % --- Executes on selection change in ListXml.
591% function ListXml_Callback(hObject, eventdata, handles)
592% Value=get(handles.ListXml,'Value');
593% if isequal(Value(1),1)
594%     set(handles.ListXml,'Value',1);
595% end
596
597
598% --- Executes on button press in clean_civ_cmx.
599function clean_civ_cmx_Callback(hObject, eventdata, handles)
600message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
601answer=msgbox_uvmat('INPUT_Y-N',message);
602if ~isequal(answer,'Yes')
603    return
604end
605set(handles.ListExperiments,'Value',1)
606ListDataDir(hObject, eventdata, handles)%update the overview of the experiment directories
607DataviewData=get(handles.datatree_browser,'UserData')
608List=DataviewData.List;
609Currentpath=get(handles.SourceDir,'String');
610[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
611Campaign=[Campaign DirExt];
612SubCampaignTest=get(handles.SubCampaignTest,'Value');
613nbdelete_tot=0;
614for iexp=1:length(List.Experiment)
615    set(handles.ListExperiments,'Value',iexp+1)
616    drawnow
617    test_mod=0;
618    ExpName=List.Experiment{iexp}.name; 
619    nbdelete=0;
620    if isfield(List.Experiment{iexp},'Device')
621        for idevice=1:length(List.Experiment{iexp}.Device)
622            DeviceName=List.Experiment{iexp}.Device{idevice}.name;     
623            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
624                currentdir=fullfile(Currentpath,Campaign,ExpName,DeviceName);
625                hdir=dir(currentdir); %list files and dirs
626                idir=0;
627                for ilist=1:length(hdir)
628                    if hdir(ilist).isdir
629                        dirname=hdir(ilist).name;
630                        if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
631                            CivDir=fullfile(currentdir,dirname)
632                            hCivDir=dir(CivDir);
633                            for ilist=1:length(hCivDir)
634                                FileName=hCivDir(ilist).name;
635                                [dd,ff,Ext]=fileparts(FileName);
636                                if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
637                                    delete(fullfile(CivDir,FileName))
638                                    nbdelete=nbdelete+1;
639                                end
640                            end
641                        end
642                    end
643                end
644             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
645                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
646                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
647                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
648                        'look at subdirectories'
649                    end
650                end
651            end
652        end
653    end
654    display([num2str(nbdelete) ' files deleted'])
655    nbdelete_tot=nbdelete_tot+nbdelete;
656end
657msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete_tot) ' files deleted by clean_civ_cmx'])
658set(handles.ListExperiments,'Value',1)
659
660%
661% % --- Executes on button press in OK.
662% function OK_Callback(hObject, eventdata, handles)
663% %------------------------------------------------------------------------
664% CurrentPath=get(handles.SourceDir,'String');
665% ListExperiments=get(handles.ListExperiments,'String');
666% IndicesExp=get(handles.ListExperiments,'Value');
667% if ~isequal(IndicesExp,1)
668%     ListExperiments=ListExperiments(IndicesExp);
669% end
670% ListDevices=get(handles.ListDevices,'String');
671% Value=get(handles.ListDevices,'Value');
672% if isequal(Value,1)
673%     msgbox_uvmat('ERROR','manually select in the GUI dataview the device being calibrated')
674%     return
675% else
676%     ListDevices=ListDevices(Value);
677% end
678% ListRecords=get(handles.ListRecords,'String');
679% Value=get(handles.ListRecords,'Value');
680% if ~isequal(Value,1)
681%     ListRecords=ListRecords(Value);
682% end
683% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
684% ListXml=get(handles.ListXml,'String');
685% Value=get(handles.ListXml,'Value');
686% if isequal(Value,1)
687%     msgbox_uvmat('ERROR','you need to select in the GUI dataview the xml files to edit')
688%     return
689% else
690%     ListXml=ListXml(Value);
691% end
692%
693% %update all the selected xml files
694% DataviewData=get(handles.datatree_browser,'UserData');
695% % answer=msgbox_uvmat('INPUT_Y-N',[num2str(length(Value)) ' xml files for device ' ListDevices{1} ' will be refreshed with ' ...
696% %     DataviewData.GeometryCalib.CalibrationType ' calibration data'])
697% % if ~isequal(answer,'Yes')
698% %     return
699% % end
700% %List.Experiment{1}.Device{1}
701% %List.Experiment{2}.Device{1}
702% for iexp=1:length(List.Experiment)
703%     ExpName=List.Experiment{iexp}.name;
704%     set(handles.ListExperiments,'Value',IndicesExp(iexp));
705%     if isfield(List.Experiment{iexp},'Device')
706%         for idevice=1:length(List.Experiment{iexp}.Device)
707%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;     
708%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
709%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
710%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
711%                     for ilistxml=1:length(ListXml)
712%                         if isequal(FileName,ListXml{ilistxml})
713%                             set(handles.ListXml,'Value',Value(ilistxml))
714%                             drawnow
715%                             xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,FileName);
716%                             update_imadoc(DataviewData.GeometryCalib,xmlfullname)
717%                             display([xmlfullname ' updated'])
718%                             break
719%                         end
720%                     end
721%                 end
722%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
723%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
724%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
725%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
726%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
727%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
728%                             for ilistxml=1:length(ListXml)
729%                                 if isequal(FileName,ListXml{ilistxml})
730%                                     set(handles.ListXml,'Value',Value(ilistxml))
731%                                     drawnow
732%                                     xmlfullname=fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName);
733%                                     update_imadoc(DataviewData.GeometryCalib,xmlfullname)
734%                                     display([xmlfullname ' updated'])
735%                                     break
736%                                 end
737%                             end
738%                         end
739%                     end
740%                 end
741%             end
742%         end
743%     end
744% end
745% set(handles.ListXml,'Value',Value)   
746%     
747%     
748%     
749%     
750%     
751%     
752%     
753% CurrentPath=get(handles.SourceDir,'String');%= get(hObject,'String');
754% ListExperiments=get(handles.ListExperiments,'String');
755% Value=get(handles.ListExperiments,'Value');
756% if ~isequal(Value,1)
757%     ListExperiments=ListExperiments(Value);
758% end
759% ListDevices=get(handles.ListDevices,'String');
760% Value=get(handles.ListDevices,'Value');
761% if isequal(Value,1)
762%     msgbox_uvmat('ERROR','manually select in the GUI datatree_browser the device being calibrated')
763%     return
764% else
765%     ListDevices=ListDevices(Value);
766% end
767% ListRecords=get(handles.ListRecords,'String');
768% Value=get(handles.ListRecords,'Value');
769% if ~isequal(Value,1)
770%     ListRecords=ListRecords(Value);
771% end
772% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
773% ListXml=get(handles.ListXml,'String');
774% Value=get(handles.ListXml,'Value');
775% if isequal(Value,1)
776%     msgbox_uvmat('ERROR','you need to select in the GUI datatree_browser the xml files to edit')
777%     return
778% else
779%     ListXml=ListXml(Value);
780% end
781% handles.output.CurrentPath=CurrentPath;
782% handles.output.ListExperiments=ListExperiments;
783% handles.output.ListDevices=ListDevices;
784% handles.output.ListRecords=ListRecords;
785% handles.output.ListXml=ListXml;
786% handles.output.List=List;
787handles.output ='OK, Calibration replicated';
788guidata(hObject, handles);% Update handles structure
789uiresume(handles.datatree_browser);
790%
791% % --- Executes on button press in Cancel.
792% function Cancel_Callback(hObject, eventdata, handles)
793% handles.output = get(hObject,'String');
794% guidata(hObject, handles); % Update handles structure
795% % Use UIRESUME instead of delete because the OutputFcn needs
796% uiresume(handles.datatree_browser);
797
798% --- Executes when user attempts to close datatree_browser.
799function datatree_browser_CloseRequestFcn(hObject, eventdata, handles)
800% if isequal(get(handles.datatree_browser, 'waitstatus'), 'waiting')
801%     % The GUI is still in UIWAIT, us UIRESUME
802%     uiresume(handles.datatree_browser);
803% else
804%     % The GUI is no longer waiting, just close it
805%     delete(handles.datatree_browser);
806% end
807delete(hObject)
Note: See TracBrowser for help on using the repository browser.