source: trunk/src/browse_data.m @ 1069

Last change on this file since 1069 was 1069, checked in by sommeria, 5 years ago

browse_data updated

File size: 33.9 KB
Line 
1
2%'browse_data': function for scanning directories in a campaign
3%------------------------------------------------------------------------
4% function varargout = series(varargin)
5% associated with the GUI browse_data.fig
6
7%=======================================================================
8% Copyright 2008-2019, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
9%   http://www.legi.grenoble-inp.fr
10%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
11%
12%     This file is part of the toolbox UVMAT.
13%
14%     UVMAT is free software; you can redistribute it and/or modify
15%     it under the terms of the GNU General Public License as published
16%     by the Free Software Foundation; either version 2 of the license,
17%     or (at your option) any later version.
18%
19%     UVMAT is distributed in the hope that it will be useful,
20%     but WITHOUT ANY WARRANTY; without even the implied warranty of
21%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22%     GNU General Public License (see LICENSE.txt) for more details.
23%=======================================================================
24
25function varargout = browse_data(varargin)
26
27% Last Modified by GUIDE v2.5 08-Jul-2019 23:32:39
28
29% Begin initialization code - DO NOT EDIT
30gui_Singleton = 1;
31gui_State = struct('gui_Name',       mfilename, ...
32    'gui_Singleton',  gui_Singleton, ...
33    'gui_OpeningFcn', @browse_data_OpeningFcn, ...
34    'gui_OutputFcn',  @browse_data_OutputFcn, ...
35    'gui_LayoutFcn',  [] , ...
36    'gui_Callback',   []);
37if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
38    gui_State.gui_Callback = str2func(varargin{1});
39end
40
41if nargout
42    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
43else
44    gui_mainfcn(gui_State, varargin{:});
45end
46% End initialization code - DO NOT EDIT
47
48%------------------------------------------------------------------------
49% --- Executes just before browse_data is made visible.
50function browse_data_OpeningFcn(hObject, eventdata, handles, InputDir,EnableMirror,MultiDevices)
51%------------------------------------------------------------------------
52
53%% Choose default command line output for browse_data
54handles.output =hObject;% 'Cancel';
55
56%% Update handles structure
57guidata(hObject, handles);
58set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
59set(hObject,'DeleteFcn',{@closefcn})%
60
61%% Determine the position of the dialog - centered on the screen
62FigPos=get(0,'DefaultFigurePosition');
63OldUnits = get(hObject, 'Units');
64set(hObject, 'Units', 'pixels');
65OldPos = get(hObject,'Position');
66FigWidth = OldPos(3);
67FigHeight = OldPos(4);
68ScreenUnits=get(0,'Units');
69set(0,'Units','pixels');
70ScreenSize=get(0,'ScreenSize');
71set(0,'Units',ScreenUnits);
72FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
73FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
74FigPos(3:4)=[FigWidth FigHeight];
75set(hObject, 'Position', FigPos);
76set(hObject, 'Units', OldUnits);
77% if exist('MultiDevices','var') && strcmp(MultiDevices,'on')
78%     set(handles.DataSeries,'Max',2)
79% else
80%     set(handles.DataSeries,'Max',1)
81% end
82if exist('EnableMirror','var') && strcmp(EnableMirror,'on')
83    set(handles.CreateMirror,'Visible','on')
84    set(handles.mirror_txt,'Visible','on')
85else
86    set(handles.CreateMirror,'Visible','off')
87    set(handles.mirror_txt,'Visible','off')
88end
89
90%% initialize the GUI
91if isempty(regexp(InputDir,'^http:'))&& ~(exist('InputDir','var') && ischar(InputDir) && exist(InputDir,'dir'))
92    InputDir=pwd;% current dir is the starting data series by default
93end
94if ischar(InputDir),InputDir={InputDir};end
95for ilist=1:numel(InputDir)
96    [ExpWithPath,DataSeries{ilist},Ext]=fileparts(InputDir{ilist});
97    DataSeries{ilist}=['+/' DataSeries{ilist} Ext];
98    [Experiment{ilist},Device{ilist},Ext]=fileparts(ExpWithPath);
99    Device{ilist}=['+/' Device{ilist} Ext];
100    [SourceDir{ilist},Experiment{ilist},Ext]=fileparts(Experiment{ilist});
101    Experiment{ilist}=['+/' Experiment{ilist} Ext];
102    if ~strcmp(SourceDir{ilist},SourceDir{1})||~strcmp(Experiment{ilist},Experiment{1})
103        msgbox_uvmat('ERROR','replicate cannot be used with multiple root folders')
104        return
105    end
106    if ~strcmp(DataSeries{ilist},DataSeries{1})
107        set(handles.DataSeries,'enable','off')
108    end
109    if ~strcmp(Device{ilist},Device{1})
110        set(handles.ListDevices,'enable','off')
111    end
112end
113s=[];
114% if exist(RootXml,'file')
115%     [s,Heading]=xml2struct(RootXml);%read the xml file
116%     if isfield(s,'SourceDir')
117%         set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened
118%         set(handles.MirrorDir,'Visible','on');%  mirror dir display
119%         set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir
120%         set(handles.CreateMirror,'String','update_mirror')
121%     end
122% end
123if isempty(s) %a source dir has been opened
124    set(handles.SourceDir,'String',SourceDir{1});
125    set(handles.MirrorDir,'Visible','off');% no mirror dir display
126    set(handles.CreateMirror,'String','create_mirror')
127end
128set(handles.DataSeries,'String',DataSeries);
129set(handles.DataSeries,'Value',(1:numel(DataSeries)));
130set(handles.ListDevices,'String',Device);
131set(handles.ListDevices,'Value',(1:numel(Device)));
132errormsg=scan_campaign(handles,SourceDir{1},Experiment{1});
133if ~isempty(errormsg)
134    msgbox_uvmat('ERROR',errormsg)
135    return
136end
137
138set(hObject,'Visible','on')
139drawnow     
140       
141%------------------------------------------------------------------------
142% --- Outputs from this function are returned to the command line.
143function varargout = browse_data_OutputFcn(hObject, eventdata, handles)
144%------------------------------------------------------------------------
145% Get default command line output from handles structure
146varargout{1} = handles.output;
147%%%%%%%%%%%%%%%%%%delete(handles.browse_data)
148
149%------------------------------------------------------------------------
150% --- Executes on button press in CreateMirror.
151function CreateMirror_Callback(hObject, eventdata, handles)
152%------------------------------------------------------------------------
153set(handles.SourceDir,'BackgroundColor',[1 1 0])% indicate action of button by yellow color
154drawnow
155SourceDir=get(handles.SourceDir,'String');
156[SourcePath,ProjectName]=fileparts(SourceDir);
157if strcmp(get(handles.MirrorDir,'Visible'),'on')
158MirrorDir=get(handles.MirrorDir,'String');% name of the mirror folder
159else% create the mirror folder if it does not exist
160MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir');
161if isempty(MirrorRoot)
162return
163elseif strcmp(MirrorRoot,SourcePath)
164msgbox_uvmat('ERROR','The mirror folder must be different from the source')
165return
166else
167MirrorDir=fullfile(MirrorRoot,ProjectName);
168end
169if exist(MirrorDir,'dir')
170msgbox_uvmat('ERROR',['The folder ' MirrorDir ' chosen as new mirror campaign already exists'])
171return
172else
173[s,errormsg]=mkdir(MirrorDir)% create the mirror dir
174if s~=1
175msgbox_uvmat('ERROR',['error in creating ' MirrorDir ': ' errormsg])
176return
177end
178end
179MirrorDoc.SourceDir=SourceDir;
180t=struct2xml(MirrorDoc);
181set(t,1,'name','DataTree');
182save(t,fullfile(MirrorDir,[ProjectName '.xml']))% create an xml file in the mirror folder to indicate its source folder
183set(handles.MirrorDir,'String',MirrorDir)
184set(handles.MirrorDir,'Visible','on')
185set(handles.CreateMirror,'String','update_mirror')
186end
187ExpName={''};
188
189%% update the mirror from the source dir
190if exist(SourceDir,'dir')
191hdir=dir(SourceDir); %list files and dirs
192idir=0;
193for ilist=1:length(hdir)
194if hdir(ilist).isdir% scan all subfolders
195dirname=hdir(ilist).name;%
196if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')%skip subfolder beginning by '0'
197idir=idir+1;
198mirror=fullfile(MirrorDir,hdir(ilist).name);% corresponding name in the mirror
199if ~exist(mirror,'dir')
200mkdir(mirror)% create the mirror folder if it does not exist
201end
202ExpName{idir}=['+/' hdir(ilist).name];% insert '+/' in the list to show that it is a folder
203end
204% look for the list of 'devices'
205else
206%warning for isolated files
207end
208end
209set(handles.ListExperiments,'String',[{'*'};ExpName'])
210set(handles.ListExperiments,'Value',1)
211update_experiments(handles,[{'*'};ExpName'],SourceDir,MirrorDir)
212% ListExperiments_Callback(hObject, eventdata, handles) % list the content of the experiment
213else
214msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory'])
215end
216set(handles.SourceDir,'BackgroundColor',[1 1 1])
217
218%------------------------------------------------------------------------
219% List the experiments in a campaign, filling the menu ListExperiments
220%------------------------------------------------------------------------
221function errormsg=scan_campaign(handles,SourceDir,Experiment)
222%------------------------------------------------------------------------
223errormsg='';
224if ~isempty(regexp(SourceDir,'^http'))|| exist(SourceDir,'dir')
225    ListStruct=dir_uvmat(SourceDir); %list files and dirs, extende to OpenDAP case
226    if numel(ListStruct)>1000% A campaign folder must contain maily a list of 'experiment' sub-folders
227        errormsg=[SourceDir ' contains too many items (>1000) to be a Project folder'];
228        return
229    end
230    [ListFiles,index]=list_dir_1(SourceDir,Experiment);
231    set(handles.ListExperiments,'String',ListFiles)
232    set(handles.ListExperiments,'Value',index)% initialise the menu selection with the folder defined by the input
233    ListExperiments_Callback([],[], handles)
234else
235    msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory'])
236end
237
238%------------------------------------------------------------------------
239% --- Executes on selection change in ListExperiments.
240%------------------------------------------------------------------------
241function ListExperiments_Callback(hObject, eventdata, handles)
242
243if strcmp(get(handles.MirrorDir,'Visible'),'on')
244    SourceDir=get(handles.MirrorDir,'String');
245else
246    SourceDir=get(handles.SourceDir,'String');
247end
248ListExperiments=get(handles.ListExperiments,'String');
249list_val=get(handles.ListExperiments,'Value');
250ListExperiments=ListExperiments(list_val);%choose the selected experiments
251ListDevices=get(handles.ListDevices,'String');% list of devices
252list_val=get(handles.ListDevices,'Value');% currently selected devices
253Device='';
254if numel(ListDevices)>=list_val
255Device=ListDevices(list_val);%choose selected devices
256end
257check_fix=strcmp(get(handles.ListDevices,'enable'),'off');
258[ListFiles,indices]=list_dir_2(SourceDir,ListExperiments,Device,check_fix);
259set(handles.ListDevices,'String',ListFiles)
260set(handles.ListDevices,'Value',indices)% initialise the menu selection with the folder defined by the input
261ListDevices_Callback([],[], handles)
262
263%------------------------------------------------------------------------
264% --- Executes on selection change in ListExperiments.
265%------------------------------------------------------------------------
266function ListDevices_Callback(hObject, eventdata, handles)
267
268ListDevices=get(handles.ListDevices,'String');% list of devices
269list_val=get(handles.ListDevices,'Value');% currently selected devices
270ListDevices=ListDevices(list_val);%choose selected devices
271if strcmp(get(handles.MirrorDir,'Visible'),'on')
272    SourceDir=get(handles.MirrorDir,'String');
273else
274    SourceDir=get(handles.SourceDir,'String');
275end
276ListExperiments=get(handles.ListExperiments,'String');
277list_val=get(handles.ListExperiments,'Value');
278ListExperiments=ListExperiments(list_val);%choose the selected experiments
279
280DataSeries=get(handles.DataSeries,'String');
281list_val=get(handles.DataSeries,'Value');
282if numel(DataSeries)>=list_val
283    DataSeries=DataSeries(list_val);
284else
285    DataSeries=[];
286end
287check_fix=strcmp(get(handles.DataSeries,'enable'),'off');
288[ListFiles,indices]=list_dir_3(SourceDir,ListExperiments,ListDevices,DataSeries,check_fix);
289set(handles.DataSeries,'String',ListFiles)
290set(handles.DataSeries,'Value',indices)% initialise the menu selection with the folder defined by the input
291
292%------------------------------------------------------------------------
293% --- List the DataSeries when a set of experiments is selected
294%------------------------------------------------------------------------
295% function list_dataseries(handles,ListExperiments,MirrorPath)
296%
297% DataSeries={};
298% for iexp=1:numel(ListExperiments)
299% if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
300% ListExperiments{iexp}(1)=[];%remove the first char '+' used to mark folders
301% ListStruct=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
302% ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
303% ListFiles=ListCells(1,:);%list of dir and file  names
304% cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
305% cell_remove_tild=regexp(ListFiles,'~$');% detect tild the end of file nqme (do not list)
306% check_keep=cellfun('isempty', cell_remove) & cellfun('isempty', cell_remove_tild);
307% check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
308% for ilist=1:numel(ListFiles)
309%     if check_keep(ilist)% loop on eligible DataSeries folders
310%         mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});%source folder
311%         if ~exist(mirror,'file') && ~exist(mirror,'dir')% if the name is a broken link
312%             delete(mirror)% delete broken link
313%         else %update the list of dataSeries
314%             [tild,msg]=fileattrib(mirror);
315%             if check_dir(ilist)
316%                 ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
317%             end
318%             if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries
319%                 DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list
320%             end
321%         end
322%     end
323% end
324% end
325% end
326% if get(handles.CheckDevices,'Value')
327% set(handles.ListDevices,'Value',1)
328% set(handles.ListDevices,'String',sort(DataSeries))
329% CheckDevices_Callback([],[], handles)
330% else
331% set(handles.DataSeries,'Value',1)
332% set(handles.DataSeries,'String',sort(DataSeries))
333% end
334
335%------------------------------------------------------------------------
336% Provide a list to display
337%------------------------------------------------------------------------
338function [ListFiles,indices]=list_dir_1(SourceDir,ListSub)
339
340    ListStruct=dir_uvmat(SourceDir); %list files and dirs, extende to OpenDAP case
341    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
342    ListFiles=ListCells(1,:);
343    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
344    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
345    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
346    check_keep=cellfun('isempty', cell_remove);
347    ListFiles=sort((ListFiles(check_keep))');
348
349if ischar(ListSub)
350    indices=find(strcmp(ListSub,ListFiles));
351else
352    indices=[];
353    for ilist=1:numel(ListSub)
354        index=find(strcmp(ListSub{ilist},ListFiles));
355        indices=[indices index];
356    end
357end
358if isempty(indices), indices=1; end
359
360%------------------------------------------------------------------------
361% Provide a list to display
362%------------------------------------------------------------------------
363function [ListFilesTot,indices]=list_dir_2(SourceDir,ListDir,ListSub,check_fix)
364ListFilesTot={};
365for ilist=1:numel(ListDir)
366    if ~isempty(regexp(ListDir{ilist},'^\+/'))
367    ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
368    ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist})); %list files and dirs, extende to OpenDAP case
369    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
370    ListFiles=ListCells(1,:);
371    check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
372    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
373    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
374    check_keep=cellfun('isempty', cell_remove);
375    ListFilesTot=[ListFilesTot (ListFiles(check_keep))];
376    end
377end
378ListFilesTot=unique(ListFilesTot);
379if ischar(ListSub)
380    indices=find(strcmp(ListSub,ListFilesTot));
381else
382    indices=[];
383    for ilist=1:numel(ListSub)
384        index=find(strcmp(ListSub{ilist},ListFilesTot));
385        indices=[indices index];
386    end
387    if check_fix
388        index_init=1:numel(ListFilesTot);
389        %indices=sort(indices)
390        index_init(indices)=[];
391       ListFilesTot=ListFilesTot([indices index_init]);
392       indices=1:numel(indices);
393    end     
394end
395if isempty(indices), indices=1; end
396
397
398%------------------------------------------------------------------------
399% Provide a list to display
400%------------------------------------------------------------------------
401function [ListFilesTot,indices]=list_dir_3(SourceDir,ListDir,ListSub,ListSubSub,check_fix)
402ListFilesTot={};
403for ilist=1:numel(ListDir)
404    if ~isempty(regexp(ListDir{ilist},'^\+/'))
405        ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
406        for isub=1:numel(ListSub)
407            if ~isempty(regexp(ListSub{isub},'^\+/'))
408                ListSub{isub}=regexprep(ListSub{isub},'^\+/','');
409                ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist},ListSub{isub})); %list files and dirs, extende to OpenDAP case
410                ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
411                ListFiles=ListCells(1,:);
412                check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
413                ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
414                cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
415                check_keep=cellfun('isempty', cell_remove);
416                ListFilesTot=[ListFilesTot (ListFiles(check_keep))];
417            end
418        end
419    end
420end
421ListFilesTot=unique(ListFilesTot);
422if ischar(ListSubSub)
423    indices=find(strcmp(ListSubSub,ListFilesTot));
424else
425    indices=[];
426    for ilist=1:numel(ListSubSub)
427        index=find(strcmp(ListSubSub{ilist},ListFilesTot));
428        indices=[indices index];
429    end
430    if check_fix
431        index_init=1:numel(ListFilesTot);
432        index_init(indices)=[];
433       ListFilesTot=ListFilesTot([indices index_init]);
434       indices=1:numel(indices);
435    end     
436end
437if isempty(indices), indices=1; end
438
439
440%------------------------------------------------------------------------
441% --- Executes when the mirror is created or updated
442%------------------------------------------------------------------------
443function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
444
445DataSeries={};
446for iexp=1:numel(ListExperiments)
447    if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
448        ListExperiments{iexp}(1)=[];
449        ListStruct=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
450        ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
451        ListFiles=ListCells(1,:);%list of dir and file  names
452        cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
453        check_keep=cellfun('isempty', cell_remove);
454        check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
455        for ilist=1:numel(ListFiles)
456            if check_keep(ilist)% loop on eligible DataSeries folders
457                DataSeries=fullfile(CampaignPath,ListExperiments{iexp},ListFiles{ilist});%source folder
458                if ~isempty(MirrorPath)
459                    mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});
460                    if exist(mirror,'file')% if mirror already exists as a file or folder
461                        [tild,msg]=fileattrib(mirror);
462                        if strcmp(msg.Name,mirror)%if the mirror name already exists as a local file or dir
463                            if msg.directory% case of a folder
464                                answer=msgbox_uvmat('INPUT_Y-N',['replace local folder ' msg.Name ' by a link to the source dir']);
465                                if strcmp(answer,'Yes')
466                                    [ss,msg]=rmdir(mirror);
467                                    if ss==1
468                                        system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
469                                    else
470                                        msgbox_uvmat('ERROR',['enable to delete local folder: ' msg]);
471                                    end
472                                end
473                            else % case of an existing mirror file
474                                answer=msgbox_uvmat('INPUT_Y-N',['replace local file ' msg.Name ' by a link to the source file']);
475                                if strcmp(answer,'Yes')
476                                    delete(mirror);
477                                    system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
478                                end
479                            end
480                        end
481                    else% create mirror to the data series if needed
482                        system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
483                    end
484                    if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries
485                        if check_dir(ilist)
486                            ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
487                        end
488                        DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list
489                    end
490                end
491            end
492        end
493    end
494end
495set(handles.DataSeries,'String',sort(DataSeries))
496
497%------------------------------------------------------------------------
498% --- Executes on button press in CampaignDoc.
499function CampaignDoc_Callback(hObject, eventdata, handles)
500%------------------------------------------------------------------------
501answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file');
502if ~isequal(answer{1},'OK')
503    return
504end
505set(handles.ListExperiments,'Value',1)
506ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
507DataviewData=get(handles.browse_data,'UserData');
508List=DataviewData.List;
509Currentpath=get(handles.SourceDir,'String');
510[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
511Campaign=[Campaign DirExt];
512t=xmltree;
513t=set(t,1,'name','CampaignDoc');
514t = attributes(t,'add',1,'source','directory');
515SubCampaignTest=get(handles.SubCampaignTest,'Value');
516root_uid=1;
517if SubCampaignTest
518    %TO DO open an exoiting xml doc
519    [t,root_uid]=add(t,1,'element','SubCampaign');
520    t =attributes(t,'add',root_uid,'DirName',Campaign);
521end
522for iexp=1:length(List.Experiment)
523    set(handles.ListExperiments,'Value',iexp+1)
524    drawnow
525    test_mod=0;
526    [t,uid_exp]=add(t,root_uid,'element','Experiment');
527    t = attributes(t,'add',uid_exp,'i',num2str(iexp));
528    ExpName=List.Experiment{iexp}.name;
529    t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
530
531    if isfield(List.Experiment{iexp},'Device')
532        for idevice=1:length(List.Experiment{iexp}.Device)
533            [t,uid_device]=add(t,uid_exp,'element','Device');
534            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
535            t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);
536            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
537                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
538                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
539                    [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
540                    if test
541                        disp([List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated'])
542                    end
543                    if isequal(Title,'ImaDoc')
544                        [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
545                        t = attributes(t,'add',uid_xml,'source','file');
546                        [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});
547                    end
548                end
549            elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
550                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
551                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
552                    [t,uid_record]=add(t,uid_device,'element','Record');
553                    t = attributes(t,'add',uid_record,'DirName',RecordName);
554                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
555                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
556                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
557                            [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
558                            if test
559                                disp([FileName ' , Heading updated'])
560                            end
561                            [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
562                            t = attributes(t,'add',uid_xml,'source','file');
563                            [t]=add(t,uid_xml,'chardata',FileName);
564                        end
565                    end
566                end
567            end
568        end
569    end
570end
571set(handles.ListExperiments,'Value',1)
572outputdir=get(handles.SourceDir,'String');
573[path,dirname]=fileparts(outputdir);
574outputfile=fullfile(outputdir,[dirname '.xml']);
575%campaigndoc(t);
576save(t,outputfile)
577
578
579
580% %------------------------------------------------------------------------
581% % --- Executes on button press in OK.
582% %------------------------------------------------------------------------
583% function OK_Callback(hObject, eventdata, handles)
584%
585% if strcmp(get(handles.MirrorDir,'Visible'),'on')
586%     Campaign=get(handles.MirrorDir,'String');
587% else
588%     Campaign=get(handles.SourceDir,'String');
589% end
590% handles.output=[];
591% handles.output.Campaign=Campaign;
592% Experiment=get(handles.ListExperiments,'String');
593% IndicesExp=get(handles.ListExperiments,'Value');
594% if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected
595%     Experiment=Experiment(IndicesExp);% use the selection of the list of experiments
596% end
597% Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
598% Device=get(handles.DataSeries,'String');
599% Value=get(handles.DataSeries,'Value');
600% Device=Device(Value);
601% Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir
602% Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
603% handles.output.Experiment=Experiment;
604% handles.output.DataSeries=Device;
605% guidata(hObject, handles);% Update handles structure
606% uiresume(handles.browse_data);
607% drawnow
608
609%------------------------------------------------------------------------
610% --- Executes on button press in HELP.
611function HELP_Callback(hObject, eventdata, handles)
612path_to_uvmat=which ('uvmat');% check the path of uvmat
613pathelp=fileparts(path_to_uvmat);
614helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
615if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
616else
617web([helpfile '#dataview'])   
618end
619
620%------------------------------------------------------------------------
621% --- Executes when user attempts to close browse_data.
622%------------------------------------------------------------------------
623function closefcn(gcbo, eventdata)
624
625hseries=findobj(allchild(0),'Tag','series');
626if ~isempty(hseries)
627    hreplicate=findobj(hseries,'Tag','Replicate');
628    set(hreplicate,'Value',0)
629end
630hcalib=findobj(allchild(0),'Tag','geometry_calib');
631if ~isempty(hcalib)
632    hreplicate=findobj(hcalib,'Tag','Replicate');
633    set(hreplicate,'Value',0)
634end
635
636% %------------------------------------------------------------------------
637% % --- Executes on key press over figure1 with no controls selected.
638% %------------------------------------------------------------------------
639% function browse_data_KeyPressFcn(hObject, eventdata, handles)
640   
641% % Check for "enter" or "escape"
642% if isequal(get(hObject,'CurrentKey'),'escape')
643%     % User said no by hitting escape
644%     handles.output = 'Cancel';
645%     
646%     % Update handles structure
647%     guidata(hObject, handles);
648%     
649%     uiresume(handles.browse_data);
650% end
651% if isequal(get(hObject,'CurrentKey'),'return')
652%     uiresume(handles.browse_data);
653% end
654
655
656% --- Executes on button press in Up.
657function Down_Callback(hObject, eventdata, handles)
658SourceDir=get(handles.SourceDir,'String');
659ListExperiments=get(handles.ListExperiments,'String');
660list_val=get(handles.ListExperiments,'Value');
661if ischar(ListExperiments)
662    Exp=ListExperiments;
663else
664    Exp=ListExperiments{list_val(1)};
665end
666Exp=regexprep(Exp,'^\+/','');
667SourceDirNew=fullfile(SourceDir,Exp);
668set(handles.SourceDir,'String',SourceDirNew);% New SourceDir
669ListDevices=get(handles.ListDevices,'String');
670DeviceIndices=get(handles.ListDevices,'Value');
671set(handles.ListExperiments,'String',ListDevices);%replace Experiments by Devices
672set(handles.ListExperiments,'Value',DeviceIndices);%replace Experiments by Devices
673DataSeries=get(handles.DataSeries,'String');
674list_val=get(handles.DataSeries,'Value');
675set(handles.ListDevices,'String',DataSeries);%replace Devices by DataSeries
676set(handles.ListDevices,'Value',list_val);%replace Devices by DataSeries
677
678[ListFiles,indices]=list_dir_3(SourceDirNew,ListDevices(DeviceIndices),DataSeries(list_val),[]);
679set(handles.DataSeries,'String',ListFiles)
680set(handles.DataSeries,'Value',indices)% initialise the menu selection with the folder defined by the input
681
682
683% --- Executes on button press in Down.
684function Up_Callback(hObject, eventdata, handles)
685SourceDir=get(handles.SourceDir,'String');
686[SourceDir,Exp]=fileparts(SourceDir);
687set(handles.SourceDir,'String',SourceDir)
688
689% set(handles.ListExperiments,'Value',indices)
690%[ListFiles,indices]=list_dir_1(SourceDir,Exp);
691% set(handles.ListExperiments,'String',ListFiles)
692% set(handles.ListExperiments,'Value',indices)
693ListDevices=get(handles.ListDevices,'String');
694DeviceIndices=get(handles.ListDevices,'Value');
695set(handles.DataSeries,'String',ListDevices);
696set(handles.DataSeries,'Value',DeviceIndices);
697
698ListExperiments=get(handles.ListExperiments,'String');
699ExpIndices=get(handles.ListExperiments,'Value');
700set(handles.ListDevices,'String',ListExperiments);
701set(handles.ListDevices,'Value',ExpIndices);
702
703set(handles.ListExperiments,'String',{['+/' Exp]})
704set(handles.ListExperiments,'Value',1)
705
706% ListExperiments=get(handles.ListExperiments,'String');
707% list_val=get(handles.ListExperiments,'Value');
708% SourceFolder=regexprep(ListExperiments{list_val(1)},'+','');
709% set(handles.SourceDir,'String',fullfile(SourceDir,SourceFolder))
710% DataSeries=get(handles.DataSeries,'String');
711% ValueDevice=get(handles.DataSeries,'Value');
712% set(handles.ListExperiments,'String',DataSeries)
713% set(handles.ListExperiments,'Value',ValueDevice)
714% ListExperiments_Callback(hObject, [], handles)
715
716
717% % --- Executes on selection change in DataSeries.
718% function DataSeries_Callback(hObject, eventdata, handles)
719% SourceDir=get(handles.SourceDir,'String');
720% ListData=get(handles.DataSeries,'String');
721% Folder=ListData{get(handles.DataSeries,'Value')};
722% if ~isempty(regexp(Folder,'^\+/'))% if a folder is selected
723%     Folder=regexprep(Folder,'\+/','');
724%     ListExperiments=get(handles.ListExperiments,'String');
725%     list_val=get(handles.ListExperiments,'Value');
726%     for iexp=1:numel(list_val)
727%         ExpName=regexprep(ListExperiments{list_val(iexp)},'\+/','');
728%         FullName=fullfile(SourceDir,ExpName,Folder);
729%         dd=dir(FullName);
730%         check_sub=1;
731%         for idir=1:numel(dd)
732%             ListData{ilist}=dd(ilist).name;
733%             if dd(ilist).isdir && ~strcmp(dd(ilist).name,'.')&& ~strcmp(dd(ilist).name,'..')&& isempty(regexp(dd(ilist).name,'^_LOG'))...
734%                     && isempty(regexp(dd(ilist).name,'^_LOG'))&& isempty(regexp(dd(ilist).name,'^_XML'))
735%                check_sub=1;
736%                ListData{ilist}=['+/' dd(ilist).name];
737%             end
738%         end
739%         if check_sub
740%         set(handles.ListDevices,'String',ListData);
741%                 set(handles.ListDevices,'Visible','on');
742%                 set(handles.DataSeries,'String',ListData)
743%                 break
744%         end
745%     end
746% end
747
748% % --- Executes on button press in CheckDevices.
749% function CheckDevices_Callback(hObject, eventdata, handles)
750% if get(handles.CheckDevices,'Value')
751%     set(handles.ListDevices,'Visible','on')
752%     ListDevices=get(handles.DataSeries,'String');
753%     Index=get(handles.DataSeries,'Value');
754%     set(handles.ListDevices,'String',ListDevices)
755%     set(handles.ListDevices,'Value',Index)
756%     set(handles.DataSeries,'Value',1)
757%     if strcmp(get(handles.MirrorDir,'Visible'),'on')
758%     MirrorPath=get(handles.MirrorDir,'String');
759%     else
760%     MirrorPath=get(handles.SourceDir,'String');
761%     end
762%     IndexExperiment=get(handles.ListExperiments,'Value');
763%     ListExperiment=get(handles.ListExperiments,'String');
764%     Experiment=ListExperiment{get(handles.ListExperiments,'Value')};
765%     Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
766%     Experiment=regexprep(Experiment,'^~','');% remove the ~ used to mark symbolic link
767%     Device=regexprep(ListDevices{Index},'^\+/','');% remove the +/ used to mark dir
768%     Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
769%     DataSeries=dir(fullfile(MirrorPath,Experiment,Device));
770%     DataSeriesCell=struct2cell(DataSeries);
771%     set(handles.DataSeries,'String',DataSeriesCell(1,:)')
772% else
773%     ListDevices=get(handles.ListDevices,'String');
774%     Index=get(handles.ListDevices,'Value');
775%     set(handles.ListDevices,'Visible','off')
776%     set(handles.DataSeries,'String',ListDevices)
777%     set(handles.DataSeries,'Value',Index)
778% end
Note: See TracBrowser for help on using the repository browser.