[569] | 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 | |
---|
[809] | 6 | %======================================================================= |
---|
[924] | 7 | % Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[809] | 8 | % http://www.legi.grenoble-inp.fr |
---|
| 9 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 10 | % |
---|
[569] | 11 | % This file is part of the toolbox UVMAT. |
---|
[809] | 12 | % |
---|
[569] | 13 | % UVMAT is free software; you can redistribute it and/or modify |
---|
[809] | 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 | % |
---|
[569] | 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 |
---|
[809] | 21 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 22 | %======================================================================= |
---|
[569] | 23 | |
---|
| 24 | function varargout = browse_data(varargin) |
---|
| 25 | |
---|
[856] | 26 | % Last Modified by GUIDE v2.5 24-Jan-2015 16:55:04 |
---|
[569] | 27 | |
---|
| 28 | % Begin initialization code - DO NOT EDIT |
---|
| 29 | gui_Singleton = 1; |
---|
| 30 | gui_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', []); |
---|
| 36 | if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
| 37 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | if nargout |
---|
| 41 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
| 42 | else |
---|
| 43 | gui_mainfcn(gui_State, varargin{:}); |
---|
| 44 | end |
---|
| 45 | % End initialization code - DO NOT EDIT |
---|
| 46 | |
---|
| 47 | %------------------------------------------------------------------------ |
---|
| 48 | % --- Executes just before browse_data is made visible. |
---|
[931] | 49 | function browse_data_OpeningFcn(hObject, eventdata, handles, DataSeries,EnableMirror,MultiDevices) |
---|
[569] | 50 | %------------------------------------------------------------------------ |
---|
[581] | 51 | |
---|
| 52 | %% Choose default command line output for browse_data |
---|
[569] | 53 | handles.output = 'Cancel'; |
---|
| 54 | |
---|
[581] | 55 | %% Update handles structure |
---|
[569] | 56 | guidata(hObject, handles); |
---|
[581] | 57 | set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display) |
---|
[569] | 58 | |
---|
[581] | 59 | %% Determine the position of the dialog - centered on the screen |
---|
[569] | 60 | FigPos=get(0,'DefaultFigurePosition'); |
---|
| 61 | OldUnits = get(hObject, 'Units'); |
---|
| 62 | set(hObject, 'Units', 'pixels'); |
---|
| 63 | OldPos = get(hObject,'Position'); |
---|
| 64 | FigWidth = OldPos(3); |
---|
| 65 | FigHeight = OldPos(4); |
---|
| 66 | ScreenUnits=get(0,'Units'); |
---|
| 67 | set(0,'Units','pixels'); |
---|
| 68 | ScreenSize=get(0,'ScreenSize'); |
---|
| 69 | set(0,'Units',ScreenUnits); |
---|
| 70 | FigPos(1)=1/2*(ScreenSize(3)-FigWidth); |
---|
| 71 | FigPos(2)=2/3*(ScreenSize(4)-FigHeight); |
---|
| 72 | FigPos(3:4)=[FigWidth FigHeight]; |
---|
| 73 | set(hObject, 'Position', FigPos); |
---|
| 74 | set(hObject, 'Units', OldUnits); |
---|
[931] | 75 | if exist('MultiDevices','var') && strcmp(MultiDevices,'on') |
---|
| 76 | set(handles.ListDevices,'Max',2) |
---|
| 77 | else |
---|
| 78 | set(handles.ListDevices,'Max',1) |
---|
| 79 | end |
---|
[837] | 80 | if exist('EnableMirror','var') && strcmp(EnableMirror,'on') |
---|
| 81 | set(handles.CreateMirror,'Visible','on') |
---|
| 82 | set(handles.mirror_txt,'Visible','on') |
---|
| 83 | else |
---|
| 84 | set(handles.CreateMirror,'Visible','off') |
---|
| 85 | set(handles.mirror_txt,'Visible','off') |
---|
| 86 | end |
---|
[856] | 87 | |
---|
| 88 | %% initialize the GUI |
---|
[934] | 89 | if ~(exist('DataSeries','var') && ischar(DataSeries) && exist(DataSeries,'dir')) |
---|
[856] | 90 | DataSeries=pwd;% current dir is the starting data series by default |
---|
| 91 | end |
---|
| 92 | [Experiment,DataSeries,Ext]=fileparts(DataSeries); |
---|
| 93 | DataSeries=[DataSeries Ext]; |
---|
| 94 | [Campaign,Experiment,Ext]=fileparts(Experiment); |
---|
| 95 | Experiment=[Experiment Ext]; |
---|
| 96 | [tild,CampaignName]=fileparts(Campaign); |
---|
| 97 | RootXml=fullfile(Campaign,[CampaignName '.xml']); |
---|
| 98 | s=[]; |
---|
| 99 | if 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') |
---|
[569] | 106 | end |
---|
| 107 | end |
---|
[856] | 108 | if 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') |
---|
| 112 | end |
---|
| 113 | errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries); |
---|
| 114 | if ~isempty(errormsg) |
---|
| 115 | msgbox_uvmat('ERROR',errormsg) |
---|
| 116 | return |
---|
| 117 | end |
---|
| 118 | set(handles.OK,'Visible','on') |
---|
| 119 | set(handles.Cancel,'Visible','on') |
---|
[569] | 120 | |
---|
[856] | 121 | set(handles.browse_data,'WindowStyle','modal')% Make the GUI modal |
---|
| 122 | set(hObject,'Visible','on') |
---|
| 123 | drawnow |
---|
| 124 | % UIWAIT makes GUI wait for user response (see UIRESUME) |
---|
| 125 | uiwait(handles.browse_data); |
---|
[837] | 126 | |
---|
[856] | 127 | |
---|
| 128 | |
---|
[569] | 129 | %------------------------------------------------------------------------ |
---|
| 130 | % --- Outputs from this function are returned to the command line. |
---|
| 131 | function varargout = browse_data_OutputFcn(hObject, eventdata, handles) |
---|
| 132 | %------------------------------------------------------------------------ |
---|
| 133 | % Get default command line output from handles structure |
---|
| 134 | varargout{1} = handles.output; |
---|
[581] | 135 | delete(handles.browse_data) |
---|
[569] | 136 | |
---|
| 137 | %------------------------------------------------------------------------ |
---|
| 138 | % --- Executes on button press in CreateMirror. |
---|
| 139 | function CreateMirror_Callback(hObject, eventdata, handles) |
---|
| 140 | %------------------------------------------------------------------------ |
---|
[733] | 141 | set(handles.SourceDir,'BackgroundColor',[1 1 0])% indicate action of button by yellow color |
---|
| 142 | drawnow |
---|
[571] | 143 | SourceDir=get(handles.SourceDir,'String'); |
---|
| 144 | [SourcePath,ProjectName]=fileparts(SourceDir); |
---|
| 145 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
[733] | 146 | MirrorDir=get(handles.MirrorDir,'String');% name of the mirror folder |
---|
| 147 | else% create the mirror folder if it does not exist |
---|
[651] | 148 | MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir'); |
---|
| 149 | if isempty(MirrorRoot) |
---|
[569] | 150 | return |
---|
[741] | 151 | elseif strcmp(MirrorRoot,SourcePath) |
---|
| 152 | msgbox_uvmat('ERROR','The mirror folder must be different from the source') |
---|
| 153 | return |
---|
[569] | 154 | else |
---|
| 155 | MirrorDir=fullfile(MirrorRoot,ProjectName); |
---|
| 156 | end |
---|
[741] | 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 |
---|
[569] | 166 | end |
---|
| 167 | MirrorDoc.SourceDir=SourceDir; |
---|
| 168 | t=struct2xml(MirrorDoc); |
---|
| 169 | set(t,1,'name','DataTree'); |
---|
[741] | 170 | save(t,fullfile(MirrorDir,[ProjectName '.xml']))% create an xml file in the mirror folder to indicate its source folder |
---|
[569] | 171 | set(handles.MirrorDir,'String',MirrorDir) |
---|
| 172 | set(handles.MirrorDir,'Visible','on') |
---|
[741] | 173 | set(handles.CreateMirror,'String','update_mirror') |
---|
[569] | 174 | end |
---|
| 175 | ExpName={''}; |
---|
[733] | 176 | |
---|
| 177 | %% update the mirror from the source dir |
---|
[569] | 178 | if exist(SourceDir,'dir') |
---|
| 179 | hdir=dir(SourceDir); %list files and dirs |
---|
| 180 | idir=0; |
---|
| 181 | for ilist=1:length(hdir) |
---|
[733] | 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' |
---|
[569] | 185 | idir=idir+1; |
---|
[733] | 186 | mirror=fullfile(MirrorDir,hdir(ilist).name);% corresponding name in the mirror |
---|
[569] | 187 | if ~exist(mirror,'dir') |
---|
[733] | 188 | mkdir(mirror)% create the mirror folder if it does not exist |
---|
[569] | 189 | end |
---|
[733] | 190 | ExpName{idir}=['+/' hdir(ilist).name];% insert '+/' in the list to show that it is a folder |
---|
[569] | 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) |
---|
[733] | 199 | update_experiments(handles,[{'*'};ExpName'],SourceDir,MirrorDir) |
---|
| 200 | % ListExperiments_Callback(hObject, eventdata, handles) % list the content of the experiment |
---|
[569] | 201 | else |
---|
| 202 | msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory']) |
---|
| 203 | end |
---|
| 204 | set(handles.SourceDir,'BackgroundColor',[1 1 1]) |
---|
| 205 | |
---|
| 206 | %------------------------------------------------------------------------ |
---|
[856] | 207 | % List the experiments in a campaign, filling the menu ListExperiments |
---|
[569] | 208 | %------------------------------------------------------------------------ |
---|
[856] | 209 | function errormsg=scan_campaign(handles,Campaign,Experiment,DataSeries) |
---|
| 210 | %------------------------------------------------------------------------ |
---|
[733] | 211 | errormsg=''; |
---|
[570] | 212 | if exist(Campaign,'dir') |
---|
[651] | 213 | ListStruct=dir(Campaign); %list files and dirs |
---|
[733] | 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 |
---|
[651] | 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))'); |
---|
[856] | 225 | index=find(strcmp(['+/' Experiment],ListFiles)); |
---|
| 226 | if isempty(index), index=0; end |
---|
[651] | 227 | set(handles.ListExperiments,'String',[{'*'};ListFiles]) |
---|
[856] | 228 | set(handles.ListExperiments,'Value',index+1)% initialise the menu selection with the folder defined by the input |
---|
[570] | 229 | ListExperiments_Callback([],[], handles) |
---|
[856] | 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 |
---|
[569] | 238 | else |
---|
[570] | 239 | msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory']) |
---|
[569] | 240 | end |
---|
| 241 | |
---|
| 242 | %------------------------------------------------------------------------ |
---|
| 243 | % --- Executes on selection change in ListExperiments. |
---|
[651] | 244 | %------------------------------------------------------------------------ |
---|
[569] | 245 | function ListExperiments_Callback(hObject, eventdata, handles) |
---|
[651] | 246 | |
---|
[571] | 247 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
[589] | 248 | MirrorPath=get(handles.MirrorDir,'String'); |
---|
[741] | 249 | else |
---|
| 250 | MirrorPath=get(handles.SourceDir,'String'); |
---|
[571] | 251 | end |
---|
[569] | 252 | ListExperiments=get(handles.ListExperiments,'String'); |
---|
| 253 | list_val=get(handles.ListExperiments,'Value'); |
---|
| 254 | if isequal(list_val(1),1) |
---|
[733] | 255 | ListExperiments=ListExperiments(2:end); %choose all experiments if the first line '*' is selected |
---|
[569] | 256 | set(handles.ListExperiments,'Value',1) |
---|
| 257 | else |
---|
| 258 | ListExperiments=ListExperiments(list_val);%choose selected experiments |
---|
| 259 | end |
---|
[733] | 260 | list_dataseries(handles,ListExperiments,MirrorPath) |
---|
[571] | 261 | |
---|
[733] | 262 | %------------------------------------------------------------------------ |
---|
| 263 | % --- List the DataSeries when a set of experiments is selected |
---|
| 264 | %------------------------------------------------------------------------ |
---|
| 265 | function list_dataseries(handles,ListExperiments,MirrorPath) |
---|
[571] | 266 | |
---|
[733] | 267 | ListDevices={}; |
---|
| 268 | for iexp=1:numel(ListExperiments) |
---|
| 269 | if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory |
---|
[741] | 270 | ListExperiments{iexp}(1)=[];%remove the first char '+' used to mark folders |
---|
[733] | 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 . ) |
---|
[934] | 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); |
---|
[733] | 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); |
---|
[934] | 285 | msg.Name=regexprep(msg.Name,'^/.','/');%remove the dot in /. at the beginning of the name |
---|
[733] | 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 |
---|
| 299 | end |
---|
| 300 | set(handles.ListDevices,'String',sort(ListDevices)) |
---|
| 301 | |
---|
[571] | 302 | %------------------------------------------------------------------------ |
---|
[733] | 303 | % --- Executes when the mirror is created or updated |
---|
[651] | 304 | %------------------------------------------------------------------------ |
---|
[733] | 305 | function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath) |
---|
[651] | 306 | |
---|
[571] | 307 | ListDevices={}; |
---|
[569] | 308 | for iexp=1:numel(ListExperiments) |
---|
[651] | 309 | if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory |
---|
| 310 | ListExperiments{iexp}(1)=[]; |
---|
[733] | 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 |
---|
[651] | 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) |
---|
[733] | 318 | if check_keep(ilist)% loop on eligible DataSeries folders |
---|
| 319 | DataSeries=fullfile(CampaignPath,ListExperiments{iexp},ListFiles{ilist});%source folder |
---|
[651] | 320 | if ~isempty(MirrorPath) |
---|
| 321 | mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist}); |
---|
[741] | 322 | if exist(mirror,'file')% if mirror already exists as a file or folder |
---|
[733] | 323 | [tild,msg]=fileattrib(mirror); |
---|
| 324 | if strcmp(msg.Name,mirror)%if the mirror name already exists as a local file or dir |
---|
[741] | 325 | if msg.directory% case of a folder |
---|
[733] | 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 |
---|
[741] | 335 | else % case of an existing mirror file |
---|
[733] | 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); |
---|
[741] | 339 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
[733] | 340 | end |
---|
| 341 | end |
---|
| 342 | end |
---|
[741] | 343 | else% create mirror to the data series if needed |
---|
| 344 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
[651] | 345 | end |
---|
[733] | 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 |
---|
[651] | 351 | end |
---|
| 352 | end |
---|
[570] | 353 | end |
---|
[569] | 354 | end |
---|
| 355 | end |
---|
| 356 | end |
---|
[651] | 357 | set(handles.ListDevices,'String',sort(ListDevices)) |
---|
[569] | 358 | |
---|
| 359 | %------------------------------------------------------------------------ |
---|
| 360 | % --- Executes on button press in CampaignDoc. |
---|
| 361 | function CampaignDoc_Callback(hObject, eventdata, handles) |
---|
| 362 | %------------------------------------------------------------------------ |
---|
[651] | 363 | answer=msgbox_uvmat('INPUT_Y-N','This function will update the global xml rpresentation of the data set and the Heading of each xml file'); |
---|
[569] | 364 | if ~isequal(answer{1},'OK') |
---|
| 365 | return |
---|
| 366 | end |
---|
| 367 | set(handles.ListExperiments,'Value',1) |
---|
| 368 | ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories |
---|
[581] | 369 | DataviewData=get(handles.browse_data,'UserData'); |
---|
[569] | 370 | List=DataviewData.List; |
---|
| 371 | Currentpath=get(handles.SourceDir,'String'); |
---|
| 372 | [Currentpath,Campaign,DirExt]=fileparts(Currentpath); |
---|
| 373 | Campaign=[Campaign DirExt]; |
---|
| 374 | t=xmltree; |
---|
| 375 | t=set(t,1,'name','CampaignDoc'); |
---|
| 376 | t = attributes(t,'add',1,'source','directory'); |
---|
| 377 | SubCampaignTest=get(handles.SubCampaignTest,'Value'); |
---|
| 378 | root_uid=1; |
---|
| 379 | if 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); |
---|
| 383 | end |
---|
| 384 | for 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 |
---|
[651] | 403 | disp([List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']) |
---|
[569] | 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 |
---|
[651] | 421 | disp([FileName ' , Heading updated']) |
---|
[569] | 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 |
---|
| 432 | end |
---|
| 433 | set(handles.ListExperiments,'Value',1) |
---|
| 434 | outputdir=get(handles.SourceDir,'String'); |
---|
| 435 | [path,dirname]=fileparts(outputdir); |
---|
| 436 | outputfile=fullfile(outputdir,[dirname '.xml']); |
---|
| 437 | %campaigndoc(t); |
---|
| 438 | save(t,outputfile) |
---|
| 439 | |
---|
[733] | 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 |
---|
[569] | 606 | |
---|
| 607 | %------------------------------------------------------------------------ |
---|
| 608 | % --- Executes on button press in OK. |
---|
[651] | 609 | %------------------------------------------------------------------------ |
---|
[569] | 610 | function OK_Callback(hObject, eventdata, handles) |
---|
[651] | 611 | |
---|
[569] | 612 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
| 613 | Campaign=get(handles.MirrorDir,'String'); |
---|
| 614 | else |
---|
| 615 | Campaign=get(handles.SourceDir,'String'); |
---|
| 616 | end |
---|
[931] | 617 | handles.output=[]; |
---|
[569] | 618 | handles.output.Campaign=Campaign; |
---|
| 619 | Experiment=get(handles.ListExperiments,'String'); |
---|
| 620 | IndicesExp=get(handles.ListExperiments,'Value'); |
---|
| 621 | if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected |
---|
| 622 | Experiment=Experiment(IndicesExp);% use the selection of the list of experiments |
---|
| 623 | end |
---|
[651] | 624 | Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir |
---|
[569] | 625 | Device=get(handles.ListDevices,'String'); |
---|
| 626 | Value=get(handles.ListDevices,'Value'); |
---|
| 627 | Device=Device(Value); |
---|
[651] | 628 | Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir |
---|
[741] | 629 | Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link |
---|
[569] | 630 | handles.output.Experiment=Experiment; |
---|
[651] | 631 | handles.output.DataSeries=Device; |
---|
[569] | 632 | guidata(hObject, handles);% Update handles structure |
---|
[581] | 633 | uiresume(handles.browse_data); |
---|
[569] | 634 | drawnow |
---|
| 635 | |
---|
[651] | 636 | %------------------------------------------------------------------------ |
---|
| 637 | % --- Executes on button press in HELP. |
---|
| 638 | function HELP_Callback(hObject, eventdata, handles) |
---|
| 639 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
| 640 | pathelp=fileparts(path_to_uvmat); |
---|
| 641 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
| 642 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
[569] | 643 | else |
---|
[651] | 644 | web([helpfile '#dataview']) |
---|
[569] | 645 | end |
---|
| 646 | |
---|
[651] | 647 | %------------------------------------------------------------------------ |
---|
[569] | 648 | % --- Executes on button press in Cancel. |
---|
[651] | 649 | %------------------------------------------------------------------------ |
---|
[569] | 650 | function Cancel_Callback(hObject, eventdata, handles) |
---|
[651] | 651 | |
---|
[569] | 652 | handles.output = get(hObject,'String'); |
---|
| 653 | guidata(hObject, handles); % Update handles structure |
---|
| 654 | % Use UIRESUME instead of delete because the OutputFcn needs |
---|
[581] | 655 | uiresume(handles.browse_data); |
---|
[569] | 656 | |
---|
[651] | 657 | %------------------------------------------------------------------------ |
---|
[581] | 658 | % --- Executes when user attempts to close browse_data. |
---|
[651] | 659 | %------------------------------------------------------------------------ |
---|
[581] | 660 | function browse_data_CloseRequestFcn(hObject, eventdata, handles) |
---|
| 661 | if isequal(get(handles.browse_data, 'waitstatus'), 'waiting') |
---|
[569] | 662 | % The GUI is still in UIWAIT, us UIRESUME |
---|
[733] | 663 | handles.output = get(hObject,'String'); |
---|
| 664 | guidata(hObject, handles); % Update handles structure |
---|
[581] | 665 | uiresume(handles.browse_data); |
---|
[569] | 666 | else |
---|
| 667 | % The GUI is no longer waiting, just close it |
---|
[581] | 668 | delete(handles.browse_data); |
---|
[569] | 669 | end |
---|
| 670 | |
---|
[651] | 671 | %------------------------------------------------------------------------ |
---|
[569] | 672 | % --- Executes on key press over figure1 with no controls selected. |
---|
[651] | 673 | %------------------------------------------------------------------------ |
---|
[581] | 674 | function browse_data_KeyPressFcn(hObject, eventdata, handles) |
---|
[651] | 675 | |
---|
[569] | 676 | % Check for "enter" or "escape" |
---|
| 677 | if 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 | |
---|
[581] | 684 | uiresume(handles.browse_data); |
---|
[569] | 685 | end |
---|
| 686 | if isequal(get(hObject,'CurrentKey'),'return') |
---|
[581] | 687 | uiresume(handles.browse_data); |
---|
[569] | 688 | end |
---|
[733] | 689 | |
---|
| 690 | |
---|
[856] | 691 | % --- Executes on button press in Browse. |
---|
| 692 | function Browse_Callback(hObject, eventdata, handles) |
---|
| 693 | ListDevices=get(handles.ListDevices,'String'); |
---|
| 694 | Device=ListDevices{get(handles.ListDevices,'Value')}; |
---|
| 695 | DataSeries=uigetfile_uvmat('open a data folder',Device,'uigetdir'); |
---|
| 696 | uiresume(handles.browse_data); |
---|
| 697 | browse_data(DataSeries) |
---|