source: trunk/src/browse_data.m @ 733

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

various improvements

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