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