source: trunk/src/browse_data.m @ 743

Last change on this file since 743 was 741, checked in by sommeria, 11 years ago

bugs corrected in browse_data and mouse_motion (z display)

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