source: trunk/src/update_project.m @ 569

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

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

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