source: trunk/src/datatree_browser.m @ 503

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

datatree_browse introduced (still work to do)
get_field revised to introduce new transform fcts, like FFT

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