source: trunk/src/browse_data.m @ 844

Last change on this file since 844 was 837, checked in by sommeria, 10 years ago

bugs corrected in uvmat: object deletion.
set_slices improved.

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