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