source: trunk/src/browse_data.m @ 822

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