source: trunk/src/browse_data.m @ 833

Last change on this file since 833 was 827, checked in by sommeria, 9 years ago

REPLICATE mode in geometry_calib improved in terms of user interface

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