source: trunk/src/dataview.m @ 2

Last change on this file since 2 was 2, checked in by gostiaux, 14 years ago
  • Initial import
  • Add .m files in src
  • Add .fig files in src
  • Add .xml config files
File size: 19.9 KB
Line 
1%TEST 'dataview': function for scanning directories in a campaign (TEST)
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI dataview.fig
5%
6%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
7%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
8%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
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%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
21
22function varargout = dataview(varargin)
23
24% Last Modified by GUIDE v2.5 28-Apr-2009 00:12:36
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', @dataview_OpeningFcn, ...
31                   'gui_OutputFcn',  @dataview_OutputFcn, ...
32                   'gui_LayoutFcn',  [] , ...
33                   'gui_Callback',   []);
34if nargin & isstr(varargin{1})
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 dataview is made visible.
47function dataview_OpeningFcn(hObject, eventdata, handles, varargin)
48
49% Choose default command line output for dataview
50handles.output = hObject;
51
52% Update handles structure
53guidata(hObject, handles);
54
55%----------------------------------------------------------------
56% --- Outputs from this function are returned to the command line.
57function varargout = dataview_OutputFcn(hObject, eventdata, handles)
58
59% Get default command line output from handles structure
60varargout{1} = handles.output;
61
62
63
64%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65%------------------------------------------------------
66% --- Executes on button press in browser.
67function browser_Callback(hObject, eventdata, handles)
68%------------------------------------------------------------------------   
69
70CurrentFile='/coriolis/bigone/PROJETS';%get(handles.RootDirectory,'String');
71set(handles.SubCampaignTest,'Value',0)
72CampaignDir=uigetdir(CurrentFile,'Open the Campaign directory'); %file browser
73set(handles.RootDirectory,'String',CampaignDir)
74RootDirectory_Callback(hObject, eventdata, handles)
75
76% --- Executes on button press in open_SubCampaign.
77function OpenSubCampaign_Callback(hObject, eventdata, handles)
78CurrentFile='/coriolis/bigone/PROJETS';%get(handles.RootDirectory,'String');
79set(handles.SubCampaignTest,'Value',1)
80CampaignDir=uigetdir(CurrentFile,'Open the Campaign directory'); %file browser
81set(handles.RootDirectory,'String',CampaignDir)
82
83RootDirectory_Callback(hObject, eventdata, handles)
84
85%------------------------------------------------------------------------
86
87function RootDirectory_Callback(hObject, eventdata, handles)
88CampaignDir=get(handles.RootDirectory,'String');
89if exist(CampaignDir,'dir')
90    hdir=dir(CampaignDir); %list files and dirs
91    idir=0;
92    for ilist=1:length(hdir)
93        if hdir(ilist).isdir
94            dirname=hdir(ilist).name;
95            if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
96                idir=idir+1;
97                ExpName{idir}=hdir(ilist).name;
98            end
99            % look for the list of 'devices'
100        else
101            %warning for isolated files
102        end
103    end
104    set(handles.ListExperiments,'String',[{'*'};ExpName'])
105    set(handles.ListExperiments,'Value',1)
106    ListExperiments_Callback(hObject, eventdata, handles)
107else
108    warndlg_uvmat(['The input ' CampaignDir ' is not a directory'],'ERROR')
109end
110
111%------------------------------------------------------------------------
112% --- Executes on selection change in ListExperiments.
113 function ListExperiments_Callback(hObject, eventdata, handles)
114CurrentPath=get(handles.RootDirectory,'String');
115ListExperiments=get(handles.ListExperiments,'String');
116list_val=get(handles.ListExperiments,'Value');
117if isequal(list_val(1),1)
118    ListExperiments=ListExperiments(2:end); %choose all experiments
119    testList=1;
120    set(handles.ListExperiments,'Value',1)
121else
122    ListExperiments=ListExperiments(list_val);%choose selected experiments
123    testList=0;
124end
125set(handles.ListDevices,'Value',1)
126set(handles.ListRecords,'Value',1)
127set(handles.ListXml,'Value',1)
128[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,{},{});
129set(handles.ListRecords,'String',[{'*'};ListRecords'])
130set(handles.ListDevices,'String',[{'*'};ListDevices'])
131set(handles.ListXml,'String',[{'*'};ListXml'])
132if testList
133    hh=get(handles.ListExperiments,'parent');
134    set(hh,'UserData',List)
135end
136set(handles.CampaignDoc,'Visible','on')
137set(handles.edit_xml,'Visible','on')
138
139%------------------------------------------------------------------------
140% --- Executes on button press in update_headings.
141function ListDevices_Callback(hObject, eventdata, handles)
142CurrentPath=get(handles.RootDirectory,'String');
143ListExperiments=get(handles.ListExperiments,'String');
144list_val=get(handles.ListExperiments,'Value');
145if isequal(list_val,1)
146    ListExperiments=ListExperiments(2:end);
147else
148    ListExperiments=ListExperiments(list_val);
149end
150set(handles.ListRecords,'Value',1)
151set(handles.ListXml,'Value',1)
152ListDevices=get(handles.ListDevices,'String');
153list_val=get(handles.ListDevices,'Value');
154if isequal(list_val,1)
155    ListDevices=ListDevices(2:end);
156else
157    ListDevices=ListDevices(list_val);
158end
159[ListDevices,ListRecords,ListXml]=ListDir(CurrentPath,ListExperiments,ListDevices,{});
160set(handles.ListRecords,'String',[{'*'};ListRecords'])
161set(handles.ListXml,'String',[{'*'};ListXml'])
162
163
164%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165
166
167
168%------------------------------------------------------------------------
169% --- Executes on selection change in ListRecords.
170function ListRecords_Callback(hObject, eventdata, handles)
171Value=get(handles.ListRecords,'Value');
172if isequal(Value(1),1)
173    set(handles.ListRecords,'Value',1);
174end
175
176%------------------------------------------------------------------------
177% --- Executes on button press in CampaignDoc.
178function CampaignDoc_Callback(hObject, eventdata, handles)
179%------------------------------------------------------------------------   
180answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file')
181if ~isequal(answer{1},'OK')
182    return
183end
184set(handles.ListExperiments,'Value',1)
185ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
186hh=get(handles.CampaignDoc,'parent');
187List=get(hh,'UserData');
188Currentpath=get(handles.RootDirectory,'String');
189[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
190Campaign=[Campaign DirExt];
191t=xmltree;
192t=set(t,1,'name','CampaignDoc');
193t = attributes(t,'add',1,'source','directory');
194SubCampaignTest=get(handles.SubCampaignTest,'Value');
195root_uid=1;
196if SubCampaignTest
197    %TO DO open an exoiting xml doc
198    [t,root_uid]=add(t,1,'element','SubCampaign');
199    t =attributes(t,'add',root_uid,'DirName',Campaign);
200end
201for iexp=1:length(List.Experiment)
202    set(handles.ListExperiments,'Value',iexp+1)
203    drawnow
204    test_mod=0;
205    [t,uid_exp]=add(t,root_uid,'element','Experiment');
206    t = attributes(t,'add',uid_exp,'i',num2str(iexp));
207    ExpName=List.Experiment{iexp}.name;
208    t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
209   
210    if isfield(List.Experiment{iexp},'Device')
211        for idevice=1:length(List.Experiment{iexp}.Device)
212            [t,uid_device]=add(t,uid_exp,'element','Device');
213            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
214            t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
215            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
216                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
217                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
218                    [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
219                    if test
220                        [List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']
221                    end
222                    if isequal(Title,'ImaDoc')
223                        [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
224                        t = attributes(t,'add',uid_xml,'source','file');
225                        [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                   
226                    end
227                end
228             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
229                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
230                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
231                    [t,uid_record]=add(t,uid_device,'element','Record');
232                    t = attributes(t,'add',uid_record,'DirName',RecordName);
233                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
234                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
235                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
236                            [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
237                            if test
238                                [FileName ' , Heading updated']
239                            end
240                            [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
241                            t = attributes(t,'add',uid_xml,'source','file');
242                            [t]=add(t,uid_xml,'chardata',FileName);
243                        end
244                    end
245                end
246            end
247        end
248    end
249end
250set(handles.ListExperiments,'Value',1)
251outputdir=get(handles.RootDirectory,'String');
252[path,dirname]=fileparts(outputdir);
253outputfile=fullfile(outputdir,[dirname '.xml']);
254%campaigndoc(t);
255save(t,outputfile)
256
257%------------------------------------------------------------------------
258% --- Executes on button press in CampaignDoc.
259function edit_xml_Callback(hObject, eventdata, handles)
260%------------------------------------------------------------------------
261CurrentPath=get(handles.RootDirectory,'String');
262%[CurrentPath,Name,Ext]=fileparts(CurrentDir);
263ListExperiments=get(handles.ListExperiments,'String');
264Value=get(handles.ListExperiments,'Value');
265if ~isequal(Value,1)
266    ListExperiments=ListExperiments(Value);
267end
268ListDevices=get(handles.ListDevices,'String');
269Value=get(handles.ListDevices,'Value');
270if ~isequal(Value,1)
271    ListDevices=ListDevices(Value);
272end
273ListRecords=get(handles.ListRecords,'String');
274Value=get(handles.ListRecords,'Value');
275if ~isequal(Value,1)
276    ListRecords=ListRecords(Value);
277end
278[ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
279ListXml=get(handles.ListXml,'String');
280Value=get(handles.ListXml,'Value');
281set(handles.ListXml,'Value',Value(1));
282if isequal(Value(1),1)
283    warndlg_uvmat('an xml file needs to be selected','ERROR')
284   return
285else
286    XmlName=ListXml{Value(1)};
287end
288for iexp=1:length(List.Experiment)
289    ExpName=List.Experiment{iexp}.name;
290    if isfield(List.Experiment{iexp},'Device')
291        for idevice=1:length(List.Experiment{iexp}.Device)
292            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
293            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
294                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
295                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}
296                    if isequal(FileName,XmlName)
297                        editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
298                        return
299                    end
300                end
301             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
302                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
303                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
304                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
305                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
306                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
307                            if isequal(FileName,XmlName)
308                                editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
309                                return
310                            end                         
311                        end
312                    end
313                end
314            end
315        end
316    end
317end
318
319
320
321%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
322% CurrentPath/Campaign: root directory
323function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
324
325 %Shema for Heading:
326%  Campaign             
327%  (SubCampaign)
328% Experiment
329%  Device
330%  (Record)
331%  ImageName
332%  DateExp
333%                 old: %Project: suppressed ( changed to Campaign)
334                       %Exp: suppressed (changed to experiment)
335                       %ImaNames: changed to ImageName
336if exist('Record','var') && ~isempty(Record)
337    xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname); 
338    testrecord=1;
339else
340    xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname);
341    testrecord=0;
342end
343if ~exist('testSubCampaign','var')
344    testSubCampaign=0;
345end
346if testSubCampaign
347   SubCampaign=Campaign;
348   [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
349   Campaign=[Campaign DirExt];
350end
351test_mod=0; %test for the modification of the xml file
352t_device=xmltree(xmlfullname);
353Title=get(t_device,1,'name');
354uid_child=children(t_device,1);
355Heading_old=[];
356uidheading=0;
357for ilist=1:length(uid_child)
358    name=get(t_device,uid_child(ilist),'name');
359    if isequal(name,'Heading')
360        uidheading=uid_child(ilist);
361    end
362end
363if uidheading
364    subt=branch(t_device,uidheading);
365    Heading_old=convert(subt);
366else
367   return % do not edit xml files without element 'Heading'
368end
369if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
370    test_mod=1;
371end
372Heading.Campaign=Campaign;
373if testSubCampaign
374    if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
375        test_mod=1;
376    end
377    Heading.SubCampaign=SubCampaign;
378end
379if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
380    test_mod=1;
381end
382Heading.Experiment=Experiment;
383if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
384    test_mod=1;
385end
386Heading.Device=Device;
387if testrecord
388    if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
389        test_mod=1;
390    end
391    Heading.Record=Record;
392end
393if isfield(Heading_old,'ImaNames')
394    test_mod=1;
395    if  ~isempty(Heading_old.ImaNames)
396        Heading.ImageName=Heading_old.ImaNames;
397    end
398end
399if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
400    Heading.ImageName=Heading_old.ImageName;
401end
402if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
403    Heading.DateExp=Heading_old.DateExp;
404end
405if test_mod && uidheading
406     uid_child=children(t_device,uidheading);
407     t_device=delete(t_device,uid_child);
408    t_device=struct2xml(Heading,t_device,uidheading);
409    backupfile=xmlfullname;
410    testexist=2;
411    while testexist==2
412       backupfile=[backupfile '~'];
413       testexist=exist(backupfile,'file');
414    end
415    [success,message]=copyfile(xmlfullname,backupfile);%make backup
416    if isequal(success,1)
417        delete(xmlfullname)
418    else
419        return
420    end
421    save(t_device,xmlfullname)
422end
423
424% --- Executes on button press in HELP.
425function HELP_Callback(hObject, eventdata, handles)
426path_to_uvmat=which ('uvmat')% check the path of uvmat
427pathelp=fileparts(path_to_uvmat);
428helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
429if isempty(dir(helpfile)), errordlg('Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
430else
431web([helpfile '#dataview'])   
432end
433
434
435
436
437% --- Executes on button press in SubCampaignTest.
438function SubCampaignTest_Callback(hObject, eventdata, handles)
439
440
441% --- Executes on selection change in ListXml.
442function ListXml_Callback(hObject, eventdata, handles)
443Value=get(handles.ListXml,'Value');
444if isequal(Value(1),1)
445    set(handles.ListXml,'Value',1);
446end
447
448
449% --- Executes on button press in clean_civ_cmx.
450function clean_civ_cmx_Callback(hObject, eventdata, handles)
451message='this function will delete all files with extensions .log, .bat, .cmx,.cmx2,.errors in the input directory(ies)';
452answer=msgbox_uvmat('INPUT_Y-N',message);
453if ~isequal(answer{1},'OK')
454    return
455end
456set(handles.ListExperiments,'Value',1)
457ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
458hh=get(handles.CampaignDoc,'parent');
459List=get(hh,'UserData');
460Currentpath=get(handles.RootDirectory,'String');
461[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
462Campaign=[Campaign DirExt];
463SubCampaignTest=get(handles.SubCampaignTest,'Value');
464nbdelete_tot=0;
465for iexp=1:length(List.Experiment)
466    set(handles.ListExperiments,'Value',iexp+1)
467    drawnow
468    test_mod=0;
469    ExpName=List.Experiment{iexp}.name; 
470    nbdelete=0;
471    if isfield(List.Experiment{iexp},'Device')
472        for idevice=1:length(List.Experiment{iexp}.Device)
473            DeviceName=List.Experiment{iexp}.Device{idevice}.name;     
474            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
475                currentdir=fullfile(Currentpath,Campaign,ExpName,DeviceName);
476                hdir=dir(currentdir); %list files and dirs
477                idir=0;
478                for ilist=1:length(hdir)
479                    if hdir(ilist).isdir
480                        dirname=hdir(ilist).name;
481                        if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')
482                            CivDir=fullfile(currentdir,dirname)
483                            hCivDir=dir(CivDir);
484                            for ilist=1:length(hCivDir)
485                                FileName=hCivDir(ilist).name;
486                                [dd,ff,Ext]=fileparts(FileName);
487                                if isequal(Ext,'.log')||isequal(Ext,'.bat')||isequal(Ext,'.cmx')||isequal(Ext,'.cmx2')|| isequal(Ext,'.errors')
488                                    delete(fullfile(CivDir,FileName))
489                                    nbdelete=nbdelete+1;
490                                end
491                            end
492                        end
493                    end
494                end
495             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
496                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
497                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
498                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
499                        'look at subdirectories'
500                    end
501                end
502            end
503        end
504    end
505    display([num2str(nbdelete) ' files deleted'])
506    nbdelete_tot=nbdelete_tot+nbdelete;
507end
508msgbox_uvmat('CONFIRMATION',['END: ' num2str(nbdelete_tot) ' files deleted by clean_civ_cmx'])
509set(handles.ListExperiments,'Value',1)
510
511
512
513
Note: See TracBrowser for help on using the repository browser.