source: trunk/src/browse_data.m @ 985

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