source: trunk/src/browse_data.m @ 570

Last change on this file since 570 was 570, checked in by sommeria, 11 years ago

bugs corrected in browse_data

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