1 | %'get_field': display variables and attributes from a Netcdf file, and RUN selected fields |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | %function varargout = get_field(varargin) |
---|
4 | % associated with the GUI get_field.fig |
---|
5 | % |
---|
6 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
7 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
8 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
9 | % This file is part of the toolbox UVMAT. |
---|
10 | % |
---|
11 | % UVMAT is free software; you can redistribute it and/or modify |
---|
12 | % it under the terms of the GNU General Public License as published by |
---|
13 | % the Free Software Foundation; either version 2 of the License, or |
---|
14 | % (at your option) any later version. |
---|
15 | % |
---|
16 | % UVMAT is distributed in the hope that it will be useful, |
---|
17 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
20 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
21 | |
---|
22 | function varargout = get_field(varargin) |
---|
23 | |
---|
24 | % Last Modified by GUIDE v2.5 26-Jul-2012 09:11:23 |
---|
25 | |
---|
26 | % Begin initialization code - DO NOT EDIT |
---|
27 | gui_Singleton = 0; |
---|
28 | gui_State = struct('gui_Name', mfilename, ... |
---|
29 | 'gui_Singleton', gui_Singleton, ... |
---|
30 | 'gui_OpeningFcn', @get_field_OpeningFcn, ... |
---|
31 | 'gui_OutputFcn', @get_field_OutputFcn, ... |
---|
32 | 'gui_LayoutFcn', [] , ... |
---|
33 | 'gui_Callback', []); |
---|
34 | if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
35 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
36 | end |
---|
37 | |
---|
38 | if nargout |
---|
39 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
40 | else |
---|
41 | gui_mainfcn(gui_State, varargin{:}); |
---|
42 | end |
---|
43 | % End initialization code - DO NOT EDIT |
---|
44 | |
---|
45 | %------------------------------------------------------------------------ |
---|
46 | % --- Executes just before get_field is made visible. |
---|
47 | function get_field_OpeningFcn(hObject, eventdata, handles,filename,multiple) |
---|
48 | %------------------------------------------------------------------------ |
---|
49 | global nb_builtin % nbre of functions to include by default in the menu of functions called by RUN |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | %% Choose default command line output for get_field |
---|
54 | handles.output = hObject; |
---|
55 | |
---|
56 | %% Update handles structure |
---|
57 | guidata(hObject, handles); |
---|
58 | set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display) |
---|
59 | |
---|
60 | %% prepare the list of RUN fcts and set their paths |
---|
61 | % functions included by default in 'get_field.m |
---|
62 | % menu_str={'PLOT';'FFT';'filter_band'}; |
---|
63 | % nb_builtin=numel(menu_str); |
---|
64 | % path_uvmat=fileparts(which('uvmat'));%path of the function 'uvmat' |
---|
65 | % addpath(fullfile(path_uvmat,'get_field')) |
---|
66 | % testexist=zeros(size(menu_str'));%default |
---|
67 | % for ilist=1:length(menu_str) |
---|
68 | % if exist(menu_str{ilist},'file') |
---|
69 | % fct_handle{ilist,1}=str2func(menu_str{ilist}); |
---|
70 | % testexist(ilist)=1; |
---|
71 | % else |
---|
72 | % fct_handle{ilist,1}=[]; |
---|
73 | % testexist(ilist)=0; |
---|
74 | % end |
---|
75 | % end |
---|
76 | % rmpath(fullfile(path_uvmat,'get_field')) |
---|
77 | % dir_perso=prefdir; |
---|
78 | |
---|
79 | % look for functions previously used (names and paths saved in the personal file uvmat_perso.mat): |
---|
80 | % profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
81 | % if exist(profil_perso,'file') |
---|
82 | % h=load (profil_perso); |
---|
83 | % if isfield(h,'get_field_fct') && iscell(h.get_field_fct) |
---|
84 | % for ilist=1:length(h.get_field_fct) |
---|
85 | % [path,file]=fileparts(h.get_field_fct{ilist}); |
---|
86 | % addpath(path) |
---|
87 | % if exist(file,'file') |
---|
88 | % h_func=str2func(file); |
---|
89 | % testexist=[testexist 1]; |
---|
90 | % else |
---|
91 | % h_func=[]; |
---|
92 | % testexist=[testexist 0]; |
---|
93 | % end |
---|
94 | % fct_handle=[fct_handle; {h_func}]; %concatene the list of paths |
---|
95 | % rmpath(path) |
---|
96 | % menu_str=[menu_str; {file}]; |
---|
97 | % end |
---|
98 | % end |
---|
99 | % end |
---|
100 | |
---|
101 | % menu_str=menu_str(testexist==1);%=menu_str(testexist~=0) |
---|
102 | % fct_handle=fct_handle(testexist==1); |
---|
103 | % menu_str=[menu_str;{'more...'}]; |
---|
104 | % set(handles.ACTION,'String',menu_str) |
---|
105 | % set(handles.ACTION,'UserData',fct_handle)% store the list of path in UserData of ACTION |
---|
106 | % set(handles.path_action,'String',fullfile(path_uvmat,'get_field')) |
---|
107 | % set(handles.ACTION,'Value',1)% PLOT option selected |
---|
108 | |
---|
109 | %% settings for 'slave' mode, called by uvamt, or 'master' mode |
---|
110 | if exist('filename','var') && ischar(filename) %transfer input file name in slave mode |
---|
111 | set(handles.inputfile,'String',filename)% prefill the input file name |
---|
112 | Field=nc2struct(filename,[]);% reads the field structure, without variables |
---|
113 | if isfield(Field,'Txt') |
---|
114 | msgbox_uvmat('ERROR',Field.Txt) |
---|
115 | else |
---|
116 | set(handles.get_field,'UserData',Field); |
---|
117 | Field_input(handles,Field); |
---|
118 | end |
---|
119 | else %master mode |
---|
120 | set(handles.inputfile,'String','') |
---|
121 | end |
---|
122 | |
---|
123 | %% load the list of previously browsed files for the upper bar menu Open |
---|
124 | % dir_perso=prefdir; |
---|
125 | % profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% |
---|
126 | % if exist(profil_perso,'file') |
---|
127 | % h=load (profil_perso); |
---|
128 | % if isfield(h,'MenuFile_1') |
---|
129 | % set(handles.MenuFile_1,'Label',h.MenuFile_1); |
---|
130 | % end |
---|
131 | % if isfield(h,'MenuFile_1') |
---|
132 | % set(handles.MenuFile_2,'Label',h.MenuFile_2); |
---|
133 | % end |
---|
134 | % if isfield(h,'MenuFile_1') |
---|
135 | % set(handles.MenuFile_3,'Label',h.MenuFile_3); |
---|
136 | % end |
---|
137 | % if isfield(h,'MenuFile_1') |
---|
138 | % set(handles.MenuFile_4,'Label',h.MenuFile_4); |
---|
139 | % end |
---|
140 | % if isfield(h,'MenuFile_1') |
---|
141 | % set(handles.MenuFile_5,'Label',h.MenuFile_5); |
---|
142 | % end |
---|
143 | % end |
---|
144 | |
---|
145 | %% put the GUI on the lower right of the sceen |
---|
146 | pos_view_field=get(hObject,'Position'); |
---|
147 | ScreenSize=get(0,'ScreenSize'); |
---|
148 | pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3); |
---|
149 | pos_view_field(2)=ScreenSize(2); |
---|
150 | set(hObject,'Position',pos_view_field) |
---|
151 | |
---|
152 | %% remove already opened get_field GUI with name get_field |
---|
153 | if ~(exist('multiple','var') && isequal(multiple,1)) %set single occurrence |
---|
154 | hget_field=findobj(allchild(0),'Name','get_field'); %hget_field(1)= new GUI |
---|
155 | if length(hget_field)>1 |
---|
156 | delete(hget_field(2)) |
---|
157 | end |
---|
158 | else |
---|
159 | set(hObject,'name','get_field_1') |
---|
160 | end |
---|
161 | |
---|
162 | |
---|
163 | %------------------------------------------------------------------------ |
---|
164 | % --- Outputs from this function are returned to the command line. |
---|
165 | function varargout = get_field_OutputFcn(hObject, eventdata, handles) |
---|
166 | %------------------------------------------------------------------------ |
---|
167 | varargout{1} = handles.output; |
---|
168 | |
---|
169 | %------------------------------------------------------------------------ |
---|
170 | % --- Executes when a new input file name is introduced. |
---|
171 | function inputfile_Callback(hObject, eventdata, handles) |
---|
172 | %------------------------------------------------------------------------ |
---|
173 | inputfile=get(handles.inputfile,'String'); |
---|
174 | Field=nc2struct(inputfile,[]);% reads the field description, without data |
---|
175 | if isfield(Field,'Txt') |
---|
176 | msgbox_uvmat('ERROR',Field.Txt) |
---|
177 | else |
---|
178 | set(handles.get_field,'UserData',Field); |
---|
179 | Field_input(handles,Field); |
---|
180 | end |
---|
181 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
182 | if ~isempty(huvmat) |
---|
183 | delete(huvmat)%delete uvmat for plot reinitialisation |
---|
184 | end |
---|
185 | |
---|
186 | %------------------------------------------------------------------------ |
---|
187 | % --- update the display when a new field is introduced. |
---|
188 | function Field_input(handles,Field) |
---|
189 | %------------------------------------------------------------------------ |
---|
190 | if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName) |
---|
191 | Tabcell(:,1)=Field.ListDimName; |
---|
192 | for iline=1:length(Field.ListDimName) |
---|
193 | Tabcell{iline,2}=num2str(Field.DimValue(iline)); |
---|
194 | end |
---|
195 | Tabchar=cell2tab(Tabcell,' = '); |
---|
196 | set(handles.dimensions,'String',Tabchar) |
---|
197 | end |
---|
198 | if ~isfield(Field,'ListVarName') |
---|
199 | return |
---|
200 | end |
---|
201 | Txt=Field.ListVarName; |
---|
202 | set(handles.variables,'Value',1) |
---|
203 | set(handles.variables,'String',[{'*'} Txt]) |
---|
204 | variables_Callback(handles.variables,[], handles) |
---|
205 | set(handles.abscissa,'String',[{''} Txt ]) |
---|
206 | set(handles.ordinate,'String',Txt) |
---|
207 | set(handles.vector_x,'String',[Txt ]) |
---|
208 | set(handles.vector_y,'String',[Txt ]) |
---|
209 | set(handles.vector_z,'String',[{''} Txt ]) |
---|
210 | set(handles.vec_color,'String',[{''} Txt ]) |
---|
211 | set(handles.coord_x_scalar,'String',[{''} Txt ]) |
---|
212 | set(handles.coord_y_scalar,'String',[{''} Txt ]) |
---|
213 | set(handles.coord_x_vectors,'String',[{''} Txt ]) |
---|
214 | set(handles.coord_y_vectors,'String',[{''} Txt ]) |
---|
215 | set(handles.coord_z_scalar,'String',[{''} Txt ]) |
---|
216 | set(handles.coord_z_vectors,'String',[{''} Txt ]) |
---|
217 | set(handles.scalar,'Value',1) |
---|
218 | |
---|
219 | set(handles.scalar,'String', Txt ) |
---|
220 | [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Field); |
---|
221 | if ~isempty(errormsg) |
---|
222 | msgbox_uvmat('ERROR',['error in get_field/Field_input/find_field_cells: ' errormsg]) |
---|
223 | return |
---|
224 | end |
---|
225 | for icell=1:numel(CellVarIndex) |
---|
226 | NbDim(icell)=max(NbDim(icell),numel(CellVarIndex{icell})); |
---|
227 | end |
---|
228 | [maxdim,imax]=max(NbDim); |
---|
229 | |
---|
230 | if maxdim>=3 |
---|
231 | set(handles.vector_z,'Visible','on') |
---|
232 | set(handles.vector_z,'String',[{''} Txt ]) |
---|
233 | set(handles.coord_z_vectors,'Visible','on') |
---|
234 | set(handles.coord_z_vectors,'String',[{''} Txt ]) |
---|
235 | set(handles.coord_z_scalar,'Visible','on') |
---|
236 | set(handles.coord_z_scalar,'String',[{''} Txt ]) |
---|
237 | else |
---|
238 | set(handles.vector_z,'Visible','off') |
---|
239 | set(handles.coord_z_vectors,'Visible','off') |
---|
240 | set(handles.coord_z_scalar,'Visible','off') |
---|
241 | end |
---|
242 | if maxdim>=2 |
---|
243 | set(handles.CheckPlot1D,'Value',0) |
---|
244 | if ~isempty(VarType{imax}.vector_x) && ~isempty(VarType{imax}.vector_y) |
---|
245 | set(handles.CheckVector,'Value',1) |
---|
246 | set(handles.CheckScalar,'Value',0) |
---|
247 | set(handles.vector_x,'Value',VarType{imax}.vector_x(1)) |
---|
248 | set(handles.vector_y,'Value',VarType{imax}.vector_y(1)) |
---|
249 | if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y) |
---|
250 | set(handles.coord_x_vectors,'Value',VarType{imax}.coord_x+1) |
---|
251 | set(handles.coord_y_vectors,'Value',VarType{imax}.coord_y+1) |
---|
252 | end |
---|
253 | if ~isempty(VarType{imax}.coord) |
---|
254 | set(handles.coord_y_vectors,'Value',VarType{imax}.coord(1)+1) |
---|
255 | if numel(VarType{imax}.coord)>=2 |
---|
256 | set(handles.coord_x_vectors,'Value',VarType{imax}.coord(2)+1) |
---|
257 | end |
---|
258 | end |
---|
259 | else |
---|
260 | set(handles.CheckScalar,'Value',1) |
---|
261 | set(handles.CheckVector,'Value',0) |
---|
262 | if isfield(VarType{imax},'scalar') && length(VarType{imax}.scalar)>=1 |
---|
263 | set(handles.scalar,'Value',VarType{imax}.scalar(1)) |
---|
264 | if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y) |
---|
265 | set(handles.coord_x_scalar,'Value',VarType{imax}.coord_x+1) |
---|
266 | set(handles.coord_y_scalar,'Value',VarType{imax}.coord_y+1) |
---|
267 | end |
---|
268 | if ~isempty(VarType{imax}.coord_z) |
---|
269 | set(handles.coord_z_scalar,'Value',VarType{imax}.coord_z+1) |
---|
270 | end |
---|
271 | if ~isempty(VarType{imax}.coord) |
---|
272 | if numel(VarType{imax}.coord)>=maxdim-2 && maxdim>=3 |
---|
273 | set(handles.coord_z_scalar,'Value',VarType{imax}.coord(maxdim-2)+1) |
---|
274 | end |
---|
275 | if numel(VarType{imax}.coord)>=maxdim-1 |
---|
276 | set(handles.coord_y_scalar,'Value',VarType{imax}.coord(maxdim-1)+1) |
---|
277 | end |
---|
278 | if numel(VarType{imax}.coord)>=maxdim |
---|
279 | set(handles.coord_x_scalar,'Value',VarType{imax}.coord(maxdim)+1) |
---|
280 | end |
---|
281 | end |
---|
282 | end |
---|
283 | end |
---|
284 | CheckPlot1D_Callback(handles.CheckPlot1D, [], handles) |
---|
285 | CheckScalar_Callback(handles.CheckScalar, [], handles) |
---|
286 | CheckVector_Callback(handles.CheckVector, [], handles) |
---|
287 | end |
---|
288 | %scalar_Callback(handles.get_field, eventdata, handles) |
---|
289 | %vector_x_Callback(handles.get_field, eventdata, handles) |
---|
290 | |
---|
291 | %------------------------------------------------------------------------ |
---|
292 | function ordinate_Callback(hObject, eventdata, handles) |
---|
293 | %------------------------------------------------------------------------ |
---|
294 | hselect_field=get(handles.inputfile,'parent'); |
---|
295 | Field=get(hselect_field,'UserData'); |
---|
296 | list=get(handles.ordinate,'String'); |
---|
297 | yindex=get(handles.ordinate,'Value'); |
---|
298 | yindex=name2index(list{yindex(1)},Field.ListVarName); |
---|
299 | if ~isempty(yindex) |
---|
300 | set(handles.variables,'Value',yindex+1) |
---|
301 | variables_Callback(hObject, eventdata, handles) |
---|
302 | end |
---|
303 | [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Field); |
---|
304 | for icell=1:numel(CellVarIndex) |
---|
305 | VarIndex=CellVarIndex{icell}; |
---|
306 | if ~isempty(find(VarIndex==yindex,1)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex)) |
---|
307 | cell_select=icell; |
---|
308 | break |
---|
309 | end |
---|
310 | end |
---|
311 | |
---|
312 | val=get(handles.abscissa,'Value'); |
---|
313 | set(handles.abscissa,'Value',min(val,2)); |
---|
314 | coord_x_index=VarType{cell_select}.coord; |
---|
315 | coord_x_index=coord_x_index(coord_x_index~=0); |
---|
316 | set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))']) |
---|
317 | |
---|
318 | %------------------------------------------------------------------------ |
---|
319 | % --- Executes on selection change in abscissa. |
---|
320 | function abscissa_Callback(hObject, eventdata, handles) |
---|
321 | %------------------------------------------------------------------------ |
---|
322 | hselect_field=get(handles.inputfile,'parent'); |
---|
323 | Field=get(hselect_field,'UserData');%current input field |
---|
324 | xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa |
---|
325 | % test_2D=get(handles.CheckVector,'Value');% =1 for vector fields |
---|
326 | % test_scalar=get(handles.CheckScalar,'Value');% =1 for scalar fields |
---|
327 | %if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa |
---|
328 | % Txt=Field.ListVarName; |
---|
329 | % set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates |
---|
330 | % xindex=[]; |
---|
331 | % else |
---|
332 | xlist=get(handles.abscissa,'String');%list of abscissa |
---|
333 | VarName=xlist{xdispindex}; %selected variable name |
---|
334 | update_field(hObject, eventdata, handles,VarName) |
---|
335 | % xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables |
---|
336 | % if ~isempty(xindex) |
---|
337 | % set(handles.variables,'Value',xindex+1) |
---|
338 | % variables_Callback(hObject, eventdata, handles) |
---|
339 | % end |
---|
340 | % set(handles.variables,'Value',xindex+1)%outline in the list of variables |
---|
341 | % variables_Callback(hObject, eventdata, handles) %display properties of the TimeVariable (dim, attributes) |
---|
342 | % if ~test_2D & ~test_scalar% look for possible varaibles to RUN in ordinate |
---|
343 | % index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa |
---|
344 | % VarIndex=[]; |
---|
345 | % for ilist=1:length(Field.VarDimIndex)%detect |
---|
346 | % index_i=Field.VarDimIndex{ilist}; |
---|
347 | % if ~isempty(index_i) |
---|
348 | % if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, RUN is possible |
---|
349 | % VarIndex=[VarIndex ilist]; |
---|
350 | % end |
---|
351 | % end |
---|
352 | % end |
---|
353 | % % set(handles.ordinate,'Value',1) |
---|
354 | % set(handles.ordinate,'String',Field.ListVarName(VarIndex)) |
---|
355 | % end |
---|
356 | % end |
---|
357 | % |
---|
358 | % update_UserData(handles) |
---|
359 | |
---|
360 | %------------------------------------------------------------------------ |
---|
361 | % --- Executes on selection change in scalar menu. |
---|
362 | function scalar_Callback(hObject, eventdata, handles) |
---|
363 | %------------------------------------------------------------------------ |
---|
364 | index=get(handles.scalar,'Value'); |
---|
365 | string=get(handles.scalar,'String'); |
---|
366 | VarName=string{index}; |
---|
367 | update_field(hObject, eventdata, handles,VarName) |
---|
368 | |
---|
369 | %eliminate time |
---|
370 | TimeDimName='';%default |
---|
371 | if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on') |
---|
372 | TimeDimList=get(handles.TimeDimensionMenu,'String'); |
---|
373 | TimeDimIndex=get(handles.TimeDimensionMenu,'Value'); |
---|
374 | TimeDimName=TimeDimList{TimeDimIndex}; |
---|
375 | end |
---|
376 | |
---|
377 | %check possible coordinates |
---|
378 | Field=get(handles.get_field,'UserData'); |
---|
379 | dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar |
---|
380 | test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate |
---|
381 | for ilist=1:numel(Field.VarDimName) |
---|
382 | dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
383 | if isequal(dimnames,{TimeDimName}) |
---|
384 | test_coord(ilist)=0;%mark time variables fo elimination |
---|
385 | end |
---|
386 | for idim=1:numel(dimnames) |
---|
387 | if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable |
---|
388 | test_coord(ilist)=0; |
---|
389 | break |
---|
390 | end |
---|
391 | end |
---|
392 | end |
---|
393 | test_coord(index)=0;%the coordinate variable must be different from the scalar |
---|
394 | |
---|
395 | string_coord=[{''};string(test_coord==1)]; |
---|
396 | val=get(handles.coord_x_scalar,'Value'); |
---|
397 | if val>numel(string_coord) |
---|
398 | set(handles.coord_x_scalar,'Value',1) |
---|
399 | end |
---|
400 | set(handles.coord_x_scalar,'String',string_coord); |
---|
401 | val=get(handles.coord_y_scalar,'Value'); |
---|
402 | if val>numel(string_coord) |
---|
403 | set(handles.coord_y_scalar,'Value',1) |
---|
404 | end |
---|
405 | set(handles.coord_y_scalar,'String',string_coord); |
---|
406 | val=get(handles.coord_y_scalar,'Value'); |
---|
407 | if val>numel(string_coord) |
---|
408 | set(handles.coord_y_scalar,'Value',1) |
---|
409 | end |
---|
410 | set(handles.coord_z_scalar,'String',string_coord); |
---|
411 | |
---|
412 | |
---|
413 | %------------------------------------------------------------------------ |
---|
414 | % --- Executes on selection change in coord_x_scalar. |
---|
415 | function coord_x_scalar_Callback(hObject, eventdata, handles) |
---|
416 | %------------------------------------------------------------------------ |
---|
417 | index=get(handles.coord_x_scalar,'Value'); |
---|
418 | string=get(handles.coord_x_scalar,'String'); |
---|
419 | VarName=string{index}; |
---|
420 | update_field(hObject, eventdata, handles,VarName) |
---|
421 | |
---|
422 | %------------------------------------------------------------------------ |
---|
423 | % --- Executes on selection change in coord_y_scalar. |
---|
424 | function coord_y_scalar_Callback(hObject, eventdata, handles) |
---|
425 | %------------------------------------------------------------------------ |
---|
426 | index=get(handles.coord_y_scalar,'Value'); |
---|
427 | string=get(handles.coord_y_scalar,'String'); |
---|
428 | VarName=string{index}; |
---|
429 | update_field(hObject, eventdata, handles,VarName) |
---|
430 | |
---|
431 | %------------------------------------------------------------------------ |
---|
432 | % --- Executes on selection change in coord_z_scalar. |
---|
433 | function coord_z_scalar_Callback(hObject, eventdata, handles) |
---|
434 | %------------------------------------------------------------------------ |
---|
435 | index=get(handles.coord_z_scalar,'Value'); |
---|
436 | string=get(handles.coord_z_scalar,'String'); |
---|
437 | VarName=string{index}; |
---|
438 | update_field(hObject, eventdata, handles,VarName) |
---|
439 | |
---|
440 | %------------------------------------------------------------------------ |
---|
441 | % --- Executes on selection change in vector_x. |
---|
442 | function vector_x_Callback(hObject, eventdata, handles) |
---|
443 | %------------------------------------------------------------------------ |
---|
444 | index=get(handles.vector_x,'Value'); |
---|
445 | string=get(handles.vector_x,'String'); |
---|
446 | VarName=string{index}; |
---|
447 | |
---|
448 | %check possible coordinates |
---|
449 | Field=get(handles.get_field,'UserData'); |
---|
450 | dim_var=Field.VarDimName{index};%list of dimensions of the selected scalar |
---|
451 | test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate |
---|
452 | test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component |
---|
453 | for ilist=1:numel(Field.VarDimName) |
---|
454 | dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
455 | if ~isequal(dimnames,dim_var) |
---|
456 | test_component(ilist)=0; |
---|
457 | end |
---|
458 | for idim=1:numel(dimnames) |
---|
459 | if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable |
---|
460 | test_coord(ilist)=0; |
---|
461 | break |
---|
462 | end |
---|
463 | end |
---|
464 | end |
---|
465 | %eliminate time |
---|
466 | if get(handles.TimeVariable,'Value') |
---|
467 | TimeName=get(handles.TimeName,'String'); |
---|
468 | index_time=find(strcmp( TimeName,Field.ListVarName)); |
---|
469 | test_coord(index_time)=0; |
---|
470 | end |
---|
471 | vlength=numel(string(test_component==1)); |
---|
472 | val=get(handles.vector_y,'Value'); |
---|
473 | if val>vlength |
---|
474 | set(handles.vector_y,'Value',1) |
---|
475 | end |
---|
476 | set(handles.vector_y,'String',[string(test_component==1)]) |
---|
477 | val=get(handles.vector_z,'Value'); |
---|
478 | if val>vlength+1 |
---|
479 | set(handles.vector_z,'Value',1) |
---|
480 | end |
---|
481 | set(handles.vector_z,'String',[{''};string(test_component==1)]) |
---|
482 | val=get(handles.vec_color,'Value'); |
---|
483 | if val>vlength+1 |
---|
484 | set(handles.vec_color,'Value',1) |
---|
485 | end |
---|
486 | set(handles.vec_color,'String',[{''};string(test_component==1)]) |
---|
487 | string_coord=[{''};string(test_coord==1)]; |
---|
488 | val=get(handles.coord_x_vectors,'Value'); |
---|
489 | if val>numel(string_coord) |
---|
490 | set(handles.coord_x_vectors,'Value',1) |
---|
491 | end |
---|
492 | set(handles.coord_x_vectors,'String',string_coord); |
---|
493 | val=get(handles.coord_y_vectors,'Value'); |
---|
494 | if val>numel(string_coord) |
---|
495 | set(handles.coord_y_vectors,'Value',1) |
---|
496 | end |
---|
497 | set(handles.coord_y_vectors,'String',string_coord); |
---|
498 | val=get(handles.coord_z_vectors,'Value'); |
---|
499 | if val>numel(string_coord) |
---|
500 | set(handles.coord_z_vectors,'Value',1) |
---|
501 | end |
---|
502 | set(handles.coord_z_vectors,'String',string_coord); |
---|
503 | |
---|
504 | update_field(hObject, eventdata, handles,VarName) |
---|
505 | |
---|
506 | %------------------------------------------------------------------------ |
---|
507 | % --- Executes on selection change in vector_y. |
---|
508 | function vector_y_Callback(hObject, eventdata, handles) |
---|
509 | %------------------------------------------------------------------------ |
---|
510 | index=get(handles.vector_y,'Value'); |
---|
511 | string=get(handles.vector_y,'String'); |
---|
512 | VarName=string{index}; |
---|
513 | update_field(hObject, eventdata, handles,VarName) |
---|
514 | |
---|
515 | %------------------------------------------------------------------------ |
---|
516 | % --- Executes on selection change in vector_z. |
---|
517 | function vector_z_Callback(hObject, eventdata, handles) |
---|
518 | %------------------------------------------------------------------------ |
---|
519 | index=get(handles.vector_z,'Value'); |
---|
520 | string=get(handles.vector_z,'String'); |
---|
521 | VarName=Astring{index}; |
---|
522 | update_field(hObject, eventdata, handles,VarName) |
---|
523 | |
---|
524 | %------------------------------------------------------------------------ |
---|
525 | % --- Executes on selection change in coord_x_vectors. |
---|
526 | function coord_x_vectors_Callback(hObject, eventdata, handles) |
---|
527 | %------------------------------------------------------------------------ |
---|
528 | index=get(handles.coord_x_vectors,'Value'); |
---|
529 | string=get(handles.coord_x_vectors,'String'); |
---|
530 | VarName=string{index}; |
---|
531 | update_field(hObject, eventdata, handles,VarName) |
---|
532 | |
---|
533 | %------------------------------------------------------------------------ |
---|
534 | % --- Executes on selection change in coord_y_vectors. |
---|
535 | function coord_y_vectors_Callback(hObject, eventdata, handles) |
---|
536 | %------------------------------------------------------------------------ |
---|
537 | index=get(handles.coord_y_vectors,'Value'); |
---|
538 | string=get(handles.coord_y_vectors,'String'); |
---|
539 | VarName=string{index}; |
---|
540 | update_field(hObject, eventdata, handles,VarName) |
---|
541 | |
---|
542 | %------------------------------------------------------------------------ |
---|
543 | % --- Executes on selection change in coord_z_scalar. |
---|
544 | function coord_z_vectors_Callback(hObject, eventdata, handles) |
---|
545 | %------------------------------------------------------------------------ |
---|
546 | index=get(handles.coord_z_vectors,'Value'); |
---|
547 | string=get(handles.coord_z_vectors,'String'); |
---|
548 | VarName=string{index}; |
---|
549 | update_field(hObject, eventdata, handles,VarName) |
---|
550 | |
---|
551 | %------------------------------------------------------------------------ |
---|
552 | % --- Executes on selection change in vec_color. |
---|
553 | function vec_color_Callback(hObject, eventdata, handles) |
---|
554 | %------------------------------------------------------------------------ |
---|
555 | index=get(handles.vec_color,'Value'); |
---|
556 | string=get(handles.vec_color,'String'); |
---|
557 | VarName=string{index}; |
---|
558 | update_field(hObject, eventdata, handles,VarName) |
---|
559 | |
---|
560 | %----------------------------------------------------------------------- |
---|
561 | function update_field(hObject, eventdata, handles,VarName) |
---|
562 | %----------------------------------------------------------------------- |
---|
563 | Field=get(handles.get_field,'UserData'); |
---|
564 | index=name2index(VarName,Field.ListVarName); |
---|
565 | if ~isempty(index) |
---|
566 | set(handles.variables,'Value',index+1) |
---|
567 | variables_Callback(hObject, eventdata, handles) |
---|
568 | end |
---|
569 | |
---|
570 | %------------------------------------------------------------------------ |
---|
571 | % update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback) |
---|
572 | function update_UserData(handles) |
---|
573 | %------------------------------------------------------------------------ |
---|
574 | return |
---|
575 | % global SubField |
---|
576 | hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface |
---|
577 | Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface |
---|
578 | if isfield(Field,'VarAttribute') |
---|
579 | VarAttribute=Field.VarAttribute; |
---|
580 | else |
---|
581 | VarAttribute={}; |
---|
582 | end |
---|
583 | |
---|
584 | |
---|
585 | % select the indices of field variables for 2D plots |
---|
586 | test_CheckPlot1D=get(handles.CheckPlot1D,'Value'); |
---|
587 | test_scalar=get(handles.CheckScalar,'Value'); |
---|
588 | test_vector=get(handles.CheckVector,'Value'); |
---|
589 | |
---|
590 | %transform if needed (calibration) |
---|
591 | list=get(handles.menu_coord,'String'); |
---|
592 | index=get(handles.menu_coord,'Value'); |
---|
593 | transform=list{index}; |
---|
594 | if ~isequal(transform,'') |
---|
595 | Field=feval(transform,Field); |
---|
596 | end |
---|
597 | VarIndex.u=[]; |
---|
598 | VarIndex.v=[]; |
---|
599 | VarIndex.w=[]; |
---|
600 | VarIndex.A=[]; |
---|
601 | VarIndex_tot=[]; |
---|
602 | iuA=[]; |
---|
603 | if test_scalar |
---|
604 | Astring=get(handles.scalar,'String'); |
---|
605 | Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox |
---|
606 | list_var=Astring(Aindex); |
---|
607 | VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName |
---|
608 | VarIndex_tot= [VarIndex_tot VarIndex.A]; |
---|
609 | DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable |
---|
610 | DimValue=Field.DimValue(DimIndex); |
---|
611 | ind=find(DimValue==1); |
---|
612 | DimIndex(ind)=[];%Mremove singleton |
---|
613 | end |
---|
614 | if test_vector |
---|
615 | Ustring=get(handles.vector_x,'String'); |
---|
616 | Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox |
---|
617 | list_var=Ustring{Uindex};%name of the selected scalar |
---|
618 | VarIndex.u=name2index(list_var,Field.ListVarName); |
---|
619 | Vstring=get(handles.vector_y,'String'); |
---|
620 | Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox |
---|
621 | list_var=Ustring{Vindex};%name of the selected scalar |
---|
622 | VarIndex.v=name2index(list_var,Field.ListVarName); |
---|
623 | if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A) |
---|
624 | iuA=VarIndex.A; %same variable used for vector and scalar |
---|
625 | VarIndex_tot(iuA)=[]; |
---|
626 | end |
---|
627 | VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v]; |
---|
628 | %dimensions |
---|
629 | DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable |
---|
630 | DimValue=Field.DimValue(DimIndex_u); |
---|
631 | ind=find(DimValue==1); |
---|
632 | DimIndex_u(ind)=[];%Mremove singleton |
---|
633 | DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable |
---|
634 | DimValue=Field.DimValue(DimIndex_v); |
---|
635 | ind=find(DimValue==1); |
---|
636 | DimIndex_v(ind)=[];%Mremove singleton |
---|
637 | if ~isequal(DimIndex_u,DimIndex_v) |
---|
638 | msgbox_uvmat('ERROR','inconsistent dimensions for u and v') |
---|
639 | set(handles.vector_y,'Value',1); |
---|
640 | return |
---|
641 | elseif test_scalar & ~isequal(DimIndex_u,DimIndex) |
---|
642 | msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color') |
---|
643 | set(handles.scalar,'Value',1); |
---|
644 | return |
---|
645 | end |
---|
646 | DimIndex=DimIndex_u; |
---|
647 | %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components |
---|
648 | end |
---|
649 | |
---|
650 | |
---|
651 | % select the TimeVariable index (or indices) for z coordinates |
---|
652 | test_grid=0; |
---|
653 | if test_scalar | test_vector |
---|
654 | nbdim=length(DimIndex); |
---|
655 | if nbdim > 3 |
---|
656 | msgbox_uvmat('ERROR','array with more than three dimensions, not supported') |
---|
657 | return |
---|
658 | else |
---|
659 | perm_ind=1:nbdim; |
---|
660 | end |
---|
661 | if nbdim==3 |
---|
662 | zstring=get(handles.coord_z_vectors_scalar,'String'); |
---|
663 | zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox |
---|
664 | list_var=zstring(zindex); |
---|
665 | VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable |
---|
666 | if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z) |
---|
667 | if zindex ~= 1 |
---|
668 | set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components |
---|
669 | return |
---|
670 | end |
---|
671 | else |
---|
672 | VarIndex_tot=[VarIndex_tot VarIndex_z]; |
---|
673 | DimIndex_z=Field.VarDimIndex{VarIndex_z}; |
---|
674 | DimValue=Field.DimValue(DimIndex_z); |
---|
675 | ind=find(DimValue==1); |
---|
676 | DimIndex_z(ind)=[];%Mremove singleton |
---|
677 | if isequal(DimIndex_z,DimIndex) |
---|
678 | VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates |
---|
679 | elseif length(DimIndex_z)==1 |
---|
680 | VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; %dimension variable |
---|
681 | ind_z=find(DimIndex==DimIndex_z(1)); |
---|
682 | perm_ind(ind_z)=1; |
---|
683 | test_grid=1; |
---|
684 | else |
---|
685 | msgbox_uvmat('ERROR','multiple dimensions for the z coordinate') |
---|
686 | return |
---|
687 | end |
---|
688 | end |
---|
689 | % if ~isempty(VarIndex_z) |
---|
690 | % DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable |
---|
691 | % if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable |
---|
692 | % VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; |
---|
693 | % ind_z=find(DimIndex==DimIndex_z(1)); |
---|
694 | % perm_ind(ind_z)=1; |
---|
695 | % test_grid=1; |
---|
696 | % end |
---|
697 | % end |
---|
698 | end |
---|
699 | end |
---|
700 | |
---|
701 | % select the TimeVariable index (or indices) for ordinate |
---|
702 | ystring=get(handles.ordinate,'String'); |
---|
703 | yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox |
---|
704 | list_var=ystring(yindex); |
---|
705 | VarIndex.y=name2index(list_var,Field.ListVarName); |
---|
706 | if isequal(VarIndex.A,VarIndex.y) |
---|
707 | set(handles.coord_y_scalar,'Value',1) |
---|
708 | elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y) |
---|
709 | set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components |
---|
710 | else |
---|
711 | for ivar=1:length(VarIndex.y) |
---|
712 | VarAttribute{VarIndex.y(ivar)}.Role='coord_y'; |
---|
713 | end |
---|
714 | VarIndex_tot=[VarIndex_tot VarIndex.y]; |
---|
715 | end |
---|
716 | if (test_scalar | test_vector) & ~isempty(VarIndex.y) |
---|
717 | DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable |
---|
718 | if length(DimIndex_y)==1 |
---|
719 | ind_y=find(DimIndex==DimIndex_y(1)); |
---|
720 | test_grid=1; |
---|
721 | if nbdim==3 |
---|
722 | VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y}; |
---|
723 | perm_ind(ind_y)=2; |
---|
724 | elseif nbdim==2 |
---|
725 | VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y}; |
---|
726 | perm_ind(ind_y)=1; |
---|
727 | end |
---|
728 | elseif test_grid |
---|
729 | msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1') |
---|
730 | end |
---|
731 | end |
---|
732 | |
---|
733 | %select the TimeVariable index for the abscissa |
---|
734 | xstring=get(handles.abscissa,'String'); |
---|
735 | xindex=get(handles.abscissa,'Value'); |
---|
736 | list_var=xstring(xindex); |
---|
737 | VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var |
---|
738 | if length(VarIndex.x)==1 |
---|
739 | DimIndex_x=Field.VarDimIndex{VarIndex.x}; |
---|
740 | DimValue=Field.DimValue(DimIndex_x); |
---|
741 | ind=find(DimValue==1); |
---|
742 | DimIndex_x(ind)=[];%Mremove singleton |
---|
743 | VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; %dimension variable |
---|
744 | % VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified) |
---|
745 | index_detect=find(VarIndex_tot==VarIndex.x); |
---|
746 | else |
---|
747 | index_detect=[];%coord x variable not already used |
---|
748 | end |
---|
749 | if isempty(index_detect) |
---|
750 | VarIndex_tot=[VarIndex_tot VarIndex.x]; |
---|
751 | elseif ~test_CheckPlot1D |
---|
752 | VarIndex.x=[]; |
---|
753 | set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa |
---|
754 | end |
---|
755 | |
---|
756 | if (test_scalar | test_vector) & ~isempty(VarIndex.x) |
---|
757 | DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable |
---|
758 | if length(DimIndex_x)==1 |
---|
759 | ind_x=find(DimIndex==DimIndex_x(1)); |
---|
760 | if nbdim==3 |
---|
761 | %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; |
---|
762 | perm_ind(ind_x)=3; |
---|
763 | elseif nbdim==2 |
---|
764 | %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; |
---|
765 | perm_ind(ind_x)=2; |
---|
766 | end |
---|
767 | if isequal(perm_ind,1:nbdim) |
---|
768 | test_grid=0; |
---|
769 | end |
---|
770 | DimIndex=DimIndex(perm_ind); |
---|
771 | elseif test_grid |
---|
772 | msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1') |
---|
773 | end |
---|
774 | if isequal(DimIndex_x,DimIndex) |
---|
775 | VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates |
---|
776 | end |
---|
777 | end |
---|
778 | |
---|
779 | %defined the selected sub-field SubField |
---|
780 | SubField.ListGlobalAttribute{1}='InputFile'; |
---|
781 | SubField.InputFile=get(handles.inputfile,'String'); |
---|
782 | SubField.ListDimName=Field.ListDimName; |
---|
783 | SubField.DimValue=Field.DimValue; |
---|
784 | SubField.ListVarName=Field.ListVarName(VarIndex_tot); |
---|
785 | SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot); |
---|
786 | |
---|
787 | testperm=0; |
---|
788 | testattr=0; |
---|
789 | for ivar=VarIndex.u |
---|
790 | VarAttribute{ivar}.Role='vector_x'; |
---|
791 | testattr=1; |
---|
792 | if test_grid |
---|
793 | VarDimIndex{ivar}=DimIndex; %permute dimensions |
---|
794 | testperm=1; |
---|
795 | end |
---|
796 | end |
---|
797 | for ivar=VarIndex.v |
---|
798 | VarAttribute{ivar}.Role='vector_y'; |
---|
799 | testattr=1; |
---|
800 | if test_grid |
---|
801 | VarDimIndex{ivar}=DimIndex;%permute dimensions |
---|
802 | testperm=1; |
---|
803 | end |
---|
804 | end |
---|
805 | for ivar=VarIndex.A |
---|
806 | if test_grid |
---|
807 | VarDimIndex{ivar}=DimIndex;%permute dimensions |
---|
808 | testperm=1; |
---|
809 | end |
---|
810 | if isempty(iuA) |
---|
811 | VarAttribute{ivar}.Role='scalar';%Role =scalar |
---|
812 | testattr=1; |
---|
813 | else |
---|
814 | VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable |
---|
815 | nbattr=length(VarAttribute); |
---|
816 | VarAttribute{nbattr}.Role='scalar'; |
---|
817 | testattr=1; |
---|
818 | end |
---|
819 | end |
---|
820 | if testperm |
---|
821 | SubField.VarDimIndex=VarDimIndex(VarIndex_tot); |
---|
822 | end |
---|
823 | if testattr |
---|
824 | SubField.VarAttribute=VarAttribute(VarIndex_tot); |
---|
825 | end |
---|
826 | set(hselect_field,'UserData',Field) |
---|
827 | |
---|
828 | %--------------------------------------------------------- |
---|
829 | % --- Executes on button press in RUN. |
---|
830 | |
---|
831 | function RUN_Callback(hObject, eventdata, handles) |
---|
832 | %--------------------------------------------------------- |
---|
833 | % set(handles.RUN,'BackgroundColor',[1 1 0])% mark use of RUN action |
---|
834 | % test_fig=get(handles.SelectFigure,'Value'); |
---|
835 | % |
---|
836 | % % plot requested in uvmat |
---|
837 | % if ~test_fig |
---|
838 | % inputfile=get(handles.inputfile,'String'); |
---|
839 | % huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
840 | % if isempty(huvmat) |
---|
841 | % input.InputFile=inputfile; |
---|
842 | % input.FieldsString={'get_field...'}; |
---|
843 | % uvmat(input) |
---|
844 | % else |
---|
845 | % set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases) |
---|
846 | % hhuvmat=guidata(huvmat); |
---|
847 | % set(hhuvmat.Fields,'Value',1) |
---|
848 | % set(hhuvmat.Fields,'String',{'get_field...'}) |
---|
849 | % uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat |
---|
850 | % end |
---|
851 | % |
---|
852 | % % other kind of plot |
---|
853 | % else %TODO: check and update: add plot on an existing axes |
---|
854 | % figcell=get(handles.list_fig,'String'); |
---|
855 | % index=get(handles.list_fig,'value'); |
---|
856 | % figstring=figcell{index}; |
---|
857 | % index=get(handles.ACTION,'Value'); |
---|
858 | % list_func=get(handles.ACTION,'UserData'); |
---|
859 | % h_fun=list_func{index}; |
---|
860 | % set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784]) |
---|
861 | % drawnow |
---|
862 | % SubField=h_fun(handles.get_field);%handles.figure1 =handles of the GUI get_field |
---|
863 | % if ~isempty(SubField) |
---|
864 | % plot_get_field(SubField,handles) |
---|
865 | % end |
---|
866 | % browse_fig(handles.list_fig); %update the list of new existing figures |
---|
867 | % end |
---|
868 | % set(handles.RUN,'BackgroundColor',[1 0 0]) |
---|
869 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
870 | hhuvmat=guidata(huvmat); |
---|
871 | FieldsMenu=get(hhuvmat.Fields,'String'); |
---|
872 | Fields=FieldsMenu{get(hhuvmat.Fields,'Value')}; |
---|
873 | check_first=strcmp(Fields,'get_field...'); % =1 if the first field sereis is selected, =0 else |
---|
874 | if ~isempty(huvmat) |
---|
875 | get_field_GUI=read_GUI(handles.get_field); |
---|
876 | if isfield(get_field_GUI,'PanelVectors') |
---|
877 | set(hhuvmat.Coord_x,'value',1) |
---|
878 | set(hhuvmat.Coord_y,'value',1) |
---|
879 | set(hhuvmat.Coord_x,'String',{get_field_GUI.PanelVectors.coord_x_vectors}) |
---|
880 | set(hhuvmat.Coord_y,'String',{get_field_GUI.PanelVectors.coord_y_vectors}) |
---|
881 | UName=get_field_GUI.PanelVectors.vector_x; |
---|
882 | VName=get_field_GUI.PanelVectors.vector_y; |
---|
883 | menu_str=[{['vec(' UName ',' VName ')']};{UName};{VName};{['norm(' UName ',' VName ')']};{'get_field...'}]; |
---|
884 | menu_color=[{''};{UName};{VName};{['norm(' UName ',' VName ')']}]; |
---|
885 | if check_first |
---|
886 | set(hhuvmat.Fields,'Value',1) |
---|
887 | set(hhuvmat.Fields,'String',menu_str) |
---|
888 | else %get_field has been called by Fields_1 |
---|
889 | set(hhuvmat.Fields_1,'Value',1) |
---|
890 | set(hhuvmat.Fields_1,'String',menu_str) |
---|
891 | end |
---|
892 | ind_menu=find(strcmp(get_field_GUI.PanelVectors.vec_color,menu_color)); |
---|
893 | if ~isempty(ind_menu) |
---|
894 | set(hhuvmat.ColorScalar,'Value',ind_menu) |
---|
895 | else |
---|
896 | set(hhuvmat.ColorScalar,'Value',1) |
---|
897 | end |
---|
898 | set(hhuvmat.ColorScalar,'String',menu_color) |
---|
899 | elseif isfield(get_field_GUI,'PanelScalar') |
---|
900 | set(hhuvmat.Coord_x,'value',1) |
---|
901 | set(hhuvmat.Coord_y,'value',1) |
---|
902 | set(hhuvmat.Coord_x,'String',{get_field_GUI.PanelScalar.coord_x_scalar}) |
---|
903 | set(hhuvmat.Coord_y,'String',{get_field_GUI.PanelScalar.coord_y_scalar}) |
---|
904 | AName=get_field_GUI.PanelScalar.scalar; |
---|
905 | if check_first |
---|
906 | menu=get(hhuvmat.Fields,'String'); |
---|
907 | else |
---|
908 | menu=get(hhuvmat.Fields_1,'String'); |
---|
909 | end |
---|
910 | ind_select=find(strcmp(AName,menu)); |
---|
911 | if isempty(ind_select) |
---|
912 | menu=[menu(1:end-1);{AName};{'get_field...'}]; |
---|
913 | ind_select=numel(menu)-1; |
---|
914 | end |
---|
915 | if check_first |
---|
916 | set(hhuvmat.Fields,'Value',ind_select); |
---|
917 | set(hhuvmat.Fields,'String',menu); |
---|
918 | else |
---|
919 | set(hhuvmat.Fields_1,'Value',ind_select); |
---|
920 | set(hhuvmat.Fields_1,'String',menu); |
---|
921 | end |
---|
922 | end |
---|
923 | if ~strcmp(get(gcbf,'tag'),'uvmat')%if uvmat is not already active |
---|
924 | uvmat('run0_Callback',hObject,eventdata,hhuvmat); %refresh uvmat |
---|
925 | end |
---|
926 | end |
---|
927 | delete(handles.get_field) |
---|
928 | % set(hhuvmat.Fields,'String',{'get_field...'}) |
---|
929 | % uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat |
---|
930 | % end |
---|
931 | |
---|
932 | %------------------------------------------------------------------------ |
---|
933 | % --- Function for plotting the current subfield |
---|
934 | function plot_get_field(SubField,handles) |
---|
935 | %------------------------------------------------------------------------ |
---|
936 | list_fig=get(handles.list_fig,'String'); |
---|
937 | val=get(handles.list_fig,'Value'); |
---|
938 | if strcmp(list_fig{val},'uvmat') |
---|
939 | set(handles.inputfile,'Enable','off')% desactivate the input file edit box |
---|
940 | set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt) |
---|
941 | set(handles.MenuOpen,'Visible','off') |
---|
942 | set(handles.MenuExport,'Visible','off') |
---|
943 | uvmat(get(handles.inputfile,'String')) |
---|
944 | elseif strcmp(list_fig{val},'view_field') |
---|
945 | view_field(SubField) |
---|
946 | else |
---|
947 | hfig=str2double(list_fig{val});% chosen figure number from tyhe GUI |
---|
948 | if isnan(hfig) |
---|
949 | hfig=figure; |
---|
950 | list_fig=[list_fig;num2str(hfig)]; |
---|
951 | set(handles.list_fig,'String',list_fig); |
---|
952 | haxes=axes; |
---|
953 | else |
---|
954 | figure(hfig); |
---|
955 | end |
---|
956 | haxes=findobj(hfig,'Type','axes'); |
---|
957 | plot_field(SubField,haxes) |
---|
958 | end |
---|
959 | |
---|
960 | % %------------------------------------------------ |
---|
961 | % % --- Executes on button press in Plot_histo. |
---|
962 | % %RUN global histograms |
---|
963 | % %------------------------------------------------- |
---|
964 | % function RUN_histo_Callback(hObject, eventdata, handles) |
---|
965 | % % hObject handle to RUN (see GCBO) |
---|
966 | % % eventdata reserved - to be defined in a future version of MATLAB |
---|
967 | % % handles structure with handles and user data (see GUIDATA) |
---|
968 | % |
---|
969 | % %timename plots |
---|
970 | % leg={}; |
---|
971 | % n=0; |
---|
972 | % if (get(handles.cm_switch,'Value')==1) |
---|
973 | % Uval_p=Uval_cm; |
---|
974 | % Vval_p=Vval_cm; |
---|
975 | % Uhist_p=Uhist_cm; |
---|
976 | % Vhist_p=Vhist_cm; |
---|
977 | % xlab='velocity (cm/s)'; |
---|
978 | % else |
---|
979 | % Uval_p=Uval; |
---|
980 | % Vval_p=Vval; |
---|
981 | % Uhist_p=Uhist; |
---|
982 | % Vhist_p=Vhist; |
---|
983 | % xlab='velocity (pixels)'; |
---|
984 | % end |
---|
985 | % if (get(handles.vector_y,'Value') == 1) |
---|
986 | % hhh=figure(2); |
---|
987 | % hold on |
---|
988 | % title([filebase ', ' strindex ', ' fieldtitle]) |
---|
989 | % plot(Uval_p,Uhist_p,'b-') |
---|
990 | % n=n+1; |
---|
991 | % leg{n}='Uhist'; |
---|
992 | % xlabel(xlab) |
---|
993 | % end |
---|
994 | % if (get(handles.Vhist_input,'Value') == 1) |
---|
995 | % hhh=figure(2); |
---|
996 | % hold on |
---|
997 | % title([filebase ', ' strindex ', ' fieldtitle]) |
---|
998 | % plot(Vval_p,Vhist_p,'r-') |
---|
999 | % n=n+1; |
---|
1000 | % leg{n}='Vhist'; |
---|
1001 | % xlabel(xlab); |
---|
1002 | % end |
---|
1003 | % if (get(handles.Chist_input,'Value') == 1) |
---|
1004 | % hhhh=figure(3); |
---|
1005 | % hold on |
---|
1006 | % title([filebase ', ' strindex ', ' fieldtitle]) |
---|
1007 | % plot(Cval,Chist,'k-') |
---|
1008 | % leg{1}='Chist'; |
---|
1009 | % end |
---|
1010 | % % hold off |
---|
1011 | % grid on |
---|
1012 | % legend(leg); |
---|
1013 | |
---|
1014 | % %------------------------------------------------------------- |
---|
1015 | % % --- Executes on button press in Save_input. |
---|
1016 | % function Save_input_Callback(hObject, eventdata, handles) |
---|
1017 | % list_str=get(handles.abscissa,'String'); |
---|
1018 | % val=get(handles.abscissa,'Value'); |
---|
1019 | % var=list_str{val}; |
---|
1020 | % hselect_field=get(handles.Save_input,'parent') |
---|
1021 | % set(hselect_field,'UserData',var); |
---|
1022 | % set(hselect_field,'Tag','idle') |
---|
1023 | |
---|
1024 | % |
---|
1025 | % %------------------------------------------------------------- |
---|
1026 | % % --- Executes on button press in save_histo. |
---|
1027 | % function save_histo_Callback(hObject, eventdata, handles) |
---|
1028 | % global filebase |
---|
1029 | % |
---|
1030 | % pathstr = fileparts(filebase) |
---|
1031 | % if (get(handles.Chist_input,'Value') == 1) |
---|
1032 | % def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']}; |
---|
1033 | % else |
---|
1034 | |
---|
1035 | % def = {[pathstr pathstr(1) 'vel_histo.fig']}; |
---|
1036 | % end |
---|
1037 | % prompt={'save figure(2) as'} |
---|
1038 | % dlg_title = 'save figure'; |
---|
1039 | % num_lines= 1; |
---|
1040 | % answer = inputdlg(prompt,dlg_title,num_lines,def) |
---|
1041 | % saveas(2,answer{1}) |
---|
1042 | |
---|
1043 | |
---|
1044 | %%------------------------------------------------------- |
---|
1045 | % --- Executes on button press in peaklocking. |
---|
1046 | %------------------------------------------------- |
---|
1047 | function peaklocking(handles) |
---|
1048 | %evaluation of peacklocking errors |
---|
1049 | %use splinhist: give spline coeff cc for a smooth histo (call spline4) |
---|
1050 | %use histsmooth(x,cc): calculate the smooth histo for any value x |
---|
1051 | %use histder(x,cc): calculate the derivative of the smooth histo |
---|
1052 | global hfig1 hfig2 hfig3 |
---|
1053 | global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval |
---|
1054 | global xval xerror yval yerror |
---|
1055 | |
---|
1056 | set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface |
---|
1057 | set(handles.Vhist_input,'Value',1) |
---|
1058 | set(handles.cm_switch,'Value',0) % put the switch to 'pixel' |
---|
1059 | |
---|
1060 | %adjust the extremal values of the histogram in U with respect to integer |
---|
1061 | %values |
---|
1062 | minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins |
---|
1063 | maximU=round(max(Uval)-0.5)+0.5; |
---|
1064 | minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval |
---|
1065 | maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value |
---|
1066 | nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below |
---|
1067 | nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above |
---|
1068 | Uval=[minim_fin:(1/nbb):maxim_fin]; |
---|
1069 | histu_min=zeros(nb_bin_min,1); |
---|
1070 | histu_max=zeros(nb_bin_max,1); |
---|
1071 | Uhist=[histu_min; Uhist ;histu_max]; % column vector |
---|
1072 | |
---|
1073 | %adjust the extremal values of the histogram in V |
---|
1074 | minimV=round(min(Vval-0.5)+0.5); |
---|
1075 | maximV=round(max(Vval-0.5)+0.5); |
---|
1076 | minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval |
---|
1077 | maxim_fin=maximV+0.5-1/(2*nbb); % last integer value |
---|
1078 | nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below |
---|
1079 | nb_bin_max=round((maxim_fin -max(Vval))*nbb); |
---|
1080 | Vval=[minim_fin:(1/nbb):maxim_fin]; |
---|
1081 | histu_min=zeros(nb_bin_min,1); |
---|
1082 | histu_max=zeros(nb_bin_max,1); |
---|
1083 | Vhist=[histu_min; Vhist ;histu_max]; % column vector |
---|
1084 | |
---|
1085 | % RUN_histo_Callback(hObject, eventdata, handles) |
---|
1086 | % %adjust the histogram to integer values: |
---|
1087 | |
---|
1088 | %histoU and V |
---|
1089 | [Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist); |
---|
1090 | [Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist); |
---|
1091 | |
---|
1092 | % selection of value ranges such that histo>=10 (enough statistics) |
---|
1093 | Uval_ind=find(Uhist>=10); |
---|
1094 | ind_min=min(Uval_ind); |
---|
1095 | ind_max=max(Uval_ind); |
---|
1096 | U_min=Uval(ind_min);% minimum allowed value |
---|
1097 | U_max=Uval(ind_max);%maximum allowed value |
---|
1098 | |
---|
1099 | % selection of value ranges such that histo>=10 (enough statistics) |
---|
1100 | Vval_ind=find(Vhist>=10); |
---|
1101 | ind_min=min(Vval_ind); |
---|
1102 | ind_max=max(Vval_ind); |
---|
1103 | V_min=Vval(ind_min);% minimum allowed value |
---|
1104 | V_max=Vval(ind_max);%maximum allowed value |
---|
1105 | |
---|
1106 | figure(4)% plot U histogram with smoothed one |
---|
1107 | plot(Uval,Uhist,'b') |
---|
1108 | grid on |
---|
1109 | hold on |
---|
1110 | plot(Uval,Uhistinter,'r'); |
---|
1111 | hold off |
---|
1112 | |
---|
1113 | figure(5)% plot V histogram with smoothed one |
---|
1114 | plot(Vval,Vhist,'b') |
---|
1115 | grid on |
---|
1116 | hold on |
---|
1117 | plot(Vval,Vhistinter,'r'); |
---|
1118 | hold off |
---|
1119 | |
---|
1120 | figure(6)% plot pixel error in two subplots |
---|
1121 | hfig4=subplot(2,1,1); |
---|
1122 | hfig5=subplot(2,1,2); |
---|
1123 | axes(hfig4) |
---|
1124 | plot(xval,xerror) |
---|
1125 | axis([U_min U_max -0.4 0.4]) |
---|
1126 | xlabel('velocity u (pix)') |
---|
1127 | ylabel('peaklocking error (pix)') |
---|
1128 | grid on |
---|
1129 | axes(hfig5) |
---|
1130 | plot(yval,yerror) |
---|
1131 | axis([V_min V_max -0.4 0.4]); |
---|
1132 | xlabel('velocity v (pix)') |
---|
1133 | ylabel('peaklocking error (pix)') |
---|
1134 | grid on |
---|
1135 | |
---|
1136 | |
---|
1137 | % ------------------------------------------------------------------ |
---|
1138 | function variables_Callback(hObject, eventdata, handles) |
---|
1139 | Tabchar={''};%default |
---|
1140 | Tabcell=[]; |
---|
1141 | hselect_field=get(handles.variables,'parent'); |
---|
1142 | Field=get(handles.get_field,'UserData'); |
---|
1143 | index=get(handles.variables,'Value');%index in the list 'variables' |
---|
1144 | |
---|
1145 | %% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected |
---|
1146 | if isequal(index,1) |
---|
1147 | set(handles.attributes_txt,'String','global attributes') |
---|
1148 | if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute) |
---|
1149 | for iline=1:length(Field.ListGlobalAttribute) |
---|
1150 | Tabcell{iline,1}=Field.ListGlobalAttribute{iline}; |
---|
1151 | if isfield(Field, Field.ListGlobalAttribute{iline}) |
---|
1152 | eval(['val=Field.' Field.ListGlobalAttribute{iline} ';']) |
---|
1153 | if ischar(val);% attribute value is char string |
---|
1154 | Tabcell{iline,2}=val; |
---|
1155 | elseif size(val,1)==1 %attribute value is a number or matlab vector |
---|
1156 | Tabcell{iline,2}=num2str(val); |
---|
1157 | end |
---|
1158 | end |
---|
1159 | end |
---|
1160 | Tabchar=cell2tab(Tabcell,'='); |
---|
1161 | end |
---|
1162 | %% list Attribute names and values associated to the Variable # index-1 |
---|
1163 | else |
---|
1164 | list_var=get(handles.variables,'String'); |
---|
1165 | var_select=list_var{index}; |
---|
1166 | set(handles.attributes_txt,'String', ['attributes of ' var_select]) |
---|
1167 | if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1 |
---|
1168 | % nbline=0; |
---|
1169 | VarAttr=Field.VarAttribute{index-1}; |
---|
1170 | if isstruct(VarAttr) |
---|
1171 | attr_list=fieldnames(VarAttr); |
---|
1172 | for iline=1:length(attr_list) |
---|
1173 | Tabcell{iline,1}=attr_list{iline}; |
---|
1174 | eval(['val=VarAttr.' attr_list{iline} ';']) |
---|
1175 | if ischar(val); |
---|
1176 | Tabcell{iline,2}=val; |
---|
1177 | else |
---|
1178 | Tabcell{iline,2}=num2str(val); |
---|
1179 | end |
---|
1180 | end |
---|
1181 | end |
---|
1182 | end |
---|
1183 | |
---|
1184 | end |
---|
1185 | if ~isempty(Tabcell) |
---|
1186 | Tabchar=cell2tab(Tabcell,'='); |
---|
1187 | Tabchar=[{''};Tabchar]; |
---|
1188 | end |
---|
1189 | set(handles.attributes,'Value',1);% select the first item |
---|
1190 | set(handles.attributes,'String',Tabchar); |
---|
1191 | |
---|
1192 | %% update dimensions; |
---|
1193 | if isfield(Field,'ListDimName') |
---|
1194 | Tabdim={};%default |
---|
1195 | if isequal(index,1)%list all dimensions |
---|
1196 | dim_indices=1:length(Field.ListDimName); |
---|
1197 | set(handles.dimensions_txt,'String', 'dimensions') |
---|
1198 | else |
---|
1199 | DimCell=Field.VarDimName{index-1}; |
---|
1200 | if ischar(DimCell) |
---|
1201 | DimCell={DimCell}; |
---|
1202 | end |
---|
1203 | dim_indices=[]; |
---|
1204 | for idim=1:length(DimCell) |
---|
1205 | dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0 |
---|
1206 | dim_index=find(dim_index,1); |
---|
1207 | dim_indices=[dim_indices dim_index]; |
---|
1208 | end |
---|
1209 | set(handles.dimensions_txt,'String', ['dimensions of ' var_select]) |
---|
1210 | end |
---|
1211 | for iline=1:length(dim_indices) |
---|
1212 | Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)}; |
---|
1213 | Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline))); |
---|
1214 | end |
---|
1215 | Tabchar=cell2tab(Tabdim,' = '); |
---|
1216 | Tabchar=[{''} ;Tabchar]; |
---|
1217 | set(handles.dimensions,'Value',1) |
---|
1218 | set(handles.dimensions,'String',Tabchar) |
---|
1219 | end |
---|
1220 | |
---|
1221 | %------------------------------------------------------------------------ |
---|
1222 | % --- Executes on button press in CheckPlot1D. |
---|
1223 | function CheckPlot1D_Callback(hObject, eventdata, handles) |
---|
1224 | %------------------------------------------------------------------------ |
---|
1225 | val=get(handles.CheckPlot1D,'Value'); |
---|
1226 | if isequal(val,0) |
---|
1227 | set(handles.Panel1Dplot,'Visible','off') |
---|
1228 | else |
---|
1229 | set(handles.Panel1Dplot,'Visible','on') |
---|
1230 | set(handles.PanelScalar,'Visible','off') |
---|
1231 | set(handles.CheckScalar,'Value',0) |
---|
1232 | set(handles.PanelVectors,'Visible','off') |
---|
1233 | set(handles.CheckVector,'Value',0) |
---|
1234 | end |
---|
1235 | |
---|
1236 | %------------------------------------------------------------------------ |
---|
1237 | % --- Executes on button press in CheckScalar. |
---|
1238 | function CheckScalar_Callback(hObject, eventdata, handles) |
---|
1239 | %------------------------------------------------------------------------ |
---|
1240 | val=get(handles.CheckScalar,'Value'); |
---|
1241 | if isequal(val,0) |
---|
1242 | set(handles.PanelScalar,'Visible','off') |
---|
1243 | else |
---|
1244 | set(handles.Panel1Dplot,'Visible','off') |
---|
1245 | set(handles.CheckPlot1D,'Value',0) |
---|
1246 | set(handles.PanelScalar,'Visible','on') |
---|
1247 | set(handles.PanelVectors,'Visible','off') |
---|
1248 | set(handles.CheckVector,'Value',0) |
---|
1249 | end |
---|
1250 | |
---|
1251 | %------------------------------------------------------------------------ |
---|
1252 | % --- Executes on button press in CheckVector. |
---|
1253 | function CheckVector_Callback(hObject, eventdata, handles) |
---|
1254 | %------------------------------------------------------------------------ |
---|
1255 | val=get(handles.CheckVector,'Value'); |
---|
1256 | if isequal(val,0) |
---|
1257 | set(handles.PanelVectors,'Visible','off') |
---|
1258 | else |
---|
1259 | set(handles.Panel1Dplot,'Visible','off') |
---|
1260 | set(handles.CheckPlot1D,'Value',0) |
---|
1261 | set(handles.PanelScalar,'Visible','off') |
---|
1262 | set(handles.CheckScalar,'Value',0) |
---|
1263 | set(handles.PanelVectors,'Visible','on') |
---|
1264 | end |
---|
1265 | |
---|
1266 | % %------------------------------------------------------------------------ |
---|
1267 | % function mouse_up_gui(ggg,eventdata,handles) |
---|
1268 | % %------------------------------------------------------------------------ |
---|
1269 | % if isequal(get(ggg,'SelectionType'),'alt') |
---|
1270 | % message=''; |
---|
1271 | % global CurData |
---|
1272 | % inputfield=get(handles.inputfile,'String'); |
---|
1273 | % if exist(inputfield,'file') |
---|
1274 | % CurData=nc2struct(inputfield); |
---|
1275 | % else |
---|
1276 | % CurData=get(ggg,'UserData');% get_field opened from a input field, not a file |
---|
1277 | % end |
---|
1278 | % %%%% TODO: put the matalb command window in front |
---|
1279 | % evalin('base','global CurData')%make CurData global in the workspace |
---|
1280 | % evalin('base','CurData') %display CurData in the workspace |
---|
1281 | % end |
---|
1282 | |
---|
1283 | %------------------------------------------------------------------------ |
---|
1284 | % --- Executes on selection change in ACTION. |
---|
1285 | %------------------------------------------------------------------------ |
---|
1286 | function ACTION_Callback(hObject, eventdata, handles) |
---|
1287 | global nb_builtin |
---|
1288 | list_ACTION=get(handles.ACTION,'String');% list menu fields |
---|
1289 | index_ACTION=get(handles.ACTION,'Value');% selected string index |
---|
1290 | ACTION= list_ACTION{index_ACTION}; % selected string |
---|
1291 | list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path) |
---|
1292 | ff=functions(list_func_handles{end}); |
---|
1293 | % add a new function to the menu |
---|
1294 | if isequal(ACTION,'more...') |
---|
1295 | [FileName, PathName] = uigetfile( ... |
---|
1296 | {'*.m', ' (*.m)'; |
---|
1297 | '*.m', '.m files '; ... |
---|
1298 | '*.*', 'All Files (*.*)'}, ... |
---|
1299 | 'Pick a file',ff.file); |
---|
1300 | if length(FileName)<2 |
---|
1301 | return |
---|
1302 | end |
---|
1303 | [pp,ACTION,ext_fct]=fileparts(FileName); |
---|
1304 | if ~isequal(ext_fct,'.m') |
---|
1305 | msgbox_uvmat('ERROR','a Matlab function .m must be introduced'); |
---|
1306 | return |
---|
1307 | end |
---|
1308 | |
---|
1309 | % insert the choice in the action menu |
---|
1310 | menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed |
---|
1311 | index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list |
---|
1312 | addpath(PathName) |
---|
1313 | list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function |
---|
1314 | set(handles.ACTION,'UserData',list_func_handles) |
---|
1315 | set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off') |
---|
1316 | %list_path{index_ACTION}=PathName; |
---|
1317 | if length(menu_str)>nb_builtin+5; |
---|
1318 | nbremove=length(menu_str)-nb_builtin-5; |
---|
1319 | menu_str(nb_builtin+1:end-5)=[]; |
---|
1320 | list_func_handles(nb_builtin+1:end-4)=[]; |
---|
1321 | index_ACTION=index_ACTION-nbremove; |
---|
1322 | set(handles.ACTION,'Value',index_ACTION) |
---|
1323 | set(handles.ACTION,'String',menu_str) |
---|
1324 | end |
---|
1325 | %record the current menu in personal file profil_perso |
---|
1326 | dir_perso=prefdir; |
---|
1327 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
1328 | get_field_fct={}; |
---|
1329 | for ilist=nb_builtin+1:length(menu_str)-1 |
---|
1330 | ff=functions(list_func_handles{ilist}); |
---|
1331 | get_field_fct{ilist-nb_builtin}=ff.file; |
---|
1332 | end |
---|
1333 | if exist(profil_perso,'file') |
---|
1334 | save(profil_perso,'get_field_fct','-append') |
---|
1335 | else |
---|
1336 | txt=ver('MATLAB'); |
---|
1337 | Release=txt.Release; |
---|
1338 | relnumb=str2num(Release(3:4)); |
---|
1339 | if relnumb >= 14 |
---|
1340 | save(profil_perso,'get_field_fct','-V6') |
---|
1341 | else |
---|
1342 | save(profil_perso, 'get_field_fct') |
---|
1343 | end |
---|
1344 | end |
---|
1345 | end |
---|
1346 | |
---|
1347 | %check the current path to the selected function |
---|
1348 | h_fun=list_func_handles{index_ACTION}; |
---|
1349 | if isa(h_fun,'function_handle') |
---|
1350 | func=functions(h_fun); |
---|
1351 | set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function |
---|
1352 | GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field |
---|
1353 | else |
---|
1354 | set(handles.path_action,'String','') |
---|
1355 | msgbox_uvmat('ERROR','unknown path to ACTION function, reload it') |
---|
1356 | return |
---|
1357 | end |
---|
1358 | |
---|
1359 | %prepare the GUI options for the selected ACTION |
---|
1360 | test_1Dplot=0; |
---|
1361 | test_scalar=0; |
---|
1362 | test_vector=0; |
---|
1363 | if iscell(GUI_input) |
---|
1364 | for ilist=1:size(GUI_input,1) |
---|
1365 | switch GUI_input{ilist,1} |
---|
1366 | %RootFile always visible |
---|
1367 | case 'CheckPlot1D' |
---|
1368 | test_1Dplot=isequal(GUI_input{ilist,2},'on'); |
---|
1369 | case 'CheckScalar' |
---|
1370 | test_scalar=isequal(GUI_input{ilist,2},'on'); |
---|
1371 | case 'CheckVector' |
---|
1372 | test_vector=isequal(GUI_input{ilist,2},'on'); |
---|
1373 | end |
---|
1374 | end |
---|
1375 | end |
---|
1376 | set(handles.CheckPlot1D,'Value',test_1Dplot); |
---|
1377 | set(handles.CheckScalar,'Value',test_scalar); |
---|
1378 | set(handles.CheckVector,'Value',test_vector); |
---|
1379 | CheckPlot1D_Callback(hObject, eventdata, handles) |
---|
1380 | CheckScalar_Callback(hObject, eventdata, handles) |
---|
1381 | CheckVector_Callback(hObject, eventdata, handles) |
---|
1382 | |
---|
1383 | |
---|
1384 | %----------------------------------------------------- |
---|
1385 | % --- browse existing figures |
---|
1386 | %----------------------------------------------------- |
---|
1387 | function browse_fig(menu_handle) |
---|
1388 | hh=findobj(allchild(0),'Type','figure'); |
---|
1389 | ilist=0; |
---|
1390 | list={}; |
---|
1391 | for ifig=1:length(hh) %look for all existing figures |
---|
1392 | name=get(hh(ifig),'Name'); |
---|
1393 | if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI |
---|
1394 | hchild=get(hh(ifig),'children');% look for axes contained in each figure |
---|
1395 | nbaxe=0; |
---|
1396 | for ichild=1:length(hchild) |
---|
1397 | Type=get(hchild(ichild),'Type'); |
---|
1398 | Tag=get(hchild(ichild),'Tag'); |
---|
1399 | if isequal(Type,'axes') |
---|
1400 | if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting |
---|
1401 | nbaxe=nbaxe+1;%count the existing axis |
---|
1402 | end |
---|
1403 | end |
---|
1404 | end |
---|
1405 | if nbaxe==1 |
---|
1406 | ilist=ilist+1;%add a line in the list of axis |
---|
1407 | list{ilist,1}=num2str(hh(ifig)); |
---|
1408 | elseif nbaxe>1 |
---|
1409 | for iaxe=1:nbaxe |
---|
1410 | ilist=ilist+1;%add a line in the list of axis |
---|
1411 | list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)]; |
---|
1412 | end |
---|
1413 | end |
---|
1414 | end |
---|
1415 | end |
---|
1416 | list=['uvmat';list]; |
---|
1417 | set(menu_handle,'Value',1) |
---|
1418 | set(menu_handle,'String',list) |
---|
1419 | |
---|
1420 | |
---|
1421 | %----------------------------------------------------- |
---|
1422 | function list_fig_Callback(hObject, eventdata, handles) |
---|
1423 | %----------------------------------------------------- |
---|
1424 | list_fig=get(handles.list_fig,'String'); |
---|
1425 | fig_val=get(handles.list_fig,'Value'); |
---|
1426 | plot_fig=list_fig{fig_val}; |
---|
1427 | if strcmp(plot_fig,'view_field') |
---|
1428 | % huvmat=findobj(allchild(0),'name','uvmat'); |
---|
1429 | % if ~isempty(huvmat) |
---|
1430 | % uistack(huvmat,'top') |
---|
1431 | % end |
---|
1432 | else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat') |
---|
1433 | sep=regexp(plot_fig,'_'); |
---|
1434 | if ~isempty(sep) |
---|
1435 | plot_fig=plot_fig([1:sep-1]); |
---|
1436 | end |
---|
1437 | if ishandle(str2num(plot_fig)) |
---|
1438 | figure(str2num(plot_fig))% display existing figure |
---|
1439 | else |
---|
1440 | browse_fig(handles.list_fig); %reset the current list of figures |
---|
1441 | end |
---|
1442 | end |
---|
1443 | |
---|
1444 | |
---|
1445 | %------------------------------------------------- |
---|
1446 | % give index numbers of the strings str in the list ListvarName |
---|
1447 | function VarIndex_y=name2index(cell_str,ListVarName) |
---|
1448 | VarIndex_y=[]; |
---|
1449 | if ischar(cell_str) |
---|
1450 | for ivar=1:length(ListVarName) |
---|
1451 | varlist=ListVarName{ivar}; |
---|
1452 | if isequal(varlist,cell_str) |
---|
1453 | VarIndex_y= ivar; |
---|
1454 | break |
---|
1455 | end |
---|
1456 | end |
---|
1457 | elseif iscell(cell_str) |
---|
1458 | for isel=1:length(cell_str) |
---|
1459 | varsel=cell_str{isel}; |
---|
1460 | for ivar=1:length(ListVarName) |
---|
1461 | varlist=ListVarName{ivar}; |
---|
1462 | if isequal(varlist,varsel) |
---|
1463 | VarIndex_y=[VarIndex_y ivar]; |
---|
1464 | end |
---|
1465 | end |
---|
1466 | end |
---|
1467 | end |
---|
1468 | |
---|
1469 | % -------------------------------------------------------------------- |
---|
1470 | function MenuOpen_Callback(hObject, eventdata, handles) |
---|
1471 | % hObject handle to MenuOpen (see GCBO) |
---|
1472 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1473 | % handles structure with handles and user data (see GUIDATA) |
---|
1474 | |
---|
1475 | |
---|
1476 | % -------------------------------------------------------------------- |
---|
1477 | function MenuExport_Callback(hObject, eventdata, handles) |
---|
1478 | % hObject handle to MenuExport (see GCBO) |
---|
1479 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1480 | % handles structure with handles and user data (see GUIDATA) |
---|
1481 | |
---|
1482 | |
---|
1483 | % -------------------------------------------------------------------- |
---|
1484 | function MenuBrowse_Callback(hObject, eventdata, handles) |
---|
1485 | |
---|
1486 | oldfile=get(handles.inputfile,'String'); |
---|
1487 | testrootfile=0; |
---|
1488 | testsubdir=0; |
---|
1489 | if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box |
---|
1490 | oldfile=''; |
---|
1491 | dir_perso=prefdir; |
---|
1492 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
1493 | if exist(profil_perso,'file') |
---|
1494 | h=load (profil_perso); |
---|
1495 | if isfield(h,'RootPath') |
---|
1496 | RootPath=h.RootPath; |
---|
1497 | end |
---|
1498 | if isfield(h,'SubDir') |
---|
1499 | SubDir=h.SubDir; |
---|
1500 | if ~isempty(SubDir) |
---|
1501 | testsubdir=1; |
---|
1502 | end |
---|
1503 | end |
---|
1504 | if isfield(h,'RootFile') |
---|
1505 | RootFile=h.RootFile; |
---|
1506 | if ~isempty(RootFile) |
---|
1507 | testrootfile=1; |
---|
1508 | end |
---|
1509 | end |
---|
1510 | end |
---|
1511 | end |
---|
1512 | if testrootfile |
---|
1513 | if ~testsubdir |
---|
1514 | oldfile=fullfile(RootPath,RootFile); |
---|
1515 | else |
---|
1516 | oldfile=fullfile(RootPath,SubDir,RootFile); |
---|
1517 | end |
---|
1518 | end |
---|
1519 | [FileName, PathName] = uigetfile( ... |
---|
1520 | {'*.nc', ' *.nc';... |
---|
1521 | '*.cdf', ' *.cdf';... |
---|
1522 | '*.*', 'All Files (*.*)'}, ... |
---|
1523 | 'Pick a file',oldfile); |
---|
1524 | |
---|
1525 | %global inputfile |
---|
1526 | fileinput=[PathName FileName];%complete file name |
---|
1527 | sizf=size(fileinput); |
---|
1528 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
1529 | set(handles.inputfile,'String',fileinput) |
---|
1530 | inputfile_Callback(hObject, eventdata, handles) |
---|
1531 | |
---|
1532 | %update list of recent files in the menubar |
---|
1533 | MenuFile_1=fileinput; |
---|
1534 | MenuFile_2=get(handles.MenuFile_1,'Label'); |
---|
1535 | MenuFile_3=get(handles.MenuFile_2,'Label'); |
---|
1536 | MenuFile_4=get(handles.MenuFile_3,'Label'); |
---|
1537 | MenuFile_5=get(handles.MenuFile_4,'Label'); |
---|
1538 | set(handles.MenuFile_1,'Label',MenuFile_1) |
---|
1539 | set(handles.MenuFile_2,'Label',MenuFile_2) |
---|
1540 | set(handles.MenuFile_3,'Label',MenuFile_3) |
---|
1541 | set(handles.MenuFile_4,'Label',MenuFile_4) |
---|
1542 | set(handles.MenuFile_5,'Label',MenuFile_5) |
---|
1543 | dir_perso=prefdir; |
---|
1544 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
1545 | display(profil_perso) |
---|
1546 | if exist(profil_perso,'file') |
---|
1547 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat |
---|
1548 | else |
---|
1549 | txt=ver('MATLAB'); |
---|
1550 | Release=txt.Release; |
---|
1551 | relnumb=str2double(Release(3:4)); |
---|
1552 | if relnumb >= 14 |
---|
1553 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat |
---|
1554 | else |
---|
1555 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat |
---|
1556 | end |
---|
1557 | end |
---|
1558 | |
---|
1559 | % -------------------------------------------------------------------- |
---|
1560 | function MenuFile_1_Callback(hObject, eventdata, handles) |
---|
1561 | fileinput=get(handles.MenuFile_1,'Label'); |
---|
1562 | set(handles.inputfile,'String',fileinput) |
---|
1563 | inputfile_Callback(hObject, eventdata, handles) |
---|
1564 | |
---|
1565 | % -------------------------------------------------------------------- |
---|
1566 | function MenuFile_2_Callback(hObject, eventdata, handles) |
---|
1567 | fileinput=get(handles.MenuFile_2,'Label'); |
---|
1568 | set(handles.inputfile,'String',fileinput) |
---|
1569 | inputfile_Callback(hObject, eventdata, handles) |
---|
1570 | |
---|
1571 | % ----------------------------------------------------------------------- |
---|
1572 | function MenuFile_3_Callback(hObject, eventdata, handles) |
---|
1573 | % ----------------------------------------------------------------------- |
---|
1574 | fileinput=get(handles.MenuFile_3,'Label'); |
---|
1575 | set(handles.inputfile,'String',fileinput) |
---|
1576 | inputfile_Callback(hObject, eventdata, handles) |
---|
1577 | |
---|
1578 | % ----------------------------------------------------------------------- |
---|
1579 | function MenuFile_4_Callback(hObject, eventdata, handles) |
---|
1580 | % ----------------------------------------------------------------------- |
---|
1581 | fileinput=get(handles.MenuFile_4,'Label'); |
---|
1582 | set(handles.inputfile,'String',fileinput) |
---|
1583 | inputfile_Callback(hObject, eventdata, handles) |
---|
1584 | |
---|
1585 | % ----------------------------------------------------------------------- |
---|
1586 | function MenuFile_5_Callback(hObject, eventdata, handles) |
---|
1587 | % ----------------------------------------------------------------------- |
---|
1588 | fileinput=get(handles.MenuFile_5,'Label'); |
---|
1589 | set(handles.inputfile,'String',fileinput) |
---|
1590 | inputfile_Callback(hObject, eventdata, handles) |
---|
1591 | |
---|
1592 | %------------------------------------------------------------------------ |
---|
1593 | function MenuExportField_Callback(hObject, eventdata, handles) |
---|
1594 | %------------------------------------------------------------------------ |
---|
1595 | global Data_get_field |
---|
1596 | % huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
1597 | inputfile=get(handles.inputfile,'String'); |
---|
1598 | Data_get_field=nc2struct(inputfile); |
---|
1599 | % Data_view_field=UvData.ProjField_2; |
---|
1600 | evalin('base','global Data_get_field')%make CurData global in the workspace |
---|
1601 | display(['content of ' inputfile ':']) |
---|
1602 | evalin('base','Data_get_field') %display CurData in the workspace |
---|
1603 | commandwindow; |
---|
1604 | |
---|
1605 | %------------------------------------------------------------------------ |
---|
1606 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
1607 | %------------------------------------------------------------------------ |
---|
1608 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
1609 | pathelp=fileparts(path_to_uvmat); |
---|
1610 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
1611 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
1612 | else |
---|
1613 | web([helpfile '#get_field']) |
---|
1614 | end |
---|
1615 | |
---|
1616 | % ----------------------------------------------------------------------- |
---|
1617 | function TimeName_Callback(hObject, eventdata, handles) |
---|
1618 | |
---|
1619 | scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates |
---|
1620 | vector_x_Callback(hObject, eventdata, handles) |
---|
1621 | |
---|
1622 | %------------------------------------------------------------------------ |
---|
1623 | % --- Executes on button press in TimeAttribute. |
---|
1624 | function TimeAttribute_Callback(hObject, eventdata, handles) |
---|
1625 | %------------------------------------------------------------------------ |
---|
1626 | val=get(handles.TimeAttribute,'Value'); |
---|
1627 | if val |
---|
1628 | set(handles.TimeAttributeMenu,'Visible','on') |
---|
1629 | Field=get(handles.get_field,'UserData'); |
---|
1630 | time_value=zeros(size(Field.ListGlobalAttribute)); |
---|
1631 | test_time=zeros(size(Field.ListGlobalAttribute)); |
---|
1632 | for ilist=1:numel(Field.ListGlobalAttribute) |
---|
1633 | if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}])) |
---|
1634 | eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';']) |
---|
1635 | if ~isempty(time_val) |
---|
1636 | time_value(ilist)=time_val; |
---|
1637 | test_time(ilist)=1; |
---|
1638 | end |
---|
1639 | end |
---|
1640 | end |
---|
1641 | ListTimeAttribute=Field.ListGlobalAttribute(test_time==1); |
---|
1642 | attr_index=get(handles.TimeAttributeMenu,'Value'); |
---|
1643 | if attr_index>numel(ListTimeAttribute) |
---|
1644 | attr_index=1; |
---|
1645 | set(handles.TimeAttributeMenu,'Value',1); |
---|
1646 | end |
---|
1647 | if isempty(ListTimeAttribute) |
---|
1648 | set(handles.TimeAttributeMenu,'String',{''}) |
---|
1649 | set(handles.TimeValue,'Visible','off') |
---|
1650 | else |
---|
1651 | set(handles.TimeValue,'Visible','on') |
---|
1652 | set(handles.TimeAttributeMenu,'String',ListTimeAttribute) |
---|
1653 | set(handles.TimeValue,'String',num2str(time_value(attr_index))) |
---|
1654 | end |
---|
1655 | set(handles.TimeDimension,'Value',0) |
---|
1656 | TimeDimension_Callback(hObject, eventdata, handles) |
---|
1657 | set(handles.TimeVariable,'Value',0) |
---|
1658 | TimeVariable_Callback(hObject, eventdata, handles) |
---|
1659 | else |
---|
1660 | set(handles.TimeAttributeMenu,'Visible','off') |
---|
1661 | set(handles.TimeValue,'Visible','off') |
---|
1662 | end |
---|
1663 | |
---|
1664 | %------------------------------------------------------------------------ |
---|
1665 | % --- Executes on selection change in TimeAttributeMenu. |
---|
1666 | function TimeAttributeMenu_Callback(hObject, eventdata, handles) |
---|
1667 | ListTimeAttribute=get(handles.TimeAttributeMenu,'String'); |
---|
1668 | index=get(handles.TimeAttributeMenu,'Value'); |
---|
1669 | AttrName=ListTimeAttribute{index}; |
---|
1670 | Field=get(handles.get_field,'UserData'); |
---|
1671 | eval(['time_val=Field.' AttrName ';']) |
---|
1672 | set(handles.TimeValue,'String',num2str(time_val)) |
---|
1673 | %------------------------------------------------------------------------ |
---|
1674 | |
---|
1675 | %------------------------------------------------------------------------ |
---|
1676 | % --- Executes on button press in TimeVariable. |
---|
1677 | function TimeDimension_Callback(hObject, eventdata, handles) |
---|
1678 | %------------------------------------------------------------------------ |
---|
1679 | val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected |
---|
1680 | if val %if check box TimeDimension is selected |
---|
1681 | Field=get(handles.get_field,'UserData');% structure describing the currently opened field |
---|
1682 | previous_menu=get(handles.TimeDimensionMenu,'String'); |
---|
1683 | if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu |
---|
1684 | ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time' |
---|
1685 | if isempty(ind_select) |
---|
1686 | ind_select=1;% select the first item in the list if 'time' is not found |
---|
1687 | end |
---|
1688 | set(handles.TimeDimensionMenu,'Value',ind_select); |
---|
1689 | set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu |
---|
1690 | end |
---|
1691 | set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible |
---|
1692 | set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible |
---|
1693 | TimeDimensionMenu_Callback(hObject, eventdata, handles) |
---|
1694 | set(handles.TimeAttribute,'Value',0) %deselect alternative options for time |
---|
1695 | set(handles.TimeVariable,'Value',0) |
---|
1696 | TimeAttribute_Callback(hObject, eventdata, handles) |
---|
1697 | else |
---|
1698 | set(handles.TimeDimensionMenu,'Visible','off') |
---|
1699 | set(handles.TimeIndexValue,'Visible','off') |
---|
1700 | end |
---|
1701 | |
---|
1702 | %------------------------------------------------------------------------ |
---|
1703 | % --- Executes on selection change in TimeDimensionMenu. |
---|
1704 | function TimeDimensionMenu_Callback(hObject, eventdata, handles) |
---|
1705 | %------------------------------------------------------------------------ |
---|
1706 | index=get(handles.TimeDimensionMenu,'Value'); |
---|
1707 | DimList=get(handles.TimeDimensionMenu,'String'); |
---|
1708 | DimName=DimList{index}; |
---|
1709 | Field=get(handles.get_field,'UserData'); |
---|
1710 | DimIndex=find(strcmp(DimName,Field.ListDimName),1); |
---|
1711 | ref_index=round(Field.DimValue(DimIndex)/2); |
---|
1712 | set(handles.TimeIndexValue,'String',num2str(ref_index)) |
---|
1713 | scalar_Callback(hObject, eventdata, handles) |
---|
1714 | vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time) |
---|
1715 | % look for a corresponding time variable and value |
---|
1716 | time_test=zeros(size(Field.VarDimName)); |
---|
1717 | for ilist=1:numel(Field.VarDimName) |
---|
1718 | if isequal(Field.VarDimName{ilist},{DimName}) |
---|
1719 | time_test(ilist)=1; |
---|
1720 | end |
---|
1721 | end |
---|
1722 | ListVariable=Field.ListVarName(time_test==1); |
---|
1723 | set(handles.TimeVariableMenu,'Value',1) |
---|
1724 | if isempty(ListVariable) |
---|
1725 | set(handles.TimeVariableMenu,'String',{''}) |
---|
1726 | set(handles.TimeVarValue,'String','') |
---|
1727 | else |
---|
1728 | set(handles.TimeVariableMenu,'String',ListVariable) |
---|
1729 | TimeVarName=ListVariable{1}; |
---|
1730 | VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables |
---|
1731 | inputfile=get(handles.inputfile,'String');% read the input file |
---|
1732 | SubField=nc2struct(inputfile,{TimeVarName}); |
---|
1733 | eval(['TimeValue=SubField.' TimeVarName '(ref_index);']) |
---|
1734 | set(handles.TimeVarValue,'Visible','on') |
---|
1735 | set(handles.TimeVariableMenu,'Visible','on') |
---|
1736 | set(handles.TimeVarValue,'String',num2str(TimeValue)) |
---|
1737 | end |
---|
1738 | |
---|
1739 | |
---|
1740 | % % ----------------------------------------------------------------------- |
---|
1741 | % % --- Executes on button press in TimeVariable. |
---|
1742 | % function TimeVariable_Callback(hObject, eventdata, handles) |
---|
1743 | % % ----------------------------------------------------------------------- |
---|
1744 | % val=get(handles.TimeVariable,'Value'); |
---|
1745 | % if val |
---|
1746 | % Field=get(handles.get_field,'UserData'); |
---|
1747 | % time_test=zeros(size(Field.VarDimName)); |
---|
1748 | % for ilist=1:numel(Field.VarDimName) |
---|
1749 | % if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension |
---|
1750 | % time_test(ilist)=1; |
---|
1751 | % end |
---|
1752 | % end |
---|
1753 | % ind_test=find(time_test); |
---|
1754 | % if isempty(time_test) |
---|
1755 | % set(handles.TimeVariable,'Value',0) |
---|
1756 | % set(handles.TimeVariableMenu,'Visible','off') |
---|
1757 | % set(handles.TimeVarValue,'Visible','off') |
---|
1758 | % else |
---|
1759 | % set(handles.TimeVariableMenu,'Visible','on') |
---|
1760 | % set(handles.TimeVarValue,'Visible','on') |
---|
1761 | % if get(handles.TimeVariableMenu,'Value')>numel(ind_test) |
---|
1762 | % set(handles.TimeVariableMenu,'Value',1) |
---|
1763 | % end |
---|
1764 | % set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test)) |
---|
1765 | % TimeVariableMenu_Callback(hObject, eventdata, handles) |
---|
1766 | % set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time |
---|
1767 | % set(handles.TimeAttribute,'Value',0) |
---|
1768 | % TimeAttribute_Callback(hObject, eventdata, handles) |
---|
1769 | % end |
---|
1770 | % else |
---|
1771 | % set(handles.TimeVariableMenu,'Visible','off') |
---|
1772 | % set(handles.TimeVarValue,'Visible','off') |
---|
1773 | % end |
---|
1774 | |
---|
1775 | % ----------------------------------------------------------------------- |
---|
1776 | % --- Executes on selection change in TimeVariableMenu. |
---|
1777 | function TimeVariableMenu_Callback(hObject, eventdata, handles) |
---|
1778 | % ----------------------------------------------------------------------- |
---|
1779 | ListVar=get(handles.TimeVariableMenu,'String'); |
---|
1780 | index=get(handles.TimeVariableMenu,'Value'); |
---|
1781 | TimeVariable=ListVar{index};% name of the selected variable |
---|
1782 | if isempty(TimeVariable)% case of blank selection |
---|
1783 | return |
---|
1784 | end |
---|
1785 | Field=get(handles.get_field,'UserData'); %index of |
---|
1786 | VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables |
---|
1787 | DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable |
---|
1788 | set(handles.TimeDimensionMenu,'Value',1) |
---|
1789 | set(handles.TimeDimensionMenu,'String',DimName) |
---|
1790 | inputfile=get(handles.inputfile,'String');% read the input file |
---|
1791 | SubField=nc2struct(inputfile,{TimeVariable}); |
---|
1792 | eval(['TimeDimension=numel(SubField.' TimeVariable ');']) |
---|
1793 | ref_index=round(TimeDimension/2); |
---|
1794 | eval(['TimeValue=SubField.' TimeVariable '(ref_index);']) |
---|
1795 | set(handles.TimeIndexValue,'String',num2str(ref_index)) |
---|
1796 | set(handles.TimeVarValue,'String',num2str(TimeValue)) |
---|
1797 | |
---|
1798 | |
---|
1799 | function TimeValue_Callback(hObject, eventdata, handles) |
---|
1800 | %TO suppress |
---|
1801 | |
---|
1802 | % ----------------------------------------------------------------------- |
---|
1803 | function TimeIndexValue_Callback(hObject, eventdata, handles) |
---|
1804 | % ----------------------------------------------------------------------- |
---|
1805 | TimeIndex=str2double(get(handles.TimeIndexValue,'String')); |
---|
1806 | TimeVarName=Field.ListVarName{time_index}; |
---|
1807 | set(handles.TimeVariable,'Value',1) |
---|
1808 | set(handles.TimeName,'String',TimeVarName) |
---|
1809 | fileinput=get(handles.inputfile,'String'); |
---|
1810 | SubField=nc2struct(fileinput,{TimeVarName}); |
---|
1811 | eval(['TimeValue=SubField.' TimeVarName '(ref_index);']); |
---|
1812 | set(handles.TimeValue,'Visible','on') |
---|
1813 | set(handles.TimeValue,'String',num2str(TimeValue)) |
---|
1814 | |
---|
1815 | % ----------------------------------------------------------------------- |
---|
1816 | function SelectFigure_Callback(hObject, eventdata, handles) |
---|
1817 | % ----------------------------------------------------------------------- |
---|
1818 | val=get(handles.SelectFigure,'Value'); |
---|
1819 | if val |
---|
1820 | set(handles.list_fig,'Visible','on') |
---|
1821 | %% look at the existing figures in the work space |
---|
1822 | browse_fig(handles.list_fig) |
---|
1823 | else |
---|
1824 | set(handles.list_fig,'Visible','off') |
---|
1825 | end |
---|
1826 | |
---|
1827 | |
---|
1828 | function TimeVarValue_Callback(hObject, eventdata, handles) |
---|
1829 | |
---|
1830 | |
---|
1831 | |
---|
1832 | % --- Executes on button press in check_rgb. |
---|
1833 | function check_rgb_Callback(hObject, eventdata, handles) |
---|