source: trunk/src/browse_data.m @ 575

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

further bug corrections in browse_data

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