source: trunk/src/browse_data.m @ 643

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

generalisation of update_imadoc, improverment of the GUI get_field

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