source: trunk/src/browse_data.m @ 1068

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

replicate updated

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