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