source: trunk/src/browse_data.m @ 576

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

grid improved for civ: computation done closer to the edge. set_grid improved.

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