[2] | 1 | %'series': master function associated to the GUI series.m for analysis field series |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function varargout = series(varargin) |
---|
| 4 | % associated with the GUI series.fig |
---|
| 5 | % |
---|
| 6 | %INPUT |
---|
| 7 | % param: structure with input parameters (link with the GUI uvmat) |
---|
[446] | 8 | % .menu_coord_str: string for the TransformName (menu for coordinate transforms) |
---|
| 9 | % .menu_coord_val: value for TransformName (menu for coordinate transforms) |
---|
[2] | 10 | % .FileName: input file name |
---|
| 11 | % .FileName_1: second input file name |
---|
| 12 | % .list_field: menu of input fields |
---|
| 13 | % .index_fields: chosen index |
---|
| 14 | % .civ1=0 or 1, .interp1, ... : input civ field type |
---|
| 15 | % |
---|
| 16 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 17 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
| 18 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 19 | % This file is part of the toolbox UVMAT. |
---|
| 20 | % |
---|
| 21 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 22 | % it under the terms of the GNU General Public License as published by |
---|
| 23 | % the Free Software Foundation; either version 2 of the License, or |
---|
| 24 | % (at your option) any later version. |
---|
| 25 | % |
---|
| 26 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 27 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 28 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 29 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
| 30 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 31 | |
---|
[408] | 32 | %------------------------------------------------------------------------ |
---|
| 33 | %------------------------------------------------------------------------ |
---|
| 34 | % I - MAIN FUNCTION series |
---|
| 35 | %------------------------------------------------------------------------ |
---|
| 36 | %------------------------------------------------------------------------ |
---|
[2] | 37 | function varargout = series(varargin) |
---|
| 38 | |
---|
| 39 | % Begin initialization code - DO NOT EDIT |
---|
| 40 | gui_Singleton = 1; |
---|
| 41 | gui_State = struct('gui_Name', mfilename, ... |
---|
| 42 | 'gui_Singleton', gui_Singleton, ... |
---|
| 43 | 'gui_OpeningFcn', @series_OpeningFcn, ... |
---|
| 44 | 'gui_OutputFcn', @series_OutputFcn, ... |
---|
| 45 | 'gui_LayoutFcn', [] , ... |
---|
| 46 | 'gui_Callback', []); |
---|
| 47 | if nargin && ischar(varargin{1}) |
---|
| 48 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
| 49 | end |
---|
| 50 | |
---|
| 51 | if nargout |
---|
| 52 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
| 53 | else |
---|
| 54 | gui_mainfcn(gui_State, varargin{:}); |
---|
| 55 | end |
---|
| 56 | % End initialization code - DO NOT EDIT |
---|
| 57 | |
---|
| 58 | %-------------------------------------------------------------------------- |
---|
| 59 | % --- Executes just before series is made visible. |
---|
| 60 | %-------------------------------------------------------------------------- |
---|
[591] | 61 | function series_OpeningFcn(hObject, eventdata, handles,Param) |
---|
| 62 | |
---|
[2] | 63 | % Choose default command line output for series |
---|
| 64 | handles.output = hObject; |
---|
| 65 | % Update handles structure |
---|
| 66 | guidata(hObject, handles); |
---|
[591] | 67 | |
---|
| 68 | %% initial settings |
---|
[156] | 69 | drawnow |
---|
[244] | 70 | set(hObject,'Units','pixels') |
---|
[526] | 71 | set(handles.PairString,'ColumnName',{'pairs'}) |
---|
[598] | 72 | set(handles.PairString,'ColumnEditable',false) |
---|
[408] | 73 | set(handles.PairString,'ColumnFormat',{'char'}) |
---|
| 74 | set(handles.PairString,'Data',{''}) |
---|
[526] | 75 | series_ResizeFcn(hObject, eventdata, handles)%resize table according to series GUI size |
---|
[332] | 76 | set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display) |
---|
[591] | 77 | % check default input data |
---|
| 78 | if ~exist('Param','var') |
---|
| 79 | Param=[]; %default |
---|
| 80 | end |
---|
| 81 | |
---|
| 82 | %% default list of functions in the mebu ActionName |
---|
| 83 | ActionList={'check_data_files';'aver_stat';'time_series';'merge_proj'};% WARNING: fits with nb_builtin_ACTION=4 in ActionName_callback |
---|
| 84 | [path_series,name,ext]=fileparts(which('series'));% path to the GUI series |
---|
| 85 | path_series_fct=fullfile(path_series,'series');%path of the functions in subdirectroy 'series' |
---|
[598] | 86 | %path_bin=fullfile(path_series,'bin');%path of the binary functions (compiled) |
---|
[591] | 87 | ActionPathList=regexprep(ActionList,'^.+$',path_series_fct);% set path=path_series to each function in the list ('^.+$'=any non empty nbre of char form beginning to end of char string) |
---|
[598] | 88 | ActionPathList=[ActionPathList ActionPathList];% set path to .sh commands for compiled functions |
---|
[591] | 89 | ActionExtList={'.m';'.sh'};% default choice of extensions (Matlab fct .m or compiled version .sh) |
---|
| 90 | RunModeList={'local';'background'};% default choice of extensions (Matlab fct .m or compiled version .sh) |
---|
| 91 | [s,w]=system('oarstat');% look for cluster system 'oar' |
---|
| 92 | if isequal(s,0) |
---|
| 93 | RunModeList=[RunModeList;{'cluster_oar'}]; |
---|
| 94 | end |
---|
| 95 | [s,w]=system('qstat');% look for cluster system 'sge' |
---|
| 96 | if isequal(s,0) |
---|
| 97 | RunModeList=[RunModeList;{'cluster_sge'}]; |
---|
| 98 | end |
---|
| 99 | set(handles.RunMode,'String',RunModeList) |
---|
| 100 | |
---|
| 101 | %% default list of functions in the mebu TransformName |
---|
| 102 | TransformList={'';'sub_field';'phys';'phys_polar'};% WARNING: must fit with the corresponding menu in uvmat and nb_builtin_transform=4 in TransformName_callback |
---|
| 103 | path_transform_fct=fullfile(path_series,'transform_field'); |
---|
| 104 | TransformPathList=regexprep(TransformList,'^.+$',path_transform_fct);% set path=path_transform_fct to each function in the list ('^.+$'=any non empty nbre of char form beginning to end of char string) |
---|
| 105 | |
---|
| 106 | %% load the personal file uvmat_perso.mat |
---|
[2] | 107 | dir_perso=prefdir; |
---|
| 108 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 109 | if exist(profil_perso,'file') |
---|
[591] | 110 | h=load (profil_perso); |
---|
| 111 | %get the list of previous input files in the upper bar menu Open |
---|
| 112 | if isfield(h,'MenuFile') |
---|
| 113 | for ifile=1:min(length(h.MenuFile),5) |
---|
| 114 | eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});']) |
---|
| 115 | end |
---|
| 116 | end |
---|
| 117 | %get the menu of actions |
---|
| 118 | if isfield(h,'ActionExtListUser') && iscell(h.ActionExtListUser) |
---|
| 119 | ActionExtList=[ActionExtList; h.ActionExtListUser]; |
---|
| 120 | end |
---|
| 121 | if isfield(h,'ActionListUser') && iscell(h.ActionListUser) && isfield(h,'ActionPathListUser') && iscell(h.ActionPathListUser) |
---|
| 122 | ActionList=[ActionList;h.ActionListUser]; |
---|
| 123 | ActionPathList=[ActionPathList;h.ActionPathListUser]; |
---|
| 124 | end |
---|
| 125 | %get the menu of transform fct |
---|
| 126 | if isfield(h,'TransformListUser') && iscell(h.TransformListUser) && isfield(h,'TransformPathListUser') && iscell(h.TransformPathListUser) |
---|
| 127 | TransformList=[TransformList;h.TransformListUser]; |
---|
| 128 | TransformPathList=[TransformPathList;h.TransformPathListUser]; |
---|
| 129 | end |
---|
[2] | 130 | end |
---|
| 131 | |
---|
[591] | 132 | %% selection of the input Action fct |
---|
| 133 | ActionCheckExist=false(size(ActionList)); |
---|
| 134 | for ilist=1:numel(ActionList) |
---|
| 135 | ActionCheckExist(ilist)=exist(fullfile(ActionPathList{ilist},[ActionList{ilist} '.m']),'file'); |
---|
[2] | 136 | end |
---|
[591] | 137 | ActionPathList=ActionPathList(ActionCheckExist,:); |
---|
| 138 | ActionList=ActionList(ActionCheckExist); |
---|
| 139 | set(handles.ActionName,'String',[ActionList;{'more...'}]) |
---|
| 140 | set(handles.ActionName,'UserData',ActionPathList) |
---|
| 141 | ActionIndex=[]; |
---|
| 142 | if isfield(Param,'ActionName')% copy the selected menu index transferred in Param from uvmat |
---|
| 143 | ActionIndex=find(strcmp(Param.ActionName,ActionList),1); |
---|
[2] | 144 | end |
---|
[591] | 145 | if isempty(ActionIndex) |
---|
| 146 | ActionIndex=1; |
---|
[2] | 147 | end |
---|
[591] | 148 | set(handles.ActionName,'Value',ActionIndex) |
---|
| 149 | set(handles.ActionPath,'String',ActionPathList{ActionIndex}) |
---|
| 150 | set(handles.ActionExt,'Value',1) |
---|
| 151 | set(handles.ActionExt,'String',ActionExtList) |
---|
[2] | 152 | |
---|
[591] | 153 | %% selection of the input transform fct |
---|
| 154 | TransformCheckExist=false(size(TransformList)); |
---|
| 155 | TransformCheckExist(1)=1;%the first option is blank: no transform, always allowed |
---|
| 156 | for ilist=2:numel(TransformList) |
---|
| 157 | TransformCheckExist(ilist)=exist(fullfile(TransformPathList{ilist},[TransformList{ilist} '.m']),'file'); |
---|
[2] | 158 | end |
---|
[591] | 159 | TransformPathList=TransformPathList(TransformCheckExist); |
---|
| 160 | TransformList=TransformList(TransformCheckExist); |
---|
| 161 | set(handles.TransformName,'String',[TransformList;{'more...'}]) |
---|
| 162 | set(handles.TransformName,'UserData',TransformPathList) |
---|
| 163 | TransformIndex=[]; |
---|
| 164 | if isfield(Param,'TransformName')% copy the selected menu index transferred in Param from uvmat |
---|
| 165 | TransformIndex=find(strcmp(Param.TransformName,TransformList),1); |
---|
[526] | 166 | end |
---|
[591] | 167 | if isempty(TransformIndex) |
---|
| 168 | TransformIndex=1; |
---|
[526] | 169 | end |
---|
[591] | 170 | set(handles.TransformName,'Value',TransformIndex) |
---|
| 171 | set(handles.TransformPath,'String',TransformPathList{TransformIndex}) |
---|
| 172 | |
---|
| 173 | %% fields input initialisation |
---|
| 174 | if isfield(Param,'list_fields')&& isfield(Param,'index_fields') &&~isempty(Param.list_fields) &&~isempty(Param.index_fields) |
---|
| 175 | set(handles.FieldName,'String',Param.list_fields);% list menu fields |
---|
| 176 | set(handles.FieldName,'Value',Param.index_fields);% selected string index |
---|
[2] | 177 | end |
---|
[591] | 178 | if isfield(Param,'Coord_x_str')&& isfield(Param,'Coord_x_val') |
---|
| 179 | set(handles.Coord_x,'String',Param.Coord_x_str);% list menu fields |
---|
| 180 | set(handles.Coord_x,'Value',Param.Coord_x_val);% selected string index |
---|
[38] | 181 | end |
---|
[591] | 182 | if isfield(Param,'Coord_y_str')&& isfield(Param,'Coord_y_val') |
---|
| 183 | set(handles.Coord_y,'String',Param.Coord_y_str);% list menu fields |
---|
| 184 | set(handles.Coord_y,'Value',Param.Coord_y_val);% selected string index |
---|
[2] | 185 | end |
---|
[39] | 186 | |
---|
[472] | 187 | %% Adjust the GUI according to the binaries available in PARAM.xml |
---|
[594] | 188 | % path_uvmat=fileparts(which('uvmat')); %path to civ |
---|
| 189 | % addpath (path_uvmat) ; %add the path to civ, (useful in case of change of working directory after civ has been s opened in the working directory) |
---|
| 190 | % errormsg=[];%default error message |
---|
| 191 | % xmlfile='PARAM.xml'; |
---|
| 192 | % if exist(xmlfile,'file') |
---|
| 193 | % try |
---|
| 194 | % t=xmltree(xmlfile); |
---|
| 195 | % sparam=convert(t); |
---|
| 196 | % catch ME |
---|
| 197 | % errormsg={' Unable to read the file PARAM.xml defining the binaries:';ME.message}; |
---|
| 198 | % end |
---|
| 199 | % else |
---|
| 200 | % errormsg=[xmlfile ' not found: path to binaries undefined']; |
---|
| 201 | % end |
---|
| 202 | % if ~isempty(errormsg) |
---|
| 203 | % msgbox_uvmat('WARNING',errormsg); |
---|
| 204 | % end |
---|
| 205 | % test_batch=0;%default: ,no batch mode available |
---|
| 206 | % if isfield(sparam,'BatchParam') && isfield(sparam.BatchParam,'BatchMode') |
---|
| 207 | % test_batch=strcmp(sparam.BatchParam.BatchMode,'sge'); %sge is currently the only implemented batch mod |
---|
| 208 | % end |
---|
| 209 | % RUNVal=get(handles.RunMode,'Value'); |
---|
| 210 | % if test_batch==0 |
---|
| 211 | % if RUNVal>2 |
---|
| 212 | % set(handles.RunMode,'Value',1) |
---|
| 213 | % end |
---|
| 214 | % set(handles.RunMode,'String',{'local';'background'}) |
---|
| 215 | % else |
---|
| 216 | % set(handles.RunMode,'String',{'local';'background';'cluster'}) |
---|
| 217 | % end |
---|
[2] | 218 | |
---|
[591] | 219 | %% introduce the input file name(s) if defined from input Param |
---|
| 220 | if isfield(Param,'FileName') |
---|
| 221 | InputTable={'','','','',''}; % refresh the file input table |
---|
| 222 | set(handles.InputTable,'Data',InputTable) |
---|
| 223 | if isfield(Param,'FileName_1') |
---|
| 224 | display_file_name(handles,Param.FileName_1,0) |
---|
| 225 | display_file_name(handles,Param.FileName,1) |
---|
| 226 | else |
---|
| 227 | display_file_name(handles,Param.FileName,0) |
---|
| 228 | end |
---|
| 229 | end |
---|
| 230 | if isfield(Param,'incr_i') |
---|
| 231 | set(handles.num_incr_i,'String',num2str(Param.incr_i)) |
---|
| 232 | end |
---|
| 233 | if isfield(Param,'incr_j') |
---|
| 234 | set(handles.num_incr_j,'String',num2str(Param.incr_j)) |
---|
| 235 | end |
---|
| 236 | |
---|
| 237 | |
---|
[408] | 238 | %------------------------------------------------------------------------ |
---|
[2] | 239 | % --- Outputs from this function are returned to the command line. |
---|
| 240 | function varargout = series_OutputFcn(hObject, eventdata, handles) |
---|
[408] | 241 | %------------------------------------------------------------------------ |
---|
[2] | 242 | % varargout cell array for returning output args (see VARARGOUT); |
---|
| 243 | % hObject handle to figure |
---|
| 244 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 245 | % handles structure with handles and user data (see GUIDATA) |
---|
| 246 | % Get default command line output from handles structure |
---|
| 247 | varargout{1} = handles.output; |
---|
| 248 | |
---|
[408] | 249 | %------------------------------------------------------------------------ |
---|
| 250 | %------------------------------------------------------------------------ |
---|
| 251 | % II - FUNCTIONS FOR INTRODUCING THE INPUT FILES |
---|
| 252 | % automatically sets the global properties when the rootfile name is introduced |
---|
[446] | 253 | % then activate the view-field actionname if selected |
---|
[408] | 254 | % it is activated either by clicking on the RootPath window or by the |
---|
| 255 | % browser |
---|
| 256 | %------------------------------------------------------------------------ |
---|
| 257 | %------------------------------------------------------------------------ |
---|
[2] | 258 | function MenuBrowse_Callback(hObject, eventdata, handles) |
---|
[408] | 259 | %------------------------------------------------------------------------ |
---|
[606] | 260 | %get the previous input file in the Input Table |
---|
| 261 | oldfile=''; %default |
---|
[350] | 262 | InputTable=get(handles.InputTable,'Data'); |
---|
[606] | 263 | if isequal(InputTable(:,1),[{''};{''};{''};{''}])%open the personal file for empty previous input |
---|
| 264 | dir_perso=prefdir; |
---|
| 265 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 266 | if exist(profil_perso,'file') |
---|
| 267 | h=load (profil_perso); |
---|
| 268 | if isfield(h,'RootPath')&&ischar(h.RootPath) |
---|
| 269 | oldfile=h.RootPath; |
---|
[472] | 270 | end |
---|
[463] | 271 | end |
---|
[606] | 272 | else% select the previous file as the first line of the input table |
---|
| 273 | oldfile=fullfile(InputTable{1,1},InputTable{1,2},InputTable{1,3}); |
---|
| 274 | end |
---|
| 275 | hfig=uigetfile_uvmat('file browser',fileparts(fileparts(oldfile))); |
---|
| 276 | uiwait(hfig); |
---|
| 277 | if ishandle(hfig) % stop if browser closed without selection |
---|
| 278 | fileinput=get(hfig,'UserData');% retrieve the input file selection |
---|
| 279 | delete(hfig) |
---|
[408] | 280 | display_file_name(handles,fileinput,0) |
---|
[2] | 281 | end |
---|
[606] | 282 | % |
---|
| 283 | % [FileName, PathName] = uigetfile( ... |
---|
| 284 | % {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)'; |
---|
| 285 | % '*.xml', '.xml files '; ... |
---|
| 286 | % '*.xls', '.xls files '; ... |
---|
| 287 | % '*.png','.png image files'; ... |
---|
| 288 | % '*.tif','.tif image files'; ... |
---|
| 289 | % '*.avi;*.AVI','.avi movie files'; ... |
---|
| 290 | % '*.nc','.netcdf files'; ... |
---|
| 291 | % '*.*', 'All Files (*.*)'}, ... |
---|
| 292 | % 'Pick a file',oldfile); |
---|
| 293 | % fileinput=[PathName FileName];%complete file name |
---|
| 294 | % [path,name,ext]=fileparts(fileinput); |
---|
| 295 | % if isequal(ext,'.xml') |
---|
| 296 | % [Param,Heading]=xml2struct(fileinput); |
---|
| 297 | % if ~strcmp(Heading,'Series') |
---|
| 298 | % msg_box_uvmat('ERROR','xml file heading is not <Series>') |
---|
| 299 | % else |
---|
| 300 | % fill_GUI(Param,handles.series);%fill the GUI with the parameters retrieved from the xml file |
---|
| 301 | % if isfield(Param,'CheckObject')&& Param.CheckObject |
---|
| 302 | % set_object(Param.ProjObject) |
---|
| 303 | % end |
---|
| 304 | % set(handles.REFRESH,'UserData',1:size(Param.InputTable,1)) |
---|
| 305 | % REFRESH_Callback([],[], handles) |
---|
| 306 | % return |
---|
| 307 | % end |
---|
| 308 | % elseif isequal(ext,'.xls') |
---|
| 309 | % msg_box_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer |
---|
| 310 | % else |
---|
| 311 | % display_file_name(handles,fileinput,0) |
---|
| 312 | % end |
---|
[2] | 313 | |
---|
| 314 | % -------------------------------------------------------------------- |
---|
| 315 | function MenuFile_1_Callback(hObject, eventdata, handles) |
---|
| 316 | fileinput=get(handles.MenuFile_1,'Label'); |
---|
[408] | 317 | display_file_name(handles,fileinput,0) |
---|
[2] | 318 | |
---|
| 319 | % -------------------------------------------------------------------- |
---|
| 320 | function MenuFile_2_Callback(hObject, eventdata, handles) |
---|
| 321 | fileinput=get(handles.MenuFile_2,'Label'); |
---|
[408] | 322 | display_file_name(handles,fileinput,0) |
---|
[2] | 323 | |
---|
| 324 | % -------------------------------------------------------------------- |
---|
| 325 | function MenuFile_3_Callback(hObject, eventdata, handles) |
---|
| 326 | fileinput=get(handles.MenuFile_3,'Label'); |
---|
[408] | 327 | display_file_name( handles,fileinput,0) |
---|
[2] | 328 | |
---|
| 329 | % -------------------------------------------------------------------- |
---|
| 330 | function MenuFile_4_Callback(hObject, eventdata, handles) |
---|
| 331 | fileinput=get(handles.MenuFile_4,'Label'); |
---|
[408] | 332 | display_file_name(handles,fileinput,0) |
---|
[2] | 333 | |
---|
| 334 | % -------------------------------------------------------------------- |
---|
| 335 | function MenuFile_5_Callback(hObject, eventdata, handles) |
---|
| 336 | fileinput=get(handles.MenuFile_5,'Label'); |
---|
[408] | 337 | display_file_name(handles,fileinput,0) |
---|
[2] | 338 | |
---|
| 339 | % -------------------------------------------------------------------- |
---|
| 340 | function MenuBrowse_insert_Callback(hObject, eventdata, handles) |
---|
[350] | 341 | InputTable=get(handles.InputTable,'Data'); |
---|
| 342 | RootPathCell=InputTable(:,1); |
---|
| 343 | SubDirCell=InputTable(:,3); |
---|
| 344 | RootFileCell=InputTable(:,2); |
---|
[2] | 345 | oldfile=''; %default |
---|
[206] | 346 | if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box |
---|
[2] | 347 | dir_perso=prefdir; |
---|
| 348 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 349 | if exist(profil_perso,'file') |
---|
| 350 | h=load (profil_perso); |
---|
| 351 | if isfield(h,'filebase')&ischar(h.filebase) |
---|
| 352 | oldfile=h.filebase; |
---|
| 353 | end |
---|
| 354 | if isfield(h,'RootPath')&ischar(h.RootPath) |
---|
| 355 | oldfile=h.RootPath; |
---|
| 356 | end |
---|
| 357 | end |
---|
| 358 | else |
---|
| 359 | oldfile=fullfile(RootPathCell{1},RootFileCell{1}); |
---|
| 360 | end |
---|
| 361 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
| 362 | {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)'; |
---|
| 363 | '*.xml', '.xml files '; ... |
---|
| 364 | '*.xls', '.xls files '; ... |
---|
| 365 | '*.png','.png image files'; ... |
---|
| 366 | '*.avi;*.AVI','.avi movie files'; ... |
---|
| 367 | '*.nc','.netcdf files'; ... |
---|
| 368 | '*.*', 'All Files (*.*)'}, ... |
---|
| 369 | 'Pick a file',oldfile); |
---|
| 370 | fileinput=[PathName FileName];%complete file name |
---|
| 371 | sizf=size(fileinput); |
---|
| 372 | if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end |
---|
| 373 | [path,name,ext]=fileparts(fileinput); |
---|
| 374 | if isequal(ext,'.xml') |
---|
[206] | 375 | msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer |
---|
[2] | 376 | elseif isequal(ext,'.xls') |
---|
[206] | 377 | msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer |
---|
[2] | 378 | else |
---|
[472] | 379 | display_file_name(handles,fileinput,'append') |
---|
[2] | 380 | end |
---|
| 381 | |
---|
| 382 | % -------------------------------------------------------------------- |
---|
| 383 | function MenuFile_insert_1_Callback(hObject, eventdata, handles) |
---|
[408] | 384 | % -------------------------------------------------------------------- |
---|
[2] | 385 | fileinput=get(handles.MenuFile_insert_1,'Label'); |
---|
[472] | 386 | display_file_name(handles,fileinput,'append') |
---|
[2] | 387 | |
---|
| 388 | % -------------------------------------------------------------------- |
---|
| 389 | function MenuFile_insert_2_Callback(hObject, eventdata, handles) |
---|
[408] | 390 | % -------------------------------------------------------------------- |
---|
[2] | 391 | fileinput=get(handles.MenuFile_insert_2,'Label'); |
---|
[472] | 392 | display_file_name(handles,fileinput,'append') |
---|
[2] | 393 | |
---|
| 394 | % -------------------------------------------------------------------- |
---|
| 395 | function MenuFile_insert_3_Callback(hObject, eventdata, handles) |
---|
[408] | 396 | % -------------------------------------------------------------------- |
---|
[2] | 397 | fileinput=get(handles.MenuFile_insert_3,'Label'); |
---|
[472] | 398 | display_file_name( handles,fileinput,'append') |
---|
[2] | 399 | |
---|
| 400 | % -------------------------------------------------------------------- |
---|
| 401 | function MenuFile_insert_4_Callback(hObject, eventdata, handles) |
---|
[408] | 402 | % -------------------------------------------------------------------- |
---|
[2] | 403 | fileinput=get(handles.MenuFile_insert_4,'Label'); |
---|
[472] | 404 | display_file_name( handles,fileinput,'append') |
---|
[2] | 405 | |
---|
| 406 | % -------------------------------------------------------------------- |
---|
| 407 | function MenuFile_insert_5_Callback(hObject, eventdata, handles) |
---|
[408] | 408 | % -------------------------------------------------------------------- |
---|
[2] | 409 | fileinput=get(handles.MenuFile_insert_5,'Label'); |
---|
[472] | 410 | display_file_name(handles,fileinput,'append') |
---|
[2] | 411 | |
---|
[89] | 412 | %------------------------------------------------------------------------ |
---|
[408] | 413 | % --- Executes when entered data in editable cell(s) in InputTable. |
---|
| 414 | function InputTable_CellEditCallback(hObject, eventdata, handles) |
---|
| 415 | %------------------------------------------------------------------------ |
---|
[472] | 416 | set(handles.REFRESH,'Visible','on') |
---|
[605] | 417 | set(handles.REFRESH_title,'Visible','on') |
---|
[408] | 418 | iview=eventdata.Indices(1); |
---|
[472] | 419 | view_set=get(handles.REFRESH,'UserData'); |
---|
| 420 | if isempty(find(view_set==iview)) |
---|
| 421 | set(handles.REFRESH,'UserData',[view_set iview]) |
---|
| 422 | end |
---|
| 423 | %% enable other menus and uicontrols |
---|
| 424 | set(handles.MenuOpen_insert,'Enable','on') |
---|
| 425 | set(handles.MenuFile_insert_1,'Enable','on') |
---|
| 426 | set(handles.MenuFile_insert_2,'Enable','on') |
---|
| 427 | set(handles.MenuFile_insert_3,'Enable','on') |
---|
| 428 | set(handles.MenuFile_insert_4,'Enable','on') |
---|
| 429 | set(handles.MenuFile_insert_5,'Enable','on') |
---|
| 430 | set(handles.RUN, 'Enable','On') |
---|
| 431 | set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red |
---|
| 432 | |
---|
| 433 | %------------------------------------------------------------------------ |
---|
| 434 | % --- Executes on button press in REFRESH. |
---|
| 435 | function REFRESH_Callback(hObject, eventdata, handles) |
---|
| 436 | %------------------------------------------------------------------------ |
---|
[408] | 437 | InputTable=get(handles.InputTable,'Data'); |
---|
[472] | 438 | view_set=get(handles.REFRESH,'UserData'); |
---|
[605] | 439 | set(handles.REFRESH,'BackgroundColor',[1 1 0])% set REFRESH button to yellow color (indicate activation) |
---|
[472] | 440 | drawnow |
---|
| 441 | for iview=view_set |
---|
| 442 | RootPath=fullfile(InputTable{iview,1},InputTable{iview,2}); |
---|
| 443 | if ~exist(RootPath,'dir') |
---|
| 444 | i1_series=[]; |
---|
| 445 | RootPath=fileparts(RootPath); %will try the upped forldr |
---|
| 446 | else |
---|
[599] | 447 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,FileInfo,MovieObject]=... |
---|
[472] | 448 | find_file_series(fullfile(InputTable{iview,1},InputTable{iview,2}),[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]); |
---|
[446] | 449 | end |
---|
[472] | 450 | if isempty(i1_series) |
---|
[605] | 451 | [FileName, PathName] = uigetfile( ... |
---|
[472] | 452 | {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)'; |
---|
| 453 | '*.xml', '.xml files '; ... |
---|
| 454 | '*.xls', '.xls files '; ... |
---|
| 455 | '*.png','.png image files'; ... |
---|
| 456 | '*.tif','.tif image files'; ... |
---|
| 457 | '*.avi;*.AVI','.avi movie files'; ... |
---|
| 458 | '*.nc','.netcdf files'; ... |
---|
| 459 | '*.*', 'All Files (*.*)'}, ... |
---|
[605] | 460 | ['unvalid entry at line ' num2str(iview) ', pick a new input file'],RootPath); |
---|
[472] | 461 | fileinput=[PathName FileName];%complete file name |
---|
[605] | 462 | if isempty(fileinput) %abandon if the operation has been cancelled: no input from browser |
---|
| 463 | set(handles.REFRESH,'BackgroundColor',[1 0 0])% set REFRESH back to red color |
---|
| 464 | return; |
---|
| 465 | end |
---|
[472] | 466 | [path,name,ext]=fileparts(fileinput); |
---|
| 467 | display_file_name(handles,fileinput,iview) |
---|
| 468 | else |
---|
[599] | 469 | update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview) |
---|
[472] | 470 | end |
---|
[446] | 471 | end |
---|
[472] | 472 | set(handles.REFRESH,'Visible','off') |
---|
[605] | 473 | set(handles.REFRESH_title,'Visible','off') |
---|
[472] | 474 | set(handles.REFRESH,'UserData',[]) |
---|
[408] | 475 | |
---|
| 476 | %------------------------------------------------------------------------ |
---|
[472] | 477 | % --- Function called when a new file is opened, either by series_OpeningFcn or by the browser |
---|
| 478 | function display_file_name(handles,fileinput,iview) |
---|
| 479 | %------------------------------------------------------------------------ |
---|
| 480 | % |
---|
[332] | 481 | % INPUT: |
---|
[472] | 482 | % handles: handles of elements in the GUI |
---|
| 483 | % fielinput: input file name, including path |
---|
| 484 | % append =0 (refresh the Input table with the new file), ='append' append a new line in the table |
---|
[332] | 485 | |
---|
[408] | 486 | %% get the input root name, indices, file extension and nomenclature NomType |
---|
| 487 | if ~exist(fileinput,'file') |
---|
| 488 | msgbox_uvmat('ERROR',['input file ' fileinput ' does not exist']) |
---|
| 489 | return |
---|
| 490 | end |
---|
| 491 | |
---|
[332] | 492 | %% enable other menus and uicontrols |
---|
| 493 | set(handles.MenuOpen_insert,'Enable','on') |
---|
| 494 | set(handles.MenuFile_insert_1,'Enable','on') |
---|
| 495 | set(handles.MenuFile_insert_2,'Enable','on') |
---|
| 496 | set(handles.MenuFile_insert_3,'Enable','on') |
---|
| 497 | set(handles.MenuFile_insert_4,'Enable','on') |
---|
| 498 | set(handles.MenuFile_insert_5,'Enable','on') |
---|
| 499 | set(handles.RUN, 'Enable','On') |
---|
| 500 | set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red |
---|
[350] | 501 | set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box to yellow |
---|
[332] | 502 | drawnow |
---|
| 503 | |
---|
[408] | 504 | %% detect root name, nomenclature and indices in the input file name: |
---|
| 505 | [FilePath,FileName,FileExt]=fileparts(fileinput); |
---|
| 506 | % detect the file type, get the movie object if relevant, and look for the corresponding file series: |
---|
| 507 | % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists |
---|
[599] | 508 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,FileInfo,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]); |
---|
[408] | 509 | if isempty(RootFile)&&isempty(i1_series) |
---|
| 510 | errormsg='no input file in the series'; |
---|
[29] | 511 | return |
---|
| 512 | end |
---|
[89] | 513 | |
---|
[376] | 514 | %% fill the list of file series |
---|
| 515 | InputTable=get(handles.InputTable,'Data'); |
---|
[472] | 516 | if strcmp(iview,'append') % display the input data as a new line in the table |
---|
| 517 | iview=size(InputTable,1); |
---|
| 518 | InputTable(iview+1,:)={'','','','',''}; |
---|
| 519 | InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}]; |
---|
| 520 | elseif iview==0 % or re-initialise the list of input file series |
---|
| 521 | iview=1; |
---|
| 522 | InputTable=[{'','','','',''};{'','','','',''}]; |
---|
| 523 | InputTable(iview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}]; |
---|
[376] | 524 | set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}]) |
---|
| 525 | set(handles.MinIndex,'Data',[{[]},{[]}]) |
---|
| 526 | set(handles.MaxIndex,'Data',[{[]},{[]}]) |
---|
[408] | 527 | set(handles.ListView,'Value',1) |
---|
| 528 | set(handles.ListView,'String',{'1'}) |
---|
[376] | 529 | end |
---|
[472] | 530 | nbview=size(InputTable,1); |
---|
| 531 | set(handles.ListView,'String',mat2cell((1:nbview)',ones(nbview,1))) |
---|
| 532 | set(handles.ListView,'Value',iview) |
---|
[376] | 533 | set(handles.InputTable,'Data',InputTable) |
---|
| 534 | |
---|
[472] | 535 | %% determine the selected reference field indices for pair display |
---|
[603] | 536 | if isempty(i1) |
---|
| 537 | i1=1; |
---|
[472] | 538 | end |
---|
[603] | 539 | if isempty(i2) |
---|
| 540 | i2=i1; |
---|
| 541 | end |
---|
| 542 | ref_i=floor((i1+i2)/2);% reference image number corresponding to the file |
---|
[472] | 543 | set(handles.num_ref_i,'String',num2str(ref_i)); |
---|
[603] | 544 | set(handles.num_ref_i,'UserData',[i1 i2]) |
---|
| 545 | if isempty(j1) |
---|
| 546 | j1=1; |
---|
[472] | 547 | end |
---|
[603] | 548 | if isempty(j2) |
---|
| 549 | j2=j1; |
---|
| 550 | end |
---|
| 551 | ref_j=floor((j1+j2)/2);% reference image number corresponding to the file |
---|
[472] | 552 | set(handles.num_ref_j,'String',num2str(ref_j)); |
---|
[603] | 553 | set(handles.num_ref_j,'UserData',[j1 j2]) |
---|
[472] | 554 | |
---|
| 555 | %% update the list of recent files in the menubar and save it for future opening |
---|
| 556 | MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};... |
---|
| 557 | {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}]; |
---|
| 558 | str_find=strcmp(fileinput,MenuFile); |
---|
| 559 | if isempty(find(str_find,1)) |
---|
| 560 | MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list |
---|
| 561 | end |
---|
| 562 | for ifile=1:min(length(MenuFile),5) |
---|
| 563 | eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});']) |
---|
| 564 | eval(['set(handles.MenuFile_insert_' num2str(ifile) ',''Label'',MenuFile{ifile});']) |
---|
| 565 | end |
---|
| 566 | dir_perso=prefdir; |
---|
| 567 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 568 | if exist(profil_perso,'file') |
---|
| 569 | save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat |
---|
| 570 | else |
---|
| 571 | save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat |
---|
| 572 | end |
---|
| 573 | |
---|
| 574 | set(handles.InputTable,'BackgroundColor',[1 1 1]) |
---|
| 575 | |
---|
| 576 | %% initiate input file series and refresh the current field view: |
---|
[599] | 577 | update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,MovieObject,iview); |
---|
[472] | 578 | |
---|
| 579 | %------------------------------------------------------------------------ |
---|
| 580 | % --- Update information about a new field series (indices to scan, timing, |
---|
| 581 | % calibration from an xml file |
---|
[599] | 582 | function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,FileInfo,VideoObject,iview) |
---|
[472] | 583 | %------------------------------------------------------------------------ |
---|
| 584 | %% update the output dir |
---|
| 585 | InputTable=get(handles.InputTable,'Data'); |
---|
| 586 | SubDir=sort(InputTable(1:end-1,2)); %set of subdirectories sorted in alphabetical order |
---|
| 587 | SubDirOut=SubDir{1}; |
---|
| 588 | if numel(SubDir)>1 |
---|
| 589 | for ilist=2:numel(SubDir) |
---|
| 590 | SubDirOut=[SubDirOut '-' SubDir{ilist}]; |
---|
| 591 | end |
---|
| 592 | end |
---|
| 593 | set(handles.OutputSubDir,'String',SubDirOut) |
---|
| 594 | |
---|
[521] | 595 | %% display the min and max indices for the file series |
---|
[554] | 596 | if size(i1_series,2)==2 && min(min(i1_series(:,1,:)))==0 |
---|
[526] | 597 | MinIndex_j=1; |
---|
[554] | 598 | MaxIndex_j=1; |
---|
| 599 | MinIndex_i=find(i1_series(:,2,:), 1 )-1; |
---|
| 600 | MaxIndex_i=find(i1_series(:,2,:), 1, 'last' )-1; |
---|
[526] | 601 | else |
---|
[554] | 602 | pair_max=squeeze(max(i1_series,[],1)); %max on pair index |
---|
| 603 | j_max=max(pair_max,[],1); |
---|
| 604 | %i_sum=sum(sum(i1_series,2),1);%sum of i1_series on the last index |
---|
| 605 | MaxIndex_i=find(j_max, 1, 'last' )-1;% max ref index i |
---|
| 606 | MinIndex_i=find(j_max, 1 )-1;% min ref index i |
---|
| 607 | diff_i_max=diff(j_max); |
---|
[526] | 608 | if isequal (diff_i_max,diff_i_max(1)*ones(size(diff_i_max))) |
---|
| 609 | set(handles.num_incr_i,'String',num2str(diff_i_max(1))) |
---|
| 610 | end |
---|
[554] | 611 | i_max=max(pair_max,[],2); |
---|
| 612 | MaxIndex_j=max(find(i_max))-1;% max ref index i |
---|
| 613 | MinIndex_j=min(find(i_max))-1;% min ref index i |
---|
| 614 | diff_j_max=diff(i_max); |
---|
[526] | 615 | if isequal (diff_j_max,diff_j_max(1)*ones(size(diff_j_max))) |
---|
| 616 | set(handles.num_incr_j,'String',num2str(diff_j_max(1))) |
---|
| 617 | end |
---|
| 618 | end |
---|
[460] | 619 | MinIndex=get(handles.MinIndex,'Data');%retrieve the min indices in the table MinIndex |
---|
| 620 | MaxIndex=get(handles.MaxIndex,'Data');%retrieve the max indices in the table MaxIndex |
---|
[554] | 621 | if isequal(MinIndex_i,-1) |
---|
| 622 | MinIndex_i=0; |
---|
| 623 | end |
---|
| 624 | if isequal(MinIndex_j,-1) |
---|
| 625 | MinIndex_j=0; |
---|
| 626 | end |
---|
[472] | 627 | MinIndex{iview,1}=MinIndex_i; |
---|
| 628 | MinIndex{iview,2}=MinIndex_j; |
---|
| 629 | MaxIndex{iview,1}=MaxIndex_i; |
---|
| 630 | MaxIndex{iview,2}=MaxIndex_j; |
---|
[460] | 631 | |
---|
| 632 | set(handles.MinIndex,'Data',MinIndex)%display the min indices in the table MinIndex |
---|
| 633 | set(handles.MaxIndex,'Data',MaxIndex)%display the max indices in the table MaxIndex |
---|
| 634 | |
---|
| 635 | %% adjust the first and last indices if requested by the bounds |
---|
| 636 | first_i=str2num(get(handles.num_first_i,'String')); |
---|
| 637 | ref_i=str2num(get(handles.num_ref_i,'String')); |
---|
| 638 | ref_j=str2num(get(handles.num_ref_j,'String')); |
---|
| 639 | if isempty(first_i) |
---|
| 640 | first_i=ref_i; |
---|
| 641 | elseif first_i < MinIndex_i |
---|
| 642 | first_i=MinIndex_i; |
---|
[526] | 643 | elseif first_i >MaxIndex_i |
---|
| 644 | first_i=MinIndex_i; |
---|
[460] | 645 | end |
---|
| 646 | first_j=str2num(get(handles.num_first_j,'String')); |
---|
| 647 | if isempty(first_j) |
---|
| 648 | first_j=ref_j; |
---|
| 649 | elseif first_j<MinIndex_j |
---|
| 650 | first_j=MinIndex_j; |
---|
[526] | 651 | elseif first_j >MaxIndex_j |
---|
| 652 | first_j=MinIndex_j; |
---|
[460] | 653 | end |
---|
| 654 | last_i=str2num(get(handles.num_last_i,'String')); |
---|
| 655 | if isempty(last_i) |
---|
| 656 | last_i=ref_i; |
---|
| 657 | elseif last_i > MaxIndex_i |
---|
| 658 | last_i=MaxIndex_i; |
---|
[526] | 659 | elseif last_i<first_i |
---|
| 660 | last_i=first_i; |
---|
[460] | 661 | end |
---|
| 662 | last_j=str2num(get(handles.num_first_j,'String')); |
---|
| 663 | if isempty(last_j) |
---|
| 664 | last_j=ref_j; |
---|
| 665 | elseif last_j>MaxIndex_j |
---|
| 666 | last_j=MaxIndex_j; |
---|
[526] | 667 | elseif last_i<first_i |
---|
| 668 | last_i=first_i; |
---|
[460] | 669 | end |
---|
| 670 | set(handles.num_first_i,'String',num2str(first_i)); |
---|
| 671 | set(handles.num_first_j,'String',num2str(first_j)); |
---|
| 672 | set(handles.num_last_i,'String',num2str(last_i)); |
---|
| 673 | set(handles.num_last_j,'String',num2str(last_j)); |
---|
| 674 | |
---|
[526] | 675 | %% read timing and total frame number from the current file (movie files) may be overrid by xml file |
---|
[408] | 676 | InputTable=get(handles.InputTable,'Data'); |
---|
| 677 | FileBase=fullfile(InputTable{iview,1},InputTable{iview,3}); |
---|
| 678 | time=[];%default |
---|
| 679 | % case of movies |
---|
| 680 | if strcmp(InputTable{iview,4},'*') |
---|
| 681 | if ~isempty(VideoObject) |
---|
| 682 | imainfo=get(VideoObject); |
---|
| 683 | time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames-1)/imainfo.FrameRate)'; |
---|
[526] | 684 | % set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec |
---|
[408] | 685 | ColorType='truecolor'; |
---|
| 686 | elseif ~isempty(imformats(regexprep(InputTable{iview,5},'^.',''))) || isequal(InputTable{iview,5},'.vol')%&& isequal(NomType,'*')% multi-frame image |
---|
| 687 | if ~isempty(InputTable{iview,2}) |
---|
| 688 | imainfo=imfinfo(fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,5}])); |
---|
| 689 | else |
---|
| 690 | imainfo=imfinfo([FileBase InputTable{iview,5}]); |
---|
| 691 | end |
---|
| 692 | ColorType=imainfo.ColorType;%='truecolor' for color images |
---|
| 693 | if length(imainfo) >1 %case of image with multiple frames |
---|
| 694 | nbfield=length(imainfo); |
---|
| 695 | nbfield_j=1; |
---|
| 696 | end |
---|
| 697 | end |
---|
| 698 | end |
---|
| 699 | |
---|
| 700 | %% read image documentation file if found%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 701 | XmlData=[]; |
---|
| 702 | NbSlice_calib={}; |
---|
[525] | 703 | XmlFileName=find_imadoc(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5}); |
---|
[599] | 704 | TimeUnit=''; |
---|
[525] | 705 | if ~isempty(XmlFileName) |
---|
| 706 | [XmlData,warntext]=imadoc2struct(XmlFileName); |
---|
[408] | 707 | if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName) |
---|
| 708 | [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName); |
---|
| 709 | end |
---|
| 710 | if isfield(XmlData,'Time') |
---|
| 711 | time=XmlData.Time; |
---|
| 712 | end |
---|
| 713 | if isfield(XmlData,'Camera') |
---|
| 714 | if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice) |
---|
| 715 | NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform |
---|
| 716 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
| 717 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series'); |
---|
| 718 | end |
---|
| 719 | end |
---|
| 720 | if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit) |
---|
| 721 | TimeUnit=XmlData.Camera.TimeUnit; |
---|
| 722 | end |
---|
| 723 | end |
---|
| 724 | if ~isempty(warntext) |
---|
| 725 | msgbox_uvmat('WARNING',warntext) |
---|
| 726 | end |
---|
| 727 | end |
---|
| 728 | |
---|
| 729 | %% update time table |
---|
[456] | 730 | if ~isempty(time) |
---|
[523] | 731 | TimeTable=get(handles.TimeTable,'Data'); |
---|
| 732 | first_i=str2num(get(handles.num_first_i,'String')); |
---|
| 733 | last_i=str2num(get(handles.num_last_i,'String')); |
---|
| 734 | first_j=str2num(get(handles.num_first_j,'String')); |
---|
| 735 | last_j=str2num(get(handles.num_last_j,'String')); |
---|
| 736 | MinIndexTable=get(handles.MinIndex,'Data'); |
---|
| 737 | MinIndex_i=MinIndexTable{iview,1}; |
---|
| 738 | MinIndex_j=MinIndexTable{iview,2}; |
---|
| 739 | MaxIndexTable=get(handles.MaxIndex,'Data'); |
---|
| 740 | MaxIndex_i=MaxIndexTable{iview,1}; |
---|
| 741 | MaxIndex_j=MaxIndexTable{iview,2}; |
---|
[553] | 742 | if isempty(MinIndex_j)% only i index |
---|
[523] | 743 | if MinIndex_i>0 |
---|
| 744 | TimeTable{iview,1}=time(MinIndex_i); |
---|
| 745 | end |
---|
| 746 | TimeTable{iview,2}=time(first_i); |
---|
| 747 | TimeTable{iview,3}=time(last_i); |
---|
| 748 | TimeTable{iview,4}=time(MaxIndex_i); |
---|
| 749 | elseif ~isempty(time) |
---|
| 750 | if MinIndex_i>0 |
---|
| 751 | TimeTable{iview,1}=time(MinIndex_i,MinIndex_j); |
---|
| 752 | end |
---|
[554] | 753 | if size(time)>=[last_i last_j] |
---|
| 754 | TimeTable{iview,2}=time(first_i,first_j); |
---|
| 755 | TimeTable{iview,3}=time(last_i,last_j); |
---|
| 756 | end |
---|
[553] | 757 | if size(time)>=[MaxIndex_i MaxIndex_j]; |
---|
[554] | 758 | TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j); |
---|
[553] | 759 | end |
---|
[456] | 760 | end |
---|
[523] | 761 | set(handles.TimeTable,'Data',TimeTable) |
---|
[408] | 762 | end |
---|
| 763 | |
---|
| 764 | %% number of slices |
---|
[460] | 765 | NbSlice=1;%default |
---|
[600] | 766 | check_calib=0; |
---|
[599] | 767 | if isfield(XmlData,'GeometryCalib') |
---|
| 768 | check_calib=1; |
---|
| 769 | if isfield(XmlData.GeometryCalib,'SliceCoord') |
---|
[408] | 770 | siz=size(XmlData.GeometryCalib.SliceCoord); |
---|
| 771 | if siz(1)>1 |
---|
| 772 | NbSlice=siz(1); |
---|
| 773 | end |
---|
[599] | 774 | end |
---|
[408] | 775 | end |
---|
[450] | 776 | set(handles.num_NbSlice,'String',num2str(NbSlice)) |
---|
| 777 | |
---|
[408] | 778 | %% update pair menus |
---|
[441] | 779 | set(handles.Pairs,'Visible','on') |
---|
| 780 | set(handles.PairString,'Visible','on') |
---|
[408] | 781 | ListView=get(handles.ListView,'String'); |
---|
| 782 | ListView{iview}=num2str(iview); |
---|
[472] | 783 | set(handles.ListView,'String',ListView); |
---|
[408] | 784 | set(handles.ListView,'Value',iview) |
---|
| 785 | update_mode(handles,i1_series,i2_series,j1_series,j2_series,time) |
---|
| 786 | |
---|
[472] | 787 | %% update the series info in 'UserData' |
---|
[408] | 788 | SeriesData=get(handles.series,'UserData'); |
---|
[603] | 789 | SeriesData.Ref_i{iview}=get(handles.num_ref_i,'UserData'); |
---|
| 790 | SeriesData.Ref_j{iview}=get(handles.num_ref_j,'UserData'); |
---|
[408] | 791 | SeriesData.i1_series{iview}=i1_series; |
---|
| 792 | SeriesData.i2_series{iview}=i2_series; |
---|
| 793 | SeriesData.j1_series{iview}=j1_series; |
---|
| 794 | SeriesData.j2_series{iview}=j2_series; |
---|
| 795 | SeriesData.FileType{iview}=FileType; |
---|
[599] | 796 | SeriesData.FileInfo{iview}=FileInfo; |
---|
[408] | 797 | SeriesData.Time{iview}=time; |
---|
[599] | 798 | if ~isempty(TimeUnit) |
---|
| 799 | SeriesData.TimeUnit=TimeUnit; |
---|
| 800 | end |
---|
| 801 | if check_calib |
---|
| 802 | SeriesData.GeometryCalib{iview}=XmlData.GeometryCalib; |
---|
| 803 | end |
---|
[408] | 804 | set(handles.series,'UserData',SeriesData) |
---|
| 805 | |
---|
[521] | 806 | %% enable j index visibilitycellfun(@isempty,regexp(PairString,'^j')) |
---|
[553] | 807 | % state='off'; |
---|
[472] | 808 | check_jindex=~cellfun(@isempty,SeriesData.j1_series); %look for non empty j indices |
---|
| 809 | if isempty(find(check_jindex)) |
---|
| 810 | enable_j(handles,'off') % no j index needed |
---|
| 811 | else |
---|
[521] | 812 | PairString=get(handles.PairString,'Data'); |
---|
| 813 | if isempty(find(cellfun(@isempty,regexp(PairString,'^j'))))% if all pair string begins by j (burst) |
---|
| 814 | enable_j(handles,'off') % no j index needed |
---|
| 815 | else |
---|
| 816 | enable_j(handles,'on') |
---|
| 817 | end |
---|
[472] | 818 | end |
---|
| 819 | |
---|
[477] | 820 | %% display the set of existing files as an image |
---|
| 821 | set(handles.FileStatus,'Units','pixels') |
---|
| 822 | Position=get(handles.FileStatus,'Position'); |
---|
| 823 | set(handles.FileStatus,'Units','normalized') |
---|
| 824 | xI=0.5:Position(3)-0.5; |
---|
| 825 | nbview=numel(SeriesData.i1_series); |
---|
[523] | 826 | pair_max=cell(1,nbview); |
---|
[477] | 827 | for iview=1:nbview |
---|
[523] | 828 | pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index |
---|
[526] | 829 | if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1) |
---|
[525] | 830 | pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index |
---|
| 831 | end |
---|
[523] | 832 | index_min(iview)=find(pair_max{iview}>0, 1 ); |
---|
| 833 | index_max(iview)=find(pair_max{iview}>0, 1, 'last' ); |
---|
[477] | 834 | end |
---|
| 835 | index_min=min(index_min); |
---|
| 836 | index_max=max(index_max); |
---|
| 837 | range_index=index_max-index_min+1; |
---|
| 838 | scale_y=Position(4)/nbview; |
---|
| 839 | scale_x=Position(3)/range_index; |
---|
| 840 | x=(0.5:range_index-0.5)*Position(3)/range_index; |
---|
| 841 | % y=(0.5:nbview-0.5)*Position(4)/nbview; |
---|
| 842 | range_y=max(1,floor(Position(4)/nbview)); |
---|
| 843 | CData=zeros(nbview*range_y,Position(3)); |
---|
| 844 | for iview=1:nbview |
---|
| 845 | ind_y=1+(iview-1)*range_y:iview*range_y; |
---|
| 846 | LineData=zeros(1,range_index); |
---|
[523] | 847 | x_index=find(pair_max{iview}>0)-index_min+1; |
---|
[477] | 848 | LineData(x_index)=1; |
---|
[591] | 849 | if numel(x)>1 |
---|
[477] | 850 | LineData=interp1(x,LineData,xI,'nearest'); |
---|
| 851 | CData(ind_y,:)=ones(size(ind_y'))*LineData; |
---|
[591] | 852 | end |
---|
[477] | 853 | end |
---|
| 854 | CData=cat(3,zeros(size(CData)),CData,zeros(size(CData))); |
---|
| 855 | set(handles.FileStatus,'CData',CData); |
---|
| 856 | |
---|
| 857 | |
---|
[472] | 858 | %% enable field and veltype menus, in accordance with the current action |
---|
| 859 | ActionName_Callback([],[], handles) |
---|
| 860 | |
---|
[441] | 861 | %% check for pair display |
---|
| 862 | check_pairs=0; |
---|
| 863 | for iview=1:numel(SeriesData.i2_series) |
---|
| 864 | if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview}) |
---|
| 865 | check_pairs=1; |
---|
| 866 | end |
---|
| 867 | end |
---|
| 868 | if check_pairs |
---|
| 869 | set(handles.Pairs,'Visible','on') |
---|
| 870 | set(handles.PairString,'Visible','on') |
---|
| 871 | else |
---|
| 872 | set(handles.Pairs,'Visible','off') |
---|
| 873 | set(handles.PairString,'Visible','off') |
---|
| 874 | end |
---|
[408] | 875 | |
---|
[477] | 876 | %% set length of waitbar |
---|
| 877 | displ_time(handles) |
---|
| 878 | |
---|
| 879 | |
---|
[525] | 880 | %% set default options in menu 'Fields' |
---|
| 881 | switch FileType |
---|
| 882 | case {'civx','civdata'} |
---|
[596] | 883 | [FieldList,ColorList]=set_field_list('U','V','C'); |
---|
[525] | 884 | set(handles.FieldName,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data |
---|
| 885 | set(handles.FieldName,'Value',2) % set menu to 'velocity |
---|
| 886 | set(handles.Coord_x,'Value',1); |
---|
| 887 | set(handles.Coord_x,'String',{'X'}); |
---|
| 888 | set(handles.Coord_y,'Value',1); |
---|
| 889 | set(handles.Coord_y,'String',{'Y'}); |
---|
| 890 | case 'netcdf' |
---|
[526] | 891 | set(handles.FieldName,'Value',1) |
---|
| 892 | set(handles.FieldName,'String',{'get_field...'}) |
---|
| 893 | if isempty(i2_series) |
---|
| 894 | i2=[]; |
---|
| 895 | else |
---|
| 896 | i2=i2_series(1,ref_j+1,ref_i+1); |
---|
| 897 | end |
---|
| 898 | if isempty(j1_series) |
---|
| 899 | j1=[];j2=[]; |
---|
| 900 | else |
---|
| 901 | j1=j1_series(1,ref_j+1,ref_i+1); |
---|
| 902 | if isempty(j2_series) |
---|
| 903 | j2=[]; |
---|
| 904 | else |
---|
| 905 | j2=j2_series(1,ref_j+1,ref_i+1); |
---|
| 906 | end |
---|
| 907 | end |
---|
| 908 | FileName=fullfile_uvmat(InputTable{iview,1},InputTable{iview,2},InputTable{iview,3},InputTable{iview,5},InputTable{iview,4},i1_series(1,ref_j+1,ref_i+1),i2,j1,j2); |
---|
[595] | 909 | % hget_field=get_field(FileName); |
---|
| 910 | % hhget_field=guidata(hget_field); |
---|
| 911 | % get_field('RUN_Callback',hhget_field.RUN,[],hhget_field); |
---|
[525] | 912 | otherwise |
---|
[526] | 913 | set(handles.FieldName,'Value',1) % set menu to 'image' |
---|
| 914 | set(handles.FieldName,'String',{'image'}) |
---|
[525] | 915 | set(handles.Coord_x,'Value',1); |
---|
| 916 | set(handles.Coord_x,'String',{'AX'}); |
---|
| 917 | set(handles.Coord_y,'Value',1); |
---|
| 918 | set(handles.Coord_y,'String',{'AY'}); |
---|
| 919 | end |
---|
[408] | 920 | |
---|
[446] | 921 | %------------------------------------------------------------------------ |
---|
| 922 | function num_first_i_Callback(hObject, eventdata, handles) |
---|
| 923 | %------------------------------------------------------------------------ |
---|
| 924 | num_last_i_Callback(hObject, eventdata, handles) |
---|
[408] | 925 | |
---|
| 926 | %------------------------------------------------------------------------ |
---|
[446] | 927 | function num_last_i_Callback(hObject, eventdata, handles) |
---|
| 928 | %------------------------------------------------------------------------ |
---|
| 929 | SeriesData=get(handles.series,'UserData'); |
---|
| 930 | if ~isfield(SeriesData,'Time') |
---|
| 931 | SeriesData.Time{1}=[]; |
---|
| 932 | end |
---|
| 933 | displ_time(handles); |
---|
| 934 | |
---|
| 935 | %------------------------------------------------------------------------ |
---|
| 936 | function num_first_j_Callback(hObject, eventdata, handles) |
---|
| 937 | %------------------------------------------------------------------------ |
---|
| 938 | num_last_j_Callback(hObject, eventdata, handles) |
---|
| 939 | |
---|
| 940 | %------------------------------------------------------------------------ |
---|
| 941 | function num_last_j_Callback(hObject, eventdata, handles) |
---|
| 942 | %------------------------------------------------------------------------ |
---|
| 943 | first_j=str2num(get(handles.num_first_j,'String')); |
---|
| 944 | last_j=str2num(get(handles.num_last_j,'String')); |
---|
| 945 | ref_j=ceil((first_j+last_j)/2); |
---|
| 946 | set(handles.num_ref_j,'String', num2str(ref_j)) |
---|
| 947 | num_ref_j_Callback(hObject, eventdata, handles) |
---|
| 948 | SeriesData=get(handles.series,'UserData'); |
---|
| 949 | if ~isfield(SeriesData,'Time') |
---|
| 950 | SeriesData.Time{1}=[]; |
---|
| 951 | end |
---|
| 952 | displ_time(handles); |
---|
| 953 | |
---|
[477] | 954 | |
---|
[446] | 955 | %------------------------------------------------------------------------ |
---|
| 956 | % ---- find the times corresponding to the first and last indices of a series |
---|
| 957 | function displ_time(handles) |
---|
| 958 | %------------------------------------------------------------------------ |
---|
| 959 | SeriesData=get(handles.series,'UserData');% |
---|
| 960 | ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))]; |
---|
| 961 | ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))]; |
---|
| 962 | TimeTable=get(handles.TimeTable,'Data'); |
---|
| 963 | Pairs=get(handles.PairString,'Data'); |
---|
| 964 | for iview=1:size(TimeTable,1) |
---|
| 965 | if size(SeriesData.Time,1)<iview |
---|
| 966 | break |
---|
| 967 | end |
---|
| 968 | i1=ref_i; |
---|
| 969 | j1=ref_j; |
---|
| 970 | i2=ref_i; |
---|
| 971 | j2=ref_j; |
---|
| 972 | % case of pairs |
---|
| 973 | if ~isempty(Pairs{iview,1}) |
---|
| 974 | r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names'); |
---|
| 975 | if isempty(r) |
---|
| 976 | r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names'); |
---|
| 977 | end |
---|
| 978 | switch r.mode |
---|
| 979 | case 'Di=' % case 'series(Di)') |
---|
| 980 | i1=ref_i-str2num(r.num1); |
---|
| 981 | i2=ref_i+str2num(r.num2); |
---|
| 982 | case 'Dj=' % case 'series(Dj)' |
---|
| 983 | j1=ref_j-str2num(r.num1); |
---|
| 984 | j2=ref_j+str2num(r.num2); |
---|
| 985 | case '-' % case 'bursts' |
---|
| 986 | j1=str2num(r.num1)*ones(size(ref_i)); |
---|
| 987 | j2=str2num(r.num2)*ones(size(ref_i)); |
---|
| 988 | end |
---|
| 989 | end |
---|
| 990 | TimeTable{iview,2}=[]; |
---|
| 991 | TimeTable{iview,3}=[]; |
---|
| 992 | if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2) |
---|
| 993 | if isempty(ref_j) |
---|
| 994 | time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2; |
---|
| 995 | time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2; |
---|
| 996 | else |
---|
| 997 | time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2; |
---|
| 998 | time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2; |
---|
| 999 | end |
---|
| 1000 | TimeTable{iview,2}=time_first; %TODO: take into account pairs |
---|
| 1001 | TimeTable{iview,3}=time_last; %TODO: take into account pairs |
---|
| 1002 | end |
---|
| 1003 | end |
---|
| 1004 | set(handles.TimeTable,'Data',TimeTable) |
---|
| 1005 | |
---|
[477] | 1006 | %% set the waitbar position with respect to the min and max in the series |
---|
| 1007 | for iview=1:numel(SeriesData.i1_series) |
---|
[526] | 1008 | pair_max{iview}=squeeze(max(SeriesData.i1_series{iview},[],1)); %max on pair index |
---|
| 1009 | if (strcmp(get(handles.num_first_j,'Visible'),'off')&& size(pair_max{iview},2)~=1) |
---|
| 1010 | pair_max{iview}=squeeze(max(pair_max{iview},[],1)); % consider only the i index |
---|
| 1011 | end |
---|
| 1012 | pair_max{iview}=reshape(pair_max{iview},1,[]); |
---|
| 1013 | index_min(iview)=find(pair_max{iview}>0, 1 ); |
---|
| 1014 | index_max(iview)=find(pair_max{iview}>0, 1, 'last' ); |
---|
[477] | 1015 | end |
---|
| 1016 | [index_min,iview_min]=min(index_min); |
---|
| 1017 | [index_max,iview_max]=min(index_max); |
---|
[526] | 1018 | if size(SeriesData.i1_series{iview_min},2)==1% movie |
---|
[533] | 1019 | index_first=ref_i(1); |
---|
| 1020 | index_last=ref_i(2); |
---|
[526] | 1021 | else |
---|
[533] | 1022 | index_first=(ref_i(1)-1)*(size(SeriesData.i1_series{iview_min},1))+ref_j(1)+1; |
---|
| 1023 | index_last=(ref_i(2)-1)*(size(SeriesData.i1_series{iview_max},1))+ref_j(2)+1; |
---|
[526] | 1024 | end |
---|
[477] | 1025 | range=index_max-index_min+1; |
---|
| 1026 | coeff_min=(index_first-index_min)/range; |
---|
| 1027 | coeff_max=(index_last-index_min+1)/range; |
---|
[533] | 1028 | Position=get(handles.Waitbar,'Position');% position of the waitbar:= [ x,y, width, height] |
---|
[477] | 1029 | Position_status=get(handles.FileStatus,'Position'); |
---|
| 1030 | Position(1)=coeff_min*Position_status(3)+Position_status(1); |
---|
| 1031 | Position(3)=Position_status(3)*(coeff_max-coeff_min); |
---|
| 1032 | set(handles.Waitbar,'Position',Position) |
---|
| 1033 | update_waitbar(handles.Waitbar,0) |
---|
| 1034 | |
---|
[446] | 1035 | %------------------------------------------------------------------------ |
---|
[408] | 1036 | % --- Executes when selected cell(s) is changed in PairString. |
---|
| 1037 | function PairString_CellSelectionCallback(hObject, eventdata, handles) |
---|
| 1038 | %------------------------------------------------------------------------ |
---|
| 1039 | set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index |
---|
| 1040 | ListView_Callback ([],[],handles) % update the list of available pairs |
---|
| 1041 | |
---|
| 1042 | %------------------------------------------------------------------------ |
---|
| 1043 | %------------------------------------------------------------------------ |
---|
| 1044 | % III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS |
---|
| 1045 | %------------------------------------------------------------------------ |
---|
| 1046 | %------------------------------------------------------------------------ |
---|
| 1047 | % --- Executes on selection change in ListView. |
---|
| 1048 | function ListView_Callback(hObject, eventdata, handles) |
---|
| 1049 | %------------------------------------------------------------------------ |
---|
| 1050 | SeriesData=get(handles.series,'UserData'); |
---|
| 1051 | i2_series=[]; |
---|
| 1052 | j2_series=[]; |
---|
| 1053 | iview=get(handles.ListView,'Value'); |
---|
| 1054 | if ~isempty(SeriesData.i2_series{iview}) |
---|
| 1055 | i2_series=SeriesData.i2_series{iview}; |
---|
| 1056 | end |
---|
| 1057 | if ~isempty(SeriesData.j2_series{iview}) |
---|
| 1058 | j2_series=SeriesData.j2_series{iview}; |
---|
| 1059 | end |
---|
| 1060 | update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},... |
---|
| 1061 | SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview}) |
---|
| 1062 | |
---|
| 1063 | %------------------------------------------------------------------------ |
---|
[2] | 1064 | % --- Executes on button press in mode. |
---|
[376] | 1065 | function mode_Callback(hObject, eventdata, handles) |
---|
[408] | 1066 | %------------------------------------------------------------------------ |
---|
[376] | 1067 | SeriesData=get(handles.series,'UserData'); |
---|
[408] | 1068 | iview=get(handles.ListView,'Value'); |
---|
[376] | 1069 | mode_list=get(handles.mode,'String'); |
---|
[408] | 1070 | mode=mode_list{get(handles.mode,'Value')}; |
---|
[376] | 1071 | if isequal(mode,'bursts') |
---|
| 1072 | enable_i(handles,'On') |
---|
| 1073 | enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice) |
---|
| 1074 | else |
---|
| 1075 | enable_i(handles,'On') |
---|
| 1076 | enable_j(handles,'Off') |
---|
| 1077 | end |
---|
[408] | 1078 | fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},... |
---|
| 1079 | SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview}) |
---|
| 1080 | ListPairs_Callback([],[],handles) |
---|
[339] | 1081 | |
---|
[408] | 1082 | %------------------------------------------------------------- |
---|
| 1083 | % --- Executes on selection in ListPairs. |
---|
| 1084 | function ListPairs_Callback(hObject,eventdata,handles) |
---|
| 1085 | %------------------------------------------------------------ |
---|
| 1086 | list_pair=get(handles.ListPairs,'String');%get the menu of image pairs |
---|
[441] | 1087 | if isempty(list_pair) |
---|
| 1088 | string=''; |
---|
| 1089 | else |
---|
| 1090 | string=list_pair{get(handles.ListPairs,'Value')}; |
---|
| 1091 | string=regexprep(string,',.*','');%removes time indication (after ',') |
---|
| 1092 | end |
---|
[408] | 1093 | PairString=get(handles.PairString,'Data'); |
---|
| 1094 | iview=get(handles.ListView,'Value'); |
---|
| 1095 | PairString{iview,1}=string; |
---|
| 1096 | % report the selected pair string to the table PairString |
---|
| 1097 | set(handles.PairString,'Data',PairString) |
---|
[2] | 1098 | |
---|
[408] | 1099 | %------------------------------------------------------------------------ |
---|
| 1100 | function num_ref_i_Callback(hObject, eventdata, handles) |
---|
| 1101 | %------------------------------------------------------------------------ |
---|
| 1102 | mode_list=get(handles.mode,'String'); |
---|
| 1103 | mode=mode_list{get(handles.mode,'Value')}; |
---|
| 1104 | SeriesData=get(handles.series,'UserData'); |
---|
| 1105 | iview=get(handles.ListView,'Value'); |
---|
| 1106 | fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},... |
---|
[446] | 1107 | SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files |
---|
[408] | 1108 | ListPairs_Callback([],[],handles) |
---|
[2] | 1109 | |
---|
[408] | 1110 | %------------------------------------------------------------------------ |
---|
| 1111 | function num_ref_j_Callback(hObject, eventdata, handles) |
---|
| 1112 | %------------------------------------------------------------------------ |
---|
| 1113 | num_ref_i_Callback(hObject, eventdata, handles) |
---|
[2] | 1114 | |
---|
[408] | 1115 | %------------------------------------------------------------------------ |
---|
| 1116 | function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time) |
---|
| 1117 | %------------------------------------------------------------------------ |
---|
[521] | 1118 | % check_burst=0; |
---|
| 1119 | if isempty(j2_series)% no j pair |
---|
[408] | 1120 | if isempty(i2_series) |
---|
| 1121 | set(handles.mode,'Value',1) |
---|
[521] | 1122 | set(handles.mode,'String',{''})% no pair menu to display |
---|
| 1123 | else |
---|
| 1124 | set(handles.mode,'Value',1) |
---|
| 1125 | set(handles.mode,'String',{'series(Di)'}) % pair menu with only option Di |
---|
[408] | 1126 | end |
---|
[521] | 1127 | else %existence of j pairs |
---|
| 1128 | pair_max=squeeze(max(i1_series,[],1)); %max on pair index |
---|
| 1129 | j_max=max(pair_max,[],1); |
---|
| 1130 | MaxIndex_i=max(find(j_max))-1;% max ref index i |
---|
| 1131 | MinIndex_i=min(find(j_max))-1;% min ref index i |
---|
| 1132 | i_max=max(pair_max,[],2); |
---|
| 1133 | MaxIndex_j=max(find(i_max))-1;% max ref index i |
---|
| 1134 | MinIndex_j=min(find(i_max))-1;% min ref index i |
---|
| 1135 | if MaxIndex_j==MinIndex_j |
---|
[408] | 1136 | set(handles.mode,'Value',1); |
---|
[521] | 1137 | set(handles.mode,'String',{'bursts'}) |
---|
| 1138 | % check_burst=1; |
---|
| 1139 | elseif MaxIndex_i==MinIndex_i |
---|
| 1140 | set(handles.mode,'Value',1); |
---|
| 1141 | set(handles.mode,'String',{'series(Dj)'}) |
---|
[456] | 1142 | else |
---|
[521] | 1143 | set(handles.mode,'String',{'bursts';'series(Dj)'}) |
---|
| 1144 | if (MaxIndex_j-MinIndex_j)>10 |
---|
| 1145 | set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values |
---|
| 1146 | else |
---|
| 1147 | set(handles.mode,'Value',1); |
---|
| 1148 | % check_burst=1; |
---|
| 1149 | end |
---|
[456] | 1150 | end |
---|
[408] | 1151 | end |
---|
[521] | 1152 | % if check_burst |
---|
| 1153 | % enable_i(handles,'On') |
---|
| 1154 | % enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice) |
---|
| 1155 | % else |
---|
| 1156 | % enable_i(handles,'On') |
---|
| 1157 | % if isempty(j1_series) |
---|
| 1158 | % enable_j(handles,'Off') |
---|
| 1159 | % else |
---|
| 1160 | % enable_j(handles,'On') |
---|
| 1161 | % end |
---|
| 1162 | % end |
---|
[408] | 1163 | fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time) |
---|
| 1164 | ListPairs_Callback([],[],handles) |
---|
[2] | 1165 | |
---|
| 1166 | %-------------------------------------------------------------- |
---|
[408] | 1167 | % determine the menu for civ1 pairstring depending on existing netcdf files |
---|
| 1168 | % with the reference indices num_ref_i and num_ref_j |
---|
[2] | 1169 | %---------------------------------------------------------------- |
---|
[408] | 1170 | function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time) |
---|
| 1171 | |
---|
[2] | 1172 | mode_list=get(handles.mode,'String'); |
---|
[408] | 1173 | mode=mode_list{get(handles.mode,'Value')}; |
---|
| 1174 | ref_i=str2num(get(handles.num_ref_i,'String')); |
---|
| 1175 | if isempty(ref_i) |
---|
| 1176 | ref_i=1; |
---|
| 1177 | end |
---|
[472] | 1178 | if strcmp(get(handles.num_ref_j,'Visible'),'on') |
---|
| 1179 | ref_j=str2num(get(handles.num_ref_j,'String')); |
---|
| 1180 | if isempty(ref_j) |
---|
| 1181 | ref_j=1; |
---|
| 1182 | end |
---|
| 1183 | else |
---|
[408] | 1184 | ref_j=1; |
---|
| 1185 | end |
---|
[2] | 1186 | TimeUnit=get(handles.TimeUnit,'String'); |
---|
| 1187 | if length(TimeUnit)>=1 |
---|
| 1188 | dtunit=['m' TimeUnit]; |
---|
| 1189 | else |
---|
| 1190 | dtunit='e-03'; |
---|
| 1191 | end |
---|
[339] | 1192 | |
---|
| 1193 | displ_pair={}; |
---|
[118] | 1194 | if strcmp(mode,'series(Di)') |
---|
[339] | 1195 | if isempty(i2_series) |
---|
| 1196 | msgbox_uvmat('ERROR','no i1-i2 pair available') |
---|
| 1197 | return |
---|
| 1198 | end |
---|
| 1199 | diff_i=i2_series-i1_series; |
---|
| 1200 | min_diff=min(diff_i(diff_i>0)); |
---|
| 1201 | max_diff=max(diff_i(diff_i>0)); |
---|
| 1202 | for ipair=min_diff:max_diff |
---|
| 1203 | if numel(diff_i(diff_i==ipair))>0 |
---|
[408] | 1204 | pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ]; |
---|
| 1205 | if ~isempty(time) |
---|
[472] | 1206 | if ref_i<=floor(ipair/2) |
---|
| 1207 | ref_i=floor(ipair/2)+1;% shift ref_i to get the first pair |
---|
| 1208 | end |
---|
[408] | 1209 | Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j); |
---|
| 1210 | pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit]; |
---|
| 1211 | end |
---|
| 1212 | displ_pair=[displ_pair;{pair_string}]; |
---|
[339] | 1213 | end |
---|
| 1214 | end |
---|
| 1215 | if ~isempty(displ_pair) |
---|
| 1216 | displ_pair=[displ_pair;{'Di=*|*'}]; |
---|
| 1217 | end |
---|
| 1218 | elseif strcmp(mode,'series(Dj)') |
---|
| 1219 | if isempty(j2_series) |
---|
| 1220 | msgbox_uvmat('ERROR','no j1-j2 pair available') |
---|
| 1221 | return |
---|
| 1222 | end |
---|
| 1223 | diff_j=j2_series-j1_series; |
---|
| 1224 | min_diff=min(diff_j(diff_j>0)); |
---|
| 1225 | max_diff=max(diff_j(diff_j>0)); |
---|
| 1226 | for ipair=min_diff:max_diff |
---|
| 1227 | if numel(diff_j(diff_j==ipair))>0 |
---|
[408] | 1228 | pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ]; |
---|
| 1229 | if ~isempty(time) |
---|
[472] | 1230 | if ref_j<=floor(ipair/2) |
---|
| 1231 | ref_j=floor(ipair/2)+1;% shift ref_i to get the first pair |
---|
| 1232 | end |
---|
[408] | 1233 | Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2)); |
---|
| 1234 | pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit]; |
---|
| 1235 | end |
---|
| 1236 | displ_pair=[displ_pair;{pair_string}]; |
---|
[339] | 1237 | end |
---|
| 1238 | end |
---|
| 1239 | if ~isempty(displ_pair) |
---|
| 1240 | displ_pair=[displ_pair;{'Dj=*|*'}]; |
---|
| 1241 | end |
---|
| 1242 | elseif strcmp(mode,'bursts') |
---|
| 1243 | if isempty(j2_series) |
---|
| 1244 | msgbox_uvmat('ERROR','no j1-j2 pair available') |
---|
| 1245 | return |
---|
| 1246 | end |
---|
| 1247 | diff_j=j2_series-j1_series; |
---|
| 1248 | min_j1=min(j1_series(j1_series>0)); |
---|
| 1249 | max_j1=max(j1_series(j1_series>0)); |
---|
| 1250 | min_j2=min(j2_series(j2_series>0)); |
---|
| 1251 | max_j2=max(j2_series(j2_series>0)); |
---|
| 1252 | for pair1=min_j1:min(max_j1,min_j1+20) |
---|
| 1253 | for pair2=min_j2:min(max_j2,min_j2+20) |
---|
| 1254 | if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0 |
---|
| 1255 | displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}]; |
---|
| 1256 | end |
---|
| 1257 | end |
---|
| 1258 | end |
---|
| 1259 | if ~isempty(displ_pair) |
---|
| 1260 | displ_pair=[displ_pair;{'j=*-*'}]; |
---|
| 1261 | end |
---|
| 1262 | end |
---|
[472] | 1263 | set(handles.num_ref_i,'String',num2str(ref_i)) % update ref_i and ref_j |
---|
| 1264 | set(handles.num_ref_j,'String',num2str(ref_j)) |
---|
[408] | 1265 | |
---|
| 1266 | %% display list of pairstring |
---|
| 1267 | displ_pair_list=get(handles.ListPairs,'String'); |
---|
[339] | 1268 | NewVal=[]; |
---|
| 1269 | if ~isempty(displ_pair_list) |
---|
[408] | 1270 | Val=get(handles.ListPairs,'Value'); |
---|
[419] | 1271 | NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir |
---|
[339] | 1272 | end |
---|
| 1273 | if ~isempty(NewVal) |
---|
[408] | 1274 | set(handles.ListPairs,'Value',NewVal) |
---|
[339] | 1275 | else |
---|
[408] | 1276 | set(handles.ListPairs,'Value',1) |
---|
[339] | 1277 | end |
---|
[408] | 1278 | set(handles.ListPairs,'String',displ_pair) |
---|
[339] | 1279 | |
---|
[408] | 1280 | %------------------------------------- |
---|
| 1281 | function enable_i(handles,state) |
---|
| 1282 | set(handles.i_txt,'Visible',state) |
---|
| 1283 | set(handles.num_first_i,'Visible',state) |
---|
| 1284 | set(handles.num_last_i,'Visible',state) |
---|
| 1285 | set(handles.num_incr_i,'Visible',state) |
---|
| 1286 | % set(handles.num_MaxIndex_i,'Visible',state) |
---|
| 1287 | set(handles.num_ref_i,'Visible',state) |
---|
| 1288 | set(handles.ref_i_text,'Visible',state) |
---|
[2] | 1289 | |
---|
[408] | 1290 | %----------------------------------- |
---|
| 1291 | function enable_j(handles,state) |
---|
| 1292 | set(handles.j_txt,'Visible',state) |
---|
| 1293 | set(handles.num_first_j,'Visible',state) |
---|
| 1294 | set(handles.num_last_j,'Visible',state) |
---|
| 1295 | set(handles.num_incr_j,'Visible',state) |
---|
| 1296 | set(handles.num_ref_j,'Visible',state) |
---|
| 1297 | set(handles.ref_j_text,'Visible',state) |
---|
[526] | 1298 | % if strcmp(state,'off') |
---|
| 1299 | % set(handles.MinIndex,'ColumnName',{'imax'}) |
---|
| 1300 | % set(handles.MinIndex,'ColumnEditable',logical(0)) |
---|
| 1301 | % else |
---|
| 1302 | % set(handles.MinIndex,'ColumnName',{'imax','jmax'}) |
---|
| 1303 | % end |
---|
[41] | 1304 | |
---|
[408] | 1305 | |
---|
[446] | 1306 | %%%%%%%%%%%%%%%%%%%% |
---|
| 1307 | %% MAIN ActionName FUNCTIONS |
---|
| 1308 | %%%%%%%%%%%%%%%%%%%% |
---|
[41] | 1309 | %------------------------------------------------------------------------ |
---|
[2] | 1310 | % --- Executes on button press in RUN. |
---|
| 1311 | function RUN_Callback(hObject, eventdata, handles) |
---|
[41] | 1312 | %------------------------------------------------------------------------ |
---|
[595] | 1313 | |
---|
[2] | 1314 | set(handles.RUN,'BusyAction','queue'); |
---|
[332] | 1315 | set(0,'CurrentFigure',handles.series) |
---|
[446] | 1316 | set(handles.RUN, 'Enable','Off') |
---|
| 1317 | set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784]) |
---|
[456] | 1318 | drawnow |
---|
[595] | 1319 | |
---|
| 1320 | %% read the input parameters and set the output dir and nomenclature |
---|
| 1321 | [Series,OutputDir,errormsg]=prepare_jobs(handles);% get parameters form the GUI series |
---|
[446] | 1322 | if ~isempty(errormsg) |
---|
[599] | 1323 | if ~strcmp(errormsg,'Cancel') |
---|
[446] | 1324 | msgbox_uvmat('ERROR',errormsg) |
---|
[599] | 1325 | end |
---|
| 1326 | STOP_Callback([],[], handles) |
---|
[472] | 1327 | return |
---|
[2] | 1328 | end |
---|
[595] | 1329 | OutputNomType=nomtype2pair(Series.InputTable{1,4});% nomenclature for output files |
---|
| 1330 | DirXml=fullfile(OutputDir,'0_XML'); |
---|
| 1331 | if ~exist(DirXml,'dir') |
---|
| 1332 | [tild,msg1]=mkdir(DirXml); |
---|
| 1333 | if ~strcmp(msg1,'') |
---|
| 1334 | msgbox_uvmat('ERROR',['cannot create ' DirXml ': ' msg1]);%error message for directory creation |
---|
| 1335 | return |
---|
| 1336 | end |
---|
| 1337 | end |
---|
| 1338 | |
---|
| 1339 | %% select the Action modes |
---|
[601] | 1340 | RunMode='local';%default |
---|
| 1341 | if isfield(Series.Action,'RunMode') |
---|
| 1342 | RunMode=Series.Action.RunMode; |
---|
| 1343 | end |
---|
[595] | 1344 | ActionExt='.m';%default |
---|
| 1345 | if isfield(Series.Action,'ActionExt') |
---|
| 1346 | ActionExt=Series.Action.ActionExt;% '.m' or '.sh' (compiled) |
---|
| 1347 | end |
---|
| 1348 | ActionName=Series.Action.ActionName; |
---|
| 1349 | ActionPath=Series.Action.ActionPath; |
---|
[594] | 1350 | path_series=fileparts(which('series')); |
---|
[472] | 1351 | |
---|
[595] | 1352 | %% create the Action fct handle if RunMode option = 'local' |
---|
[594] | 1353 | if strcmp(RunMode,'local') |
---|
| 1354 | if ~isequal(ActionPath,path_series) |
---|
| 1355 | eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION |
---|
| 1356 | if ~exist(ActionPath,'dir') |
---|
| 1357 | msgbox_uvmat('ERROR',['The prescribed function path ' ActionPath ' does not exist']); |
---|
| 1358 | return |
---|
| 1359 | end |
---|
| 1360 | if ~isequal(spath,ActionPath) |
---|
| 1361 | addpath(ActionPath)% add the prescribed path if not the current one |
---|
| 1362 | end |
---|
| 1363 | end |
---|
| 1364 | eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION |
---|
| 1365 | if ~isequal(ActionPath,path_series) |
---|
| 1366 | rmpath(ActionPath)% add the prescribed path if not the current one |
---|
| 1367 | end |
---|
| 1368 | end |
---|
| 1369 | |
---|
| 1370 | %% Get RunTime code from the file PARAM.xml (needed to run compiled functions) |
---|
| 1371 | errormsg='';%default error message |
---|
| 1372 | xmlfile=fullfile(path_series,'PARAM.xml'); |
---|
| 1373 | test_batch=0;%default: ,no batch mode available |
---|
| 1374 | if ~exist(xmlfile,'file') |
---|
| 1375 | [success,message]=copyfile(fullfile(path_series,'PARAM.xml.default'),xmlfile); |
---|
| 1376 | end |
---|
| 1377 | RunTime=''; |
---|
| 1378 | if strcmp(ActionExt,'.sh') |
---|
| 1379 | if exist(xmlfile,'file') |
---|
| 1380 | s=xml2struct(xmlfile); |
---|
[598] | 1381 | if strcmp(RunMode,'cluster_oar') && isfield(s,'BatchParam') |
---|
[594] | 1382 | if isfield(s.BatchParam,'RunTime') |
---|
| 1383 | RunTime=s.BatchParam.RunTime; |
---|
| 1384 | end |
---|
| 1385 | if isfield(s.BatchParam,'NbCore') |
---|
| 1386 | NbCore=s.BatchParam.NbCore; |
---|
| 1387 | end |
---|
| 1388 | elseif (strcmp(RunMode,'background')||strcmp(RunMode,'local')) && isfield(s,'RunParam') |
---|
| 1389 | if isfield(s.RunParam,'RunTime') |
---|
| 1390 | RunTime=s.RunParam.RunTime; |
---|
| 1391 | end |
---|
| 1392 | if isfield(s.RunParam,'NbCore') |
---|
| 1393 | NbCore=s.RunParam.NbCore; |
---|
| 1394 | end |
---|
| 1395 | end |
---|
| 1396 | end |
---|
[598] | 1397 | if isempty(RunTime) && strcmp(RunMode,'cluster_oar') |
---|
[594] | 1398 | msgbox_uvmat('ERROR','RunTime name not found in PARAM.xml, compiled version .sh cannot run on cluster') |
---|
| 1399 | return |
---|
| 1400 | end |
---|
[598] | 1401 | % Series.RunTime=RunTime; |
---|
[594] | 1402 | end |
---|
[595] | 1403 | |
---|
| 1404 | %% set nbre of cluster cores and processes |
---|
| 1405 | switch RunMode |
---|
| 1406 | case {'local','background'} |
---|
| 1407 | NbCore=1;% no need to split the calculation |
---|
| 1408 | case 'cluster_oar' |
---|
| 1409 | if strcmp(Series.Action.ActionExt,'.m')% case of Matlab function (uncompiled) |
---|
| 1410 | NbCore=1;% one core used only (limitation of Matlab licences) |
---|
| 1411 | msgbox_uvmat('WARNING','Number of cores =1: select the compiled version civ_matlab.sh for multi-core processing'); |
---|
| 1412 | extra_oar=''; |
---|
| 1413 | else |
---|
[591] | 1414 | answer=inputdlg({'Number of cores (max 36)','extra oar options'},'oarsub parameter',1,{'12',''}); |
---|
| 1415 | NbCore=str2double(answer{1}); |
---|
[595] | 1416 | extra_oar=answer{2}; |
---|
| 1417 | end |
---|
| 1418 | end |
---|
| 1419 | if ~isfield(Series.IndexRange,'NbSlice') |
---|
| 1420 | Series.IndexRange.NbSlice=[]; |
---|
| 1421 | end |
---|
| 1422 | if isempty(Series.IndexRange.NbSlice) |
---|
[591] | 1423 | NbProcess=NbCore;% choose one process per core |
---|
[594] | 1424 | else |
---|
[595] | 1425 | NbProcess=Series.IndexRange.NbSlice;% the nbre of run processes is equal to the number of slices |
---|
| 1426 | NbCore=min(NbCore,NbProcess);% at least one process per core |
---|
[591] | 1427 | end |
---|
[602] | 1428 | |
---|
[594] | 1429 | |
---|
| 1430 | %% read index ranges |
---|
| 1431 | first_i=1; |
---|
| 1432 | last_i=1; |
---|
| 1433 | incr_i=1; |
---|
| 1434 | first_j=1; |
---|
| 1435 | last_j=1; |
---|
[602] | 1436 | incr_j=1; |
---|
[594] | 1437 | if isfield(Series.IndexRange,'first_i') |
---|
| 1438 | first_i=Series.IndexRange.first_i; |
---|
| 1439 | incr_i=Series.IndexRange.incr_i; |
---|
| 1440 | last_i=Series.IndexRange.last_i; |
---|
| 1441 | end |
---|
| 1442 | if isfield(Series.IndexRange,'first_j') |
---|
| 1443 | first_j=Series.IndexRange.first_j; |
---|
| 1444 | last_j=Series.IndexRange.last_j; |
---|
[602] | 1445 | incr_j=Series.IndexRange.incr_j; |
---|
[594] | 1446 | end |
---|
| 1447 | if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),... |
---|
[595] | 1448 | set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return |
---|
[594] | 1449 | else |
---|
| 1450 | BlockLength=ceil(numel(first_i:incr_i:last_i)/NbProcess); |
---|
| 1451 | end |
---|
[602] | 1452 | nbfield_j=numel(first_j:incr_j:last_j); |
---|
[594] | 1453 | |
---|
[604] | 1454 | %% record nbre of output files and starting time for computation for status |
---|
[602] | 1455 | StatusData=get(handles.status,'UserData'); |
---|
[605] | 1456 | if isfield(StatusData,'OutputFileMode') |
---|
[604] | 1457 | switch StatusData.OutputFileMode |
---|
| 1458 | case 'NbInput' |
---|
| 1459 | StatusData.NbOutputFile=numel(first_i,incr_i:last_i)*numel(first_j,incr_j:last_j); |
---|
| 1460 | case 'NbInput_i' |
---|
| 1461 | StatusData.NbOutputFile=numel(first_i,incr_i:last_i); |
---|
| 1462 | case 'NbSlice' |
---|
| 1463 | StatusData.NbOutputFile=str2num(get(handles.num_NbSlice,'String')); |
---|
| 1464 | end |
---|
[605] | 1465 | end |
---|
[604] | 1466 | StatusData.TimeStart=now; |
---|
| 1467 | set(handles.status,'UserData',StatusData) |
---|
[602] | 1468 | |
---|
[595] | 1469 | %% direct processing on the current Matlab session |
---|
| 1470 | if strcmp (RunMode,'local') |
---|
| 1471 | Series.RUNHandle=handles.RUN; |
---|
| 1472 | Series.WaitbarHandle=handles.Waitbar; |
---|
| 1473 | for iprocess=1:NbProcess |
---|
| 1474 | if isempty(Series.IndexRange.NbSlice) |
---|
[601] | 1475 | Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i; |
---|
[598] | 1476 | if Series.IndexRange.first_i>last_i |
---|
| 1477 | break |
---|
| 1478 | end |
---|
[601] | 1479 | Series.IndexRange.last_i=min(first_i+(iprocess)*BlockLength*incr_i-1,last_i); |
---|
[595] | 1480 | else |
---|
| 1481 | Series.IndexRange.first_i= first_i+iprocess-1; |
---|
| 1482 | Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice; |
---|
| 1483 | end |
---|
| 1484 | t=struct2xml(Series); |
---|
| 1485 | t=set(t,1,'name','Series'); |
---|
| 1486 | filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,... |
---|
| 1487 | Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j); |
---|
| 1488 | save(t,filexml); |
---|
| 1489 | switch ActionExt |
---|
| 1490 | case '.m' |
---|
| 1491 | h_fun(Series); |
---|
| 1492 | case '.sh' |
---|
| 1493 | switch computer |
---|
| 1494 | case {'PCWIN','PCWIN64'} %Windows system |
---|
| 1495 | filexml=regexprep(filexml,'\\','\\\\');% add '\' so that '\' are left as characters |
---|
[598] | 1496 | system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]);% TODO: adapt to DOS system |
---|
[595] | 1497 | case {'GLNX86','GLNXA64','MACI64'}%Linux system |
---|
[598] | 1498 | system([fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml]); |
---|
[591] | 1499 | end |
---|
[472] | 1500 | end |
---|
[595] | 1501 | end |
---|
| 1502 | elseif strcmp(get(handles.OutputDirExt,'Visible'),'off') |
---|
| 1503 | msgbox_uvmat('ERROR',['no output file for Action ' ActionName ', use run mode = local']);% a output dir is needed for background option |
---|
| 1504 | return |
---|
| 1505 | else |
---|
| 1506 | %% processing on a different session of the same computer (background) or cluster, create executable files |
---|
| 1507 | batch_file_list=cell(NbProcess,1);% initiate the list of executable files |
---|
| 1508 | DirBat=fullfile(OutputDir,'0_BAT'); |
---|
| 1509 | %create subdirectory for executable files |
---|
| 1510 | if ~exist(DirBat,'dir') |
---|
| 1511 | [tild,msg1]=mkdir(DirBat); |
---|
| 1512 | if ~strcmp(msg1,'') |
---|
| 1513 | msgbox_uvmat('ERROR',['cannot create ' DirBat ': ' msg1]);%error message for directory creation |
---|
| 1514 | return |
---|
[472] | 1515 | end |
---|
[595] | 1516 | end |
---|
| 1517 | %create subdirectory for log files |
---|
| 1518 | DirLog=fullfile(OutputDir,'0_LOG'); |
---|
| 1519 | if ~exist(DirLog,'dir') |
---|
| 1520 | [tild,msg1]=mkdir(DirLog); |
---|
| 1521 | if ~strcmp(msg1,'') |
---|
| 1522 | msgbox_uvmat('ERROR',['cannot create ' DirLog ': ' msg1]);%error message for directory creation |
---|
| 1523 | return |
---|
| 1524 | end |
---|
| 1525 | end |
---|
| 1526 | for iprocess=1:NbProcess |
---|
| 1527 | if isempty(Series.IndexRange.NbSlice)% process by blocks of i index |
---|
[601] | 1528 | Series.IndexRange.first_i=first_i+(iprocess-1)*BlockLength*incr_i; |
---|
[598] | 1529 | if Series.IndexRange.first_i>last_i |
---|
| 1530 | NbProcess=iprocess-1; |
---|
| 1531 | break% leave the loop, we are at the end of the calculation |
---|
| 1532 | end |
---|
[601] | 1533 | Series.IndexRange.last_i=min(last_i,first_i+(iprocess)*BlockLength*incr_i-1); |
---|
[595] | 1534 | else% process by slices of i index if NbSlice is defined, computation in a single process if NbSlice =1 |
---|
| 1535 | Series.IndexRange.first_i= first_i+iprocess-1; |
---|
| 1536 | Series.IndexRange.incr_i=incr_i*Series.IndexRange.NbSlice; |
---|
| 1537 | end |
---|
| 1538 | |
---|
| 1539 | % create, fill and save the xml parameter file |
---|
| 1540 | t=struct2xml(Series); |
---|
| 1541 | t=set(t,1,'name','Series'); |
---|
| 1542 | filexml=fullfile_uvmat(DirXml,'',Series.InputTable{1,3},'.xml',OutputNomType,... |
---|
| 1543 | Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j); |
---|
| 1544 | save(t,filexml);% save the parameter file |
---|
| 1545 | |
---|
| 1546 | %create the executable file |
---|
[598] | 1547 | % filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.bat',OutputNomType,... |
---|
| 1548 | % Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j); |
---|
| 1549 | filebat=fullfile_uvmat(DirBat,'',Series.InputTable{1,3},'.sh',OutputNomType,... |
---|
| 1550 | Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j); |
---|
[595] | 1551 | batch_file_list{iprocess}=filebat; |
---|
| 1552 | [fid,message]=fopen(filebat,'w');% create the executable file |
---|
| 1553 | if isequal(fid,-1) |
---|
| 1554 | msgbox_uvmat('ERROR', ['creation of .bat file: ' message]); |
---|
| 1555 | return |
---|
| 1556 | end |
---|
| 1557 | |
---|
| 1558 | % set the log file name |
---|
| 1559 | filelog=fullfile_uvmat(DirLog,'',Series.InputTable{1,3},'.log',OutputNomType,... |
---|
| 1560 | Series.IndexRange.first_i,Series.IndexRange.last_i,first_j,last_j); |
---|
| 1561 | |
---|
| 1562 | % fill and save the executable file |
---|
| 1563 | switch ActionExt |
---|
| 1564 | case '.m'% Matlab function |
---|
| 1565 | switch computer |
---|
| 1566 | case {'GLNX86','GLNXA64','MACI64'} |
---|
| 1567 | cmd=[... |
---|
| 1568 | '#!/bin/bash \n'... |
---|
| 1569 | '. /etc/sysprofile \n'... |
---|
| 1570 | 'matlab -nodisplay -nosplash -nojvm -logfile ''' filelog ''' <<END_MATLAB \n'... |
---|
| 1571 | 'addpath(''' path_series '''); \n'... |
---|
| 1572 | 'addpath(''' Series.Action.ActionPath '''); \n'... |
---|
| 1573 | '' Series.Action.ActionName '( ''' filexml '''); \n'... |
---|
| 1574 | 'exit \n'... |
---|
| 1575 | 'END_MATLAB \n']; |
---|
| 1576 | fprintf(fid,cmd);%fill the executable file with the char string cmd |
---|
| 1577 | fclose(fid);% close the executable file |
---|
| 1578 | system(['chmod +x ' filebat]);% set the file to executable |
---|
| 1579 | case {'PCWIN','PCWIN64'} |
---|
| 1580 | text_matlabscript=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')... |
---|
| 1581 | ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'... |
---|
| 1582 | 'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'... |
---|
| 1583 | '' Series.Action.ActionName '( ''' regexprep(filexml,'\\','\\\\') ''');exit"']; |
---|
| 1584 | fprintf(fid,text_matlabscript);%fill the executable file with the char string cmd |
---|
| 1585 | fclose(fid);% close the executable file |
---|
[591] | 1586 | end |
---|
[595] | 1587 | case '.sh' % compiled Matlab function |
---|
| 1588 | switch computer |
---|
| 1589 | case {'GLNX86','GLNXA64','MACI64'} |
---|
| 1590 | cmd=['#!/bin/bash \n '... |
---|
| 1591 | '#$ -cwd \n '... |
---|
| 1592 | 'hostname && date \n '... |
---|
| 1593 | 'umask 002 \n'... |
---|
[598] | 1594 | fullfile(ActionPath,[ActionName '.sh']) ' ' RunTime ' ' filexml];%allow writting access to created files for user group |
---|
[595] | 1595 | fprintf(fid,cmd);%fill the executable file with the char string cmd |
---|
| 1596 | fclose(fid);% close the executable file |
---|
| 1597 | system(['chmod +x ' filebat]);% set the file to executable |
---|
[591] | 1598 | |
---|
[595] | 1599 | case {'PCWIN','PCWIN64'} % TODO: adapt to Windows system |
---|
| 1600 | % cmd=['matlab -automation -logfile ' regexprep(filelog,'\\','\\\\')... |
---|
| 1601 | % ' -r "addpath(''' regexprep(path_series,'\\','\\\\') ''');'... |
---|
| 1602 | % 'addpath(''' regexprep(Series.Action.ActionPath,'\\','\\\\') ''');'... |
---|
| 1603 | % '' Series.Action.ActionName '( ''' regexprep(filexml,'\\','\\\\') ''');exit"']; |
---|
| 1604 | fprintf(fid,cmd); |
---|
[591] | 1605 | fclose(fid); |
---|
[595] | 1606 | % dos([filebat ' &']); |
---|
[591] | 1607 | end |
---|
| 1608 | end |
---|
[595] | 1609 | end |
---|
[472] | 1610 | end |
---|
| 1611 | |
---|
[595] | 1612 | %% launch the executable files for background or cluster processing |
---|
| 1613 | switch RunMode |
---|
| 1614 | case 'background' |
---|
| 1615 | for iprocess=1:NbProcess |
---|
[604] | 1616 | system([batch_file_list{iprocess} ' &'])% directly execute the command file for each process |
---|
[595] | 1617 | end |
---|
| 1618 | case 'cluster_oar' % option 'oar-parexec' used |
---|
| 1619 | %create subdirectory for oar command and log files |
---|
| 1620 | DirOAR=fullfile(OutputDir,'0_OAR'); |
---|
| 1621 | if ~exist(DirOAR,'dir') |
---|
| 1622 | [tild,msg1]=mkdir(DirOAR); |
---|
| 1623 | if ~strcmp(msg1,'') |
---|
| 1624 | msgbox_uvmat('ERROR',['cannot create ' DirOAR ': ' msg1]);%error message for directory creation |
---|
| 1625 | return |
---|
| 1626 | end |
---|
| 1627 | end |
---|
[602] | 1628 | max_walltime=3600*12; % 12h max total calculation |
---|
| 1629 | walltime_onejob=600;%seconds, max estimated time for asingle file index value |
---|
[595] | 1630 | filename_joblist=fullfile(DirOAR,'job_list.txt');%create name of the global executable file |
---|
| 1631 | fid=fopen(filename_joblist,'w'); |
---|
| 1632 | for p=1:length(batch_file_list) |
---|
[598] | 1633 | fprintf(fid,[batch_file_list{p} '\n']);% list of exe files |
---|
[595] | 1634 | end |
---|
| 1635 | fclose(fid); |
---|
| 1636 | system(['chmod +x ' filename_joblist]);% set the file to executable |
---|
| 1637 | oar_command=['oarsub -n CIVX '... |
---|
| 1638 | '-t idempotent --checkpoint ' num2str(walltime_onejob+60) ' '... |
---|
| 1639 | '-l /core=' num2str(NbCore) ','... |
---|
[602] | 1640 | 'walltime=' datestr(min(1.05*walltime_onejob/86400*max(NbProcess*BlockLength*nbfield_j,NbCore)/NbCore,max_walltime/86400),13) ' '... |
---|
[595] | 1641 | '-E ' regexprep(filename_joblist,'\.txt\>','.stderr') ' '... |
---|
| 1642 | '-O ' regexprep(filename_joblist,'\.txt\>','.stdout') ' '... |
---|
| 1643 | extra_oar ' '... |
---|
| 1644 | '"oar-parexec -s -f ' filename_joblist ' '... |
---|
| 1645 | '-l ' filename_joblist '.log"\n']; |
---|
| 1646 | filename_oarcommand=fullfile(DirOAR,'oar_command'); |
---|
| 1647 | fid=fopen(filename_oarcommand,'w'); |
---|
| 1648 | fprintf(fid,oar_command); |
---|
| 1649 | fclose(fid); |
---|
| 1650 | fprintf(oar_command);% display in command line |
---|
| 1651 | %system(['chmod +x ' oar_command]);% set the file to executable |
---|
| 1652 | system(oar_command); |
---|
| 1653 | end |
---|
| 1654 | |
---|
| 1655 | %% reset the GUI series |
---|
| 1656 | update_waitbar(handles.Waitbar,1); % put the waitbar to end position to indicate launching is finished |
---|
[446] | 1657 | set(handles.RUN, 'Enable','On') |
---|
| 1658 | set(handles.RUN,'BackgroundColor',[1 0 0]) |
---|
[591] | 1659 | set(handles.RUN, 'Value',0) |
---|
[2] | 1660 | |
---|
[446] | 1661 | %------------------------------------------------------------------------ |
---|
| 1662 | function STOP_Callback(hObject, eventdata, handles) |
---|
| 1663 | %------------------------------------------------------------------------ |
---|
| 1664 | set(handles.RUN, 'BusyAction','cancel') |
---|
| 1665 | set(handles.RUN,'BackgroundColor',[1 0 0]) |
---|
| 1666 | set(handles.RUN,'enable','on') |
---|
[591] | 1667 | set(handles.RUN, 'Value',0) |
---|
[446] | 1668 | |
---|
[472] | 1669 | % %------------------------------------------------------------------------ |
---|
| 1670 | % % --- Executes on button press in BIN. |
---|
| 1671 | % function BIN_Callback(hObject, eventdata, handles) |
---|
| 1672 | % %------------------------------------------------------------------------ |
---|
| 1673 | % cmd=['#!/bin/bash \n '... |
---|
| 1674 | % '#$ -cwd \n '... |
---|
| 1675 | % 'hostname && date \n '... |
---|
| 1676 | % 'umask 002 \n'... |
---|
| 1677 | % Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc']; |
---|
| 1678 | % |
---|
[446] | 1679 | %------------------------------------------------------------------------ |
---|
[456] | 1680 | % --- Main launch command, called by RUN and BATCH |
---|
[591] | 1681 | |
---|
[595] | 1682 | function [Series,OutputDir,errormsg]=prepare_jobs(handles) |
---|
[472] | 1683 | %INPUT: |
---|
| 1684 | % handles: handles of graphic objects on the GUI series |
---|
| 1685 | |
---|
[446] | 1686 | %------------------------------------------------------------------------ |
---|
[595] | 1687 | OutputDir=''; |
---|
[446] | 1688 | errormsg=''; |
---|
[594] | 1689 | |
---|
[446] | 1690 | %% Read parameters from series |
---|
| 1691 | Series=read_GUI(handles.series); |
---|
| 1692 | |
---|
| 1693 | %% get_field GUI |
---|
[595] | 1694 | % if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field') |
---|
| 1695 | % if strcmp(Series.InputFields.Field,'get_field...') |
---|
| 1696 | % hget_field=findobj(allchild(0),'name','get_field'); |
---|
| 1697 | % Series.GetField=read_GUI(hget_field); |
---|
[594] | 1698 | % end |
---|
| 1699 | % end |
---|
[26] | 1700 | |
---|
[595] | 1701 | %% create the output data directory |
---|
[446] | 1702 | %determine the root file corresponding to the first sub dir |
---|
[591] | 1703 | if get(handles.RUN,'value') && isfield(Series,'OutputSubDir') |
---|
| 1704 | SubDirOut=[get(handles.OutputSubDir,'String') Series.OutputDirExt]; |
---|
[446] | 1705 | SubDirOutNew=SubDirOut; |
---|
| 1706 | SeriesData=get(handles.series,'UserData'); |
---|
[591] | 1707 | if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && SeriesData.AllowInputSort |
---|
[446] | 1708 | [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order |
---|
| 1709 | Series.InputTable=Series.InputTable(iview,:); |
---|
[421] | 1710 | end |
---|
[448] | 1711 | detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if the dir already exist |
---|
[450] | 1712 | check_create=1; %need to create the result directory by default |
---|
[446] | 1713 | while detect |
---|
[448] | 1714 | answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']); |
---|
[599] | 1715 | if strcmp(answer,'Cancel') |
---|
| 1716 | errormsg='Cancel'; |
---|
| 1717 | return |
---|
| 1718 | elseif strcmp(answer,'Yes') |
---|
[448] | 1719 | detect=0; |
---|
| 1720 | check_create=0; |
---|
| 1721 | else |
---|
| 1722 | r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number |
---|
| 1723 | if isempty(r) |
---|
| 1724 | r(1).root=[SubDirOutNew '_']; |
---|
| 1725 | r(1).num1='0'; |
---|
| 1726 | end |
---|
| 1727 | SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1 |
---|
| 1728 | detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if the dir already exists |
---|
| 1729 | check_create=1; |
---|
[408] | 1730 | end |
---|
| 1731 | end |
---|
[448] | 1732 | Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,''); |
---|
[446] | 1733 | Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output |
---|
[448] | 1734 | set(handles.OutputDirExt,'String',Series.OutputDirExt) |
---|
[595] | 1735 | OutputDir=fullfile(Series.InputTable{1,1},[Series.OutputSubDir Series.OutputDirExt]);% full name (with path) of output directory |
---|
| 1736 | if check_create % create output directory if it does not exist |
---|
[472] | 1737 | [tild,msg1]=mkdir(OutputDir); |
---|
[446] | 1738 | if ~strcmp(msg1,'') |
---|
[472] | 1739 | errormsg=['cannot create ' OutputDir ': ' msg1];%error message for directory creation |
---|
[446] | 1740 | return |
---|
[421] | 1741 | end |
---|
[408] | 1742 | end |
---|
[595] | 1743 | % RootOut=fullfile(OutputDir,Series.InputTable{1,3});% name of the parameter xml file set in this directory |
---|
[408] | 1744 | end |
---|
[595] | 1745 | |
---|
| 1746 | %% removes unused information on Series |
---|
| 1747 | if isfield(Series,'Pairs') |
---|
| 1748 | Series=rmfield(Series,'Pairs'); %info Pairs not needed for output |
---|
| 1749 | end |
---|
[472] | 1750 | Series.IndexRange=rmfield(Series.IndexRange,'TimeTable'); |
---|
[598] | 1751 | % Series.IndexRange=rmfield(Series.IndexRange,'MinIndex'); |
---|
| 1752 | % Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex'); |
---|
[591] | 1753 | empty_line=false(size(Series.InputTable,1),1); |
---|
[472] | 1754 | for iline=1:size(Series.InputTable,1) |
---|
| 1755 | empty_line(iline)=isequal(Series.InputTable(iline,1:3),{'','',''}); |
---|
| 1756 | end |
---|
[591] | 1757 | Series.InputTable(empty_line,:)=[]; |
---|
[408] | 1758 | |
---|
[41] | 1759 | %------------------------------------------------------------------------ |
---|
[446] | 1760 | % --- Executes on selection change in ActionName. |
---|
| 1761 | function ActionName_Callback(hObject, eventdata, handles) |
---|
[41] | 1762 | %------------------------------------------------------------------------ |
---|
[591] | 1763 | %% stop any ongoing series processing |
---|
| 1764 | if isequal(get(handles.RUN,'Value'),1) |
---|
| 1765 | answer= msgbox_uvmat('INPUT_Y-N','stop current Action process?'); |
---|
| 1766 | if strcmp(answer,'Yes') |
---|
| 1767 | STOP_Callback(hObject, eventdata, handles) |
---|
| 1768 | else |
---|
| 1769 | return |
---|
| 1770 | end |
---|
| 1771 | end |
---|
[598] | 1772 | set(handles.ActionName,'BackgroundColor',[1 1 0]) |
---|
| 1773 | drawnow |
---|
[591] | 1774 | |
---|
| 1775 | %% get Action name and path |
---|
| 1776 | nb_builtin_ACTION=4; %nbre of functions initially proposed in the menu ActionName (as defined in the Opening fct of series) |
---|
| 1777 | ActionList=get(handles.ActionName,'String');% list menu fields |
---|
| 1778 | ActionIndex=get(handles.ActionName,'Value'); |
---|
| 1779 | if ~isequal(ActionIndex,1) |
---|
| 1780 | InputTable=get(handles.InputTable,'Data'); |
---|
| 1781 | if isempty(InputTable{1,4}) |
---|
| 1782 | msgbox_uvmat('ERROR','no input file available: use Open in the menu bar') |
---|
| 1783 | return |
---|
| 1784 | end |
---|
| 1785 | end |
---|
| 1786 | ActionName= ActionList{get(handles.ActionName,'Value')}; % selected function name |
---|
| 1787 | ActionPathList=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ActionName |
---|
| 1788 | |
---|
| 1789 | %% add a new function to the menu if 'more...' has been selected in the menu ActionName |
---|
| 1790 | if isequal(ActionName,'more...') |
---|
| 1791 | [FileName, PathName] = uigetfile( ... |
---|
| 1792 | {'*.m', ' (*.m)'; |
---|
[2] | 1793 | '*.m', '.m files '; ... |
---|
| 1794 | '*.*', 'All Files (*.*)'}, ... |
---|
[591] | 1795 | 'Pick a series processing function ',get(handles.ActionPath,'String')); |
---|
[2] | 1796 | if length(FileName)<2 |
---|
| 1797 | return |
---|
| 1798 | end |
---|
[591] | 1799 | [ActionPath,ActionName,ActionExt]=fileparts(FileName); |
---|
[598] | 1800 | |
---|
| 1801 | % insert the choice in the menu ActionName |
---|
[591] | 1802 | ActionIndex=find(strcmp(ActionName,ActionList),1);% look for the selected function in the menu Action |
---|
| 1803 | if isempty(ActionIndex)%the input string does not exist in the menu |
---|
| 1804 | ActionIndex= length(ActionList); |
---|
| 1805 | ActionList=[ActionList(1:end-1);{ActionName};ActionList(end)];% the selected function is appended in the menu, before the last item 'more...' |
---|
| 1806 | set(handles.ActionName,'String',ActionList) |
---|
| 1807 | end |
---|
[2] | 1808 | |
---|
[598] | 1809 | % record the file extension and extend the path list if it is a new extension |
---|
[591] | 1810 | ActionExtList=get(handles.ActionExt,'String'); |
---|
| 1811 | ActionExtIndex=find(strcmp(ActionExt,ActionExtList), 1); |
---|
| 1812 | if isempty(ActionExtIndex) |
---|
| 1813 | set(handles.ActionExt,'String',[ActionExtList;{ActionExt}]) |
---|
[598] | 1814 | ActionExtIndex=numel(ActionExtList)+1; |
---|
[591] | 1815 | ActionPathNew=cell(size(ActionPathList,1),1);%new column of ActionPath |
---|
| 1816 | ActionPathList=[ActionPathList ActionPathNew]; |
---|
| 1817 | end |
---|
| 1818 | set(handles.ActionName,'UserData',ActionPathList); |
---|
[598] | 1819 | |
---|
| 1820 | % remove old Action options in the menu (keeping a menu length <nb_builtin_ACTION+5) |
---|
| 1821 | if length(ActionList)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu |
---|
| 1822 | nbremove=length(ActionList)-nb_builtin_ACTION-5; |
---|
| 1823 | ActionList(nb_builtin_ACTION+1:end-5)=[]; |
---|
| 1824 | ActionPathList(nb_builtin_ACTION+1:end-4,:)=[]; |
---|
| 1825 | ActionIndex=ActionIndex-nbremove; |
---|
| 1826 | end |
---|
[591] | 1827 | |
---|
[598] | 1828 | % record action menu, choice and path |
---|
| 1829 | set(handles.ActionName,'Value',ActionIndex) |
---|
| 1830 | set(handles.ActionName,'String',ActionList) |
---|
| 1831 | set(handles.ActionExt,'Value',ActionExtIndex) |
---|
| 1832 | ActionPathList{ActionIndex,ActionExtIndex}=PathName; |
---|
| 1833 | |
---|
| 1834 | %record the user defined menu additions in personal file profil_perso |
---|
[591] | 1835 | dir_perso=prefdir; |
---|
| 1836 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
[598] | 1837 | if nb_builtin_ACTION+1<=numel(ActionList)-1 |
---|
[591] | 1838 | ActionListUser=ActionList(nb_builtin_ACTION+1:numel(ActionList)-1); |
---|
| 1839 | ActionPathListUser=ActionPathList(nb_builtin_ACTION+1:numel(ActionList)-1,:); |
---|
| 1840 | ActionExtListUser={}; |
---|
| 1841 | if numel(ActionExtList)>2 |
---|
| 1842 | ActionExtListUser=ActionExtList(3:end); |
---|
| 1843 | end |
---|
| 1844 | if exist(profil_perso,'file') |
---|
| 1845 | save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-append') |
---|
| 1846 | else |
---|
| 1847 | save(profil_perso,'ActionListUser','ActionPathListUser','ActionExtListUser','-V6') |
---|
| 1848 | end |
---|
| 1849 | end |
---|
[2] | 1850 | end |
---|
| 1851 | |
---|
[591] | 1852 | %% check the current ActionPath to the selected function |
---|
[594] | 1853 | ActionPath=ActionPathList{ActionIndex};%current recorded path |
---|
| 1854 | set(handles.ActionPath,'String',ActionPath); %show the path to the senlected function |
---|
[2] | 1855 | |
---|
[591] | 1856 | %% reinitialise the waitbar |
---|
[477] | 1857 | update_waitbar(handles.Waitbar,0) |
---|
| 1858 | |
---|
[591] | 1859 | %% default setting for the visibility of the GUI elements |
---|
[598] | 1860 | % set(handles.FieldTransform,'Visible','off') |
---|
| 1861 | % set(handles.CheckObject,'Visible','off'); |
---|
| 1862 | % set(handles.ProjObject,'Visible','off'); |
---|
| 1863 | % set(handles.CheckMask,'Visible','off') |
---|
| 1864 | % set(handles.Mask,'Visible','off') |
---|
[591] | 1865 | |
---|
[594] | 1866 | %% create the function handle for Action |
---|
| 1867 | path_series=which('series'); |
---|
| 1868 | if ~isequal(ActionPath,path_series) |
---|
| 1869 | eval(['spath=which(''' ActionName ''');']) %spath = current path of the selected function ACTION |
---|
| 1870 | if ~exist(ActionPath,'dir') |
---|
| 1871 | errormsg=['The prescribed function path ' ActionPath ' does not exist']; |
---|
| 1872 | return |
---|
| 1873 | end |
---|
| 1874 | if ~isequal(spath,ActionPath) |
---|
| 1875 | addpath(ActionPath)% add the prescribed path if not the current one |
---|
| 1876 | end |
---|
| 1877 | end |
---|
| 1878 | eval(['h_fun=@' ActionName ';'])%create a function handle for ACTION |
---|
| 1879 | if ~isequal(ActionPath,path_series) |
---|
| 1880 | rmpath(ActionPath)% add the prescribed path if not the current one |
---|
| 1881 | end |
---|
| 1882 | |
---|
[598] | 1883 | %% Activate the Action fct |
---|
| 1884 | [Series,tild,errormsg]=prepare_jobs(handles);% read the parameters from the GUI series |
---|
[591] | 1885 | if ~isempty(errormsg) |
---|
[599] | 1886 | if ~strcmp(errormsg,'Cancel') |
---|
[591] | 1887 | msgbox_uvmat('ERROR',errormsg) |
---|
[599] | 1888 | end |
---|
[591] | 1889 | return |
---|
[29] | 1890 | end |
---|
[591] | 1891 | ParamOut=h_fun(Series); |
---|
| 1892 | |
---|
[598] | 1893 | %% Put the first line of the selected Action fct as tooltip help |
---|
[244] | 1894 | try |
---|
[591] | 1895 | [fid,errormsg] =fopen([ActionName '.m']); |
---|
[244] | 1896 | InputText=textscan(fid,'%s',1,'delimiter','\n'); |
---|
[553] | 1897 | fclose(fid); |
---|
[456] | 1898 | set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help |
---|
[244] | 1899 | end |
---|
[2] | 1900 | |
---|
[591] | 1901 | %% Detect the types of input files |
---|
[472] | 1902 | SeriesData=get(handles.series,'UserData'); |
---|
[591] | 1903 | nb_civ=0;nb_netcdf=0; |
---|
| 1904 | if ~isempty(SeriesData) |
---|
| 1905 | nb_civ=numel(find(strcmp('civx',SeriesData.FileType)|strcmp('civdata',SeriesData.FileType))); |
---|
| 1906 | nb_netcdf=numel(find(strcmp('netcdf',SeriesData.FileType))); |
---|
| 1907 | end |
---|
| 1908 | |
---|
| 1909 | %% Check whether alphabetical sorting of input Subdir is alowed by the Action fct (for multiples series entries) |
---|
| 1910 | SeriesData.AllowInputSort=0;%default |
---|
| 1911 | if isfield(ParamOut,'AllowInputSort')&&isequal(ParamOut.AllowInputSort,'on') |
---|
| 1912 | SeriesData.AllowInputSort=1; |
---|
| 1913 | end |
---|
| 1914 | |
---|
| 1915 | %% Impose the whole input file index range if requested |
---|
| 1916 | if isfield(ParamOut,'WholeIndexRange')&&isequal(ParamOut.WholeIndexRange,'on') |
---|
| 1917 | MinIndex=get(handles.MinIndex,'Data'); |
---|
| 1918 | MaxIndex=get(handles.MaxIndex,'Data'); |
---|
| 1919 | if ~isempty(MinIndex) |
---|
| 1920 | set(handles.num_first_i,'String',num2str(MinIndex{1})) |
---|
| 1921 | set(handles.num_last_i,'String',num2str(MaxIndex{1})) |
---|
| 1922 | set(handles.num_incr_i,'String','1') |
---|
| 1923 | if size(MinIndex,2)>=2 |
---|
| 1924 | set(handles.num_first_j,'String',num2str(MinIndex{1,2})) |
---|
| 1925 | set(handles.num_last_j,'String',num2str(MaxIndex{1,2})) |
---|
| 1926 | set(handles.num_incr_j,'String','1') |
---|
| 1927 | end |
---|
[2] | 1928 | end |
---|
[594] | 1929 | else |
---|
| 1930 | % check index ranges |
---|
| 1931 | first_i=1;last_i=1;first_j=1;last_j=1; |
---|
| 1932 | if isfield(Series.IndexRange,'first_i') |
---|
| 1933 | first_i=Series.IndexRange.first_i; |
---|
[604] | 1934 | incr_i=Series.IndexRange.incr_i; |
---|
[594] | 1935 | last_i=Series.IndexRange.last_i; |
---|
[2] | 1936 | end |
---|
[594] | 1937 | if isfield(Series.IndexRange,'first_j') |
---|
| 1938 | first_j=Series.IndexRange.first_j; |
---|
[604] | 1939 | incr_j=Series.IndexRange.incr_j; |
---|
[594] | 1940 | last_j=Series.IndexRange.last_j; |
---|
| 1941 | end |
---|
| 1942 | if last_i < first_i || last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),... |
---|
| 1943 | set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end; |
---|
| 1944 | end |
---|
[591] | 1945 | |
---|
| 1946 | %% NbSlice visibility |
---|
| 1947 | NbSliceVisible='off';%default |
---|
| 1948 | if isfield(ParamOut,'NbSlice') && isequal(ParamOut.NbSlice,'on') |
---|
| 1949 | NbSliceVisible='on'; |
---|
| 1950 | set(handles.num_NbProcess,'String',get(handles.num_NbSlice,'String'))% the nbre of processes is imposed as the nbre of slices |
---|
| 1951 | else |
---|
| 1952 | set(handles.num_NbProcess,'String','')% free nbre of processes |
---|
[2] | 1953 | end |
---|
[591] | 1954 | set(handles.num_NbSlice,'Visible',NbSliceVisible) |
---|
| 1955 | set(handles.NbSlice_title,'Visible',NbSliceVisible) |
---|
[2] | 1956 | |
---|
[591] | 1957 | %% Visibility of VelType and VelType_1 menus |
---|
| 1958 | VelTypeVisible='off'; %hidden by default |
---|
| 1959 | VelType_1Visible='off'; |
---|
| 1960 | InputFieldsVisible='off';%visibility of the frame Fields |
---|
| 1961 | if isfield(ParamOut,'VelType') |
---|
| 1962 | if strcmp( ParamOut.VelType,'one')||strcmp( ParamOut.VelType,'two') |
---|
| 1963 | if nb_civ>=1 |
---|
| 1964 | VelTypeVisible='on'; |
---|
| 1965 | InputFieldsVisible='on'; |
---|
| 1966 | end |
---|
| 1967 | end |
---|
| 1968 | if strcmp( ParamOut.VelType,'two') |
---|
| 1969 | if nb_civ>=2 |
---|
| 1970 | VelType_1Visible='on'; |
---|
| 1971 | end |
---|
| 1972 | end |
---|
| 1973 | end |
---|
| 1974 | set(handles.VelType,'Visible',VelTypeVisible) |
---|
| 1975 | set(handles.VelType_text,'Visible',VelTypeVisible); |
---|
| 1976 | set(handles.VelType_1,'Visible',VelType_1Visible) |
---|
| 1977 | set(handles.VelType_text_1,'Visible',VelType_1Visible); |
---|
| 1978 | |
---|
| 1979 | %% Visibility of FieldName and FieldName_1 menus |
---|
| 1980 | FieldNameVisible='off'; %hidden by default |
---|
| 1981 | FieldName_1Visible='off'; %hidden by default |
---|
| 1982 | if isfield(ParamOut,'FieldName') |
---|
| 1983 | if strcmp( ParamOut.FieldName,'one')||strcmp( ParamOut.FieldName,'two') |
---|
| 1984 | if (nb_civ+nb_netcdf)>=1 |
---|
| 1985 | InputFieldsVisible='on'; |
---|
| 1986 | FieldNameVisible='on'; |
---|
| 1987 | end |
---|
| 1988 | end |
---|
| 1989 | if strcmp( ParamOut.FieldName,'two') |
---|
| 1990 | if (nb_civ+nb_netcdf)>=1 |
---|
| 1991 | FieldName_1Visible='on'; |
---|
| 1992 | end |
---|
| 1993 | end |
---|
| 1994 | end |
---|
| 1995 | set(handles.InputFields,'Visible',InputFieldsVisible) |
---|
| 1996 | set(handles.FieldName,'Visible',FieldNameVisible) % test for MenuBorser |
---|
| 1997 | set(handles.FieldName_1,'Visible',FieldName_1Visible) |
---|
| 1998 | |
---|
| 1999 | %% Visibility of FieldTransform menu |
---|
| 2000 | FieldTransformVisible='off'; %hidden by default |
---|
| 2001 | if isfield(ParamOut,'FieldTransform') |
---|
| 2002 | FieldTransformVisible=ParamOut.FieldTransform; |
---|
| 2003 | TransformName_Callback([],[], handles) |
---|
| 2004 | end |
---|
| 2005 | set(handles.FieldTransform,'Visible',FieldTransformVisible) |
---|
[606] | 2006 | if isfield(ParamOut,'TransformPath') |
---|
| 2007 | set(handles.ActionExt,'UserData',ParamOut.TransformPath) |
---|
| 2008 | else |
---|
| 2009 | set(handles.ActionExt,'UserData',[]) |
---|
| 2010 | end |
---|
[591] | 2011 | |
---|
| 2012 | %% Visibility of projection object |
---|
| 2013 | ProjObjectVisible='off'; %hidden by default |
---|
| 2014 | if isfield(ParamOut,'ProjObject') |
---|
| 2015 | ProjObjectVisible=ParamOut.ProjObject; |
---|
| 2016 | end |
---|
| 2017 | set(handles.CheckObject,'Visible',ProjObjectVisible) |
---|
| 2018 | if ~get(handles.CheckObject,'Value') |
---|
| 2019 | ProjObjectVisible='off'; |
---|
| 2020 | end |
---|
| 2021 | set(handles.ProjObject,'Visible',ProjObjectVisible) |
---|
| 2022 | set(handles.DeleteObject,'Visible',ProjObjectVisible) |
---|
| 2023 | set(handles.ViewObject,'Visible',ProjObjectVisible) |
---|
| 2024 | |
---|
| 2025 | |
---|
| 2026 | %% Visibility of mask input |
---|
| 2027 | MaskVisible='off'; %hidden by default |
---|
| 2028 | if isfield(ParamOut,'Mask') |
---|
| 2029 | MaskVisible=ParamOut.Mask; |
---|
| 2030 | end |
---|
| 2031 | set(handles.Mask,'Visible',MaskVisible) |
---|
| 2032 | set(handles.CheckMask,'Visible',MaskVisible); |
---|
| 2033 | |
---|
| 2034 | %% definition of the directory containing the output files |
---|
| 2035 | OutputDirVisible='off'; |
---|
| 2036 | if isfield(ParamOut,'OutputDirExt')&&~isempty(ParamOut.OutputDirExt) |
---|
| 2037 | set(handles.OutputDirExt,'String',ParamOut.OutputDirExt) |
---|
| 2038 | OutputDirVisible='on'; |
---|
| 2039 | end |
---|
| 2040 | set(handles.OutputDirExt,'Visible',OutputDirVisible) |
---|
| 2041 | set(handles.OutputSubDir,'Visible',OutputDirVisible) |
---|
| 2042 | set(handles.OutputDir_title,'Visible',OutputDirVisible) |
---|
| 2043 | set(handles.RunMode,'Visible',OutputDirVisible) |
---|
| 2044 | set(handles.ActionExt,'Visible',OutputDirVisible) |
---|
| 2045 | set(handles.RunMode_title,'Visible',OutputDirVisible) |
---|
| 2046 | set(handles.ActionExt_title,'Visible',OutputDirVisible) |
---|
| 2047 | |
---|
[602] | 2048 | %% Expected nbre of output files |
---|
| 2049 | if isfield(ParamOut,'OutputFileMode') |
---|
[604] | 2050 | StatusData.OutputFileMode=ParamOut.OutputFileMode; |
---|
[602] | 2051 | set(handles.status,'UserData',StatusData) |
---|
| 2052 | end |
---|
| 2053 | |
---|
[591] | 2054 | %% definition of an additional parameter set, determined by an ancillary GUI |
---|
| 2055 | if isfield(ParamOut,'ActionInput') |
---|
| 2056 | set(handles.ActionInput,'Visible','on') |
---|
| 2057 | set(handles.ActionInput_title,'Visible','on') |
---|
[598] | 2058 | set(handles.ActionInputView,'Visible','on') |
---|
| 2059 | set(handles.ActionInputView,'Value',0) |
---|
[591] | 2060 | set(handles.ActionInput,'String',ActionName) |
---|
[598] | 2061 | ParamOut.ActionInput.Program=ActionName; % record the program in ActionInput |
---|
[591] | 2062 | SeriesData.ActionInput=ParamOut.ActionInput; |
---|
| 2063 | else |
---|
| 2064 | set(handles.ActionInput,'Visible','off') |
---|
| 2065 | set(handles.ActionInput_title,'Visible','off') |
---|
[598] | 2066 | set(handles.ActionInputView,'Visible','off') |
---|
[591] | 2067 | if isfield(SeriesData,'ActionInput') |
---|
| 2068 | SeriesData=rmfield(SeriesData,'ActionInput'); |
---|
| 2069 | end |
---|
| 2070 | end |
---|
| 2071 | set(handles.series,'UserData',SeriesData) |
---|
[598] | 2072 | set(handles.ActionName,'BackgroundColor',[1 1 1]) |
---|
[591] | 2073 | |
---|
[41] | 2074 | %------------------------------------------------------------------------ |
---|
[598] | 2075 | % --- Executes on button press in ActionInputView. |
---|
| 2076 | function ActionInputView_Callback(hObject, eventdata, handles) |
---|
| 2077 | %------------------------------------------------------------------------ |
---|
| 2078 | if get(handles.ActionInputView,'Value') |
---|
| 2079 | ActionName_Callback(hObject, eventdata, handles) |
---|
| 2080 | end |
---|
| 2081 | |
---|
| 2082 | %------------------------------------------------------------------------ |
---|
[446] | 2083 | % --- Executes on selection change in FieldName. |
---|
| 2084 | function FieldName_Callback(hObject, eventdata, handles) |
---|
[41] | 2085 | %------------------------------------------------------------------------ |
---|
[446] | 2086 | field_str=get(handles.FieldName,'String'); |
---|
| 2087 | field_index=get(handles.FieldName,'Value'); |
---|
[2] | 2088 | field=field_str{field_index(1)}; |
---|
[595] | 2089 | if isequal(field,'get_field...') |
---|
| 2090 | hget_field=findobj(allchild(0),'name','get_field'); |
---|
| 2091 | if ~isempty(hget_field) |
---|
| 2092 | delete(hget_field)%delete opened versions of get_field |
---|
| 2093 | end |
---|
| 2094 | Series=read_GUI(handles.series); |
---|
| 2095 | Series.InputTable=Series.InputTable(1,:); |
---|
| 2096 | filecell=get_file_series(Series); |
---|
| 2097 | if exist(filecell{1,1},'file') |
---|
| 2098 | GetFieldData=get_field(filecell{1,1}); |
---|
| 2099 | FieldList={}; |
---|
| 2100 | XName=GetFieldData.XVarName; |
---|
| 2101 | if GetFieldData.CheckVector |
---|
| 2102 | UName=GetFieldData.PanelVectors.vector_x; |
---|
| 2103 | VName=GetFieldData.PanelVectors.vector_y; |
---|
| 2104 | XName=GetFieldData.XVarName; |
---|
| 2105 | YName=GetFieldData.YVarName; |
---|
| 2106 | CName=GetFieldData.PanelVectors.vec_color; |
---|
| 2107 | [FieldList,VecColorList]=set_field_list(UName,VName,CName); |
---|
| 2108 | elseif GetFieldData.CheckScalar |
---|
| 2109 | AName=GetFieldData.PanelScalar.scalar; |
---|
| 2110 | XName=GetFieldData.XVarName; |
---|
| 2111 | YName=GetFieldData.YVarName; |
---|
| 2112 | FieldList={AName}; |
---|
| 2113 | elseif GetFieldData.CheckPlot1D; |
---|
| 2114 | YName=GetFieldData.CheckPlot1D.ordinate; |
---|
| 2115 | end |
---|
| 2116 | set(handles.Coord_x,'String',{XName}) |
---|
| 2117 | set(handles.Coord_y,'String',{YName}) |
---|
| 2118 | set(handles.FieldName,'Value',1) |
---|
| 2119 | set(handles.FieldName,'String',[FieldList; {'get_field...'}]); |
---|
| 2120 | % set(handles.ColorScalar,'Value',1) |
---|
| 2121 | % set(handles.ColorScalar,'String',VecColorList); |
---|
| 2122 | % UvData.FileType{1}='netcdf'; |
---|
| 2123 | % set(handles.uvmat,'UserData',UvData) |
---|
| 2124 | end |
---|
| 2125 | % elseif isequal(field,'more...') |
---|
| 2126 | % str=calc_field; |
---|
| 2127 | % [ind_answer,v] = listdlg('PromptString','Select a file:',... |
---|
| 2128 | % 'SelectionMode','single',... |
---|
| 2129 | % 'ListString',str); |
---|
| 2130 | % % edit the choice in the fields and actionname menu |
---|
| 2131 | % scalar=cell2mat(str(ind_answer)); |
---|
| 2132 | % update_menu(handles.FieldName,scalar) |
---|
[2] | 2133 | end |
---|
| 2134 | |
---|
[41] | 2135 | %------------------------------------------------------------------------ |
---|
[446] | 2136 | % --- Executes on selection change in FieldName_1. |
---|
| 2137 | function FieldName_1_Callback(hObject, eventdata, handles) |
---|
[41] | 2138 | %------------------------------------------------------------------------ |
---|
[446] | 2139 | field_str=get(handles.FieldName_1,'String'); |
---|
| 2140 | field_index=get(handles.FieldName_1,'Value'); |
---|
[2] | 2141 | field=field_str{field_index}; |
---|
| 2142 | if isequal(field,'get_field...') |
---|
| 2143 | hget_field=findobj(allchild(0),'name','get_field_1'); |
---|
| 2144 | if ~isempty(hget_field) |
---|
| 2145 | delete(hget_field) |
---|
| 2146 | end |
---|
[332] | 2147 | SeriesData=get(handles.series,'UserData'); |
---|
[2] | 2148 | filename=SeriesData.CurrentInputFile_1; |
---|
| 2149 | if exist(filename,'file') |
---|
| 2150 | hget_field=get_field(filename); |
---|
| 2151 | set(hget_field,'name','get_field_1') |
---|
| 2152 | end |
---|
[595] | 2153 | % elseif isequal(field,'more...') |
---|
| 2154 | % str=calc_field; |
---|
| 2155 | % [ind_answer,v] = listdlg('PromptString','Select a file:',... |
---|
| 2156 | % 'SelectionMode','single',... |
---|
| 2157 | % 'ListString',str); |
---|
| 2158 | % % edit the choice in the fields and actionname menu |
---|
| 2159 | % scalar=cell2mat(str(ind_answer)); |
---|
| 2160 | % update_menu(handles.FieldName_1,scalar) |
---|
[2] | 2161 | end |
---|
[29] | 2162 | |
---|
[244] | 2163 | |
---|
[2] | 2164 | %%%%%%%%%%%%% |
---|
| 2165 | function [ind_remove]=find_pairs(dirpair,ind_i,last_i) |
---|
[339] | 2166 | indsel=ind_i; |
---|
| 2167 | indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series |
---|
| 2168 | indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds |
---|
| 2169 | if ~isempty(indiff) |
---|
| 2170 | indiff2=diff(indiff); |
---|
| 2171 | indiffp=[indiff2 1]; |
---|
| 2172 | indiffm=[1 indiff2]; |
---|
| 2173 | ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets |
---|
| 2174 | ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets |
---|
| 2175 | %for each multiplet, select the most recent file |
---|
| 2176 | ind_remove=[]; |
---|
| 2177 | for i=1:length(ind_multi_m) |
---|
| 2178 | ind_pairs=ind_multi_m(i):ind_multi_p(i); |
---|
| 2179 | for imulti=1:length(ind_pairs) |
---|
| 2180 | datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation |
---|
[2] | 2181 | end |
---|
[339] | 2182 | [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date |
---|
| 2183 | ind_s=indsort2(1:end-1);% |
---|
| 2184 | ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one |
---|
| 2185 | end |
---|
| 2186 | end |
---|
[2] | 2187 | |
---|
[89] | 2188 | %------------------------------------------------------------------------ |
---|
[408] | 2189 | % --- determine the list of index pairstring of processing file |
---|
[32] | 2190 | function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode) |
---|
[89] | 2191 | %------------------------------------------------------------------------ |
---|
[32] | 2192 | num_i1=num_i;% set of first image numbers by default |
---|
| 2193 | num_i2=num_i; |
---|
| 2194 | num_j1=num_j; |
---|
| 2195 | num_j2=num_j; |
---|
| 2196 | num_i_out=num_i; |
---|
| 2197 | num_j_out=num_j; |
---|
[339] | 2198 | % if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2') |
---|
| 2199 | if isequal(mode,'series(Di)') |
---|
[32] | 2200 | num_i1_line=num_i+ind_shift(3);% set of first image numbers |
---|
| 2201 | num_i2_line=num_i+ind_shift(4); |
---|
| 2202 | % adjust the first and last field number |
---|
| 2203 | indsel=find(num_i1_line >= 1); |
---|
| 2204 | num_i_out=num_i(indsel); |
---|
| 2205 | num_i1_line=num_i1_line(indsel); |
---|
| 2206 | num_i2_line=num_i2_line(indsel); |
---|
| 2207 | num_j1=meshgrid(num_j,ones(size(num_i1_line))); |
---|
| 2208 | num_j2=meshgrid(num_j,ones(size(num_i1_line))); |
---|
| 2209 | [xx,num_i1]=meshgrid(num_j,num_i1_line); |
---|
| 2210 | [xx,num_i2]=meshgrid(num_j,num_i2_line); |
---|
[339] | 2211 | elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts') |
---|
[32] | 2212 | if isequal(mode,'bursts') %case of bursts (png_old or png_2D) |
---|
| 2213 | num_j1=ind_shift(1)*ones(size(num_i)); |
---|
| 2214 | num_j2=ind_shift(2)*ones(size(num_i)); |
---|
| 2215 | else |
---|
| 2216 | num_j1_col=num_j+ind_shift(1);% set of first image numbers |
---|
| 2217 | num_j2_col=num_j+ind_shift(2); |
---|
| 2218 | % adjust the first field number |
---|
| 2219 | indsel=find((num_j1_col >= 1)); |
---|
| 2220 | num_j_out=num_j(indsel); |
---|
| 2221 | num_j1_col=num_j1_col(indsel); |
---|
| 2222 | num_j2_col=num_j2_col(indsel); |
---|
| 2223 | [num_i1,num_j1]=meshgrid(num_i,num_j1_col); |
---|
| 2224 | [num_i2,num_j2]=meshgrid(num_i,num_j2_col); |
---|
| 2225 | end |
---|
| 2226 | end |
---|
[2] | 2227 | |
---|
[41] | 2228 | %------------------------------------------------------------------------ |
---|
[446] | 2229 | % --- Executes on button press in CheckObject. |
---|
| 2230 | function CheckObject_Callback(hObject, eventdata, handles) |
---|
[41] | 2231 | %------------------------------------------------------------------------ |
---|
[606] | 2232 | hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle |
---|
[446] | 2233 | value=get(handles.CheckObject,'Value'); |
---|
[2] | 2234 | if value |
---|
[606] | 2235 | SeriesData=get(handles.series,'UserData'); |
---|
| 2236 | if ~(isfield(SeriesData,'ProjObject')&&~isempty(SeriesData.ProjObject)) |
---|
| 2237 | if ishandle(hset_object) |
---|
| 2238 | uistack(hset_object,'top')% show the GUI set_object if opened |
---|
| 2239 | else |
---|
| 2240 | %get the object file |
---|
| 2241 | InputTable=get(handles.InputTable,'Data'); |
---|
| 2242 | defaultname=InputTable{1,1}; |
---|
| 2243 | if isempty(defaultname) |
---|
| 2244 | defaultname={''}; |
---|
| 2245 | end |
---|
| 2246 | [FileName, PathName] = uigetfile( ... |
---|
| 2247 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
| 2248 | '*.xml', '.xml files '; ... |
---|
| 2249 | '*.mat', '.mat matlab files '}, ... |
---|
| 2250 | 'Pick an xml object file (or use uvmat to create it)',defaultname); |
---|
| 2251 | fileinput=[PathName FileName];%complete file name |
---|
| 2252 | sizf=size(fileinput); |
---|
| 2253 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
| 2254 | %read the file |
---|
| 2255 | data=xml2struct(fileinput); |
---|
| 2256 | if ~isfield(data,'Type') |
---|
| 2257 | msgbox_uvmat('ERROR',[fileinput ' is not an object xml file']) |
---|
| 2258 | return |
---|
| 2259 | end |
---|
| 2260 | if ~isfield(data,'ProjMode') |
---|
| 2261 | data.ProjMode='none'; |
---|
| 2262 | end |
---|
| 2263 | hset_object=set_object(data);% call the set_object interface |
---|
[41] | 2264 | end |
---|
[606] | 2265 | ProjObject=read_GUI(hset_object); |
---|
| 2266 | set(handles.ProjObject,'String',ProjObject.Name);%display the object name |
---|
| 2267 | SeriesData=get(handles.series,'UserData'); |
---|
| 2268 | SeriesData.ProjObject=ProjObject; |
---|
| 2269 | set(handles.series,'UserData',SeriesData); |
---|
| 2270 | end |
---|
| 2271 | set(handles.DeleteObject,'Visible','on'); |
---|
| 2272 | set(handles.ViewObject,'Visible','on'); |
---|
| 2273 | set(handles.ProjObject,'Visible','on'); |
---|
[2] | 2274 | else |
---|
[606] | 2275 | set(handles.DeleteObject,'Visible','off'); |
---|
| 2276 | set(handles.ViewObject,'Visible','off'); |
---|
| 2277 | if ~ishandle(hset_object) |
---|
| 2278 | set(handles.ViewObject,'Value',0); |
---|
| 2279 | end |
---|
| 2280 | set(handles.ProjObject,'Visible','off'); |
---|
[2] | 2281 | end |
---|
[446] | 2282 | %set(handles.series,'UserData',SeriesData) |
---|
[2] | 2283 | |
---|
| 2284 | %-------------------------------------------------------------- |
---|
[446] | 2285 | function CheckMask_Callback(hObject, eventdata, handles) |
---|
| 2286 | value=get(handles.CheckMask,'Value'); |
---|
[2] | 2287 | if value |
---|
[41] | 2288 | msgbox_uvmat('ERROR','not implemented yet') |
---|
[2] | 2289 | end |
---|
| 2290 | %-------------------------------------------------------------- |
---|
| 2291 | |
---|
[41] | 2292 | %------------------------------------------------------------------- |
---|
[2] | 2293 | %'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m' |
---|
| 2294 | function ncbrowser_uvmat(hObject, eventdata) |
---|
[41] | 2295 | %------------------------------------------------------------------- |
---|
[2] | 2296 | bla=get(gcbo,'String'); |
---|
| 2297 | ind=get(gcbo,'Value'); |
---|
| 2298 | filename=cell2mat(bla(ind)); |
---|
| 2299 | blank=find(filename==' '); |
---|
| 2300 | filename=filename(1:blank-1); |
---|
| 2301 | get_field(filename) |
---|
| 2302 | |
---|
[41] | 2303 | % ------------------------------------------------------------------ |
---|
[2] | 2304 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
[41] | 2305 | %------------------------------------------------------------------- |
---|
[2] | 2306 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
| 2307 | pathelp=fileparts(path_to_uvmat); |
---|
[36] | 2308 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
| 2309 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package') |
---|
[2] | 2310 | else |
---|
[36] | 2311 | addpath (fullfile(pathelp,'uvmat_doc')) |
---|
| 2312 | web([helpfile '#series']) |
---|
[2] | 2313 | end |
---|
| 2314 | |
---|
[41] | 2315 | %------------------------------------------------------------------- |
---|
[446] | 2316 | % --- Executes on selection change in TransformName. |
---|
| 2317 | function TransformName_Callback(hObject, eventdata, handles) |
---|
[591] | 2318 | %---------------------------------------------------------------------- |
---|
| 2319 | TransformList=get(handles.TransformName,'String'); |
---|
| 2320 | TransformIndex=get(handles.TransformName,'Value'); |
---|
| 2321 | TransformName=TransformList{TransformIndex}; |
---|
| 2322 | TransformPathList=get(handles.TransformName,'UserData'); |
---|
| 2323 | nb_builtin_transform=4; |
---|
| 2324 | % ff=functions(list_transform{end}); |
---|
| 2325 | if isequal(TransformName,'more...'); |
---|
| 2326 | % coord_fct=''; |
---|
| 2327 | % prompt = {'Enter the name of the transform function'}; |
---|
| 2328 | % dlg_title = 'user defined transform'; |
---|
| 2329 | % num_lines= 1; |
---|
| 2330 | [FileName, PathName] = uigetfile( ... |
---|
[39] | 2331 | {'*.m', ' (*.m)'; |
---|
| 2332 | '*.m', '.m files '; ... |
---|
| 2333 | '*.*', 'All Files (*.*)'}, ... |
---|
[591] | 2334 | 'Pick a transform function',get(handles.TransformPath,'String')); |
---|
| 2335 | if isequal(FileName,0) |
---|
| 2336 | return %browser closed without choice |
---|
| 2337 | end |
---|
[39] | 2338 | if isequal(PathName(end),'/')||isequal(PathName(end),'\') |
---|
| 2339 | PathName(end)=[]; |
---|
| 2340 | end |
---|
[591] | 2341 | [TransformPath,TransformName,TransformExt]=fileparts(FileName);% removes extension .m |
---|
| 2342 | if ~strcmp(TransformExt,'.m') |
---|
[39] | 2343 | msgbox_uvmat('ERROR','a Matlab function .m must be introduced'); |
---|
| 2344 | return |
---|
| 2345 | end |
---|
[591] | 2346 | % insert the choice in the menu |
---|
| 2347 | TransformIndex=find(strcmp(TransformName,TransformList),1);% look for the selected function in the menu Action |
---|
| 2348 | if isempty(TransformIndex)%the input string does not exist in the menu |
---|
| 2349 | TransformIndex= length(TransformList); |
---|
| 2350 | TransformList=[TransformList(1:end-1);{TransformnName};TransformList(end)];% the selected function is appended in the menu, before the last item 'more...' |
---|
| 2351 | set(handles.TransformName,'String',TransformList) |
---|
| 2352 | TransformPathList=[TransformPathList;{TransformPath}]; |
---|
| 2353 | end |
---|
[39] | 2354 | % save the new menu in the personal file 'uvmat_perso.mat' |
---|
| 2355 | dir_perso=prefdir;%personal Matalb directory |
---|
| 2356 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 2357 | if exist(profil_perso,'file') |
---|
[591] | 2358 | for ilist=nb_builtin_transform+1:numel(TransformPathList) |
---|
| 2359 | TransformListUser{ilist-nb_builtin_transform}=TransformList{ilist}; |
---|
| 2360 | TransformPathListUser{ilist-nb_builtin_transform}=TransformPathList{ilist}; |
---|
[39] | 2361 | end |
---|
[591] | 2362 | save (profil_perso,'TransformPathListUser','TransformListUser','-append'); %store the root name for future opening of uvmat |
---|
[39] | 2363 | end |
---|
| 2364 | end |
---|
[2] | 2365 | |
---|
[591] | 2366 | %display the current function path |
---|
| 2367 | set(handles.TransformPath,'String',TransformPathList{TransformIndex}); %show the path to the senlected function |
---|
| 2368 | set(handles.TransformName,'UserData',TransformPathList); |
---|
[350] | 2369 | |
---|
| 2370 | |
---|
[446] | 2371 | % -------------------------------------------------------------------- |
---|
| 2372 | function MenuExportConfig_Callback(hObject, eventdata, handles) |
---|
| 2373 | global Series |
---|
[596] | 2374 | [Series,errormsg]=prepare_jobs(handles); |
---|
[358] | 2375 | |
---|
[446] | 2376 | evalin('base','global Series')%make CurData global in the workspace |
---|
| 2377 | display('current series config :') |
---|
| 2378 | evalin('base','Series') %display CurData in the workspace |
---|
| 2379 | commandwindow; %brings the Matlab command window to the front |
---|
[472] | 2380 | |
---|
| 2381 | |
---|
[603] | 2382 | % -------------------------------------------------------------------- |
---|
| 2383 | function MenuImportConfig_Callback(hObject, eventdata, handles) |
---|
| 2384 | % -------------------------------------------------------------------- |
---|
| 2385 | InputTable=get(handles.InputTable,'Data'); |
---|
| 2386 | [FileName, PathName] = uigetfile( ... |
---|
| 2387 | {'*.xml', ' (*.xml)'; |
---|
| 2388 | '*.xml', '.xml files '; ... |
---|
| 2389 | '*.*', 'All Files (*.*)'}, ... |
---|
| 2390 | 'Pick a file',InputTable{1,1}); |
---|
| 2391 | filexml=[PathName FileName];%complete file name |
---|
| 2392 | if isempty(filexml),return;end %abandon if no file is introduced by the browser |
---|
| 2393 | Param=xml2struct(filexml); |
---|
| 2394 | fill_GUI(Param,handles.series) |
---|
| 2395 | |
---|
[472] | 2396 | % --- Executes on selection change in RunMode. |
---|
| 2397 | function RunMode_Callback(hObject, eventdata, handles) |
---|
[525] | 2398 | |
---|
[526] | 2399 | % --- Executes on selection change in Coord_x. |
---|
| 2400 | function Coord_x_Callback(hObject, eventdata, handles) |
---|
[525] | 2401 | |
---|
| 2402 | |
---|
[526] | 2403 | % --- Executes on selection change in Coord_y. |
---|
| 2404 | function Coord_y_Callback(hObject, eventdata, handles) |
---|
[525] | 2405 | |
---|
| 2406 | |
---|
| 2407 | |
---|
[526] | 2408 | % --- Executes when series is resized. |
---|
| 2409 | function series_ResizeFcn(hObject, eventdata, handles) |
---|
| 2410 | %% input table |
---|
| 2411 | set(handles.InputTable,'Unit','pixel') |
---|
| 2412 | Pos=get(handles.InputTable,'Position'); |
---|
| 2413 | set(handles.InputTable,'Unit','normalized') |
---|
| 2414 | ColumnWidth=round([0.5 0.14 0.14 0.14 0.08]*(Pos(3)-52)); |
---|
| 2415 | ColumnWidth=num2cell(ColumnWidth); |
---|
| 2416 | set(handles.InputTable,'ColumnWidth',ColumnWidth) |
---|
| 2417 | |
---|
| 2418 | %% MinIndex and MaxIndex |
---|
| 2419 | set(handles.MinIndex,'Unit','pixel') |
---|
| 2420 | Pos=get(handles.MinIndex,'Position'); |
---|
| 2421 | set(handles.MinIndex,'Unit','normalized') |
---|
| 2422 | ColumnWidth=get(handles.MinIndex,'ColumnWidth'); |
---|
| 2423 | if numel(ColumnWidth)==2 |
---|
| 2424 | ColumnWidth=num2cell(floor([0.5 0.5]*(Pos(3)-20))); |
---|
| 2425 | else |
---|
| 2426 | ColumnWidth={Pos(3)-5}; |
---|
| 2427 | end |
---|
| 2428 | set(handles.MinIndex,'ColumnWidth',ColumnWidth) |
---|
| 2429 | set(handles.MaxIndex,'ColumnWidth',ColumnWidth) |
---|
| 2430 | |
---|
| 2431 | %% TimeTable |
---|
| 2432 | set(handles.TimeTable,'Unit','pixel') |
---|
| 2433 | Pos=get(handles.TimeTable,'Position'); |
---|
| 2434 | set(handles.TimeTable,'Unit','normalized') |
---|
| 2435 | ColumnWidth=get(handles.TimeTable,'ColumnWidth'); |
---|
| 2436 | ColumnWidth=num2cell(floor([0.25 0.25 0.25 0.25]*(Pos(3)-20))); |
---|
| 2437 | set(handles.TimeTable,'ColumnWidth',ColumnWidth) |
---|
| 2438 | |
---|
| 2439 | |
---|
| 2440 | %% PairString |
---|
| 2441 | set(handles.PairString,'Unit','pixel') |
---|
| 2442 | Pos=get(handles.PairString,'Position'); |
---|
| 2443 | set(handles.PairString,'Unit','normalized') |
---|
| 2444 | set(handles.PairString,'ColumnWidth',{Pos(3)-5}) |
---|
[586] | 2445 | |
---|
| 2446 | |
---|
| 2447 | % --- Executes on button press in status. |
---|
| 2448 | function status_Callback(hObject, eventdata, handles) |
---|
[591] | 2449 | |
---|
[595] | 2450 | if get(handles.status,'Value') |
---|
| 2451 | set(handles.status,'BackgroundColor',[1 1 0]) |
---|
| 2452 | drawnow |
---|
[604] | 2453 | %StatusData.time_ref=get(handles.RUN,'UserData');% get the time of launch |
---|
[595] | 2454 | Param=read_GUI(handles.series); |
---|
| 2455 | RootPath=Param.InputTable{1,1}; |
---|
[599] | 2456 | if ~isfield(Param,'OutputSubDir') |
---|
| 2457 | msgbox_uvmat('ERROR','no directory defined for output files') |
---|
| 2458 | return |
---|
| 2459 | end |
---|
[595] | 2460 | OutputSubDir=[Param.OutputSubDir Param.OutputDirExt];% subdirectory for output files |
---|
| 2461 | OutputDir=fullfile(RootPath,OutputSubDir); |
---|
| 2462 | hfig=findobj(allchild(0),'name','series_status'); |
---|
| 2463 | if isempty(hfig) |
---|
[604] | 2464 | ScreenSize=get(0,'ScreenSize'); |
---|
| 2465 | hfig=figure('DeleteFcn',@stop_status,'Position',[ScreenSize(3)-600 ScreenSize(4)-640 560 600]); |
---|
[595] | 2466 | set(hfig,'MenuBar','none')% suppress the menu bar |
---|
| 2467 | set(hfig,'NumberTitle','off')%suppress the fig number in the title |
---|
| 2468 | set(hfig,'name','series_status') |
---|
| 2469 | set(hfig,'tag','series_status') |
---|
| 2470 | uicontrol('Style','listbox','Units','normalized', 'Position',[0.05 0.09 0.9 0.71], 'Callback', @view_file,'tag','list','UserData',OutputDir); |
---|
| 2471 | uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.87 0.9 0.1],'tag','titlebox','Max',2,'String',OutputDir); |
---|
| 2472 | uicontrol('Style','frame','Units','normalized', 'Position', [0.05 0.81 0.9 0.05]); |
---|
| 2473 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.7 0.01 0.2 0.07],'String','Close','FontWeight','bold','FontUnits','points','FontSize',11,'Callback',@stop_status); |
---|
[606] | 2474 | uicontrol('Style','pushbutton','Units','normalized', 'Position', [0.1 0.01 0.2 0.07],'String','Refresh','FontWeight','bold','FontUnits','points','FontSize',11,'Callback',@refresh_GUI); |
---|
[604] | 2475 | %set(hrefresh,'UserData',StatusData) |
---|
[595] | 2476 | BarPosition=[0.05 0.81 0.01 0.05]; |
---|
| 2477 | uicontrol('Style','frame','Units','normalized', 'Position',BarPosition ,'BackgroundColor',[1 0 0],'tag','waitbar'); |
---|
| 2478 | drawnow |
---|
| 2479 | end |
---|
[606] | 2480 | refresh_GUI(hfig) |
---|
[595] | 2481 | else |
---|
| 2482 | %% delete current display fig if selection is off |
---|
[586] | 2483 | set(handles.status,'BackgroundColor',[0 1 0]) |
---|
| 2484 | hfig=findobj(allchild(0),'name','series_status'); |
---|
| 2485 | if ~isempty(hfig) |
---|
| 2486 | delete(hfig) |
---|
| 2487 | end |
---|
| 2488 | return |
---|
| 2489 | end |
---|
[595] | 2490 | |
---|
| 2491 | |
---|
| 2492 | %------------------------------------------------------------------------ |
---|
| 2493 | % launched by selecting a file on the list |
---|
| 2494 | function view_file(hObject, eventdata) |
---|
[604] | 2495 | %------------------------------------------------------------------------ |
---|
[595] | 2496 | list=get(hObject,'String'); |
---|
| 2497 | index=get(hObject,'Value'); |
---|
| 2498 | rootroot=get(hObject,'UserData'); |
---|
| 2499 | selectname=list{index}; |
---|
| 2500 | ind_dot=regexp(selectname,'\.\.\.'); |
---|
| 2501 | if ~isempty(ind_dot) |
---|
| 2502 | selectname=selectname(1:ind_dot-1); |
---|
[586] | 2503 | end |
---|
[595] | 2504 | FullSelectName=fullfile(rootroot,selectname); |
---|
| 2505 | if exist(FullSelectName,'dir')% a directory has been selected |
---|
| 2506 | ListFiles=dir(FullSelectName); |
---|
| 2507 | ListDisplay=cell(numel(ListFiles),1); |
---|
| 2508 | for ilist=2:numel(ListDisplay)% suppress the first line '.' |
---|
| 2509 | ListDisplay{ilist-1}=ListFiles(ilist).name; |
---|
| 2510 | end |
---|
| 2511 | set(hObject,'Value',1) |
---|
| 2512 | set(hObject,'String',ListDisplay) |
---|
| 2513 | if strcmp(selectname,'..') |
---|
| 2514 | FullSelectName=fileparts(fileparts(FullSelectName)); |
---|
| 2515 | end |
---|
| 2516 | set(hObject,'UserData',FullSelectName) |
---|
| 2517 | hfig=get(hObject,'parent'); |
---|
| 2518 | htitlebox=findobj(hfig,'tag','titlebox'); |
---|
| 2519 | set(htitlebox,'String',FullSelectName) |
---|
| 2520 | elseif exist(FullSelectName,'file')%visualise the vel field if it exists |
---|
| 2521 | FileType=get_file_type(FullSelectName); |
---|
| 2522 | if strcmp(FileType,'txt') |
---|
| 2523 | edit(FullSelectName) |
---|
[598] | 2524 | elseif strcmp(FileType,'xml') |
---|
| 2525 | editxml(FullSelectName) |
---|
[595] | 2526 | else |
---|
| 2527 | uvmat(FullSelectName) |
---|
| 2528 | end |
---|
| 2529 | set(gcbo,'Value',1) |
---|
| 2530 | end |
---|
[591] | 2531 | |
---|
[595] | 2532 | |
---|
[591] | 2533 | %------------------------------------------------------------------------ |
---|
| 2534 | % launched by refreshing the status figure |
---|
[606] | 2535 | function refresh_GUI(hfig) |
---|
[591] | 2536 | %------------------------------------------------------------------------ |
---|
[595] | 2537 | htitlebox=findobj(hfig,'tag','titlebox'); |
---|
[591] | 2538 | hlist=findobj(hfig,'tag','list'); |
---|
[604] | 2539 | hseries=findobj(allchild(0),'tag','series'); |
---|
| 2540 | hstatus=findobj(hseries,'tag','status'); |
---|
| 2541 | StatusData=get(hstatus,'UserData'); |
---|
[595] | 2542 | OutputDir=get(htitlebox,'String'); |
---|
[602] | 2543 | if ischar(OutputDir),OutputDir={OutputDir};end |
---|
| 2544 | ListFiles=dir(OutputDir{1}); |
---|
[604] | 2545 | if numel(ListFiles)<1 |
---|
| 2546 | return |
---|
| 2547 | end |
---|
| 2548 | ListFiles(1)=[];%removes the first line ='.' |
---|
[591] | 2549 | ListDisplay=cell(numel(ListFiles),1); |
---|
[602] | 2550 | testrecent=0; |
---|
[604] | 2551 | datnum=zeros(numel(ListDisplay),1); |
---|
| 2552 | for ilist=1:numel(ListDisplay) |
---|
| 2553 | ListDisplay{ilist}=ListFiles(ilist).name; |
---|
[602] | 2554 | if ~ListFiles(ilist).isdir && isfield(ListFiles(ilist),'datenum') |
---|
| 2555 | datnum(ilist)=ListFiles(ilist).datenum;%only available in recent matlab versions |
---|
| 2556 | testrecent=1; |
---|
| 2557 | end |
---|
[591] | 2558 | end |
---|
| 2559 | set(hlist,'String',ListDisplay) |
---|
[602] | 2560 | |
---|
| 2561 | %% Look at date of creation |
---|
[604] | 2562 | ListDisplay=ListDisplay(datnum~=0); |
---|
[602] | 2563 | datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files |
---|
[606] | 2564 | NbOutputFile=[]; |
---|
[602] | 2565 | if isempty(datnum) |
---|
| 2566 | if testrecent |
---|
| 2567 | message='no civ result created yet'; |
---|
| 2568 | else |
---|
| 2569 | message=''; |
---|
| 2570 | end |
---|
| 2571 | else |
---|
| 2572 | [first,indfirst]=min(datnum); |
---|
| 2573 | [last,indlast]=max(datnum); |
---|
[604] | 2574 | NbOutputFile_str='?'; |
---|
| 2575 | NbOutputFile=[]; |
---|
| 2576 | if isfield(StatusData,'NbOutputFile') |
---|
| 2577 | NbOutputFile=StatusData.NbOutputFile; |
---|
| 2578 | NbOutputFile_str=num2str(NbOutputFile); |
---|
| 2579 | end |
---|
| 2580 | message={[num2str(numel(datnum)) ' file(s) done over ' NbOutputFile_str] ;['oldest modification: ' ListDisplay{indfirst} ' : ' datestr(first)];... |
---|
[602] | 2581 | ['latest modification: ' ListDisplay{indlast} ' : ' datestr(last)]}; |
---|
| 2582 | end |
---|
[604] | 2583 | set(htitlebox,'String', [OutputDir{1};message]) |
---|
| 2584 | |
---|
| 2585 | %% update the waitbar |
---|
[602] | 2586 | hwaitbar=findobj(hfig,'tag','waitbar'); |
---|
[604] | 2587 | if ~isempty(NbOutputFile) |
---|
| 2588 | BarPosition=get(hwaitbar,'Position'); |
---|
| 2589 | BarPosition(3)=0.9*numel(datnum)/NbOutputFile; |
---|
| 2590 | set(hwaitbar,'Position',BarPosition) |
---|
| 2591 | end |
---|
[602] | 2592 | %TODO: adjust waitbar |
---|
| 2593 | |
---|
[591] | 2594 | % civ_files=get(hfig,'UserData'); |
---|
| 2595 | |
---|
| 2596 | % [filepath,filename,ext]=fileparts(civ_files{1}); |
---|
| 2597 | % [tild,SubDir,extdir]=fileparts(filepath); |
---|
| 2598 | % SubDir=[SubDir extdir]; |
---|
| 2599 | % option_civ=StatusData.option_civ; |
---|
| 2600 | % nbfiles=numel(civ_files); |
---|
| 2601 | % testrecent=0; |
---|
| 2602 | % count=0; |
---|
| 2603 | % datnum=zeros(1,nbfiles); |
---|
| 2604 | % filefound=cell(1,nbfiles); |
---|
| 2605 | % for ifile=1:nbfiles |
---|
| 2606 | % detect=exist(civ_files{ifile},'file'); % check the existence of the file |
---|
| 2607 | % option=0; |
---|
| 2608 | % if detect==0 |
---|
| 2609 | % option_str='not created'; |
---|
| 2610 | % else |
---|
| 2611 | % datfile=dir(civ_files{ifile}); |
---|
| 2612 | % if isfield(datfile,'datenum') |
---|
| 2613 | % datnum(ifile)=datfile.datenum;%only available in recent matlab versions |
---|
| 2614 | % testrecent=1; |
---|
| 2615 | % end |
---|
| 2616 | % filefound(ifile)={datfile.name}; |
---|
| 2617 | % |
---|
| 2618 | % % check the content netcdf file |
---|
| 2619 | % Data=nc2struct(civ_files{ifile},'ListGlobalAttribute','CivStage','patch2','fix2','civ2','patch','fix'); |
---|
| 2620 | % option_list={'civ1','fix1','patch1','civ2','fix2','patch2'}; |
---|
| 2621 | % if ~isempty(Data.CivStage) |
---|
| 2622 | % option=Data.CivStage;%case of Matlab civ |
---|
| 2623 | % else |
---|
| 2624 | % if ~isempty(Data.patch2) && isequal(Data.patch2,1) |
---|
| 2625 | % option=6; |
---|
| 2626 | % elseif ~isempty(Data.fix2) && isequal(Data.fix2,1) |
---|
| 2627 | % option=5; |
---|
| 2628 | % elseif ~isempty(Data.civ2) && isequal(Data.civ2,1); |
---|
| 2629 | % option=4; |
---|
| 2630 | % elseif ~isempty(Data.patch) && isequal(Data.patch,1); |
---|
| 2631 | % option=3; |
---|
| 2632 | % elseif ~isempty(Data.fix) && isequal(Data.fix,1); |
---|
| 2633 | % option=2; |
---|
| 2634 | % else |
---|
| 2635 | % option=1; |
---|
| 2636 | % end |
---|
| 2637 | % end |
---|
| 2638 | % option_str=option_list{option}; |
---|
| 2639 | % if datnum(ifile)<StatusData.time_ref |
---|
| 2640 | % option_str=[option_str ' --OLD--']; |
---|
| 2641 | % end |
---|
| 2642 | % end |
---|
| 2643 | % if option >= option_civ |
---|
| 2644 | % count=count+1; |
---|
| 2645 | % end |
---|
| 2646 | % [filepath,filename,ext]=fileparts(civ_files{ifile}); |
---|
| 2647 | % Tabchar{ifile,1}=[fullfile(SubDir,filename) ext '...' option_str]; |
---|
| 2648 | % end |
---|
| 2649 | % datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files |
---|
| 2650 | % if isempty(datnum) |
---|
| 2651 | % if testrecent |
---|
| 2652 | % message='no civ result created yet'; |
---|
| 2653 | % else |
---|
| 2654 | % message=''; |
---|
| 2655 | % end |
---|
| 2656 | % else |
---|
| 2657 | % datnum=datnum(datnum~=0);%keep the non zero values corresponding to existing files |
---|
| 2658 | % [first,ind]=min(datnum); |
---|
| 2659 | % [last,indlast]=max(datnum); |
---|
| 2660 | % message={[num2str(count) ' file(s) done over ' num2str(nbfiles)] ;['oldest modification: ' cell2mat(filefound(ind)) ' : ' datestr(first)];... |
---|
| 2661 | % ['latest modification: ' cell2mat(filefound(indlast)) ' : ' datestr(last)]}; |
---|
| 2662 | % end |
---|
| 2663 | % hlist=findobj(hfig,'tag','list'); |
---|
[595] | 2664 | % htitlebox=findobj(hfig,'tag','titlebox'); |
---|
[591] | 2665 | % hwaitbar=findobj(hfig,'tag','waitbar'); |
---|
| 2666 | % set(hlist,'String',Tabchar) |
---|
[595] | 2667 | % set(htitlebox,'String', message) |
---|
[604] | 2668 | % |
---|
[591] | 2669 | %------------------------------------------------------------------------ |
---|
| 2670 | % launched by deleting the status figure |
---|
| 2671 | function stop_status(hObject, eventdata) |
---|
| 2672 | %------------------------------------------------------------------------ |
---|
| 2673 | hciv=findobj(allchild(0),'tag','series'); |
---|
| 2674 | hhciv=guidata(hciv); |
---|
| 2675 | set(hhciv.status,'value',0) %reset the status uicontrol in the GUI civ |
---|
| 2676 | set(hhciv.status,'BackgroundColor',[0 1 0]) |
---|
| 2677 | delete(gcbf) |
---|
| 2678 | |
---|
| 2679 | % --- Executes on selection change in ActionExt. |
---|
| 2680 | function ActionExt_Callback(hObject, eventdata, handles) |
---|
| 2681 | ActionExtList=get(handles.ActionExt,'String'); |
---|
| 2682 | ActionExt=ActionExtList{get(handles.ActionExt,'Value')}; |
---|
| 2683 | ActionList=get(handles.ActionName,'String'); |
---|
| 2684 | ActionName=ActionList{get(handles.ActionName,'Value')}; |
---|
[606] | 2685 | TransformPath=''; |
---|
| 2686 | if ~isempty(get(handles.ActionExt,'UserData')) |
---|
| 2687 | TransformPath=get(handles.ActionExt,'UserData'); |
---|
| 2688 | end |
---|
[591] | 2689 | if strcmp(ActionExt,'.sh') |
---|
[606] | 2690 | set(handles.ActionExt,'BackgroundColor',[1 1 0]) |
---|
[594] | 2691 | ActionFullName=fullfile(get(handles.ActionPath,'String'),[ActionName '.sh']); |
---|
[591] | 2692 | if ~exist(ActionFullName,'file') |
---|
| 2693 | answer=msgbox_uvmat('INPUT_Y-N','compiled version has not been created: compile now?'); |
---|
| 2694 | if strcmp(answer,'Yes') |
---|
[606] | 2695 | set(handles.ActionExt,'BackgroundColor',[1 1 0]) |
---|
| 2696 | path_uvmat=fileparts(which('series')); |
---|
[591] | 2697 | currentdir=pwd; |
---|
[606] | 2698 | cd(get(handles.ActionPath,'String'))% go to the directory of Action |
---|
| 2699 | % addpath(get(handles.TransformPath,'String')) |
---|
| 2700 | addpath(path_uvmat)% add the path to uvmat to run the fct 'compile' |
---|
| 2701 | % addpath(fullfile(path_uvmat,'transform_field'))% add the path to uvmat to run the fct 'compile' |
---|
| 2702 | compile(ActionName,TransformPath) |
---|
[591] | 2703 | cd(currentdir) |
---|
| 2704 | end |
---|
[606] | 2705 | |
---|
| 2706 | else |
---|
| 2707 | sh_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.sh'])); |
---|
| 2708 | m_file_info=dir(fullfile(get(handles.ActionPath,'String'),[ActionName '.m'])); |
---|
| 2709 | if isfield(m_file_info,'datenum') && m_file_info.datenum>sh_file_info.datenum |
---|
| 2710 | set(handles.ActionExt,'BackgroundColor',[1 1 0]) |
---|
| 2711 | drawnow |
---|
| 2712 | answer=msgbox_uvmat('INPUT_Y-N',[ActionName '.sh needs to be updated: recompile now?']); |
---|
| 2713 | if strcmp(answer,'Yes') |
---|
| 2714 | path_uvmat=fileparts(which('series')); |
---|
| 2715 | currentdir=pwd; |
---|
| 2716 | cd(get(handles.ActionPath,'String'))% go to the directory of Action |
---|
| 2717 | % addpath(get(handles.TransformPath,'String')) |
---|
| 2718 | addpath(path_uvmat)% add the path to uvmat to run the fct 'compile' |
---|
| 2719 | addpath(fullfile(path_uvmat,'transform_field'))% add the path to uvmat to run the fct 'compile' |
---|
| 2720 | compile(ActionName,TransformPath) |
---|
| 2721 | cd(currentdir) |
---|
| 2722 | end |
---|
[594] | 2723 | end |
---|
| 2724 | end |
---|
[606] | 2725 | set(handles.ActionExt,'BackgroundColor',[1 1 1]) |
---|
[591] | 2726 | end |
---|
| 2727 | |
---|
| 2728 | |
---|
| 2729 | function ActionInput_Callback(hObject, eventdata, handles) |
---|
| 2730 | |
---|
| 2731 | |
---|
| 2732 | % --- Executes on button press in DeleteObject. |
---|
| 2733 | function DeleteObject_Callback(hObject, eventdata, handles) |
---|
| 2734 | if get(handles.DeleteObject,'Value') |
---|
| 2735 | SeriesData=get(handles.series,'UserData'); |
---|
| 2736 | SeriesData.ProjObject=[]; |
---|
| 2737 | set(handles.series,'UserData',SeriesData) |
---|
| 2738 | set(handles.ProjObject,'String','') |
---|
| 2739 | set(handles.CheckObject,'Value',0) |
---|
| 2740 | set(handles.DeleteObject,'Visible','off') |
---|
| 2741 | set(handles.ViewObject,'Visible','off') |
---|
[606] | 2742 | set(handles.DeleteObject,'Value',0) |
---|
[591] | 2743 | end |
---|
| 2744 | |
---|
| 2745 | % --- Executes on button press in ViewObject. |
---|
| 2746 | function ViewObject_Callback(hObject, eventdata, handles) |
---|
| 2747 | if get(handles.ViewObject,'Value') |
---|
| 2748 | UserData=get(handles.series,'UserData'); |
---|
| 2749 | set_object(UserData.ProjObject) |
---|
| 2750 | else |
---|
| 2751 | hset_object=findobj(allchild(0),'Tag','set_object'); |
---|
| 2752 | if ~isempty(hset_object) |
---|
| 2753 | delete(hset_object) |
---|
| 2754 | end |
---|
| 2755 | end |
---|
| 2756 | |
---|
| 2757 | |
---|
| 2758 | function num_NbProcess_Callback(hObject, eventdata, handles) |
---|
| 2759 | |
---|
| 2760 | |
---|
| 2761 | function num_NbSlice_Callback(hObject, eventdata, handles) |
---|
| 2762 | NbSlice=str2num(get(handles.num_NbSlice,'String')); |
---|
| 2763 | set(handles.num_NbProcess,'String',num2str(NbSlice)) |
---|