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