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