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