source: trunk/src/browse_data.m @ 1065

Last change on this file since 1065 was 1064, checked in by sommeria, 6 years ago

calibration repaired

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