source: trunk/src/update_project.m @ 491

Last change on this file since 491 was 488, checked in by sommeria, 12 years ago

introduce update_project (modified version of dataview) to create a mirror directory tree with symbolic links to the source data

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