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