source: trunk/src/browse_data.m @ 932

Last change on this file since 932 was 931, checked in by sommeria, 5 years ago

various

File size: 29.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-2016, 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') && 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        check_keep=cellfun('isempty', cell_remove);
276        check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
277        for ilist=1:numel(ListFiles)
278            if check_keep(ilist)% loop on eligible DataSeries folders
279                mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});%source folder
280                if ~exist(mirror,'file') && ~exist(mirror,'dir')% if the name is a broken link
281                    delete(mirror)% delete broken link
282                else %update the list of dataSeries
283                    [tild,msg]=fileattrib(mirror);
284                    if ~strcmp(msg.Name,mirror)% if it is a link
285                        ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list
286                    end
287                    if check_dir(ilist)
288                        ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
289                    end
290                    if isempty(find(strcmp(ListFiles{ilist},ListDevices), 1))% if the item is not already in ListDevices
291                        ListDevices=[ListDevices;ListFiles{ilist}]; %append the item to the list
292                    end                   
293                end
294            end
295        end
296    end
297end
298set(handles.ListDevices,'String',sort(ListDevices))
299
300%------------------------------------------------------------------------
301% --- Executes when the mirror is created or updated
302%------------------------------------------------------------------------
303 function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath)
304
305ListDevices={};
306for iexp=1:numel(ListExperiments)
307    if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory
308        ListExperiments{iexp}(1)=[];
309        ListStruct=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the source experiment directory
310        ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray
311        ListFiles=ListCells(1,:);%list of dir and file  names
312        cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . )
313        check_keep=cellfun('isempty', cell_remove);
314        check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files
315        for ilist=1:numel(ListFiles)
316            if check_keep(ilist)% loop on eligible DataSeries folders
317                DataSeries=fullfile(CampaignPath,ListExperiments{iexp},ListFiles{ilist});%source folder
318                if ~isempty(MirrorPath)
319                    mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist});
320                    if exist(mirror,'file')% if mirror already exists as a file or folder
321                        [tild,msg]=fileattrib(mirror);
322                        if strcmp(msg.Name,mirror)%if the mirror name already exists as a local file or dir
323                            if msg.directory% case of a folder
324                                answer=msgbox_uvmat('INPUT_Y-N',['replace local folder ' msg.Name ' by a link to the source dir']);
325                                if strcmp(answer,'Yes')
326                                    [ss,msg]=rmdir(mirror);
327                                    if ss==1
328                                        system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder
329                                    else
330                                        msgbox_uvmat('ERROR',['enable to delete local folder: ' msg]);
331                                    end
332                                end
333                            else % case of an existing mirror file
334                                answer=msgbox_uvmat('INPUT_Y-N',['replace local file ' msg.Name ' by a link to the source file']);
335                                if strcmp(answer,'Yes')
336                                    delete(mirror);
337                                    system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder                                 
338                                end
339                            end
340                        end
341                    else% create mirror to the data series if needed
342                        system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder                     
343                    end
344                    if isempty(find(strcmp(ListFiles{ilist},ListDevices), 1))% if the item is not already in ListDevices
345                        if check_dir(ilist)
346                            ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list
347                        end
348                        ListDevices=[ListDevices;ListFiles{ilist}]; %append the item to the list
349                    end
350                end
351            end
352        end
353    end
354end
355set(handles.ListDevices,'String',sort(ListDevices))
356
357%------------------------------------------------------------------------
358% --- Executes on button press in CampaignDoc.
359function CampaignDoc_Callback(hObject, eventdata, handles)
360%------------------------------------------------------------------------   
361answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file');
362if ~isequal(answer{1},'OK')
363    return
364end
365set(handles.ListExperiments,'Value',1)
366ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories
367DataviewData=get(handles.browse_data,'UserData');
368List=DataviewData.List;
369Currentpath=get(handles.SourceDir,'String');
370[Currentpath,Campaign,DirExt]=fileparts(Currentpath);
371Campaign=[Campaign DirExt];
372t=xmltree;
373t=set(t,1,'name','CampaignDoc');
374t = attributes(t,'add',1,'source','directory');
375SubCampaignTest=get(handles.SubCampaignTest,'Value');
376root_uid=1;
377if SubCampaignTest
378    %TO DO open an exoiting xml doc
379    [t,root_uid]=add(t,1,'element','SubCampaign');
380    t =attributes(t,'add',root_uid,'DirName',Campaign);
381end
382for iexp=1:length(List.Experiment)
383    set(handles.ListExperiments,'Value',iexp+1)
384    drawnow
385    test_mod=0;
386    [t,uid_exp]=add(t,root_uid,'element','Experiment');
387    t = attributes(t,'add',uid_exp,'i',num2str(iexp));
388    ExpName=List.Experiment{iexp}.name;
389    t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name);
390   
391    if isfield(List.Experiment{iexp},'Device')
392        for idevice=1:length(List.Experiment{iexp}.Device)
393            [t,uid_device]=add(t,uid_exp,'element','Device');
394            DeviceName=List.Experiment{iexp}.Device{idevice}.name;
395            t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name);       
396            if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
397                for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
398                    FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
399                    [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest);
400                    if test
401                        disp([List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated'])
402                    end
403                    if isequal(Title,'ImaDoc')
404                        [t,uid_xml]=add(t,uid_device,'element','ImaDoc');
405                        t = attributes(t,'add',uid_xml,'source','file');
406                        [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml});                   
407                    end
408                end
409             elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
410                for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
411                    RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
412                    [t,uid_record]=add(t,uid_device,'element','Record');
413                    t = attributes(t,'add',uid_record,'DirName',RecordName);
414                    if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
415                        for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
416                            FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
417                            [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest);
418                            if test
419                                disp([FileName ' , Heading updated'])
420                            end
421                            [t,uid_xml]=add(t,uid_record,'element','ImaDoc');
422                            t = attributes(t,'add',uid_xml,'source','file');
423                            [t]=add(t,uid_xml,'chardata',FileName);
424                        end
425                    end
426                end
427            end
428        end
429    end
430end
431set(handles.ListExperiments,'Value',1)
432outputdir=get(handles.SourceDir,'String');
433[path,dirname]=fileparts(outputdir);
434outputfile=fullfile(outputdir,[dirname '.xml']);
435%campaigndoc(t);
436save(t,outputfile)
437
438% %------------------------------------------------------------------------
439% % --- Executes on button press in CampaignDoc.
440% function edit_xml_Callback(hObject, eventdata, handles)
441% %------------------------------------------------------------------------
442% CurrentPath=get(handles.SourceDir,'String');
443% %[CurrentPath,Name,Ext]=fileparts(CurrentDir);
444% ListExperiments=get(handles.ListExperiments,'String');
445% Value=get(handles.ListExperiments,'Value');
446% if ~isequal(Value,1)
447%     ListExperiments=ListExperiments(Value);
448% end
449% ListDevices=get(handles.ListDevices,'String');
450% Value=get(handles.ListDevices,'Value');
451% if ~isequal(Value,1)
452%     ListDevices=ListDevices(Value);
453% end
454% ListRecords=get(handles.ListRecords,'String');
455% Value=get(handles.ListRecords,'Value');
456% if ~isequal(Value,1)
457%     ListRecords=ListRecords(Value);
458% end
459% [ListDevices,ListRecords,ListXml,List]=ListDir(CurrentPath,ListExperiments,ListDevices,ListRecords);
460% ListXml=get(handles.ListXml,'String');
461% Value=get(handles.ListXml,'Value');
462% set(handles.ListXml,'Value',Value(1));
463% if isequal(Value(1),1)
464%     msgbox_uvmat('ERROR','an xml file needs to be selected')
465%    return
466% else
467%     XmlName=ListXml{Value(1)};
468% end
469% for iexp=1:length(List.Experiment)
470%     ExpName=List.Experiment{iexp}.name;
471%     if isfield(List.Experiment{iexp},'Device')
472%         for idevice=1:length(List.Experiment{iexp}.Device)
473%             DeviceName=List.Experiment{iexp}.Device{idevice}.name;
474%             if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile')
475%                 for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile)
476%                     FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml};
477%                     if isequal(FileName,XmlName)
478%                         editxml(fullfile(CurrentPath,ExpName,DeviceName,FileName));
479%                         return
480%                     end
481%                 end
482%              elseif isfield(List.Experiment{iexp}.Device{idevice},'Record')
483%                 for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record)
484%                     RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name;
485%                     if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile')
486%                         for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile)
487%                             FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml};
488%                             if isequal(FileName,XmlName)
489%                                 editxml(fullfile(CurrentPath,ExpName,DeviceName,RecordName,FileName));
490%                                 return
491%                             end                         
492%                         end
493%                     end
494%                 end
495%             end
496%         end
497%     end
498% end
499%
500%
501%
502% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503% % CurrentPath/Campaign: root directory
504% function  [Title,test_mod]=check_heading(Currentpath,Campaign,Experiment,Device,Record,xmlname,testSubCampaign)
505%
506%  %Shema for Heading:
507% %  Campaign             
508% %  (SubCampaign)
509% % Experiment
510% %  Device
511% %  (Record)
512% %  ImageName
513% %  DateExp
514% %                 old: %Project: suppressed ( changed to Campaign)
515%                        %Exp: suppressed (changed to experiment)
516%                        %ImaNames: changed to ImageName
517% if exist('Record','var') && ~isempty(Record)
518%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,Record,xmlname); 
519%     testrecord=1;
520% else
521%     xmlfullname=fullfile(Currentpath,Campaign,Experiment,Device,xmlname);
522%     testrecord=0;
523% end
524% if ~exist('testSubCampaign','var')
525%     testSubCampaign=0;
526% end
527% if testSubCampaign
528%    SubCampaign=Campaign;
529%    [Currentpath,Campaign,DirExt]=fileparts(Currentpath);
530%    Campaign=[Campaign DirExt];
531% end
532% test_mod=0; %test for the modification of the xml file
533% t_device=xmltree(xmlfullname);
534% Title=get(t_device,1,'name');
535% uid_child=children(t_device,1);
536% Heading_old=[];
537% uidheading=0;
538% for ilist=1:length(uid_child)
539%     name=get(t_device,uid_child(ilist),'name');
540%     if isequal(name,'Heading')
541%         uidheading=uid_child(ilist);
542%     end
543% end
544% if uidheading
545%     subt=branch(t_device,uidheading);
546%     Heading_old=convert(subt);
547% else
548%    return % do not edit xml files without element 'Heading'
549% end
550% if ~(isfield(Heading_old,'Campaign')&& isequal(Heading_old.Campaign,Campaign))
551%     test_mod=1;
552% end
553% Heading.Campaign=Campaign;
554% if testSubCampaign
555%     if ~(isfield(Heading_old,'SubCampaign')&& isequal(Heading_old.SubCampaign,SubCampaign))
556%         test_mod=1;
557%     end
558%     Heading.SubCampaign=SubCampaign;
559% end
560% if ~(isfield(Heading_old,'Experiment')&& isequal(Heading_old.Experiment,Experiment))
561%     test_mod=1;
562% end
563% Heading.Experiment=Experiment;
564% if ~(isfield(Heading_old,'Device')&& isequal(Heading_old.Device,Device))
565%     test_mod=1;
566% end
567% Heading.Device=Device;
568% if testrecord
569%     if ~(isfield(Heading_old,'Record')&& isequal(Heading_old.Record,Record))
570%         test_mod=1;
571%     end
572%     Heading.Record=Record;
573% end
574% if isfield(Heading_old,'ImaNames')
575%     test_mod=1;
576%     if  ~isempty(Heading_old.ImaNames)
577%         Heading.ImageName=Heading_old.ImaNames;
578%     end
579% end
580% if isfield(Heading_old,'ImageName')&& ~isempty(Heading_old.ImageName)
581%     Heading.ImageName=Heading_old.ImageName;
582% end
583% if isfield(Heading_old,'DateExp')&& ~isempty(Heading_old.DateExp)
584%     Heading.DateExp=Heading_old.DateExp;
585% end
586% if test_mod && uidheading
587%      uid_child=children(t_device,uidheading);
588%      t_device=delete(t_device,uid_child);
589%     t_device=struct2xml(Heading,t_device,uidheading);
590%     backupfile=xmlfullname;
591%     testexist=2;
592%     while testexist==2
593%        backupfile=[backupfile '~'];
594%        testexist=exist(backupfile,'file');
595%     end
596%     [success,message]=copyfile(xmlfullname,backupfile);%make backup
597%     if isequal(success,1)
598%         delete(xmlfullname)
599%     else
600%         return
601%     end
602%     save(t_device,xmlfullname)
603% end
604
605%------------------------------------------------------------------------
606% --- Executes on button press in OK.
607%------------------------------------------------------------------------
608function OK_Callback(hObject, eventdata, handles)
609
610if strcmp(get(handles.MirrorDir,'Visible'),'on')
611    Campaign=get(handles.MirrorDir,'String');
612else
613    Campaign=get(handles.SourceDir,'String');
614end
615handles.output=[];
616handles.output.Campaign=Campaign;
617Experiment=get(handles.ListExperiments,'String');
618IndicesExp=get(handles.ListExperiments,'Value');
619if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected
620    Experiment=Experiment(IndicesExp);% use the selection of the list of experiments
621end
622Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir
623Device=get(handles.ListDevices,'String');
624Value=get(handles.ListDevices,'Value');
625Device=Device(Value);
626Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir
627Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link
628handles.output.Experiment=Experiment;
629handles.output.DataSeries=Device;
630guidata(hObject, handles);% Update handles structure
631uiresume(handles.browse_data);
632drawnow
633
634%------------------------------------------------------------------------
635% --- Executes on button press in HELP.
636function HELP_Callback(hObject, eventdata, handles)
637path_to_uvmat=which ('uvmat');% check the path of uvmat
638pathelp=fileparts(path_to_uvmat);
639helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html');
640if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC')
641else
642web([helpfile '#dataview'])   
643end
644
645%------------------------------------------------------------------------
646% --- Executes on button press in Cancel.
647%------------------------------------------------------------------------
648function Cancel_Callback(hObject, eventdata, handles)
649   
650handles.output = get(hObject,'String');
651guidata(hObject, handles); % Update handles structure
652% Use UIRESUME instead of delete because the OutputFcn needs
653uiresume(handles.browse_data);
654
655%------------------------------------------------------------------------
656% --- Executes when user attempts to close browse_data.
657%------------------------------------------------------------------------
658function browse_data_CloseRequestFcn(hObject, eventdata, handles)
659if isequal(get(handles.browse_data, 'waitstatus'), 'waiting')
660    % The GUI is still in UIWAIT, us UIRESUME
661    handles.output = get(hObject,'String');
662    guidata(hObject, handles); % Update handles structure
663    uiresume(handles.browse_data);
664else
665    % The GUI is no longer waiting, just close it
666    delete(handles.browse_data);
667end
668
669%------------------------------------------------------------------------
670% --- Executes on key press over figure1 with no controls selected.
671%------------------------------------------------------------------------
672function browse_data_KeyPressFcn(hObject, eventdata, handles)
673   
674% Check for "enter" or "escape"
675if isequal(get(hObject,'CurrentKey'),'escape')
676    % User said no by hitting escape
677    handles.output = 'Cancel';
678   
679    % Update handles structure
680    guidata(hObject, handles);
681   
682    uiresume(handles.browse_data);
683end
684if isequal(get(hObject,'CurrentKey'),'return')
685    uiresume(handles.browse_data);
686end
687
688
689% --- Executes on button press in Browse.
690function Browse_Callback(hObject, eventdata, handles)
691ListDevices=get(handles.ListDevices,'String');
692Device=ListDevices{get(handles.ListDevices,'Value')};
693DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir');
694uiresume(handles.browse_data);
695browse_data(DataSeries)
Note: See TracBrowser for help on using the repository browser.