source: trunk/src/browse_data.m @ 1076

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

LIF calibration with mode replicate

File size: 35.5 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);
78if exist('EnableMirror','var') && strcmp(EnableMirror,'on')
79    set(handles.CreateMirror,'Visible','on')
80    set(handles.mirror_txt,'Visible','on')
81else
82    set(handles.CreateMirror,'Visible','off')
83    set(handles.mirror_txt,'Visible','off')
84end
85
86%% initialize the GUI
87if isempty(regexp(InputDir,'^http:'))&& ~(exist('InputDir','var') && ischar(InputDir) && exist(InputDir,'dir'))
88    InputDir=pwd;% current dir is the starting data series by default
89end
90if ischar(InputDir),InputDir={InputDir};end
91for ilist=1:numel(InputDir)
92    [ExpWithPath,DataSeries{ilist},Ext]=fileparts(InputDir{ilist});
93    DataSeries{ilist}=['+/' DataSeries{ilist} Ext];
94    [Experiment{ilist},Device{ilist},Ext]=fileparts(ExpWithPath);
95    Device{ilist}=['+/' Device{ilist} Ext];
96    [SourceDir{ilist},Experiment{ilist},Ext]=fileparts(Experiment{ilist});
97    Experiment{ilist}=['+/' Experiment{ilist} Ext];
98    if ~strcmp(SourceDir{ilist},SourceDir{1})||~strcmp(Experiment{ilist},Experiment{1})
99        msgbox_uvmat('ERROR','replicate cannot be used with multiple root folders')
100        return
101    end
102    if ~strcmp(DataSeries{ilist},DataSeries{1})
103        set(handles.DataSeries,'enable','off')
104    end
105    if ~strcmp(Device{ilist},Device{1})
106        set(handles.ListDevices,'enable','off')
107    end
108end
109s=[];
110if isempty(s) %a source dir has been opened
111    set(handles.SourceDir,'String',SourceDir{1});
112    set(handles.MirrorDir,'Visible','off');% no mirror dir display
113    set(handles.CreateMirror,'String','create_mirror')
114end
115set(handles.DataSeries,'String',DataSeries);
116set(handles.DataSeries,'Value',(1:numel(DataSeries)));
117set(handles.ListDevices,'String',Device);
118set(handles.ListDevices,'Value',(1:numel(Device)));
119errormsg=scan_campaign(handles,SourceDir{1},Experiment{1});
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 SourceDir.
138function SourceDir_Callback(hObject, eventdata, handles)
139SourceDir=get(handles.SourceDir,'String');
140ListExp=get(handles.ListExperiments,'String');
141ListExp=ListExp(get(handles.ListExperiments,'Value'));
142errormsg=scan_campaign(handles,SourceDir,ListExp);
143if ~isempty(errormsg)
144    msgbox_uvmat('ERROR',errormsg)
145    return
146end
147%------------------------------------------------------------------------
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    index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
344    check_dir=cell2mat(ListCells(index_isdir,:));% =1 for directories, =0 for files
345    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
346    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
347    check_keep=cellfun('isempty', cell_remove);
348    ListFiles=sort((ListFiles(check_keep))');
349
350if ischar(ListSub)
351    indices=find(strcmp(ListSub,ListFiles));
352else
353    indices=[];
354    for ilist=1:numel(ListSub)
355        index=find(strcmp(ListSub{ilist},ListFiles));
356        indices=[indices index];
357    end
358end
359if isempty(indices), indices=1; end
360
361%------------------------------------------------------------------------
362% Provide a list to display
363%------------------------------------------------------------------------
364function [ListFilesTot,indices]=list_dir_2(SourceDir,ListDir,ListSub,check_fix)
365ListFilesTot={};
366for ilist=1:numel(ListDir)
367    if ~isempty(regexp(ListDir{ilist},'^\+/'))
368    ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
369    ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist})); %list files and dirs, extende to OpenDAP case
370    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
371    ListFiles=ListCells(1,:);
372    index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
373    check_dir=cell2mat(ListCells(index_isdir,:));% =1 for directories, =0 for files
374    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
375    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
376    check_keep=cellfun('isempty', cell_remove);
377    ListFilesTot=[ListFilesTot (ListFiles(check_keep))];
378    end
379end
380ListFilesTot=unique(ListFilesTot);
381if ischar(ListSub)
382    indices=find(strcmp(ListSub,ListFilesTot));
383else
384    indices=[];
385    for ilist=1:numel(ListSub)
386        index=find(strcmp(ListSub{ilist},ListFilesTot));
387        indices=[indices index];
388    end
389    if check_fix
390        index_init=1:numel(ListFilesTot);
391        %indices=sort(indices)
392        index_init(indices)=[];
393       ListFilesTot=ListFilesTot([indices index_init]);
394       indices=1:numel(indices);
395    end     
396end
397if isempty(indices), indices=1; end
398
399
400%------------------------------------------------------------------------
401% Provide the list (ListFilesTot) to display in DataSeries with the selected indices
402%------------------------------------------------------------------------
403function [ListFilesTot,indices]=list_dir_3(SourceDir,ListDir,ListSub,ListSubSub,check_fix)
404% INPUT:
405%SourceDir: path to the displayed directories
406%ListDir: list of file and folder names under SourceDir (column 'Experiments')
407%ListSub: list of file and folder in the second column 'Devices')
408%ListSubSub: prvious list of file and folder in the third column 'DataSeries', used to mark the selected indices
409ListFilesTot={};
410for ilist=1:numel(ListDir)
411    if ~isempty(regexp(ListDir{ilist},'^\+/'))
412        ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
413        for isub=1:numel(ListSub)
414            if ~isempty(regexp(ListSub{isub},'^\+/'))
415                ListSub{isub}=regexprep(ListSub{isub},'^\+/','');
416                ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist},ListSub{isub})); %list files and dirs, extende to OpenDAP case
417                ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
418                ListFiles=ListCells(1,:);
419                check_xml=~cellfun('isempty',regexp(ListFiles,'(\.xml|~)$'));% detect non xml files and files not marked by ~
420                index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
421                check_dir=cell2mat(ListCells(index_isdir,:));% =1 for directories, =0 for files
422                nbfiles=numel(find(~check_xml & ~check_dir));% number of non xml files
423                check_dir=check_dir & cellfun('isempty', regexp(ListFiles,'^(-|\.|\+/\.)'));% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
424                ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
425                %cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )         
426                ListFiles=ListFiles(check_dir | check_xml);           
427                ListFilesTot=[ListFilesTot ListFiles];
428                if nbfiles>0
429                    ListFilesTot=[ListFilesTot {[num2str(nbfiles) ' files']}];
430                end
431            end
432        end
433    end
434end
435ListFilesTot=unique(ListFilesTot);
436if ischar(ListSubSub)
437    indices=find(strcmp(ListSubSub,ListFilesTot));
438else
439    indices=[];
440    for ilist=1:numel(ListSubSub)
441        index=find(strcmp(ListSubSub{ilist},ListFilesTot));
442        if check_fix && isempty(index)
443            ListFilesTot=[ListFilesTot {['---' ListSubSub{ilist}]}];
444            index=numel(ListFilesTot);
445        end
446        indices=[indices index];
447    end
448    if check_fix
449        index_init=1:numel(ListFilesTot);
450        index_init(indices)=[];
451       ListFilesTot=ListFilesTot([indices index_init]);
452       indices=1:numel(indices);
453    end     
454end
455if isempty(indices), indices=1; end
456
457
458%------------------------------------------------------------------------
459% --- Executes when the mirror is created or updated
460%------------------------------------------------------------------------
461function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
462
463DataSeries={};
464for iexp=1:numel(ListExperiments)
465    if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
466        ListExperiments{iexp}(1)=[];
467        ListStruct=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
468        ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
469        ListFiles=ListCells(1,:);%list of dir and file  names
470        cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
471        check_keep=cellfun('isempty', cell_remove);
472        index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
473        check_dir=cell2mat(ListCells(index_isdir,:));% =1 for directories, =0 for files
474        for ilist=1:numel(ListFiles)
475            if check_keep(ilist)% loop on eligible DataSeries folders
476                DataSeries=fullfile(CampaignPath,ListExperiments{iexp},ListFiles{ilist});%source folder
477                if ~isempty(MirrorPath)
478                    mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});
479                    if exist(mirror,'file')% if mirror already exists as a file or folder
480                        [tild,msg]=fileattrib(mirror);
481                        if strcmp(msg.Name,mirror)%if the mirror name already exists as a local file or dir
482                            if msg.directory% case of a folder
483                                answer=msgbox_uvmat('INPUT_Y-N',['replace local folder ' msg.Name ' by a link to the source dir']);
484                                if strcmp(answer,'Yes')
485                                    [ss,msg]=rmdir(mirror);
486                                    if ss==1
487                                        system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
488                                    else
489                                        msgbox_uvmat('ERROR',['enable to delete local folder: ' msg]);
490                                    end
491                                end
492                            else % case of an existing mirror file
493                                answer=msgbox_uvmat('INPUT_Y-N',['replace local file ' msg.Name ' by a link to the source file']);
494                                if strcmp(answer,'Yes')
495                                    delete(mirror);
496                                    system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
497                                end
498                            end
499                        end
500                    else% create mirror to the data series if needed
501                        system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
502                    end
503                    if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries
504                        if check_dir(ilist)
505                            ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
506                        end
507                        DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list
508                    end
509                end
510            end
511        end
512    end
513end
514set(handles.DataSeries,'String',sort(DataSeries))
515
516%------------------------------------------------------------------------
517% --- Executes on button press in CampaignDoc.
518function CampaignDoc_Callback(hObject, eventdata, handles)
519%------------------------------------------------------------------------
520answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file');
521if ~isequal(answer{1},'OK')
522    return
523end
524set(handles.ListExperiments,'Value',1)
525ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
526DataviewData=get(handles.browse_data,'UserData');
527List=DataviewData.List;
528Currentpath=get(handles.SourceDir,'String');
529[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
530Campaign=[Campaign DirExt];
531t=xmltree;
532t=set(t,1,'name','CampaignDoc');
533t = attributes(t,'add',1,'source','directory');
534SubCampaignTest=get(handles.SubCampaignTest,'Value');
535root_uid=1;
536if SubCampaignTest
537    %TO DO open an exoiting xml doc
538    [t,root_uid]=add(t,1,'element','SubCampaign');
539    t =attributes(t,'add',root_uid,'DirName',Campaign);
540end
541for iexp=1:length(List.Experiment)
542    set(handles.ListExperiments,'Value',iexp+1)
543    drawnow
544    test_mod=0;
545    [t,uid_exp]=add(t,root_uid,'element','Experiment');
546    t = attributes(t,'add',uid_exp,'i',num2str(iexp));
547    ExpName=List.Experiment{iexp}.name;
548    t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
549
550    if isfield(List.Experiment{iexp},'Device')
551        for idevice=1:length(List.Experiment{iexp}.Device)
552            [t,uid_device]=add(t,uid_exp,'element','Device');
553            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
554            t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);
555            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
556                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
557                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
558                    [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
559                    if test
560                        disp([List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated'])
561                    end
562                    if isequal(Title,'ImaDoc')
563                        [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
564                        t = attributes(t,'add',uid_xml,'source','file');
565                        [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});
566                    end
567                end
568            elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
569                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
570                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
571                    [t,uid_record]=add(t,uid_device,'element','Record');
572                    t = attributes(t,'add',uid_record,'DirName',RecordName);
573                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
574                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
575                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
576                            [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
577                            if test
578                                disp([FileName ' , Heading updated'])
579                            end
580                            [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
581                            t = attributes(t,'add',uid_xml,'source','file');
582                            [t]=add(t,uid_xml,'chardata',FileName);
583                        end
584                    end
585                end
586            end
587        end
588    end
589end
590set(handles.ListExperiments,'Value',1)
591outputdir=get(handles.SourceDir,'String');
592[path,dirname]=fileparts(outputdir);
593outputfile=fullfile(outputdir,[dirname '.xml']);
594%campaigndoc(t);
595save(t,outputfile)
596
597
598
599% %------------------------------------------------------------------------
600% % --- Executes on button press in OK.
601% %------------------------------------------------------------------------
602% function OK_Callback(hObject, eventdata, handles)
603%
604% if strcmp(get(handles.MirrorDir,'Visible'),'on')
605%     Campaign=get(handles.MirrorDir,'String');
606% else
607%     Campaign=get(handles.SourceDir,'String');
608% end
609% handles.output=[];
610% handles.output.Campaign=Campaign;
611% Experiment=get(handles.ListExperiments,'String');
612% IndicesExp=get(handles.ListExperiments,'Value');
613% if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected
614%     Experiment=Experiment(IndicesExp);% use the selection of the list of experiments
615% end
616% Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
617% Device=get(handles.DataSeries,'String');
618% Value=get(handles.DataSeries,'Value');
619% Device=Device(Value);
620% Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir
621% Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
622% handles.output.Experiment=Experiment;
623% handles.output.DataSeries=Device;
624% guidata(hObject, handles);% Update handles structure
625% uiresume(handles.browse_data);
626% drawnow
627
628%------------------------------------------------------------------------
629% --- Executes on button press in HELP.
630function HELP_Callback(hObject, eventdata, handles)
631path_to_uvmat=which ('uvmat');% check the path of uvmat
632pathelp=fileparts(path_to_uvmat);
633helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
634if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
635else
636web([helpfile '#dataview'])   
637end
638
639%------------------------------------------------------------------------
640% --- Executes when user attempts to close browse_data.
641%------------------------------------------------------------------------
642function closefcn(gcbo, eventdata)
643
644hseries=findobj(allchild(0),'Tag','series');
645if ~isempty(hseries)
646    hreplicate=findobj(hseries,'Tag','Replicate');
647    set(hreplicate,'Value',0)
648end
649hcalib=findobj(allchild(0),'Tag','geometry_calib');
650if ~isempty(hcalib)
651    hreplicate=findobj(hcalib,'Tag','Replicate');
652    set(hreplicate,'Value',0)
653end
654
655% %------------------------------------------------------------------------
656% % --- Executes on key press over figure1 with no controls selected.
657% %------------------------------------------------------------------------
658% function browse_data_KeyPressFcn(hObject, eventdata, handles)
659   
660% % Check for "enter" or "escape"
661% if isequal(get(hObject,'CurrentKey'),'escape')
662%     % User said no by hitting escape
663%     handles.output = 'Cancel';
664%     
665%     % Update handles structure
666%     guidata(hObject, handles);
667%     
668%     uiresume(handles.browse_data);
669% end
670% if isequal(get(hObject,'CurrentKey'),'return')
671%     uiresume(handles.browse_data);
672% end
673
674
675% --- Executes on button press in Up.
676function Down_Callback(hObject, eventdata, handles)
677SourceDir=get(handles.SourceDir,'String');
678ListExperiments=get(handles.ListExperiments,'String');
679list_val=get(handles.ListExperiments,'Value');
680if ischar(ListExperiments)
681    Exp=ListExperiments;
682else
683    Exp=ListExperiments{list_val(1)};
684end
685Exp=regexprep(Exp,'^\+/','');
686SourceDirNew=fullfile(SourceDir,Exp);
687set(handles.SourceDir,'String',SourceDirNew);% New SourceDir
688ListDevices=get(handles.ListDevices,'String');
689DeviceIndices=get(handles.ListDevices,'Value');
690set(handles.ListExperiments,'String',ListDevices);%replace Experiments by Devices
691set(handles.ListExperiments,'Value',DeviceIndices);%replace Experiments by Devices
692DataSeries=get(handles.DataSeries,'String');
693list_val=get(handles.DataSeries,'Value');
694set(handles.ListDevices,'String',DataSeries);%replace Devices by DataSeries
695set(handles.ListDevices,'Value',list_val);%replace Devices by DataSeries
696
697[ListFiles,indices]=list_dir_3(SourceDirNew,ListDevices(DeviceIndices),DataSeries(list_val),[],0);
698set(handles.DataSeries,'String',ListFiles)
699set(handles.DataSeries,'Value',indices)% initialise the menu selection with the folder defined by the input
700
701
702% --- Executes on button press in Down.
703function Up_Callback(hObject, eventdata, handles)
704SourceDir=get(handles.SourceDir,'String');
705[SourceDir,Exp]=fileparts(SourceDir);
706set(handles.SourceDir,'String',SourceDir)
707
708% set(handles.ListExperiments,'Value',indices)
709%[ListFiles,indices]=list_dir_1(SourceDir,Exp);
710% set(handles.ListExperiments,'String',ListFiles)
711% set(handles.ListExperiments,'Value',indices)
712ListDevices=get(handles.ListDevices,'String');
713DeviceIndices=get(handles.ListDevices,'Value');
714set(handles.DataSeries,'String',ListDevices);
715set(handles.DataSeries,'Value',DeviceIndices);
716
717ListExperiments=get(handles.ListExperiments,'String');
718ExpIndices=get(handles.ListExperiments,'Value');
719set(handles.ListDevices,'String',ListExperiments);
720set(handles.ListDevices,'Value',ExpIndices);
721
722set(handles.ListExperiments,'String',{['+/' Exp]})
723set(handles.ListExperiments,'Value',1)
724
725% ListExperiments=get(handles.ListExperiments,'String');
726% list_val=get(handles.ListExperiments,'Value');
727% SourceFolder=regexprep(ListExperiments{list_val(1)},'+','');
728% set(handles.SourceDir,'String',fullfile(SourceDir,SourceFolder))
729% DataSeries=get(handles.DataSeries,'String');
730% ValueDevice=get(handles.DataSeries,'Value');
731% set(handles.ListExperiments,'String',DataSeries)
732% set(handles.ListExperiments,'Value',ValueDevice)
733% ListExperiments_Callback(hObject, [], handles)
734
735
736% % --- Executes on selection change in DataSeries.
737% function DataSeries_Callback(hObject, eventdata, handles)
738% SourceDir=get(handles.SourceDir,'String');
739% ListData=get(handles.DataSeries,'String');
740% Folder=ListData{get(handles.DataSeries,'Value')};
741% if ~isempty(regexp(Folder,'^\+/'))% if a folder is selected
742%     Folder=regexprep(Folder,'\+/','');
743%     ListExperiments=get(handles.ListExperiments,'String');
744%     list_val=get(handles.ListExperiments,'Value');
745%     for iexp=1:numel(list_val)
746%         ExpName=regexprep(ListExperiments{list_val(iexp)},'\+/','');
747%         FullName=fullfile(SourceDir,ExpName,Folder);
748%         dd=dir(FullName);
749%         check_sub=1;
750%         for idir=1:numel(dd)
751%             ListData{ilist}=dd(ilist).name;
752%             if dd(ilist).isdir && ~strcmp(dd(ilist).name,'.')&& ~strcmp(dd(ilist).name,'..')&& isempty(regexp(dd(ilist).name,'^_LOG'))...
753%                     && isempty(regexp(dd(ilist).name,'^_LOG'))&& isempty(regexp(dd(ilist).name,'^_XML'))
754%                check_sub=1;
755%                ListData{ilist}=['+/' dd(ilist).name];
756%             end
757%         end
758%         if check_sub
759%         set(handles.ListDevices,'String',ListData);
760%                 set(handles.ListDevices,'Visible','on');
761%                 set(handles.DataSeries,'String',ListData)
762%                 break
763%         end
764%     end
765% end
766
767% % --- Executes on button press in CheckDevices.
768% function CheckDevices_Callback(hObject, eventdata, handles)
769% if get(handles.CheckDevices,'Value')
770%     set(handles.ListDevices,'Visible','on')
771%     ListDevices=get(handles.DataSeries,'String');
772%     Index=get(handles.DataSeries,'Value');
773%     set(handles.ListDevices,'String',ListDevices)
774%     set(handles.ListDevices,'Value',Index)
775%     set(handles.DataSeries,'Value',1)
776%     if strcmp(get(handles.MirrorDir,'Visible'),'on')
777%     MirrorPath=get(handles.MirrorDir,'String');
778%     else
779%     MirrorPath=get(handles.SourceDir,'String');
780%     end
781%     IndexExperiment=get(handles.ListExperiments,'Value');
782%     ListExperiment=get(handles.ListExperiments,'String');
783%     Experiment=ListExperiment{get(handles.ListExperiments,'Value')};
784%     Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
785%     Experiment=regexprep(Experiment,'^~','');% remove the ~ used to mark symbolic link
786%     Device=regexprep(ListDevices{Index},'^\+/','');% remove the +/ used to mark dir
787%     Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
788%     DataSeries=dir(fullfile(MirrorPath,Experiment,Device));
789%     DataSeriesCell=struct2cell(DataSeries);
790%     set(handles.DataSeries,'String',DataSeriesCell(1,:)')
791% else
792%     ListDevices=get(handles.ListDevices,'String');
793%     Index=get(handles.ListDevices,'Value');
794%     set(handles.ListDevices,'Visible','off')
795%     set(handles.DataSeries,'String',ListDevices)
796%     set(handles.DataSeries,'Value',Index)
797% end
798
799
800% --- Executes when user attempts to close browse_data.
801function browse_data_CloseRequestFcn(hObject, eventdata, handles)
802% hObject    handle to browse_data (see GCBO)
803% eventdata  reserved - to be defined in a future version of MATLAB
804% handles    structure with handles and user data (see GUIDATA)
805
806% Hint: delete(hObject) closes the figure
807delete(hObject);
Note: See TracBrowser for help on using the repository browser.