[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 | %======================================================================= |
---|
[1061] | 7 | % Copyright 2008-2019, 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 | |
---|
[1063] | 26 | % Last Modified by GUIDE v2.5 17-Apr-2019 18:15:24 |
---|
[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. |
---|
[1059] | 49 | function browse_data_OpeningFcn(hObject, eventdata, handles, InputDir,EnableMirror,MultiDevices) |
---|
[569] | 50 | %------------------------------------------------------------------------ |
---|
[581] | 51 | |
---|
| 52 | %% Choose default command line output for browse_data |
---|
[1059] | 53 | handles.output =hObject;% 'Cancel'; |
---|
[569] | 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) |
---|
[1059] | 58 | set(hObject,'DeleteFcn',{@closefcn})% |
---|
[569] | 59 | |
---|
[581] | 60 | %% Determine the position of the dialog - centered on the screen |
---|
[569] | 61 | FigPos=get(0,'DefaultFigurePosition'); |
---|
| 62 | OldUnits = get(hObject, 'Units'); |
---|
| 63 | set(hObject, 'Units', 'pixels'); |
---|
| 64 | OldPos = get(hObject,'Position'); |
---|
| 65 | FigWidth = OldPos(3); |
---|
| 66 | FigHeight = OldPos(4); |
---|
| 67 | ScreenUnits=get(0,'Units'); |
---|
| 68 | set(0,'Units','pixels'); |
---|
| 69 | ScreenSize=get(0,'ScreenSize'); |
---|
| 70 | set(0,'Units',ScreenUnits); |
---|
| 71 | FigPos(1)=1/2*(ScreenSize(3)-FigWidth); |
---|
| 72 | FigPos(2)=2/3*(ScreenSize(4)-FigHeight); |
---|
| 73 | FigPos(3:4)=[FigWidth FigHeight]; |
---|
| 74 | set(hObject, 'Position', FigPos); |
---|
| 75 | set(hObject, 'Units', OldUnits); |
---|
[931] | 76 | if exist('MultiDevices','var') && strcmp(MultiDevices,'on') |
---|
[1063] | 77 | set(handles.DataSeries,'Max',2) |
---|
[931] | 78 | else |
---|
[1063] | 79 | set(handles.DataSeries,'Max',1) |
---|
[931] | 80 | end |
---|
[837] | 81 | if exist('EnableMirror','var') && strcmp(EnableMirror,'on') |
---|
| 82 | set(handles.CreateMirror,'Visible','on') |
---|
| 83 | set(handles.mirror_txt,'Visible','on') |
---|
| 84 | else |
---|
| 85 | set(handles.CreateMirror,'Visible','off') |
---|
| 86 | set(handles.mirror_txt,'Visible','off') |
---|
| 87 | end |
---|
[856] | 88 | |
---|
| 89 | %% initialize the GUI |
---|
[1059] | 90 | if isempty(regexp(InputDir,'^http:'))&& ~(exist('InputDir','var') && ischar(InputDir) && exist(InputDir,'dir')) |
---|
| 91 | InputDir=pwd;% current dir is the starting data series by default |
---|
[856] | 92 | end |
---|
[1059] | 93 | % [Experiment,DataSeries,Ext]=fileparts(DataSeries); |
---|
| 94 | % DataSeries=[DataSeries Ext]; |
---|
| 95 | % [Campaign,Experiment,Ext]=fileparts(Experiment); |
---|
| 96 | % Experiment=[Experiment Ext]; |
---|
| 97 | [ExpWithPath,DataSeries]=fileparts(InputDir); |
---|
| 98 | [Campaign,Experiment,Ext]=fileparts(ExpWithPath); |
---|
[856] | 99 | [tild,CampaignName]=fileparts(Campaign); |
---|
| 100 | RootXml=fullfile(Campaign,[CampaignName '.xml']); |
---|
| 101 | s=[]; |
---|
| 102 | if exist(RootXml,'file') |
---|
| 103 | [s,Heading]=xml2struct(RootXml);%read the xml file |
---|
| 104 | if isfield(s,'SourceDir') |
---|
| 105 | set(handles.SourceDir,'String',s.SourceDir);%display the source dir if a mirror has been opened |
---|
| 106 | set(handles.MirrorDir,'Visible','on');% mirror dir display |
---|
| 107 | set(handles.MirrorDir,'String',Campaign);%display the opened mirror dir |
---|
| 108 | set(handles.CreateMirror,'String','update_mirror') |
---|
[569] | 109 | end |
---|
| 110 | end |
---|
[856] | 111 | if isempty(s) %a source dir has been opened |
---|
| 112 | set(handles.SourceDir,'String',Campaign); |
---|
| 113 | set(handles.MirrorDir,'Visible','off');% no mirror dir display |
---|
| 114 | set(handles.CreateMirror,'String','create_mirror') |
---|
| 115 | end |
---|
[1059] | 116 | errormsg=scan_campaign(handles,Campaign,Experiment,ExpWithPath); |
---|
[856] | 117 | if ~isempty(errormsg) |
---|
| 118 | msgbox_uvmat('ERROR',errormsg) |
---|
| 119 | return |
---|
| 120 | end |
---|
[1059] | 121 | % set(handles.OK,'Visible','on') |
---|
| 122 | % set(handles.Cancel,'Visible','on') |
---|
[569] | 123 | |
---|
[1059] | 124 | %set(handles.browse_data,'WindowStyle','modal')% Make the GUI |
---|
| 125 | %modal%%%%%%%%%%%%%%%%%%%%%%% |
---|
[856] | 126 | set(hObject,'Visible','on') |
---|
| 127 | drawnow |
---|
[1059] | 128 | % UIWAIT makes GUI wait for user response (see UIRESUME)%%%%%%%%%%%%%%%%TO |
---|
| 129 | % CHECK |
---|
| 130 | %uiwait(handles.browse_data); |
---|
[837] | 131 | |
---|
[856] | 132 | |
---|
| 133 | |
---|
[569] | 134 | %------------------------------------------------------------------------ |
---|
| 135 | % --- Outputs from this function are returned to the command line. |
---|
| 136 | function varargout = browse_data_OutputFcn(hObject, eventdata, handles) |
---|
| 137 | %------------------------------------------------------------------------ |
---|
| 138 | % Get default command line output from handles structure |
---|
| 139 | varargout{1} = handles.output; |
---|
[1059] | 140 | %%%%%%%%%%%%%%%%%%delete(handles.browse_data) |
---|
[569] | 141 | |
---|
| 142 | %------------------------------------------------------------------------ |
---|
| 143 | % --- Executes on button press in CreateMirror. |
---|
| 144 | function CreateMirror_Callback(hObject, eventdata, handles) |
---|
| 145 | %------------------------------------------------------------------------ |
---|
[733] | 146 | set(handles.SourceDir,'BackgroundColor',[1 1 0])% indicate action of button by yellow color |
---|
| 147 | drawnow |
---|
[571] | 148 | SourceDir=get(handles.SourceDir,'String'); |
---|
| 149 | [SourcePath,ProjectName]=fileparts(SourceDir); |
---|
| 150 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
[733] | 151 | MirrorDir=get(handles.MirrorDir,'String');% name of the mirror folder |
---|
| 152 | else% create the mirror folder if it does not exist |
---|
[651] | 153 | MirrorRoot=uigetfile_uvmat('select the folder which must contain the mirror directory:',SourcePath,'uigetdir'); |
---|
| 154 | if isempty(MirrorRoot) |
---|
[569] | 155 | return |
---|
[741] | 156 | elseif strcmp(MirrorRoot,SourcePath) |
---|
| 157 | msgbox_uvmat('ERROR','The mirror folder must be different from the source') |
---|
| 158 | return |
---|
[569] | 159 | else |
---|
| 160 | MirrorDir=fullfile(MirrorRoot,ProjectName); |
---|
| 161 | end |
---|
[741] | 162 | if exist(MirrorDir,'dir') |
---|
| 163 | msgbox_uvmat('ERROR',['The folder ' MirrorDir ' chosen as new mirror campaign already exists']) |
---|
| 164 | return |
---|
| 165 | else |
---|
| 166 | [s,errormsg]=mkdir(MirrorDir)% create the mirror dir |
---|
| 167 | if s~=1 |
---|
| 168 | msgbox_uvmat('ERROR',['error in creating ' MirrorDir ': ' errormsg]) |
---|
| 169 | return |
---|
| 170 | end |
---|
[569] | 171 | end |
---|
| 172 | MirrorDoc.SourceDir=SourceDir; |
---|
| 173 | t=struct2xml(MirrorDoc); |
---|
| 174 | set(t,1,'name','DataTree'); |
---|
[741] | 175 | save(t,fullfile(MirrorDir,[ProjectName '.xml']))% create an xml file in the mirror folder to indicate its source folder |
---|
[569] | 176 | set(handles.MirrorDir,'String',MirrorDir) |
---|
| 177 | set(handles.MirrorDir,'Visible','on') |
---|
[741] | 178 | set(handles.CreateMirror,'String','update_mirror') |
---|
[569] | 179 | end |
---|
| 180 | ExpName={''}; |
---|
[733] | 181 | |
---|
| 182 | %% update the mirror from the source dir |
---|
[569] | 183 | if exist(SourceDir,'dir') |
---|
| 184 | hdir=dir(SourceDir); %list files and dirs |
---|
| 185 | idir=0; |
---|
| 186 | for ilist=1:length(hdir) |
---|
[733] | 187 | if hdir(ilist).isdir% scan all subfolders |
---|
| 188 | dirname=hdir(ilist).name;% |
---|
| 189 | if ~isequal(dirname(1),'.')&&~isequal(dirname(1),'0')%skip subfolder beginning by '0' |
---|
[569] | 190 | idir=idir+1; |
---|
[733] | 191 | mirror=fullfile(MirrorDir,hdir(ilist).name);% corresponding name in the mirror |
---|
[569] | 192 | if ~exist(mirror,'dir') |
---|
[733] | 193 | mkdir(mirror)% create the mirror folder if it does not exist |
---|
[569] | 194 | end |
---|
[733] | 195 | ExpName{idir}=['+/' hdir(ilist).name];% insert '+/' in the list to show that it is a folder |
---|
[569] | 196 | end |
---|
| 197 | % look for the list of 'devices' |
---|
| 198 | else |
---|
| 199 | %warning for isolated files |
---|
| 200 | end |
---|
| 201 | end |
---|
| 202 | set(handles.ListExperiments,'String',[{'*'};ExpName']) |
---|
| 203 | set(handles.ListExperiments,'Value',1) |
---|
[733] | 204 | update_experiments(handles,[{'*'};ExpName'],SourceDir,MirrorDir) |
---|
| 205 | % ListExperiments_Callback(hObject, eventdata, handles) % list the content of the experiment |
---|
[569] | 206 | else |
---|
| 207 | msgbox_uvmat('ERROR',['The input ' SourceDir ' is not a directory']) |
---|
| 208 | end |
---|
| 209 | set(handles.SourceDir,'BackgroundColor',[1 1 1]) |
---|
| 210 | |
---|
| 211 | %------------------------------------------------------------------------ |
---|
[856] | 212 | % List the experiments in a campaign, filling the menu ListExperiments |
---|
[569] | 213 | %------------------------------------------------------------------------ |
---|
[1063] | 214 | function errormsg=scan_campaign(handles,Campaign,Experiment,DataInput) |
---|
[856] | 215 | %------------------------------------------------------------------------ |
---|
[733] | 216 | errormsg=''; |
---|
[1037] | 217 | if ~isempty(regexp(Campaign,'^http'))|| exist(Campaign,'dir') |
---|
| 218 | ListStruct=dir_uvmat(Campaign); %list files and dirs |
---|
[733] | 219 | if numel(ListStruct)>1000% A campaign folder must contain maily a list of 'experiment' sub-folders |
---|
[1059] | 220 | errormsg=[Campaign ' contains too many items (>1000) to be a Project folder']; |
---|
[733] | 221 | return |
---|
| 222 | end |
---|
[651] | 223 | ListCells=struct2cell(ListStruct);% transform dir struct to a cell arrray |
---|
| 224 | ListFiles=ListCells(1,:);%list of dir and file names |
---|
| 225 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files |
---|
| 226 | ListFiles(check_dir)=regexprep(ListFiles(check_dir),'^.+','+/$0');% put '+/' in front of dir name display |
---|
| 227 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
| 228 | check_keep=cellfun('isempty', cell_remove); |
---|
| 229 | ListFiles=sort((ListFiles(check_keep))'); |
---|
[856] | 230 | index=find(strcmp(['+/' Experiment],ListFiles)); |
---|
[1059] | 231 | if isempty(index), index=1; end |
---|
| 232 | set(handles.ListExperiments,'String',ListFiles) |
---|
| 233 | set(handles.ListExperiments,'Value',index)% initialise the menu selection with the folder defined by the input |
---|
[570] | 234 | ListExperiments_Callback([],[], handles) |
---|
[1063] | 235 | DataSeries=get(handles.DataSeries,'String'); |
---|
| 236 | index=find(strcmp(['+/' DataInput],DataSeries)); |
---|
[856] | 237 | if isempty(index) |
---|
[1063] | 238 | index=find(strcmp(['~/' DataInput],DataSeries)); |
---|
[856] | 239 | end |
---|
| 240 | if ~isempty(index) |
---|
[1063] | 241 | set(handles.DataSeries,'Value',index) |
---|
[856] | 242 | end |
---|
[569] | 243 | else |
---|
[570] | 244 | msgbox_uvmat('ERROR',['The input ' Campaign ' is not a directory']) |
---|
[569] | 245 | end |
---|
| 246 | |
---|
| 247 | %------------------------------------------------------------------------ |
---|
| 248 | % --- Executes on selection change in ListExperiments. |
---|
[651] | 249 | %------------------------------------------------------------------------ |
---|
[569] | 250 | function ListExperiments_Callback(hObject, eventdata, handles) |
---|
[651] | 251 | |
---|
[571] | 252 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
[589] | 253 | MirrorPath=get(handles.MirrorDir,'String'); |
---|
[741] | 254 | else |
---|
| 255 | MirrorPath=get(handles.SourceDir,'String'); |
---|
[571] | 256 | end |
---|
[569] | 257 | ListExperiments=get(handles.ListExperiments,'String'); |
---|
| 258 | list_val=get(handles.ListExperiments,'Value'); |
---|
[1064] | 259 | ListExperiments=ListExperiments(list_val);%choose selected experiments |
---|
[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 | |
---|
[1063] | 267 | DataSeries={}; |
---|
[733] | 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); |
---|
[1059] | 285 | % msg.Name=regexprep(msg.Name,'^/.','/');%remove the dot in /. at the beginning of the name |
---|
| 286 | % if ~strcmp(msg.Name,mirror)% if it is a link |
---|
| 287 | % ListFiles{ilist}=['~' ListFiles{ilist}];%mark link by '@' in the list |
---|
| 288 | % end |
---|
[733] | 289 | if check_dir(ilist) |
---|
| 290 | ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list |
---|
| 291 | end |
---|
[1063] | 292 | if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries |
---|
| 293 | DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list |
---|
[733] | 294 | end |
---|
| 295 | end |
---|
| 296 | end |
---|
| 297 | end |
---|
| 298 | end |
---|
| 299 | end |
---|
[1064] | 300 | if get(handles.CheckDevices,'Value') |
---|
| 301 | set(handles.ListDevices,'Value',1) |
---|
| 302 | set(handles.ListDevices,'String',sort(DataSeries)) |
---|
| 303 | CheckDevices_Callback([],[], handles) |
---|
| 304 | else |
---|
[1063] | 305 | set(handles.DataSeries,'Value',1) |
---|
| 306 | set(handles.DataSeries,'String',sort(DataSeries)) |
---|
[1064] | 307 | end |
---|
[733] | 308 | |
---|
[571] | 309 | %------------------------------------------------------------------------ |
---|
[733] | 310 | % --- Executes when the mirror is created or updated |
---|
[651] | 311 | %------------------------------------------------------------------------ |
---|
[733] | 312 | function update_experiments(handles,ListExperiments,CampaignPath,MirrorPath) |
---|
[651] | 313 | |
---|
[1063] | 314 | DataSeries={}; |
---|
[569] | 315 | for iexp=1:numel(ListExperiments) |
---|
[651] | 316 | if strcmp(ListExperiments{iexp}(1),'+')% if the item is a directory |
---|
| 317 | ListExperiments{iexp}(1)=[]; |
---|
[733] | 318 | ListStruct=dir(fullfile(CampaignPath,ListExperiments{iexp})); %list files and dir in the source experiment directory |
---|
| 319 | ListCells=struct2cell(ListStruct);%transform dir struct to a cell arrray |
---|
[651] | 320 | ListFiles=ListCells(1,:);%list of dir and file names |
---|
| 321 | cell_remove=regexp(ListFiles,'^(-|\.|\+/\.)');% detect strings beginning by '-' ,'.' or '+/.'(dir beginning by . ) |
---|
| 322 | check_keep=cellfun('isempty', cell_remove); |
---|
| 323 | check_dir=cell2mat(ListCells(4,:));% =1 for directories, =0 for files |
---|
| 324 | for ilist=1:numel(ListFiles) |
---|
[733] | 325 | if check_keep(ilist)% loop on eligible DataSeries folders |
---|
| 326 | DataSeries=fullfile(CampaignPath,ListExperiments{iexp},ListFiles{ilist});%source folder |
---|
[651] | 327 | if ~isempty(MirrorPath) |
---|
| 328 | mirror=fullfile(MirrorPath,ListExperiments{iexp},ListFiles{ilist}); |
---|
[741] | 329 | if exist(mirror,'file')% if mirror already exists as a file or folder |
---|
[733] | 330 | [tild,msg]=fileattrib(mirror); |
---|
| 331 | if strcmp(msg.Name,mirror)%if the mirror name already exists as a local file or dir |
---|
[741] | 332 | if msg.directory% case of a folder |
---|
[733] | 333 | answer=msgbox_uvmat('INPUT_Y-N',['replace local folder ' msg.Name ' by a link to the source dir']); |
---|
| 334 | if strcmp(answer,'Yes') |
---|
| 335 | [ss,msg]=rmdir(mirror); |
---|
| 336 | if ss==1 |
---|
| 337 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
| 338 | else |
---|
| 339 | msgbox_uvmat('ERROR',['enable to delete local folder: ' msg]); |
---|
| 340 | end |
---|
| 341 | end |
---|
[741] | 342 | else % case of an existing mirror file |
---|
[733] | 343 | answer=msgbox_uvmat('INPUT_Y-N',['replace local file ' msg.Name ' by a link to the source file']); |
---|
| 344 | if strcmp(answer,'Yes') |
---|
| 345 | delete(mirror); |
---|
[741] | 346 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
[733] | 347 | end |
---|
| 348 | end |
---|
| 349 | end |
---|
[741] | 350 | else% create mirror to the data series if needed |
---|
| 351 | system(['ln -s ' DataSeries ' ' mirror]); % create the link to the source folder |
---|
[651] | 352 | end |
---|
[1063] | 353 | if isempty(find(strcmp(ListFiles{ilist},DataSeries), 1))% if the item is not already in DataSeries |
---|
[733] | 354 | if check_dir(ilist) |
---|
| 355 | ListFiles{ilist}=['+/' ListFiles{ilist}];%mark dir by '+' in the list |
---|
| 356 | end |
---|
[1063] | 357 | DataSeries=[DataSeries;ListFiles{ilist}]; %append the item to the list |
---|
[651] | 358 | end |
---|
| 359 | end |
---|
[570] | 360 | end |
---|
[569] | 361 | end |
---|
| 362 | end |
---|
| 363 | end |
---|
[1063] | 364 | set(handles.DataSeries,'String',sort(DataSeries)) |
---|
[569] | 365 | |
---|
| 366 | %------------------------------------------------------------------------ |
---|
| 367 | % --- Executes on button press in CampaignDoc. |
---|
| 368 | function CampaignDoc_Callback(hObject, eventdata, handles) |
---|
| 369 | %------------------------------------------------------------------------ |
---|
[651] | 370 | 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] | 371 | if ~isequal(answer{1},'OK') |
---|
| 372 | return |
---|
| 373 | end |
---|
| 374 | set(handles.ListExperiments,'Value',1) |
---|
| 375 | ListExperiments_Callback(hObject, eventdata, handles)%update the overview of the experiment directories |
---|
[581] | 376 | DataviewData=get(handles.browse_data,'UserData'); |
---|
[569] | 377 | List=DataviewData.List; |
---|
| 378 | Currentpath=get(handles.SourceDir,'String'); |
---|
| 379 | [Currentpath,Campaign,DirExt]=fileparts(Currentpath); |
---|
| 380 | Campaign=[Campaign DirExt]; |
---|
| 381 | t=xmltree; |
---|
| 382 | t=set(t,1,'name','CampaignDoc'); |
---|
| 383 | t = attributes(t,'add',1,'source','directory'); |
---|
| 384 | SubCampaignTest=get(handles.SubCampaignTest,'Value'); |
---|
| 385 | root_uid=1; |
---|
| 386 | if SubCampaignTest |
---|
| 387 | %TO DO open an exoiting xml doc |
---|
| 388 | [t,root_uid]=add(t,1,'element','SubCampaign'); |
---|
| 389 | t =attributes(t,'add',root_uid,'DirName',Campaign); |
---|
| 390 | end |
---|
| 391 | for iexp=1:length(List.Experiment) |
---|
| 392 | set(handles.ListExperiments,'Value',iexp+1) |
---|
| 393 | drawnow |
---|
| 394 | test_mod=0; |
---|
| 395 | [t,uid_exp]=add(t,root_uid,'element','Experiment'); |
---|
| 396 | t = attributes(t,'add',uid_exp,'i',num2str(iexp)); |
---|
| 397 | ExpName=List.Experiment{iexp}.name; |
---|
| 398 | t = attributes(t,'add',uid_exp,'DirName',List.Experiment{iexp}.name); |
---|
| 399 | |
---|
| 400 | if isfield(List.Experiment{iexp},'Device') |
---|
| 401 | for idevice=1:length(List.Experiment{iexp}.Device) |
---|
| 402 | [t,uid_device]=add(t,uid_exp,'element','Device'); |
---|
| 403 | DeviceName=List.Experiment{iexp}.Device{idevice}.name; |
---|
| 404 | t = attributes(t,'add',uid_device,'DirName',List.Experiment{iexp}.Device{idevice}.name); |
---|
| 405 | if isfield(List.Experiment{iexp}.Device{idevice},'xmlfile') |
---|
| 406 | for ixml=1:length(List.Experiment{iexp}.Device{idevice}.xmlfile) |
---|
| 407 | FileName=List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}; |
---|
| 408 | [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,[],FileName,SubCampaignTest); |
---|
| 409 | if test |
---|
[651] | 410 | disp([List.Experiment{iexp}.Device{idevice}.xmlfile{ixml} ' , Heading updated']) |
---|
[569] | 411 | end |
---|
| 412 | if isequal(Title,'ImaDoc') |
---|
| 413 | [t,uid_xml]=add(t,uid_device,'element','ImaDoc'); |
---|
| 414 | t = attributes(t,'add',uid_xml,'source','file'); |
---|
| 415 | [t]=add(t,uid_xml,'chardata',List.Experiment{iexp}.Device{idevice}.xmlfile{ixml}); |
---|
| 416 | end |
---|
| 417 | end |
---|
| 418 | elseif isfield(List.Experiment{iexp}.Device{idevice},'Record') |
---|
| 419 | for irecord=1:length(List.Experiment{iexp}.Device{idevice}.Record) |
---|
| 420 | RecordName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.name; |
---|
| 421 | [t,uid_record]=add(t,uid_device,'element','Record'); |
---|
| 422 | t = attributes(t,'add',uid_record,'DirName',RecordName); |
---|
| 423 | if isfield(List.Experiment{iexp}.Device{idevice}.Record{irecord},'xmlfile') |
---|
| 424 | for ixml=1:length(List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile) |
---|
| 425 | FileName=List.Experiment{iexp}.Device{idevice}.Record{irecord}.xmlfile{ixml}; |
---|
| 426 | [Title,test]=check_heading(Currentpath,Campaign,ExpName,DeviceName,RecordName,FileName,SubCampaignTest); |
---|
| 427 | if test |
---|
[651] | 428 | disp([FileName ' , Heading updated']) |
---|
[569] | 429 | end |
---|
| 430 | [t,uid_xml]=add(t,uid_record,'element','ImaDoc'); |
---|
| 431 | t = attributes(t,'add',uid_xml,'source','file'); |
---|
| 432 | [t]=add(t,uid_xml,'chardata',FileName); |
---|
| 433 | end |
---|
| 434 | end |
---|
| 435 | end |
---|
| 436 | end |
---|
| 437 | end |
---|
| 438 | end |
---|
| 439 | end |
---|
| 440 | set(handles.ListExperiments,'Value',1) |
---|
| 441 | outputdir=get(handles.SourceDir,'String'); |
---|
| 442 | [path,dirname]=fileparts(outputdir); |
---|
| 443 | outputfile=fullfile(outputdir,[dirname '.xml']); |
---|
| 444 | %campaigndoc(t); |
---|
| 445 | save(t,outputfile) |
---|
| 446 | |
---|
| 447 | |
---|
[1059] | 448 | |
---|
[569] | 449 | %------------------------------------------------------------------------ |
---|
| 450 | % --- Executes on button press in OK. |
---|
[651] | 451 | %------------------------------------------------------------------------ |
---|
[569] | 452 | function OK_Callback(hObject, eventdata, handles) |
---|
[651] | 453 | |
---|
[569] | 454 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
| 455 | Campaign=get(handles.MirrorDir,'String'); |
---|
| 456 | else |
---|
| 457 | Campaign=get(handles.SourceDir,'String'); |
---|
| 458 | end |
---|
[931] | 459 | handles.output=[]; |
---|
[569] | 460 | handles.output.Campaign=Campaign; |
---|
| 461 | Experiment=get(handles.ListExperiments,'String'); |
---|
| 462 | IndicesExp=get(handles.ListExperiments,'Value'); |
---|
| 463 | if ~isequal(IndicesExp,1)% if first element ('*') selected all the experiments are selected |
---|
| 464 | Experiment=Experiment(IndicesExp);% use the selection of the list of experiments |
---|
| 465 | end |
---|
[651] | 466 | Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir |
---|
[1063] | 467 | Device=get(handles.DataSeries,'String'); |
---|
| 468 | Value=get(handles.DataSeries,'Value'); |
---|
[569] | 469 | Device=Device(Value); |
---|
[651] | 470 | Device=regexprep(Device,'^\+/','');% remove the +/ used to mark dir |
---|
[741] | 471 | Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link |
---|
[569] | 472 | handles.output.Experiment=Experiment; |
---|
[651] | 473 | handles.output.DataSeries=Device; |
---|
[569] | 474 | guidata(hObject, handles);% Update handles structure |
---|
[581] | 475 | uiresume(handles.browse_data); |
---|
[569] | 476 | drawnow |
---|
| 477 | |
---|
[651] | 478 | %------------------------------------------------------------------------ |
---|
| 479 | % --- Executes on button press in HELP. |
---|
| 480 | function HELP_Callback(hObject, eventdata, handles) |
---|
| 481 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
| 482 | pathelp=fileparts(path_to_uvmat); |
---|
| 483 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
| 484 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
[569] | 485 | else |
---|
[651] | 486 | web([helpfile '#dataview']) |
---|
[569] | 487 | end |
---|
| 488 | |
---|
[651] | 489 | %------------------------------------------------------------------------ |
---|
[581] | 490 | % --- Executes when user attempts to close browse_data. |
---|
[651] | 491 | %------------------------------------------------------------------------ |
---|
[1059] | 492 | function closefcn(gcbo, eventdata) |
---|
| 493 | % if isequal(get(handles.browse_data, 'waitstatus'), 'waiting') |
---|
| 494 | % % The GUI is still in UIWAIT, us UIRESUME |
---|
| 495 | % handles.output = get(hObject,'String'); |
---|
| 496 | % guidata(hObject, handles); % Update handles structure |
---|
| 497 | % uiresume(handles.browse_data); |
---|
| 498 | % else |
---|
| 499 | % % The GUI is no longer waiting, just close it |
---|
| 500 | % delete(handles.browse_data); |
---|
| 501 | % end |
---|
| 502 | hseries=findobj(allchild(0),'Tag','series'); |
---|
| 503 | if ~isempty(hseries) |
---|
| 504 | hreplicate=findobj(hseries,'Tag','Replicate'); |
---|
| 505 | set(hreplicate,'Value',0) |
---|
[569] | 506 | end |
---|
[1059] | 507 | hcalib=findobj(allchild(0),'Tag','geometry_calib'); |
---|
| 508 | if ~isempty(hcalib) |
---|
| 509 | hreplicate=findobj(hcalib,'Tag','Replicate'); |
---|
| 510 | set(hreplicate,'Value',0) |
---|
| 511 | end |
---|
[569] | 512 | |
---|
[651] | 513 | %------------------------------------------------------------------------ |
---|
[569] | 514 | % --- Executes on key press over figure1 with no controls selected. |
---|
[651] | 515 | %------------------------------------------------------------------------ |
---|
[581] | 516 | function browse_data_KeyPressFcn(hObject, eventdata, handles) |
---|
[651] | 517 | |
---|
[569] | 518 | % Check for "enter" or "escape" |
---|
| 519 | if isequal(get(hObject,'CurrentKey'),'escape') |
---|
| 520 | % User said no by hitting escape |
---|
| 521 | handles.output = 'Cancel'; |
---|
| 522 | |
---|
| 523 | % Update handles structure |
---|
| 524 | guidata(hObject, handles); |
---|
| 525 | |
---|
[581] | 526 | uiresume(handles.browse_data); |
---|
[569] | 527 | end |
---|
| 528 | if isequal(get(hObject,'CurrentKey'),'return') |
---|
[581] | 529 | uiresume(handles.browse_data); |
---|
[569] | 530 | end |
---|
[733] | 531 | |
---|
| 532 | |
---|
[1059] | 533 | % --- Executes on button press in Up. |
---|
| 534 | function Up_Callback(hObject, eventdata, handles) |
---|
| 535 | SourceDir=get(handles.SourceDir,'String'); |
---|
| 536 | browse_data(SourceDir) |
---|
| 537 | |
---|
| 538 | |
---|
| 539 | % --- Executes on button press in Down. |
---|
| 540 | function Down_Callback(hObject, eventdata, handles) |
---|
| 541 | SourceDir=get(handles.SourceDir,'String'); |
---|
| 542 | ListExperiments=get(handles.ListExperiments,'String'); |
---|
| 543 | list_val=get(handles.ListExperiments,'Value'); |
---|
| 544 | SourceFolder=regexprep(ListExperiments{list_val(1)},'+',''); |
---|
| 545 | set(handles.SourceDir,'String',fullfile(SourceDir,SourceFolder)) |
---|
[1063] | 546 | DataSeries=get(handles.DataSeries,'String'); |
---|
| 547 | ValueDevice=get(handles.DataSeries,'Value'); |
---|
| 548 | set(handles.ListExperiments,'String',DataSeries) |
---|
[1059] | 549 | set(handles.ListExperiments,'Value',ValueDevice) |
---|
| 550 | ListExperiments_Callback(hObject, [], handles) |
---|
[1063] | 551 | |
---|
| 552 | |
---|
| 553 | % --- Executes on selection change in DataSeries. |
---|
| 554 | function DataSeries_Callback(hObject, eventdata, handles) |
---|
| 555 | |
---|
| 556 | |
---|
| 557 | % --- Executes on button press in CheckDevices. |
---|
| 558 | function CheckDevices_Callback(hObject, eventdata, handles) |
---|
| 559 | if get(handles.CheckDevices,'Value') |
---|
| 560 | set(handles.ListDevices,'Visible','on') |
---|
[1064] | 561 | ListDevices=get(handles.DataSeries,'String'); |
---|
| 562 | Index=get(handles.DataSeries,'Value'); |
---|
| 563 | set(handles.ListDevices,'String',ListDevices) |
---|
| 564 | set(handles.ListDevices,'Value',Index) |
---|
| 565 | set(handles.DataSeries,'Value',1) |
---|
| 566 | if strcmp(get(handles.MirrorDir,'Visible'),'on') |
---|
| 567 | MirrorPath=get(handles.MirrorDir,'String'); |
---|
| 568 | else |
---|
| 569 | MirrorPath=get(handles.SourceDir,'String'); |
---|
| 570 | end |
---|
| 571 | IndexExperiment=get(handles.ListExperiments,'Value'); |
---|
| 572 | ListExperiment=get(handles.ListExperiments,'String'); |
---|
| 573 | Experiment=ListExperiment{get(handles.ListExperiments,'Value')}; |
---|
| 574 | Experiment=regexprep(Experiment,'^\+/','');% remove the +/ used to mark dir |
---|
| 575 | Experiment=regexprep(Experiment,'^~','');% remove the ~ used to mark symbolic link |
---|
| 576 | Device=regexprep(ListDevices{Index},'^\+/','');% remove the +/ used to mark dir |
---|
| 577 | Device=regexprep(Device,'^~','');% remove the ~ used to mark symbolic link |
---|
| 578 | DataSeries=dir(fullfile(MirrorPath,Experiment,Device)); |
---|
| 579 | DataSeriesCell=struct2cell(DataSeries); |
---|
| 580 | set(handles.DataSeries,'String',DataSeriesCell(1,:)') |
---|
[1063] | 581 | else |
---|
[1064] | 582 | ListDevices=get(handles.ListDevices,'String'); |
---|
| 583 | Index=get(handles.ListDevices,'Value'); |
---|
[1063] | 584 | set(handles.ListDevices,'Visible','off') |
---|
[1064] | 585 | set(handles.DataSeries,'String',ListDevices) |
---|
| 586 | set(handles.DataSeries,'Value',Index) |
---|
[1063] | 587 | end |
---|