source: trunk/src/browse_data.m @ 581

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

clean the transform field functions

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