source: trunk/src/browse_data.m @ 569

Last change on this file since 569 was 569, checked in by sommeria, 8 years ago

many corrections; introduction of browse_data to scan the whole set of data, used also to replicate data in calibration mode

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