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-2016, 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 | |
---|
24 | function varargout = browse_data(varargin) |
---|
25 | |
---|
26 | % Last Modified by GUIDE v2.5 24-Jan-2015 16:55:04 |
---|
27 | |
---|
28 | % Begin initialization code - DO NOT EDIT |
---|
29 | gui_Singleton = 1; |
---|
30 | gui_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', []); |
---|
36 | if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
37 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
38 | end |
---|
39 | |
---|
40 | if nargout |
---|
41 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
42 | else |
---|
43 | gui_mainfcn(gui_State, varargin{:}); |
---|
44 | end |
---|
45 | % End initialization code - DO NOT EDIT |
---|
46 | |
---|
47 | %------------------------------------------------------------------------ |
---|
48 | % --- Executes just before browse_data is made visible. |
---|
49 | function browse_data_OpeningFcn(hObject, eventdata, handles, DataSeries,EnableMirror) |
---|
50 | %------------------------------------------------------------------------ |
---|
51 | |
---|
52 | %% Choose default command line output for browse_data |
---|
53 | handles.output = 'Cancel'; |
---|
54 | |
---|
55 | %% Update handles structure |
---|
56 | guidata(hObject, handles); |
---|
57 | set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display) |
---|
58 | |
---|
59 | %% Determine the position of the dialog - centered on the screen |
---|
60 | FigPos=get(0,'DefaultFigurePosition'); |
---|
61 | OldUnits = get(hObject, 'Units'); |
---|
62 | set(hObject, 'Units', 'pixels'); |
---|
63 | OldPos = get(hObject,'Position'); |
---|
64 | FigWidth = OldPos(3); |
---|
65 | FigHeight = OldPos(4); |
---|
66 | ScreenUnits=get(0,'Units'); |
---|
67 | set(0,'Units','pixels'); |
---|
68 | ScreenSize=get(0,'ScreenSize'); |
---|
69 | set(0,'Units',ScreenUnits); |
---|
70 | FigPos(1)=1/2*(ScreenSize(3)-FigWidth); |
---|
71 | FigPos(2)=2/3*(ScreenSize(4)-FigHeight); |
---|
72 | FigPos(3:4)=[FigWidth FigHeight]; |
---|
73 | set(hObject, 'Position', FigPos); |
---|
74 | set(hObject, 'Units', OldUnits); |
---|
75 | if exist('EnableMirror','var') && strcmp(EnableMirror,'on') |
---|
76 | set(handles.CreateMirror,'Visible','on') |
---|
77 | set(handles.mirror_txt,'Visible','on') |
---|
78 | else |
---|
79 | set(handles.CreateMirror,'Visible','off') |
---|
80 | set(handles.mirror_txt,'Visible','off') |
---|
81 | end |
---|
82 | |
---|
83 | %% initialize the GUI |
---|
84 | if ~(exist('DataSeries','var') && exist(DataSeries,'dir')) |
---|
85 | DataSeries=pwd;% current dir is the starting data series by default |
---|
86 | end |
---|
87 | [Experiment,DataSeries,Ext]=fileparts(DataSeries); |
---|
88 | DataSeries=[DataSeries Ext]; |
---|
89 | [Campaign,Experiment,Ext]=fileparts(Experiment); |
---|
90 | Experiment=[Experiment Ext]; |
---|
91 | [tild,CampaignName]=fileparts(Campaign); |
---|
92 | RootXml=fullfile(Campaign,[CampaignName '.xml']); |
---|
93 | s=[]; |
---|
94 | if exist(RootXml,'file') |
---|
95 | [s,Heading]=xml2struct(RootXml);%read the xml file |
---|
96 | if isfield(s,'SourceDir') |
---|
97 | set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened |
---|
98 | set(handles.MirrorDir,'Visible','on');% mirror dir display |
---|
99 | set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir |
---|
100 | set(handles.CreateMirror,'String','update_mirror') |
---|
101 | end |
---|
102 | end |
---|
103 | if isempty(s) %a source dir has been opened |
---|
104 | set(handles.SourceDir,'String',Campaign); |
---|
105 | set(handles.MirrorDir,'Visible','off');% no mirror dir display |
---|
106 | set(handles.CreateMirror,'String','create_mirror') |
---|
107 | end |
---|
108 | errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries); |
---|
109 | if ~isempty(errormsg) |
---|
110 | msgbox_uvmat('ERROR',errormsg) |
---|
111 | return |
---|
112 | end |
---|
113 | set(handles.OK,'Visible','on') |
---|
114 | set(handles.Cancel,'Visible','on') |
---|
115 | |
---|
116 | set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal |
---|
117 | set(hObject,'Visible','on') |
---|
118 | drawnow |
---|
119 | % UIWAIT makes GUI wait for user response (see UIRESUME) |
---|
120 | uiwait(handles.browse_data); |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | %------------------------------------------------------------------------ |
---|
125 | % --- Outputs from this function are returned to the command line. |
---|
126 | function varargout = browse_data_OutputFcn(hObject, eventdata, handles) |
---|
127 | %------------------------------------------------------------------------ |
---|
128 | % Get default command line output from handles structure |
---|
129 | varargout{1} = handles.output; |
---|
130 | delete(handles.browse_data) |
---|
131 | |
---|
132 | %------------------------------------------------------------------------ |
---|
133 | % --- Executes on button press in CreateMirror. |
---|
134 | function CreateMirror_Callback(hObject, eventdata, handles) |
---|
135 | %------------------------------------------------------------------------ |
---|
136 | set(handles.SourceDir,'BackgroundColor',[1 1 0])% indicate action of button by yellow color |
---|
137 | drawnow |
---|
138 | SourceDir=get(handles.SourceDir,'String'); |
---|
139 | [SourcePath,ProjectName]=fileparts(SourceDir); |
---|
140 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
141 | MirrorDir=get(handles.MirrorDir,'String');% name of the mirror folder |
---|
142 | else% create the mirror folder if it does not exist |
---|
143 | MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir'); |
---|
144 | if isempty(MirrorRoot) |
---|
145 | return |
---|
146 | elseif strcmp(MirrorRoot,SourcePath) |
---|
147 | msgbox_uvmat('ERROR','The mirror folder must be different from the source') |
---|
148 | return |
---|
149 | else |
---|
150 | MirrorDir=fullfile(MirrorRoot,ProjectName); |
---|
151 | end |
---|
152 | if exist(MirrorDir,'dir') |
---|
153 | msgbox_uvmat('ERROR',['The folder ' MirrorDir ' chosen as new mirror campaign already exists']) |
---|
154 | return |
---|
155 | else |
---|
156 | [s,errormsg]=mkdir(MirrorDir)% create the mirror dir |
---|
157 | if s~=1 |
---|
158 | msgbox_uvmat('ERROR',['error in creating ' MirrorDir ': ' errormsg]) |
---|
159 | return |
---|
160 | end |
---|
161 | end |
---|
162 | MirrorDoc.SourceDir=SourceDir; |
---|
163 | t=struct2xml(MirrorDoc); |
---|
164 | set(t,1,'name','DataTree'); |
---|
165 | save(t,fullfile(MirrorDir,[ProjectName '.xml']))% create an xml file in the mirror folder to indicate its source folder |
---|
166 | set(handles.MirrorDir,'String',MirrorDir) |
---|
167 | set(handles.MirrorDir,'Visible','on') |
---|
168 | set(handles.CreateMirror,'String','update_mirror') |
---|
169 | end |
---|
170 | ExpName={''}; |
---|
171 | |
---|
172 | %% update the mirror from the source dir |
---|
173 | if exist(SourceDir,'dir') |
---|
174 | hdir=dir(SourceDir); %list files and dirs |
---|
175 | idir=0; |
---|
176 | for ilist=1:length(hdir) |
---|
177 | if hdir(ilist).isdir% scan all subfolders |
---|
178 | dirname=hdir(ilist).name;% |
---|
179 | if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')%skip subfolder beginning by '0' |
---|
180 | idir=idir+1; |
---|
181 | mirror=fullfile(MirrorDir,hdir(ilist).name);% corresponding name in the mirror |
---|
182 | if ~exist(mirror,'dir') |
---|
183 | mkdir(mirror)% create the mirror folder if it does not exist |
---|
184 | end |
---|
185 | ExpName{idir}=['+/' hdir(ilist).name];% insert '+/' in the list to show that it is a folder |
---|
186 | end |
---|
187 | % look for the list of 'devices' |
---|
188 | else |
---|
189 | %warning for isolated files |
---|
190 | end |
---|
191 | end |
---|
192 | set(handles.ListExperiments,'String',[{'*'};ExpName']) |
---|
193 | set(handles.ListExperiments,'Value',1) |
---|
194 | update_experiments(handles,[{'*'};ExpName'],SourceDir,MirrorDir) |
---|
195 | % ListExperiments_Callback(hObject, eventdata, handles) % list the content of the experiment |
---|
196 | else |
---|
197 | msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory']) |
---|
198 | end |
---|
199 | set(handles.SourceDir,'BackgroundColor',[1 1 1]) |
---|
200 | |
---|
201 | %------------------------------------------------------------------------ |
---|
202 | % List the experiments in a campaign, filling the menu ListExperiments |
---|
203 | %------------------------------------------------------------------------ |
---|
204 | function errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries) |
---|
205 | %------------------------------------------------------------------------ |
---|
206 | errormsg=''; |
---|
207 | if exist(Campaign,'dir') |
---|
208 | ListStruct=dir(Campaign); %list files and dirs |
---|
209 | if numel(ListStruct)>1000% A campaign folder must contain maily a list of 'experiment' sub-folders |
---|
210 | errormsg=[Campaign ' contains too many items (>1000) to be a Campaign folder']; |
---|
211 | return |
---|
212 | end |
---|
213 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
---|
214 | ListFiles=ListCells(1,:);%list of dir and file names |
---|
215 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files |
---|
216 | ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display |
---|
217 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
218 | check_keep=cellfun('isempty', cell_remove); |
---|
219 | ListFiles=sort((ListFiles(check_keep))'); |
---|
220 | index=find(strcmp(['+/' Experiment],ListFiles)); |
---|
221 | if isempty(index), index=0; end |
---|
222 | set(handles.ListExperiments,'String',[{'*'};ListFiles]) |
---|
223 | set(handles.ListExperiments,'Value',index+1)% initialise the menu selection with the folder defined by the input |
---|
224 | ListExperiments_Callback([],[], handles) |
---|
225 | ListDevices=get(handles.ListDevices,'String'); |
---|
226 | index=find(strcmp(['+/' DataSeries],ListDevices)); |
---|
227 | if isempty(index) |
---|
228 | index=find(strcmp(['~/' DataSeries],ListDevices)); |
---|
229 | end |
---|
230 | if ~isempty(index) |
---|
231 | set(handles.ListDevices,'Value',index) |
---|
232 | end |
---|
233 | else |
---|
234 | msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory']) |
---|
235 | end |
---|
236 | |
---|
237 | %------------------------------------------------------------------------ |
---|
238 | % --- Executes on selection change in ListExperiments. |
---|
239 | %------------------------------------------------------------------------ |
---|
240 | function ListExperiments_Callback(hObject, eventdata, handles) |
---|
241 | |
---|
242 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
243 | MirrorPath=get(handles.MirrorDir,'String'); |
---|
244 | else |
---|
245 | MirrorPath=get(handles.SourceDir,'String'); |
---|
246 | end |
---|
247 | ListExperiments=get(handles.ListExperiments,'String'); |
---|
248 | list_val=get(handles.ListExperiments,'Value'); |
---|
249 | if isequal(list_val(1),1) |
---|
250 | ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' is selected |
---|
251 | set(handles.ListExperiments,'Value',1) |
---|
252 | else |
---|
253 | ListExperiments=ListExperiments(list_val);%choose selected experiments |
---|
254 | end |
---|
255 | list_dataseries(handles,ListExperiments,MirrorPath) |
---|
256 | |
---|
257 | %------------------------------------------------------------------------ |
---|
258 | % --- List the DataSeries when a set of experiments is selected |
---|
259 | %------------------------------------------------------------------------ |
---|
260 | function list_dataseries(handles,ListExperiments,MirrorPath) |
---|
261 | |
---|
262 | ListDevices={}; |
---|
263 | for iexp=1:numel(ListExperiments) |
---|
264 | if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory |
---|
265 | ListExperiments{iexp}(1)=[];%remove the first char '+' used to mark folders |
---|
266 | ListStruct=dir(fullfile(MirrorPath,ListExperiments{iexp})); %list files and dir in the source experiment directory |
---|
267 | ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray |
---|
268 | ListFiles=ListCells(1,:);%list of dir and file names |
---|
269 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
270 | check_keep=cellfun('isempty', cell_remove); |
---|
271 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files |
---|
272 | for ilist=1:numel(ListFiles) |
---|
273 | if check_keep(ilist)% loop on eligible DataSeries folders |
---|
274 | mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});%source folder |
---|
275 | if ~exist(mirror,'file') && ~exist(mirror,'dir')% if the name is a broken link |
---|
276 | delete(mirror)% delete broken link |
---|
277 | else %update the list of dataSeries |
---|
278 | [tild,msg]=fileattrib(mirror); |
---|
279 | if ~strcmp(msg.Name,mirror)% if it is a link |
---|
280 | ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list |
---|
281 | end |
---|
282 | if check_dir(ilist) |
---|
283 | ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list |
---|
284 | end |
---|
285 | if isempty(find(strcmp(ListFiles{ilist},ListDevices), 1))% if the item is not already in ListDevices |
---|
286 | ListDevices=[ListDevices;ListFiles{ilist}]; %append the item to the list |
---|
287 | end |
---|
288 | end |
---|
289 | end |
---|
290 | end |
---|
291 | end |
---|
292 | end |
---|
293 | set(handles.ListDevices,'String',sort(ListDevices)) |
---|
294 | |
---|
295 | %------------------------------------------------------------------------ |
---|
296 | % --- Executes when the mirror is created or updated |
---|
297 | %------------------------------------------------------------------------ |
---|
298 | function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath) |
---|
299 | |
---|
300 | ListDevices={}; |
---|
301 | for iexp=1:numel(ListExperiments) |
---|
302 | if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory |
---|
303 | ListExperiments{iexp}(1)=[]; |
---|
304 | ListStruct=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the source experiment directory |
---|
305 | ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray |
---|
306 | ListFiles=ListCells(1,:);%list of dir and file names |
---|
307 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
308 | check_keep=cellfun('isempty', cell_remove); |
---|
309 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files |
---|
310 | for ilist=1:numel(ListFiles) |
---|
311 | if check_keep(ilist)% loop on eligible DataSeries folders |
---|
312 | DataSeries=fullfile(CampaignPath,ListExperiments{iexp},ListFiles{ilist});%source folder |
---|
313 | if ~isempty(MirrorPath) |
---|
314 | mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist}); |
---|
315 | if exist(mirror,'file')% if mirror already exists as a file or folder |
---|
316 | [tild,msg]=fileattrib(mirror); |
---|
317 | if strcmp(msg.Name,mirror)%if the mirror name already exists as a local file or dir |
---|
318 | if msg.directory% case of a folder |
---|
319 | answer=msgbox_uvmat('INPUT_Y-N',['replace local folder ' msg.Name ' by a link to the source dir']); |
---|
320 | if strcmp(answer,'Yes') |
---|
321 | [ss,msg]=rmdir(mirror); |
---|
322 | if ss==1 |
---|
323 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
324 | else |
---|
325 | msgbox_uvmat('ERROR',['enable to delete local folder: ' msg]); |
---|
326 | end |
---|
327 | end |
---|
328 | else % case of an existing mirror file |
---|
329 | answer=msgbox_uvmat('INPUT_Y-N',['replace local file ' msg.Name ' by a link to the source file']); |
---|
330 | if strcmp(answer,'Yes') |
---|
331 | delete(mirror); |
---|
332 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
333 | end |
---|
334 | end |
---|
335 | end |
---|
336 | else% create mirror to the data series if needed |
---|
337 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
338 | end |
---|
339 | if isempty(find(strcmp(ListFiles{ilist},ListDevices), 1))% if the item is not already in ListDevices |
---|
340 | if check_dir(ilist) |
---|
341 | ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list |
---|
342 | end |
---|
343 | ListDevices=[ListDevices;ListFiles{ilist}]; %append the item to the list |
---|
344 | end |
---|
345 | end |
---|
346 | end |
---|
347 | end |
---|
348 | end |
---|
349 | end |
---|
350 | set(handles.ListDevices,'String',sort(ListDevices)) |
---|
351 | |
---|
352 | %------------------------------------------------------------------------ |
---|
353 | % --- Executes on button press in CampaignDoc. |
---|
354 | function CampaignDoc_Callback(hObject, eventdata, handles) |
---|
355 | %------------------------------------------------------------------------ |
---|
356 | 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'); |
---|
357 | if ~isequal(answer{1},'OK') |
---|
358 | return |
---|
359 | end |
---|
360 | set(handles.ListExperiments,'Value',1) |
---|
361 | ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories |
---|
362 | DataviewData=get(handles.browse_data,'UserData'); |
---|
363 | List=DataviewData.List; |
---|
364 | Currentpath=get(handles.SourceDir,'String'); |
---|
365 | [Currentpath,Campaign,DirExt]=fileparts(Currentpath); |
---|
366 | Campaign=[Campaign DirExt]; |
---|
367 | t=xmltree; |
---|
368 | t=set(t,1,'name','CampaignDoc'); |
---|
369 | t = attributes(t,'add',1,'source','directory'); |
---|
370 | SubCampaignTest=get(handles.SubCampaignTest,'Value'); |
---|
371 | root_uid=1; |
---|
372 | if SubCampaignTest |
---|
373 | %TO DO open an exoiting xml doc |
---|
374 | [t,root_uid]=add(t,1,'element','SubCampaign'); |
---|
375 | t =attributes(t,'add',root_uid,'DirName',Campaign); |
---|
376 | end |
---|
377 | for iexp=1:length(List.Experiment) |
---|
378 | set(handles.ListExperiments,'Value',iexp+1) |
---|
379 | drawnow |
---|
380 | test_mod=0; |
---|
381 | [t,uid_exp]=add(t,root_uid,'element','Experiment'); |
---|
382 | t = attributes(t,'add',uid_exp,'i',num2str(iexp)); |
---|
383 | ExpName=List.Experiment{iexp}.name; |
---|
384 | t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name); |
---|
385 | |
---|
386 | if isfield(List.Experiment{iexp},'Device') |
---|
387 | for idevice=1:length(List.Experiment{iexp}.Device) |
---|
388 | [t,uid_device]=add(t,uid_exp,'element','Device'); |
---|
389 | DeviceName=List.Experiment{iexp}.Device{idevice}.name; |
---|
390 | t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name); |
---|
391 | if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile') |
---|
392 | for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile) |
---|
393 | FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}; |
---|
394 | [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest); |
---|
395 | if test |
---|
396 | disp([List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']) |
---|
397 | end |
---|
398 | if isequal(Title,'ImaDoc') |
---|
399 | [t,uid_xml]=add(t,uid_device,'element','ImaDoc'); |
---|
400 | t = attributes(t,'add',uid_xml,'source','file'); |
---|
401 | [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}); |
---|
402 | end |
---|
403 | end |
---|
404 | elseif isfield(List.Experiment{iexp}.Device{idevice},'Record') |
---|
405 | for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record) |
---|
406 | RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name; |
---|
407 | [t,uid_record]=add(t,uid_device,'element','Record'); |
---|
408 | t = attributes(t,'add',uid_record,'DirName',RecordName); |
---|
409 | if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile') |
---|
410 | for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile) |
---|
411 | FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}; |
---|
412 | [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest); |
---|
413 | if test |
---|
414 | disp([FileName ' , Heading updated']) |
---|
415 | end |
---|
416 | [t,uid_xml]=add(t,uid_record,'element','ImaDoc'); |
---|
417 | t = attributes(t,'add',uid_xml,'source','file'); |
---|
418 | [t]=add(t,uid_xml,'chardata',FileName); |
---|
419 | end |
---|
420 | end |
---|
421 | end |
---|
422 | end |
---|
423 | end |
---|
424 | end |
---|
425 | end |
---|
426 | set(handles.ListExperiments,'Value',1) |
---|
427 | outputdir=get(handles.SourceDir,'String'); |
---|
428 | [path,dirname]=fileparts(outputdir); |
---|
429 | outputfile=fullfile(outputdir,[dirname '.xml']); |
---|
430 | %campaigndoc(t); |
---|
431 | save(t,outputfile) |
---|
432 | |
---|
433 | % %------------------------------------------------------------------------ |
---|
434 | % % --- Executes on button press in CampaignDoc. |
---|
435 | % function edit_xml_Callback(hObject, eventdata, handles) |
---|
436 | % %------------------------------------------------------------------------ |
---|
437 | % CurrentPath=get(handles.SourceDir,'String'); |
---|
438 | % %[CurrentPath,Name,Ext]=fileparts(CurrentDir); |
---|
439 | % ListExperiments=get(handles.ListExperiments,'String'); |
---|
440 | % Value=get(handles.ListExperiments,'Value'); |
---|
441 | % if ~isequal(Value,1) |
---|
442 | % ListExperiments=ListExperiments(Value); |
---|
443 | % end |
---|
444 | % ListDevices=get(handles.ListDevices,'String'); |
---|
445 | % Value=get(handles.ListDevices,'Value'); |
---|
446 | % if ~isequal(Value,1) |
---|
447 | % ListDevices=ListDevices(Value); |
---|
448 | % end |
---|
449 | % ListRecords=get(handles.ListRecords,'String'); |
---|
450 | % Value=get(handles.ListRecords,'Value'); |
---|
451 | % if ~isequal(Value,1) |
---|
452 | % ListRecords=ListRecords(Value); |
---|
453 | % end |
---|
454 | % [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords); |
---|
455 | % ListXml=get(handles.ListXml,'String'); |
---|
456 | % Value=get(handles.ListXml,'Value'); |
---|
457 | % set(handles.ListXml,'Value',Value(1)); |
---|
458 | % if isequal(Value(1),1) |
---|
459 | % msgbox_uvmat('ERROR','an xml file needs to be selected') |
---|
460 | % return |
---|
461 | % else |
---|
462 | % XmlName=ListXml{Value(1)}; |
---|
463 | % end |
---|
464 | % for iexp=1:length(List.Experiment) |
---|
465 | % ExpName=List.Experiment{iexp}.name; |
---|
466 | % if isfield(List.Experiment{iexp},'Device') |
---|
467 | % for idevice=1:length(List.Experiment{iexp}.Device) |
---|
468 | % DeviceName=List.Experiment{iexp}.Device{idevice}.name; |
---|
469 | % if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile') |
---|
470 | % for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile) |
---|
471 | % FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}; |
---|
472 | % if isequal(FileName,XmlName) |
---|
473 | % editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName)); |
---|
474 | % return |
---|
475 | % end |
---|
476 | % end |
---|
477 | % elseif isfield(List.Experiment{iexp}.Device{idevice},'Record') |
---|
478 | % for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record) |
---|
479 | % RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name; |
---|
480 | % if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile') |
---|
481 | % for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile) |
---|
482 | % FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}; |
---|
483 | % if isequal(FileName,XmlName) |
---|
484 | % editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName)); |
---|
485 | % return |
---|
486 | % end |
---|
487 | % end |
---|
488 | % end |
---|
489 | % end |
---|
490 | % end |
---|
491 | % end |
---|
492 | % end |
---|
493 | % end |
---|
494 | % |
---|
495 | % |
---|
496 | % |
---|
497 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
498 | % % CurrentPath/Campaign: root directory |
---|
499 | % function [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign) |
---|
500 | % |
---|
501 | % %Shema for Heading: |
---|
502 | % % Campaign |
---|
503 | % % (SubCampaign) |
---|
504 | % % Experiment |
---|
505 | % % Device |
---|
506 | % % (Record) |
---|
507 | % % ImageName |
---|
508 | % % DateExp |
---|
509 | % % old: %Project: suppressed ( changed to Campaign) |
---|
510 | % %Exp: suppressed (changed to experiment) |
---|
511 | % %ImaNames: changed to ImageName |
---|
512 | % if exist('Record','var') && ~isempty(Record) |
---|
513 | % xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname); |
---|
514 | % testrecord=1; |
---|
515 | % else |
---|
516 | % xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname); |
---|
517 | % testrecord=0; |
---|
518 | % end |
---|
519 | % if ~exist('testSubCampaign','var') |
---|
520 | % testSubCampaign=0; |
---|
521 | % end |
---|
522 | % if testSubCampaign |
---|
523 | % SubCampaign=Campaign; |
---|
524 | % [Currentpath,Campaign,DirExt]=fileparts(Currentpath); |
---|
525 | % Campaign=[Campaign DirExt]; |
---|
526 | % end |
---|
527 | % test_mod=0; %test for the modification of the xml file |
---|
528 | % t_device=xmltree(xmlfullname); |
---|
529 | % Title=get(t_device,1,'name'); |
---|
530 | % uid_child=children(t_device,1); |
---|
531 | % Heading_old=[]; |
---|
532 | % uidheading=0; |
---|
533 | % for ilist=1:length(uid_child) |
---|
534 | % name=get(t_device,uid_child(ilist),'name'); |
---|
535 | % if isequal(name,'Heading') |
---|
536 | % uidheading=uid_child(ilist); |
---|
537 | % end |
---|
538 | % end |
---|
539 | % if uidheading |
---|
540 | % subt=branch(t_device,uidheading); |
---|
541 | % Heading_old=convert(subt); |
---|
542 | % else |
---|
543 | % return % do not edit xml files without element 'Heading' |
---|
544 | % end |
---|
545 | % if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign)) |
---|
546 | % test_mod=1; |
---|
547 | % end |
---|
548 | % Heading.Campaign=Campaign; |
---|
549 | % if testSubCampaign |
---|
550 | % if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign)) |
---|
551 | % test_mod=1; |
---|
552 | % end |
---|
553 | % Heading.SubCampaign=SubCampaign; |
---|
554 | % end |
---|
555 | % if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment)) |
---|
556 | % test_mod=1; |
---|
557 | % end |
---|
558 | % Heading.Experiment=Experiment; |
---|
559 | % if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device)) |
---|
560 | % test_mod=1; |
---|
561 | % end |
---|
562 | % Heading.Device=Device; |
---|
563 | % if testrecord |
---|
564 | % if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record)) |
---|
565 | % test_mod=1; |
---|
566 | % end |
---|
567 | % Heading.Record=Record; |
---|
568 | % end |
---|
569 | % if isfield(Heading_old,'ImaNames') |
---|
570 | % test_mod=1; |
---|
571 | % if ~isempty(Heading_old.ImaNames) |
---|
572 | % Heading.ImageName=Heading_old.ImaNames; |
---|
573 | % end |
---|
574 | % end |
---|
575 | % if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName) |
---|
576 | % Heading.ImageName=Heading_old.ImageName; |
---|
577 | % end |
---|
578 | % if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp) |
---|
579 | % Heading.DateExp=Heading_old.DateExp; |
---|
580 | % end |
---|
581 | % if test_mod && uidheading |
---|
582 | % uid_child=children(t_device,uidheading); |
---|
583 | % t_device=delete(t_device,uid_child); |
---|
584 | % t_device=struct2xml(Heading,t_device,uidheading); |
---|
585 | % backupfile=xmlfullname; |
---|
586 | % testexist=2; |
---|
587 | % while testexist==2 |
---|
588 | % backupfile=[backupfile '~']; |
---|
589 | % testexist=exist(backupfile,'file'); |
---|
590 | % end |
---|
591 | % [success,message]=copyfile(xmlfullname,backupfile);%make backup |
---|
592 | % if isequal(success,1) |
---|
593 | % delete(xmlfullname) |
---|
594 | % else |
---|
595 | % return |
---|
596 | % end |
---|
597 | % save(t_device,xmlfullname) |
---|
598 | % end |
---|
599 | |
---|
600 | %------------------------------------------------------------------------ |
---|
601 | % --- Executes on button press in OK. |
---|
602 | %------------------------------------------------------------------------ |
---|
603 | function OK_Callback(hObject, eventdata, handles) |
---|
604 | |
---|
605 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
606 | Campaign=get(handles.MirrorDir,'String'); |
---|
607 | else |
---|
608 | Campaign=get(handles.SourceDir,'String'); |
---|
609 | end |
---|
610 | handles.output.Campaign=Campaign; |
---|
611 | Experiment=get(handles.ListExperiments,'String'); |
---|
612 | IndicesExp=get(handles.ListExperiments,'Value'); |
---|
613 | if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected |
---|
614 | Experiment=Experiment(IndicesExp);% use the selection of the list of experiments |
---|
615 | end |
---|
616 | Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir |
---|
617 | Device=get(handles.ListDevices,'String'); |
---|
618 | Value=get(handles.ListDevices,'Value'); |
---|
619 | Device=Device(Value); |
---|
620 | Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir |
---|
621 | Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link |
---|
622 | handles.output.Experiment=Experiment; |
---|
623 | handles.output.DataSeries=Device; |
---|
624 | guidata(hObject, handles);% Update handles structure |
---|
625 | uiresume(handles.browse_data); |
---|
626 | drawnow |
---|
627 | |
---|
628 | %------------------------------------------------------------------------ |
---|
629 | % --- Executes on button press in HELP. |
---|
630 | function HELP_Callback(hObject, eventdata, handles) |
---|
631 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
632 | pathelp=fileparts(path_to_uvmat); |
---|
633 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
634 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
635 | else |
---|
636 | web([helpfile '#dataview']) |
---|
637 | end |
---|
638 | |
---|
639 | %------------------------------------------------------------------------ |
---|
640 | % --- Executes on button press in Cancel. |
---|
641 | %------------------------------------------------------------------------ |
---|
642 | function Cancel_Callback(hObject, eventdata, handles) |
---|
643 | |
---|
644 | handles.output = get(hObject,'String'); |
---|
645 | guidata(hObject, handles); % Update handles structure |
---|
646 | % Use UIRESUME instead of delete because the OutputFcn needs |
---|
647 | uiresume(handles.browse_data); |
---|
648 | |
---|
649 | %------------------------------------------------------------------------ |
---|
650 | % --- Executes when user attempts to close browse_data. |
---|
651 | %------------------------------------------------------------------------ |
---|
652 | function browse_data_CloseRequestFcn(hObject, eventdata, handles) |
---|
653 | if isequal(get(handles.browse_data, 'waitstatus'), 'waiting') |
---|
654 | % The GUI is still in UIWAIT, us UIRESUME |
---|
655 | handles.output = get(hObject,'String'); |
---|
656 | guidata(hObject, handles); % Update handles structure |
---|
657 | uiresume(handles.browse_data); |
---|
658 | else |
---|
659 | % The GUI is no longer waiting, just close it |
---|
660 | delete(handles.browse_data); |
---|
661 | end |
---|
662 | |
---|
663 | %------------------------------------------------------------------------ |
---|
664 | % --- Executes on key press over figure1 with no controls selected. |
---|
665 | %------------------------------------------------------------------------ |
---|
666 | function browse_data_KeyPressFcn(hObject, eventdata, handles) |
---|
667 | |
---|
668 | % Check for "enter" or "escape" |
---|
669 | if isequal(get(hObject,'CurrentKey'),'escape') |
---|
670 | % User said no by hitting escape |
---|
671 | handles.output = 'Cancel'; |
---|
672 | |
---|
673 | % Update handles structure |
---|
674 | guidata(hObject, handles); |
---|
675 | |
---|
676 | uiresume(handles.browse_data); |
---|
677 | end |
---|
678 | if isequal(get(hObject,'CurrentKey'),'return') |
---|
679 | uiresume(handles.browse_data); |
---|
680 | end |
---|
681 | |
---|
682 | |
---|
683 | % --- Executes on button press in Browse. |
---|
684 | function Browse_Callback(hObject, eventdata, handles) |
---|
685 | ListDevices=get(handles.ListDevices,'String'); |
---|
686 | Device=ListDevices{get(handles.ListDevices,'Value')}; |
---|
687 | DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir'); |
---|
688 | uiresume(handles.browse_data); |
---|
689 | browse_data(DataSeries) |
---|