source: trunk/src/browse_data.m @ 1071

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