source: trunk/src/browse_data.m @ 1150

Last change on this file since 1150 was 1150, checked in by sommeria, 4 months ago

browse_data improved

File size: 33.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-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
9%   http://www.legi.grenoble-inp.fr
10%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.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
155SourcePath=get(handles.SourceDir,'String');
156if ~isempty(regexp(SourcePath,'^http'))
157    SourcePath=pwd;
158    SourcePath=regexprep(SourcePath,'^\/.fsnet','/fsnet');
159end
160
161
162ProjectList=get(handles.ListExperiments,'String');
163ProjectName=ProjectList{get(handles.ListExperiments,'Value')};
164ProjectName=regexprep(ProjectName,'^\+/','');
165if strcmp(get(handles.MirrorDir,'Visible'),'on')
166    MirrorDir=get(handles.MirrorDir,'String');% name of the mirror folder
167else% create the mirror folder if it does not exist
168    MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir');
169    if isempty(MirrorRoot)
170        return
171    elseif strcmp(MirrorRoot,SourcePath)
172        msgbox_uvmat('ERROR','The mirror folder must be different from the source')
173        return
174    else
175        MirrorDir=fullfile(MirrorRoot,ProjectName);
176    end
177    if exist(MirrorDir,'dir')
178        msgbox_uvmat('ERROR',['The folder ' MirrorDir ' chosen as new mirror campaign already exists'])
179        return
180    else
181        [s,errormsg]=mkdir(MirrorDir);% create the mirror dir
182        if s~=1
183            msgbox_uvmat('ERROR',['error in creating ' MirrorDir ': ' errormsg])
184            return
185        end
186    end
187    SourceDir=fullfile(SourcePath,ProjectName);
188    MirrorDoc.SourceDir=SourceDir;
189    t=struct2xml(MirrorDoc);
190    set(t,1,'name','DataTree');
191    save(t,fullfile(MirrorDir,[ProjectName '.xml']))% create an xml file in the mirror folder to indicate its source folder
192    set(handles.MirrorDir,'String',MirrorDir)
193    set(handles.MirrorDir,'Visible','on')
194    set(handles.CreateMirror,'String','update_mirror')
195end
196ExpName={''};
197
198%% update the mirror from the source dir
199if exist(SourceDir,'dir')
200    hdir=dir(SourceDir); %list files and dirs
201    idir=0;
202    for ilist=1:length(hdir)
203        if hdir(ilist).isdir% scan all subfolders
204            dirname=hdir(ilist).name;%
205            if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')%skip subfolder beginning by '0'
206                idir=idir+1;
207                mirror=fullfile(MirrorDir,hdir(ilist).name);% corresponding name in the mirror
208                if ~exist(mirror,'dir')
209                    mkdir(mirror)% create the mirror folder if it does not exist
210                end
211                ExpName{idir}=['+/' hdir(ilist).name];% insert '+/' in the list to show that it is a folder
212            end
213            % look for the list of 'devices'
214        else
215            %warning for isolated files
216        end
217    end
218    set(handles.ListExperiments,'String',[{'*'};ExpName'])
219    set(handles.ListExperiments,'Value',1)
220    update_experiments(handles,[{'*'};ExpName'],SourceDir,MirrorDir)
221    % ListExperiments_Callback(hObject, eventdata, handles) % list the content of the experiment
222else
223    msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory'])
224end
225set(handles.SourceDir,'BackgroundColor',[1 1 1])
226
227%------------------------------------------------------------------------
228% List the experiments in a campaign, filling the menu ListExperiments
229%------------------------------------------------------------------------
230function errormsg=scan_campaign(handles,SourceDir,Experiment)
231%------------------------------------------------------------------------
232errormsg='';
233if ~isempty(regexp(SourceDir,'^http'))|| exist(SourceDir,'dir')
234    ListStruct=dir_uvmat(SourceDir); %list files and dirs, extende to OpenDAP case
235    if numel(ListStruct)>1000% A campaign folder must contain maily a list of 'experiment' sub-folders
236        errormsg=[SourceDir ' contains too many items (>1000) to be a Project folder'];
237        return
238    end
239    [ListFiles,index]=list_dir_1(SourceDir,Experiment);
240    set(handles.ListExperiments,'String',ListFiles)
241    set(handles.ListExperiments,'Value',index)% initialise the menu selection with the folder defined by the input
242    ListExperiments_Callback([],[], handles)
243else
244    msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory'])
245end
246
247%------------------------------------------------------------------------
248% --- Executes on selection change in ListExperiments.
249%------------------------------------------------------------------------
250function ListExperiments_Callback(hObject, eventdata, handles)
251
252if strcmp(get(handles.MirrorDir,'Visible'),'on')
253    SourceDir=get(handles.MirrorDir,'String');
254else
255    SourceDir=get(handles.SourceDir,'String');
256end
257ListExperiments=get(handles.ListExperiments,'String');
258list_val=get(handles.ListExperiments,'Value');
259ListExperiments=ListExperiments(list_val);%choose the selected experiments
260ListDevices=get(handles.ListDevices,'String');% list of devices
261list_val=get(handles.ListDevices,'Value');% currently selected devices
262Device='';
263if numel(ListDevices)>=list_val
264Device=ListDevices(list_val);%choose selected devices
265end
266check_fix=strcmp(get(handles.ListDevices,'enable'),'off');
267[ListFiles,indices]=list_dir_2(SourceDir,ListExperiments,Device,check_fix);
268set(handles.ListDevices,'String',ListFiles)
269set(handles.ListDevices,'Value',indices)% initialise the menu selection with the folder defined by the input
270ListDevices_Callback([],[], handles)
271
272%------------------------------------------------------------------------
273% --- Executes on selection change in ListExperiments.
274%------------------------------------------------------------------------
275function ListDevices_Callback(hObject, eventdata, handles)
276
277ListDevices=get(handles.ListDevices,'String');% list of devices
278list_val=get(handles.ListDevices,'Value');% currently selected devices
279ListDevices=ListDevices(list_val);%choose selected devices
280if strcmp(get(handles.MirrorDir,'Visible'),'on')
281    SourceDir=get(handles.MirrorDir,'String');
282else
283    SourceDir=get(handles.SourceDir,'String');
284end
285ListExperiments=get(handles.ListExperiments,'String');
286list_val=get(handles.ListExperiments,'Value');
287ListExperiments=ListExperiments(list_val);%choose the selected experiments
288
289DataSeries=get(handles.DataSeries,'String');
290list_val=get(handles.DataSeries,'Value');
291if numel(DataSeries)>=list_val
292    DataSeries=DataSeries(list_val);
293else
294    DataSeries=[];
295end
296check_fix=strcmp(get(handles.DataSeries,'enable'),'off');
297[ListFiles,indices]=list_dir_3(SourceDir,ListExperiments,ListDevices,DataSeries,check_fix);
298set(handles.DataSeries,'String',ListFiles)
299set(handles.DataSeries,'Value',indices)% initialise the menu selection with the folder defined by the input
300
301%------------------------------------------------------------------------
302% --- List the DataSeries when a set of experiments is selected
303%------------------------------------------------------------------------
304% function list_dataseries(handles,ListExperiments,MirrorPath)
305%
306% DataSeries={};
307% for iexp=1:numel(ListExperiments)
308% if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
309% ListExperiments{iexp}(1)=[];%remove the first char '+' used to mark folders
310% ListStruct=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
311% ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
312% ListFiles=ListCells(1,:);%list of dir and file  names
313% cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
314% cell_remove_tild=regexp(ListFiles,'~$');% detect tild the end of file nqme (do not list)
315% check_keep=cellfun('isempty', cell_remove) & cellfun('isempty', cell_remove_tild);
316% check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
317% for ilist=1:numel(ListFiles)
318%     if check_keep(ilist)% loop on eligible DataSeries folders
319%         mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});%source folder
320%         if ~exist(mirror,'file') && ~exist(mirror,'dir')% if the name is a broken link
321%             delete(mirror)% delete broken link
322%         else %update the list of dataSeries
323%             [tild,msg]=fileattrib(mirror);
324%             if check_dir(ilist)
325%                 ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
326%             end
327%             if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries
328%                 DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list
329%             end
330%         end
331%     end
332% end
333% end
334% end
335% if get(handles.CheckDevices,'Value')
336% set(handles.ListDevices,'Value',1)
337% set(handles.ListDevices,'String',sort(DataSeries))
338% CheckDevices_Callback([],[], handles)
339% else
340% set(handles.DataSeries,'Value',1)
341% set(handles.DataSeries,'String',sort(DataSeries))
342% end
343
344%------------------------------------------------------------------------
345% Provide a list to display
346%------------------------------------------------------------------------
347function [ListFiles,indices]=list_dir_1(SourceDir,ListSub)
348
349    ListStruct=dir_uvmat(SourceDir); %list files and dirs, extende to OpenDAP case
350    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
351    ListFiles=ListCells(1,:);
352    index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
353    check_dir=cell2mat(ListCells(index_isdir,:));% =1 for directories, =0 for files
354    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
355    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
356    check_keep=cellfun('isempty', cell_remove);
357    ListFiles=sort((ListFiles(check_keep))');
358
359if ischar(ListSub)
360    indices=find(strcmp(ListSub,ListFiles));
361else
362    indices=[];
363    for ilist=1:numel(ListSub)
364        index=find(strcmp(ListSub{ilist},ListFiles));
365        indices=[indices index];
366    end
367end
368if isempty(indices), indices=1; end
369
370%------------------------------------------------------------------------
371% Provide a list to display
372%------------------------------------------------------------------------
373function [ListFilesTot,indices]=list_dir_2(SourceDir,ListDir,ListSub,check_fix)
374ListFilesTot={};
375for ilist=1:numel(ListDir)
376    if ~isempty(regexp(ListDir{ilist},'^\+/'))
377    ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
378    ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist})); %list files and dirs, extende to OpenDAP case
379    ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
380    ListFiles=ListCells(1,:);
381    index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
382    check_dir=cell2mat(ListCells(index_isdir,:));% =1 for directories, =0 for files
383    ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
384    cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
385    check_keep=cellfun('isempty', cell_remove);
386    ListFilesTot=[ListFilesTot (ListFiles(check_keep))];
387    end
388end
389ListFilesTot=unique(ListFilesTot);
390if ischar(ListSub)
391    indices=find(strcmp(ListSub,ListFilesTot));
392else
393    indices=[];
394    for ilist=1:numel(ListSub)
395        index=find(strcmp(ListSub{ilist},ListFilesTot));
396        indices=[indices index];
397    end
398    if check_fix
399        index_init=1:numel(ListFilesTot);
400        %indices=sort(indices)
401        index_init(indices)=[];
402       ListFilesTot=ListFilesTot([indices index_init]);
403       indices=1:numel(indices);
404    end     
405end
406if isempty(indices), indices=1; end
407
408
409%------------------------------------------------------------------------
410% Provide the list (ListFilesTot) to display in DataSeries with the selected indices
411%------------------------------------------------------------------------
412function [ListFilesTot,indices]=list_dir_3(SourceDir,ListDir,ListSub,ListSubSub,check_fix)
413% INPUT:
414%SourceDir: path to the displayed directories
415%ListDir: list of file and folder names under SourceDir (column 'Experiments')
416%ListSub: list of file and folder in the second column 'Devices')
417%ListSubSub: prvious list of file and folder in the third column 'DataSeries', used to mark the selected indices
418ListFilesTot={};
419for ilist=1:numel(ListDir)
420    if ~isempty(regexp(ListDir{ilist},'^\+/'))
421        ListDir{ilist}=regexprep(ListDir{ilist},'^\+/','');
422        for isub=1:numel(ListSub)
423            if ~isempty(regexp(ListSub{isub},'^\+/'))
424                ListSub{isub}=regexprep(ListSub{isub},'^\+/','');
425                ListStruct=dir_uvmat(fullfile(SourceDir,ListDir{ilist},ListSub{isub})); %list files and dirs, extende to OpenDAP case
426                ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray
427                ListFiles=ListCells(1,:);
428                check_xml=~cellfun('isempty',regexp(ListFiles,'\.xml$'));% detect  xml files
429                check_tild=~cellfun('isempty',regexp(ListFiles,'~$'));% detect  ~  files
430                index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
431                check_dir=cell2mat(ListCells(index_isdir,:));% =1 for directories, =0 for files
432                nbfiles=numel(find(~check_xml & ~check_dir & ~check_tild));% number of non xml files
433                check_dir=check_dir & cellfun('isempty', regexp(ListFiles,'^(-|\.|\+/\.)'));% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
434                ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display
435                %cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )         
436                ListFiles=ListFiles(check_dir | check_xml);           
437                ListFilesTot=[ListFilesTot ListFiles];
438                if nbfiles>0
439                    ListFilesTot=[ListFilesTot {[num2str(nbfiles) ' files']}];
440                end
441            end
442        end
443    end
444end
445ListFilesTot=unique(ListFilesTot);
446if ischar(ListSubSub)
447    indices=find(strcmp(ListSubSub,ListFilesTot));
448else
449    indices=[];
450    for ilist=1:numel(ListSubSub)
451        index=find(strcmp(ListSubSub{ilist},ListFilesTot));
452        if check_fix && isempty(index)
453            ListFilesTot=[ListFilesTot {['---' ListSubSub{ilist}]}];
454            index=numel(ListFilesTot);
455        end
456        indices=[indices index];
457    end
458    if check_fix
459        index_init=1:numel(ListFilesTot);
460        index_init(indices)=[];
461       ListFilesTot=ListFilesTot([indices index_init]);
462       indices=1:numel(indices);
463    end     
464end
465if isempty(indices), indices=1; end
466
467
468%------------------------------------------------------------------------
469% --- Executes when the mirror is created or updated
470%------------------------------------------------------------------------
471function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
472
473DataSeries={};
474for iexp=1:numel(ListExperiments)
475    if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
476        ListExperiments{iexp}(1)=[];
477        ListStruct=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
478        ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
479        ListFiles=ListCells(1,:);%list of dir and file  names
480        cell_remove=regexp(ListFiles,'^((-|\.|\+/\.))');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
481        check_keep=cellfun('isempty', cell_remove);
482        index_isdir=find(strcmp('isdir',fieldnames(ListStruct)));
483        check_dir=cell2mat(ListCells(index_isdir,:));% =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);%transfer list of devices to DataSeries
725set(handles.DataSeries,'Value',DeviceIndices);
726
727ListExperiments=get(handles.ListExperiments,'String');
728ExpIndices=get(handles.ListExperiments,'Value');
729set(handles.ListDevices,'String',ListExperiments);%transfer list of experiments to devices
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)
743ListExperiments_Callback(hObject, [], handles)
744SourceDir_Callback(hObject, [], handles)
745
746
747% --- Executes when user attempts to close browse_data.
748function browse_data_CloseRequestFcn(hObject, eventdata, handles)
749% hObject    handle to browse_data (see GCBO)
750% eventdata  reserved - to be defined in a future version of MATLAB
751% handles    structure with handles and user data (see GUIDATA)
752
753% Hint: delete(hObject) closes the figure
754delete(hObject);
Note: See TracBrowser for help on using the repository browser.