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