1 | %'get_field': display variables and attributes from a Netcdf file, and OK 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 05-May-2013 23:54:32 |
---|
25 | |
---|
26 | % Begin initialization code - DO NOT EDIT |
---|
27 | gui_Singleton = 1; |
---|
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,ParamIn) |
---|
48 | %------------------------------------------------------------------------ |
---|
49 | global nb_builtin % nbre of functions to include by default in the menu of functions called by RUN |
---|
50 | |
---|
51 | %% Choose default command line output for get_field |
---|
52 | handles.output = 'Cancel'; |
---|
53 | |
---|
54 | %% Update handles structure |
---|
55 | guidata(hObject, handles); |
---|
56 | set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display) |
---|
57 | |
---|
58 | %% settings for 'slave' mode, called by uvmat, or 'master' mode |
---|
59 | if exist('filename','var') && ischar(filename) %transfer input file name in slave mode |
---|
60 | set(handles.inputfile,'String',filename)% prefill the input file name |
---|
61 | Field=nc2struct(filename,[]);% reads the field structure, without the variables |
---|
62 | if isfield(Field,'Txt') |
---|
63 | msgbox_uvmat('ERROR',['get_field/nc2struct/' Field.Txt]) |
---|
64 | else |
---|
65 | if ~exist('ParamIn','var') |
---|
66 | ParamIn=[]; |
---|
67 | end |
---|
68 | Field_input(handles,Field,ParamIn); |
---|
69 | end |
---|
70 | else %master mode |
---|
71 | set(handles.inputfile,'String','') |
---|
72 | end |
---|
73 | |
---|
74 | %% put the GUI on the lower right of the sceen |
---|
75 | set(hObject,'Unit','pixel') |
---|
76 | pos_view_field=get(hObject,'Position'); |
---|
77 | ScreenSize=get(0,'ScreenSize'); |
---|
78 | pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3); |
---|
79 | pos_view_field(2)=ScreenSize(2); |
---|
80 | set(hObject,'Position',pos_view_field) |
---|
81 | set(handles.get_field,'WindowStyle','modal')% Make the GUI modal |
---|
82 | drawnow |
---|
83 | uiwait(handles.get_field); |
---|
84 | |
---|
85 | %------------------------------------------------------------------------ |
---|
86 | % --- update the display when a new field is introduced. |
---|
87 | function Field_input(handles,Field,ParamIn) |
---|
88 | %------------------------------------------------------------------------ |
---|
89 | |
---|
90 | %% fill the list and values of dimensions |
---|
91 | if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName) |
---|
92 | Tabcell(:,1)=Field.ListDimName; |
---|
93 | for iline=1:length(Field.ListDimName) |
---|
94 | Tabcell{iline,2}=num2str(Field.DimValue(iline)); |
---|
95 | end |
---|
96 | Tabchar=cell2tab(Tabcell,' = '); |
---|
97 | set(handles.dimensions,'String',Tabchar) |
---|
98 | end |
---|
99 | if ~isfield(Field,'ListVarName') |
---|
100 | return |
---|
101 | end |
---|
102 | |
---|
103 | %% fill the list of variables |
---|
104 | Txt=Field.ListVarName; |
---|
105 | set(handles.variables,'Value',1) |
---|
106 | set(handles.variables,'String',[{'*'} Txt]) |
---|
107 | variables_Callback(handles.variables,[], handles) |
---|
108 | |
---|
109 | % set(handles.abscissa,'String',[{''} Txt ]) |
---|
110 | set(handles.ordinate,'String',Txt) |
---|
111 | set(handles.vector_x,'String',[Txt ]) |
---|
112 | set(handles.vector_y,'String',[Txt ]) |
---|
113 | set(handles.vector_z,'String',[{''} Txt ]) |
---|
114 | set(handles.vec_color,'String',[{''} Txt ]) |
---|
115 | set(handles.XVarName,'String',[{''} Txt ]) |
---|
116 | set(handles.YVarName,'String',[{''} Txt ]) |
---|
117 | set(handles.ZVarName,'String',[{''} Txt ]) |
---|
118 | % set(handles.coord_x_vectors,'String',[{''} Txt ]) |
---|
119 | % set(handles.coord_y_vectors,'String',[{''} Txt ]) |
---|
120 | % set(handles.YVarName,'String',[{''} Txt ]) |
---|
121 | % set(handles.TimeVarName,'String',[{''} Txt ]) |
---|
122 | set(handles.scalar,'Value',1) |
---|
123 | set(handles.scalar,'String', Txt ) |
---|
124 | |
---|
125 | %% ananlyse the input field cells |
---|
126 | [CellInfo,NbDim,errormsg]=find_field_cells(Field); |
---|
127 | if ~isempty(errormsg) |
---|
128 | msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg]) |
---|
129 | return |
---|
130 | end |
---|
131 | [Field.MaxDim,imax]=max(NbDim); |
---|
132 | % look at variables with a single dimension |
---|
133 | for ilist=1:numel(Field.VarDimName) |
---|
134 | if ischar(Field.VarDimName{ilist}) |
---|
135 | Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell |
---|
136 | end |
---|
137 | NbDim=numel(Field.VarDimName{ilist});% TODO eliminate singleton dimensions |
---|
138 | check_singleton=false(1,NbDim); |
---|
139 | for idim=1:NbDim |
---|
140 | dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName); |
---|
141 | check_singleton(idim)=isequal(Field.DimValue(dim_index),1); |
---|
142 | end |
---|
143 | Field.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton); |
---|
144 | Field.NbDim(ilist)=numel(Field.VarDimName{ilist}); |
---|
145 | if Field.NbDim(ilist)==1 |
---|
146 | Field.VarDimName{ilist}=cell2mat(Field.VarDimName{ilist}); |
---|
147 | end |
---|
148 | end |
---|
149 | SingleVarName=Field.ListVarName(Field.NbDim==1);%list of variables with a single dim |
---|
150 | MultiVarName=Field.ListVarName(Field.NbDim>1); |
---|
151 | check_dim=zeros(size(Field.VarDimName)); |
---|
152 | for ilist=1:numel(Field.VarDimName); |
---|
153 | if iscell(Field.VarDimName{ilist})% exclude single dim |
---|
154 | for idim=1:numel(Field.VarDimName{ilist}) |
---|
155 | check_dim=check_dim|strcmp(Field.VarDimName{ilist}{idim},Field.VarDimName); |
---|
156 | end |
---|
157 | end |
---|
158 | end |
---|
159 | Field.SingleVarName=Field.ListVarName(find(check_dim));%list of variables with a single dim |
---|
160 | Field.SingleDimName=Field.VarDimName(find(check_dim));% corresponding list of dimensions for variables with a single dim |
---|
161 | Field.MaxDim=max(Field.NbDim); |
---|
162 | |
---|
163 | %% set time mode |
---|
164 | ListSwitchVarIndexTime={'file index'}; |
---|
165 | % look at global attributes with numerical values |
---|
166 | check_numvalue=false; |
---|
167 | check_time=false; |
---|
168 | for ilist=1:numel(Field.ListGlobalAttribute) |
---|
169 | Value=Field.(Field.ListGlobalAttribute{ilist}); |
---|
170 | check_numvalue(ilist)=isnumeric(Value); |
---|
171 | check_time(ilist)=~isempty(find(regexp(Field.ListGlobalAttribute{ilist},'Time'),1)); |
---|
172 | end |
---|
173 | Field.ListNumAttributes=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value |
---|
174 | if ~isempty(Field.ListNumAttributes) |
---|
175 | ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}]; |
---|
176 | end |
---|
177 | nboption=numel(ListSwitchVarIndexTime); |
---|
178 | if Field.MaxDim>=2 |
---|
179 | ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'dim index'}]; |
---|
180 | end |
---|
181 | if Field.MaxDim>=4 |
---|
182 | option=nboption+1; |
---|
183 | elseif ~isempty(find(check_time, 1)) |
---|
184 | option=2; |
---|
185 | else |
---|
186 | option=1; |
---|
187 | end |
---|
188 | set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime) |
---|
189 | set(handles.SwitchVarIndexTime,'Value',option) |
---|
190 | set(handles.get_field,'UserData',Field);% record the finput field structure |
---|
191 | SwitchVarIndexTime_Callback([],[], handles) |
---|
192 | |
---|
193 | %% set z coordinate menu if relevant |
---|
194 | if Field.MaxDim>=3 |
---|
195 | set(handles.vector_z,'Visible','on') |
---|
196 | set(handles.vector_z,'String',[{''} Txt ]) |
---|
197 | set(handles.ZVarName,'Visible','on') |
---|
198 | set(handles.SwitchVarIndexZ,'Visible','on') |
---|
199 | set(handles.Z_title,'Visible','on') |
---|
200 | else |
---|
201 | set(handles.vector_z,'Visible','off') |
---|
202 | set(handles.ZVarName,'Visible','off') |
---|
203 | set(handles.SwitchVarIndexZ,'Visible','off') |
---|
204 | set(handles.Z_title,'Visible','off') |
---|
205 | end |
---|
206 | |
---|
207 | %% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields |
---|
208 | if Field.MaxDim>=2 % case of 2D (or 3D) fields |
---|
209 | set(handles.CheckPlot1D,'Value',0) |
---|
210 | if isfield(CellInfo{imax},'VarIndex_vector_x') && isfield(CellInfo{imax},'VarIndex_vector_y') |
---|
211 | set(handles.CheckVector,'Value',1) |
---|
212 | set(handles.CheckScalar,'Value',0) |
---|
213 | set(handles.vector_x,'Value',CellInfo{imax}.VarIndex_vector_x(1)) |
---|
214 | set(handles.vector_y,'Value',CellInfo{imax}.VarIndex_vector_y(1)) |
---|
215 | else |
---|
216 | set(handles.CheckScalar,'Value',1) |
---|
217 | set(handles.CheckVector,'Value',0) |
---|
218 | end |
---|
219 | else % case of 1D fields |
---|
220 | set(handles.CheckPlot1D,'Value',1) |
---|
221 | set(handles.CheckScalar,'Value',0) |
---|
222 | set(handles.CheckVector,'Value',0) |
---|
223 | end |
---|
224 | |
---|
225 | %% Make choices in menus from input |
---|
226 | if exist('ParamIn','var')&&~isempty(ParamIn) |
---|
227 | fill_GUI(ParamIn,handles.get_field); |
---|
228 | end |
---|
229 | CheckPlot1D_Callback(handles.CheckPlot1D, [], handles) |
---|
230 | CheckScalar_Callback(handles.CheckScalar, [], handles) |
---|
231 | CheckVector_Callback(handles.CheckVector, [], handles) |
---|
232 | |
---|
233 | %------------------------------------------------------------------------ |
---|
234 | % --- Outputs from this function are returned to the command line. |
---|
235 | function varargout = get_field_OutputFcn(hObject, eventdata, handles) |
---|
236 | %------------------------------------------------------------------------ |
---|
237 | varargout{1} = handles.output; |
---|
238 | delete(handles.get_field) |
---|
239 | |
---|
240 | |
---|
241 | % ----------------------------------------------------------------------- |
---|
242 | % --- Activated by selection in the list of variables |
---|
243 | function variables_Callback(hObject, eventdata, handles) |
---|
244 | % ----------------------------------------------------------------------- |
---|
245 | Tabchar={''};%default |
---|
246 | Tabcell=[]; |
---|
247 | hselect_field=get(handles.variables,'parent'); |
---|
248 | Field=get(handles.get_field,'UserData'); |
---|
249 | index=get(handles.variables,'Value');%index in the list 'variables' |
---|
250 | |
---|
251 | %% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected |
---|
252 | if isequal(index,1) |
---|
253 | set(handles.attributes_txt,'String','global attributes') |
---|
254 | if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute) |
---|
255 | for iline=1:length(Field.ListGlobalAttribute) |
---|
256 | Tabcell{iline,1}=Field.ListGlobalAttribute{iline}; |
---|
257 | if isfield(Field, Field.ListGlobalAttribute{iline}) |
---|
258 | eval(['val=Field.' Field.ListGlobalAttribute{iline} ';']) |
---|
259 | if ischar(val);% attribute value is char string |
---|
260 | Tabcell{iline,2}=val; |
---|
261 | elseif size(val,1)==1 %attribute value is a number or matlab vector |
---|
262 | Tabcell{iline,2}=num2str(val); |
---|
263 | end |
---|
264 | end |
---|
265 | end |
---|
266 | Tabchar=cell2tab(Tabcell,'='); |
---|
267 | end |
---|
268 | %% list Attribute names and values associated to the Variable # index-1 |
---|
269 | else |
---|
270 | list_var=get(handles.variables,'String'); |
---|
271 | var_select=list_var{index}; |
---|
272 | set(handles.attributes_txt,'String', ['attributes of ' var_select]) |
---|
273 | if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1 |
---|
274 | % nbline=0; |
---|
275 | VarAttr=Field.VarAttribute{index-1}; |
---|
276 | if isstruct(VarAttr) |
---|
277 | attr_list=fieldnames(VarAttr); |
---|
278 | for iline=1:length(attr_list) |
---|
279 | Tabcell{iline,1}=attr_list{iline}; |
---|
280 | eval(['val=VarAttr.' attr_list{iline} ';']) |
---|
281 | if ischar(val); |
---|
282 | Tabcell{iline,2}=val; |
---|
283 | else |
---|
284 | Tabcell{iline,2}=num2str(val); |
---|
285 | end |
---|
286 | end |
---|
287 | end |
---|
288 | end |
---|
289 | |
---|
290 | end |
---|
291 | if ~isempty(Tabcell) |
---|
292 | Tabchar=cell2tab(Tabcell,'='); |
---|
293 | Tabchar=[{''};Tabchar]; |
---|
294 | end |
---|
295 | set(handles.attributes,'Value',1);% select the first item |
---|
296 | set(handles.attributes,'String',Tabchar); |
---|
297 | |
---|
298 | %% update dimensions; |
---|
299 | if isfield(Field,'ListDimName') |
---|
300 | Tabdim={};%default |
---|
301 | if isequal(index,1)%list all dimensions |
---|
302 | dim_indices=1:length(Field.ListDimName); |
---|
303 | set(handles.dimensions_txt,'String', 'dimensions') |
---|
304 | else |
---|
305 | DimCell=Field.VarDimName{index-1}; |
---|
306 | if ischar(DimCell) |
---|
307 | DimCell={DimCell}; |
---|
308 | end |
---|
309 | dim_indices=[]; |
---|
310 | for idim=1:length(DimCell) |
---|
311 | dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0 |
---|
312 | dim_index=find(dim_index,1); |
---|
313 | dim_indices=[dim_indices dim_index]; |
---|
314 | end |
---|
315 | set(handles.dimensions_txt,'String', ['dimensions of ' var_select]) |
---|
316 | end |
---|
317 | for iline=1:length(dim_indices) |
---|
318 | Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)}; |
---|
319 | Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline))); |
---|
320 | end |
---|
321 | Tabchar=cell2tab(Tabdim,' = '); |
---|
322 | Tabchar=[{''} ;Tabchar]; |
---|
323 | set(handles.dimensions,'Value',1) |
---|
324 | set(handles.dimensions,'String',Tabchar) |
---|
325 | end |
---|
326 | |
---|
327 | |
---|
328 | |
---|
329 | %------------------------------------------------------------------------ |
---|
330 | % --- Executes on button press in CheckPlot1D. |
---|
331 | function CheckPlot1D_Callback(hObject, eventdata, handles) |
---|
332 | %------------------------------------------------------------------------ |
---|
333 | val=get(handles.CheckPlot1D,'Value'); |
---|
334 | if isequal(val,0) |
---|
335 | set(handles.Panel1Dplot,'Visible','off') |
---|
336 | else |
---|
337 | set(handles.Panel1Dplot,'Visible','on') |
---|
338 | set(handles.PanelScalar,'Visible','off') |
---|
339 | set(handles.CheckScalar,'Value',0) |
---|
340 | set(handles.PanelVectors,'Visible','off') |
---|
341 | set(handles.CheckVector,'Value',0) |
---|
342 | set(handles.XVarName,'Visible','on') |
---|
343 | set(handles.SwitchVarIndexX,'Visible','on') |
---|
344 | set(handles.X_title,'Visible','on') |
---|
345 | set(handles.YVarName,'Visible','off') |
---|
346 | set(handles.SwitchVarIndexY,'Visible','off') |
---|
347 | set(handles.Y_title,'Visible','off') |
---|
348 | set(handles.ZVarName,'Visible','off') |
---|
349 | set(handles.SwitchVarIndexZ,'Visible','off') |
---|
350 | set(handles.Z_title,'Visible','off') |
---|
351 | ordinate_Callback(hObject, eventdata, handles) |
---|
352 | end |
---|
353 | |
---|
354 | %------------------------------------------------------------------------ |
---|
355 | function ordinate_Callback(hObject, eventdata, handles) |
---|
356 | %------------------------------------------------------------------------ |
---|
357 | Field=get(handles.get_field,'UserData'); |
---|
358 | list=get(handles.ordinate,'String'); |
---|
359 | yindex=get(handles.ordinate,'Value'); |
---|
360 | yindex=name2index(list{yindex(1)},Field.ListVarName); |
---|
361 | if ~isempty(yindex) |
---|
362 | set(handles.variables,'Value',yindex+1) |
---|
363 | variables_Callback(hObject, eventdata, handles) |
---|
364 | end |
---|
365 | [CellInfo,NbDim,errormsg]=find_field_cells(Field); |
---|
366 | %[CellVarIndex,NbDim,VarRole,errormsg]=find_field_cells(Field); |
---|
367 | for icell=1:numel(CellInfo) |
---|
368 | VarIndex=CellInfo{icell}.VarIndex; |
---|
369 | if ~isempty(find(VarIndex==yindex,1)) && (isempty(CellInfo{icell}.VarIndex_coord_x)||~isequal(CellInfo{icell}.VarIndex_coord_x,VarIndex)) |
---|
370 | cell_select=icell; |
---|
371 | break |
---|
372 | end |
---|
373 | end |
---|
374 | val=get(handles.abscissa,'Value'); |
---|
375 | set(handles.abscissa,'Value',min(val,2)); |
---|
376 | coord_x_index=CellInfo{cell_select}.VarIndex_coord_x; |
---|
377 | coord_x_index=coord_x_index(coord_x_index~=0); |
---|
378 | set(handles.XVarName,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))']) |
---|
379 | |
---|
380 | %------------------------------------------------------------------------ |
---|
381 | % --- Executes on button press in CheckScalar. |
---|
382 | function CheckScalar_Callback(hObject, eventdata, handles) |
---|
383 | %------------------------------------------------------------------------ |
---|
384 | val=get(handles.CheckScalar,'Value'); |
---|
385 | if isequal(val,0) |
---|
386 | set(handles.PanelScalar,'Visible','off') |
---|
387 | else |
---|
388 | set(handles.Panel1Dplot,'Visible','off') |
---|
389 | set(handles.CheckPlot1D,'Value',0) |
---|
390 | set(handles.PanelScalar,'Visible','on') |
---|
391 | set(handles.PanelVectors,'Visible','off') |
---|
392 | set(handles.CheckVector,'Value',0) |
---|
393 | end |
---|
394 | |
---|
395 | %------------------------------------------------------------------------ |
---|
396 | % --- Executes on button press in CheckVector. |
---|
397 | function CheckVector_Callback(hObject, eventdata, handles) |
---|
398 | %------------------------------------------------------------------------ |
---|
399 | val=get(handles.CheckVector,'Value'); |
---|
400 | if isequal(val,0) |
---|
401 | set(handles.PanelVectors,'Visible','off') |
---|
402 | else |
---|
403 | set(handles.Panel1Dplot,'Visible','off') |
---|
404 | set(handles.CheckPlot1D,'Value',0) |
---|
405 | set(handles.PanelScalar,'Visible','off') |
---|
406 | set(handles.CheckScalar,'Value',0) |
---|
407 | set(handles.PanelVectors,'Visible','on') |
---|
408 | set(handles.XVarName,'Visible','on') |
---|
409 | set(handles.YVarName,'Visible','on') |
---|
410 | set(handles.X_title,'Visible','on') |
---|
411 | set(handles.Y_title,'Visible','on') |
---|
412 | end |
---|
413 | |
---|
414 | |
---|
415 | %------------------------------------------------------------------------ |
---|
416 | % --- Executes on selection change in scalar menu. |
---|
417 | function scalar_Callback(hObject, eventdata, handles) |
---|
418 | %------------------------------------------------------------------------ |
---|
419 | Field=get(handles.get_field,'UserData'); |
---|
420 | index=get(handles.scalar,'Value'); |
---|
421 | string=get(handles.scalar,'String'); |
---|
422 | VarName=string{index}; |
---|
423 | update_field(hObject, eventdata, handles,VarName) |
---|
424 | |
---|
425 | %eliminate time |
---|
426 | TimeDimName='';%default |
---|
427 | SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String'); |
---|
428 | TimeVarOption=SwitchVarIndexTime{get(handles.SwitchVarIndexTime,'Value')}; |
---|
429 | if strcmp(TimeVarOption,'variable') |
---|
430 | List=get(handles.TimeVarName,'String'); |
---|
431 | TimeVarName=List{get(handles.TimeVarName,'Value')}; |
---|
432 | elseif strcmp(TimeVarOption,'dim index') |
---|
433 | List=get(handles.TimeVarName,'String'); |
---|
434 | TimeDimName=List{get(handles.TimeVarName,'Value')}; |
---|
435 | end |
---|
436 | % A completer |
---|
437 | % if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on') |
---|
438 | % TimeDimList=get(handles.TimeDimensionMenu,'String'); |
---|
439 | % TimeDimIndex=get(handles.TimeDimensionMenu,'Value'); |
---|
440 | % TimeDimName=TimeDimList{TimeDimIndex}; |
---|
441 | % end |
---|
442 | |
---|
443 | %check possible coordinates |
---|
444 | Field=get(handles.get_field,'UserData'); |
---|
445 | dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar |
---|
446 | test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate |
---|
447 | for ilist=1:numel(Field.VarDimName) |
---|
448 | dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
449 | if isequal(dimnames,TimeDimName) |
---|
450 | test_coord(ilist)=0;%mark time variables fo elimination |
---|
451 | end |
---|
452 | if ischar(dimnames) |
---|
453 | dimnames={dimnames}; |
---|
454 | end |
---|
455 | for idim=1:numel(dimnames) |
---|
456 | if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable |
---|
457 | test_coord(ilist)=0; |
---|
458 | break |
---|
459 | end |
---|
460 | end |
---|
461 | end |
---|
462 | test_coord(index)=0;%the coordinate variable must be different from the scalar |
---|
463 | |
---|
464 | string_coord=[{''};string(test_coord==1)]; |
---|
465 | val=get(handles.XVarName,'Value'); |
---|
466 | if val>numel(string_coord) |
---|
467 | set(handles.XVarName,'Value',1) |
---|
468 | end |
---|
469 | set(handles.XVarName,'String',string_coord); |
---|
470 | val=get(handles.ZVarName,'Value'); |
---|
471 | if val>numel(string_coord) |
---|
472 | set(handles.ZVarName,'Value',1) |
---|
473 | end |
---|
474 | set(handles.ZVarName,'String',string_coord); |
---|
475 | val=get(handles.ZVarName,'Value'); |
---|
476 | if val>numel(string_coord) |
---|
477 | set(handles.ZVarName,'Value',1) |
---|
478 | end |
---|
479 | set(handles.YVarName,'String',string_coord); |
---|
480 | |
---|
481 | |
---|
482 | %------------------------------------------------------------------------ |
---|
483 | % --- Executes on selection change in abscissa. |
---|
484 | function abscissa_Callback(hObject, eventdata, handles) |
---|
485 | %------------------------------------------------------------------------ |
---|
486 | hselect_field=get(handles.inputfile,'parent'); |
---|
487 | Field=get(hselect_field,'UserData');%current input field |
---|
488 | xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa |
---|
489 | % test_2D=get(handles.CheckVector,'Value');% =1 for vector fields |
---|
490 | % test_scalar=get(handles.CheckScalar,'Value');% =1 for scalar fields |
---|
491 | %if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa |
---|
492 | % Txt=Field.ListVarName; |
---|
493 | % set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates |
---|
494 | % xindex=[]; |
---|
495 | % else |
---|
496 | xlist=get(handles.abscissa,'String');%list of abscissa |
---|
497 | VarName=xlist{xdispindex}; %selected variable name |
---|
498 | update_field(hObject, eventdata, handles,VarName) |
---|
499 | % xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables |
---|
500 | % if ~isempty(xindex) |
---|
501 | % set(handles.variables,'Value',xindex+1) |
---|
502 | % variables_Callback(hObject, eventdata, handles) |
---|
503 | % end |
---|
504 | % set(handles.variables,'Value',xindex+1)%outline in the list of variables |
---|
505 | % variables_Callback(hObject, eventdata, handles) %display properties of the TimeVariable (dim, attributes) |
---|
506 | % if ~test_2D & ~test_scalar% look for possible varaibles to OK in ordinate |
---|
507 | % index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa |
---|
508 | % VarIndex=[]; |
---|
509 | % for ilist=1:length(Field.VarDimIndex)%detect |
---|
510 | % index_i=Field.VarDimIndex{ilist}; |
---|
511 | % if ~isempty(index_i) |
---|
512 | % if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, OK is possible |
---|
513 | % VarIndex=[VarIndex ilist]; |
---|
514 | % end |
---|
515 | % end |
---|
516 | % end |
---|
517 | % % set(handles.ordinate,'Value',1) |
---|
518 | % set(handles.ordinate,'String',Field.ListVarName(VarIndex)) |
---|
519 | % end |
---|
520 | % end |
---|
521 | % |
---|
522 | % update_UserData(handles) |
---|
523 | |
---|
524 | |
---|
525 | |
---|
526 | %------------------------------------------------------------------------ |
---|
527 | % --- Executes on selection change in XVarName. |
---|
528 | function XVarName_Callback(hObject, eventdata, handles) |
---|
529 | %------------------------------------------------------------------------ |
---|
530 | index=get(handles.XVarName,'Value'); |
---|
531 | string=get(handles.XVarName,'String'); |
---|
532 | VarName=string{index}; |
---|
533 | update_field(hObject, eventdata, handles,VarName) |
---|
534 | |
---|
535 | %------------------------------------------------------------------------ |
---|
536 | % --- Executes on selection change in ZVarName. |
---|
537 | function ZVarName_Callback(hObject, eventdata, handles) |
---|
538 | %------------------------------------------------------------------------ |
---|
539 | index=get(handles.ZVarName,'Value'); |
---|
540 | string=get(handles.ZVarName,'String'); |
---|
541 | VarName=string{index}; |
---|
542 | update_field(hObject, eventdata, handles,VarName) |
---|
543 | |
---|
544 | %------------------------------------------------------------------------ |
---|
545 | % --- Executes on selection change in YVarName. |
---|
546 | function YVarName_Callback(hObject, eventdata, handles) |
---|
547 | %------------------------------------------------------------------------ |
---|
548 | index=get(handles.YVarName,'Value'); |
---|
549 | string=get(handles.YVarName,'String'); |
---|
550 | VarName=string{index}; |
---|
551 | update_field(hObject, eventdata, handles,VarName) |
---|
552 | |
---|
553 | %------------------------------------------------------------------------ |
---|
554 | % --- Executes on selection change in vector_x. |
---|
555 | function vector_x_Callback(hObject, eventdata, handles) |
---|
556 | %------------------------------------------------------------------------ |
---|
557 | index=get(handles.vector_x,'Value'); |
---|
558 | string=get(handles.vector_x,'String'); |
---|
559 | VarName=string{index}; |
---|
560 | |
---|
561 | %check possible coordinates |
---|
562 | Field=get(handles.get_field,'UserData'); |
---|
563 | dim_var=Field.VarDimName{index};%list of dimensions of the selected variable |
---|
564 | test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate |
---|
565 | test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component |
---|
566 | for ilist=1:numel(Field.VarDimName) |
---|
567 | dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
568 | if ~isequal(dimnames,dim_var) |
---|
569 | test_component(ilist)=0; |
---|
570 | end |
---|
571 | for idim=1:numel(dimnames) |
---|
572 | if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable |
---|
573 | test_coord(ilist)=0; |
---|
574 | break |
---|
575 | end |
---|
576 | end |
---|
577 | end |
---|
578 | %eliminate time |
---|
579 | if get(handles.TimeVariable,'Value') |
---|
580 | TimeName=get(handles.TimeName,'String'); |
---|
581 | index_time=find(strcmp( TimeName,Field.ListVarName)); |
---|
582 | test_coord(index_time)=0; |
---|
583 | end |
---|
584 | vlength=numel(string(test_component==1)); |
---|
585 | val=get(handles.vector_y,'Value'); |
---|
586 | if val>vlength |
---|
587 | set(handles.vector_y,'Value',1) |
---|
588 | end |
---|
589 | set(handles.vector_y,'String',[string(test_component==1)]) |
---|
590 | val=get(handles.vector_z,'Value'); |
---|
591 | if val>vlength+1 |
---|
592 | set(handles.vector_z,'Value',1) |
---|
593 | end |
---|
594 | set(handles.vector_z,'String',[{''};string(test_component==1)]) |
---|
595 | val=get(handles.vec_color,'Value'); |
---|
596 | if val>vlength+1 |
---|
597 | set(handles.vec_color,'Value',1) |
---|
598 | end |
---|
599 | set(handles.vec_color,'String',[{''};string(test_component==1)]) |
---|
600 | string_coord=[{''};string(test_coord==1)]; |
---|
601 | val=get(handles.XVarName,'Value'); |
---|
602 | if val>numel(string_coord) |
---|
603 | set(handles.XVarName,'Value',1) |
---|
604 | end |
---|
605 | set(handles.XVarName,'Visible','on'); |
---|
606 | set(handles.XVarName,'String',string_coord); |
---|
607 | val=get(handles.YVarName,'Value'); |
---|
608 | if val>numel(string_coord) |
---|
609 | set(handles.YVarName,'Value',1) |
---|
610 | end |
---|
611 | set(handles.YVarName,'Visible','on'); |
---|
612 | set(handles.YVarName,'String',string_coord); |
---|
613 | val=get(handles.TimeVarName,'Value'); |
---|
614 | if val>numel(string_coord) |
---|
615 | set(handles.TimeVarName,'Value',1) |
---|
616 | end |
---|
617 | set(handles.TimeVarName,'String',string_coord); |
---|
618 | |
---|
619 | update_field(hObject, eventdata, handles,VarName) |
---|
620 | |
---|
621 | %------------------------------------------------------------------------ |
---|
622 | % --- Executes on selection change in vector_y. |
---|
623 | function vector_y_Callback(hObject, eventdata, handles) |
---|
624 | %------------------------------------------------------------------------ |
---|
625 | index=get(handles.vector_y,'Value'); |
---|
626 | string=get(handles.vector_y,'String'); |
---|
627 | VarName=string{index}; |
---|
628 | update_field(hObject, eventdata, handles,VarName) |
---|
629 | |
---|
630 | %------------------------------------------------------------------------ |
---|
631 | % --- Executes on selection change in vector_z. |
---|
632 | function vector_z_Callback(hObject, eventdata, handles) |
---|
633 | %------------------------------------------------------------------------ |
---|
634 | index=get(handles.vector_z,'Value'); |
---|
635 | string=get(handles.vector_z,'String'); |
---|
636 | VarName=Astring{index}; |
---|
637 | update_field(hObject, eventdata, handles,VarName) |
---|
638 | |
---|
639 | %------------------------------------------------------------------------ |
---|
640 | % --- Executes on selection change in coord_x_vectors. |
---|
641 | function coord_x_vectors_Callback(hObject, eventdata, handles) |
---|
642 | %------------------------------------------------------------------------ |
---|
643 | index=get(handles.coord_x_vectors,'Value'); |
---|
644 | string=get(handles.coord_x_vectors,'String'); |
---|
645 | VarName=string{index}; |
---|
646 | update_field(hObject, eventdata, handles,VarName) |
---|
647 | |
---|
648 | %------------------------------------------------------------------------ |
---|
649 | % --- Executes on selection change in coord_y_vectors. |
---|
650 | function coord_y_vectors_Callback(hObject, eventdata, handles) |
---|
651 | %------------------------------------------------------------------------ |
---|
652 | index=get(handles.coord_y_vectors,'Value'); |
---|
653 | string=get(handles.coord_y_vectors,'String'); |
---|
654 | VarName=string{index}; |
---|
655 | update_field(hObject, eventdata, handles,VarName) |
---|
656 | |
---|
657 | %------------------------------------------------------------------------ |
---|
658 | % --- Executes on selection change in YVarName. |
---|
659 | function TimeVarName_Callback(hObject, eventdata, handles) |
---|
660 | %------------------------------------------------------------------------ |
---|
661 | index=get(handles.TimeVarName,'Value'); |
---|
662 | string=get(handles.TimeVarName,'String'); |
---|
663 | VarName=string{index}; |
---|
664 | update_field(hObject, eventdata, handles,VarName) |
---|
665 | |
---|
666 | %------------------------------------------------------------------------ |
---|
667 | % --- Executes on selection change in vec_color. |
---|
668 | function vec_color_Callback(hObject, eventdata, handles) |
---|
669 | %------------------------------------------------------------------------ |
---|
670 | index=get(handles.vec_color,'Value'); |
---|
671 | string=get(handles.vec_color,'String'); |
---|
672 | VarName=string{index}; |
---|
673 | update_field(hObject, eventdata, handles,VarName) |
---|
674 | |
---|
675 | %----------------------------------------------------------------------- |
---|
676 | function update_field(hObject, eventdata, handles,VarName) |
---|
677 | %----------------------------------------------------------------------- |
---|
678 | Field=get(handles.get_field,'UserData'); |
---|
679 | index=name2index(VarName,Field.ListVarName); |
---|
680 | if ~isempty(index) |
---|
681 | set(handles.variables,'Value',index+1) |
---|
682 | variables_Callback(hObject, eventdata, handles) |
---|
683 | end |
---|
684 | |
---|
685 | %------------------------------------------------------------------------ |
---|
686 | % update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback) |
---|
687 | function update_UserData(handles) |
---|
688 | %------------------------------------------------------------------------ |
---|
689 | return |
---|
690 | % global SubField |
---|
691 | hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface |
---|
692 | Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface |
---|
693 | if isfield(Field,'VarAttribute') |
---|
694 | VarAttribute=Field.VarAttribute; |
---|
695 | else |
---|
696 | VarAttribute={}; |
---|
697 | end |
---|
698 | |
---|
699 | |
---|
700 | % select the indices of field variables for 2D plots |
---|
701 | test_CheckPlot1D=get(handles.CheckPlot1D,'Value'); |
---|
702 | test_scalar=get(handles.CheckScalar,'Value'); |
---|
703 | test_vector=get(handles.CheckVector,'Value'); |
---|
704 | |
---|
705 | %transform if needed (calibration) |
---|
706 | list=get(handles.menu_coord,'String'); |
---|
707 | index=get(handles.menu_coord,'Value'); |
---|
708 | transform=list{index}; |
---|
709 | if ~isequal(transform,'') |
---|
710 | Field=feval(transform,Field); |
---|
711 | end |
---|
712 | VarIndex.u=[]; |
---|
713 | VarIndex.v=[]; |
---|
714 | VarIndex.w=[]; |
---|
715 | VarIndex.A=[]; |
---|
716 | VarIndex_tot=[]; |
---|
717 | iuA=[]; |
---|
718 | if test_scalar |
---|
719 | Astring=get(handles.scalar,'String'); |
---|
720 | Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox |
---|
721 | list_var=Astring(Aindex); |
---|
722 | VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName |
---|
723 | VarIndex_tot= [VarIndex_tot VarIndex.A]; |
---|
724 | DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable |
---|
725 | DimValue=Field.DimValue(DimIndex); |
---|
726 | ind=find(DimValue==1); |
---|
727 | DimIndex(ind)=[];%Mremove singleton |
---|
728 | end |
---|
729 | if test_vector |
---|
730 | Ustring=get(handles.vector_x,'String'); |
---|
731 | Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox |
---|
732 | list_var=Ustring{Uindex};%name of the selected scalar |
---|
733 | VarIndex.u=name2index(list_var,Field.ListVarName); |
---|
734 | Vstring=get(handles.vector_y,'String'); |
---|
735 | Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox |
---|
736 | list_var=Ustring{Vindex};%name of the selected scalar |
---|
737 | VarIndex.v=name2index(list_var,Field.ListVarName); |
---|
738 | if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A) |
---|
739 | iuA=VarIndex.A; %same variable used for vector and scalar |
---|
740 | VarIndex_tot(iuA)=[]; |
---|
741 | end |
---|
742 | VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v]; |
---|
743 | %dimensions |
---|
744 | DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable |
---|
745 | DimValue=Field.DimValue(DimIndex_u); |
---|
746 | ind=find(DimValue==1); |
---|
747 | DimIndex_u(ind)=[];%Mremove singleton |
---|
748 | DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable |
---|
749 | DimValue=Field.DimValue(DimIndex_v); |
---|
750 | ind=find(DimValue==1); |
---|
751 | DimIndex_v(ind)=[];%Mremove singleton |
---|
752 | if ~isequal(DimIndex_u,DimIndex_v) |
---|
753 | msgbox_uvmat('ERROR','inconsistent dimensions for u and v') |
---|
754 | set(handles.vector_y,'Value',1); |
---|
755 | return |
---|
756 | elseif test_scalar & ~isequal(DimIndex_u,DimIndex) |
---|
757 | msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color') |
---|
758 | set(handles.scalar,'Value',1); |
---|
759 | return |
---|
760 | end |
---|
761 | DimIndex=DimIndex_u; |
---|
762 | %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components |
---|
763 | end |
---|
764 | |
---|
765 | |
---|
766 | % select the TimeVariable index (or indices) for z coordinates |
---|
767 | test_grid=0; |
---|
768 | if test_scalar | test_vector |
---|
769 | nbdim=length(DimIndex); |
---|
770 | if nbdim > 3 |
---|
771 | msgbox_uvmat('ERROR','array with more than three dimensions, not supported') |
---|
772 | return |
---|
773 | else |
---|
774 | perm_ind=1:nbdim; |
---|
775 | end |
---|
776 | if nbdim==3 |
---|
777 | zstring=get(handles.coord_z_vectors_scalar,'String'); |
---|
778 | zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox |
---|
779 | list_var=zstring(zindex); |
---|
780 | VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable |
---|
781 | if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z) |
---|
782 | if zindex ~= 1 |
---|
783 | set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components |
---|
784 | return |
---|
785 | end |
---|
786 | else |
---|
787 | VarIndex_tot=[VarIndex_tot VarIndex_z]; |
---|
788 | DimIndex_z=Field.VarDimIndex{VarIndex_z}; |
---|
789 | DimValue=Field.DimValue(DimIndex_z); |
---|
790 | ind=find(DimValue==1); |
---|
791 | DimIndex_z(ind)=[];%Mremove singleton |
---|
792 | if isequal(DimIndex_z,DimIndex) |
---|
793 | VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates |
---|
794 | elseif length(DimIndex_z)==1 |
---|
795 | VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; %dimension variable |
---|
796 | ind_z=find(DimIndex==DimIndex_z(1)); |
---|
797 | perm_ind(ind_z)=1; |
---|
798 | test_grid=1; |
---|
799 | else |
---|
800 | msgbox_uvmat('ERROR','multiple dimensions for the z coordinate') |
---|
801 | return |
---|
802 | end |
---|
803 | end |
---|
804 | % if ~isempty(VarIndex_z) |
---|
805 | % DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable |
---|
806 | % if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable |
---|
807 | % VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; |
---|
808 | % ind_z=find(DimIndex==DimIndex_z(1)); |
---|
809 | % perm_ind(ind_z)=1; |
---|
810 | % test_grid=1; |
---|
811 | % end |
---|
812 | % end |
---|
813 | end |
---|
814 | end |
---|
815 | |
---|
816 | % select the TimeVariable index (or indices) for ordinate |
---|
817 | ystring=get(handles.ordinate,'String'); |
---|
818 | yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox |
---|
819 | list_var=ystring(yindex); |
---|
820 | VarIndex.y=name2index(list_var,Field.ListVarName); |
---|
821 | if isequal(VarIndex.A,VarIndex.y) |
---|
822 | set(handles.ZVarName,'Value',1) |
---|
823 | elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y) |
---|
824 | set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components |
---|
825 | else |
---|
826 | for ivar=1:length(VarIndex.y) |
---|
827 | VarAttribute{VarIndex.y(ivar)}.Role='coord_y'; |
---|
828 | end |
---|
829 | VarIndex_tot=[VarIndex_tot VarIndex.y]; |
---|
830 | end |
---|
831 | if (test_scalar | test_vector) & ~isempty(VarIndex.y) |
---|
832 | DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable |
---|
833 | if length(DimIndex_y)==1 |
---|
834 | ind_y=find(DimIndex==DimIndex_y(1)); |
---|
835 | test_grid=1; |
---|
836 | if nbdim==3 |
---|
837 | VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y}; |
---|
838 | perm_ind(ind_y)=2; |
---|
839 | elseif nbdim==2 |
---|
840 | VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y}; |
---|
841 | perm_ind(ind_y)=1; |
---|
842 | end |
---|
843 | elseif test_grid |
---|
844 | msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1') |
---|
845 | end |
---|
846 | end |
---|
847 | |
---|
848 | %select the TimeVariable index for the abscissa |
---|
849 | xstring=get(handles.abscissa,'String'); |
---|
850 | xindex=get(handles.abscissa,'Value'); |
---|
851 | list_var=xstring(xindex); |
---|
852 | VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var |
---|
853 | if length(VarIndex.x)==1 |
---|
854 | DimIndex_x=Field.VarDimIndex{VarIndex.x}; |
---|
855 | DimValue=Field.DimValue(DimIndex_x); |
---|
856 | ind=find(DimValue==1); |
---|
857 | DimIndex_x(ind)=[];%Mremove singleton |
---|
858 | VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; %dimension variable |
---|
859 | % VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified) |
---|
860 | index_detect=find(VarIndex_tot==VarIndex.x); |
---|
861 | else |
---|
862 | index_detect=[];%coord x variable not already used |
---|
863 | end |
---|
864 | if isempty(index_detect) |
---|
865 | VarIndex_tot=[VarIndex_tot VarIndex.x]; |
---|
866 | elseif ~test_CheckPlot1D |
---|
867 | VarIndex.x=[]; |
---|
868 | set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa |
---|
869 | end |
---|
870 | |
---|
871 | if (test_scalar | test_vector) & ~isempty(VarIndex.x) |
---|
872 | DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable |
---|
873 | if length(DimIndex_x)==1 |
---|
874 | ind_x=find(DimIndex==DimIndex_x(1)); |
---|
875 | if nbdim==3 |
---|
876 | %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; |
---|
877 | perm_ind(ind_x)=3; |
---|
878 | elseif nbdim==2 |
---|
879 | %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; |
---|
880 | perm_ind(ind_x)=2; |
---|
881 | end |
---|
882 | if isequal(perm_ind,1:nbdim) |
---|
883 | test_grid=0; |
---|
884 | end |
---|
885 | DimIndex=DimIndex(perm_ind); |
---|
886 | elseif test_grid |
---|
887 | msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1') |
---|
888 | end |
---|
889 | if isequal(DimIndex_x,DimIndex) |
---|
890 | VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates |
---|
891 | end |
---|
892 | end |
---|
893 | |
---|
894 | %defined the selected sub-field SubField |
---|
895 | SubField.ListGlobalAttribute{1}='InputFile'; |
---|
896 | SubField.InputFile=get(handles.inputfile,'String'); |
---|
897 | SubField.ListDimName=Field.ListDimName; |
---|
898 | SubField.DimValue=Field.DimValue; |
---|
899 | SubField.ListVarName=Field.ListVarName(VarIndex_tot); |
---|
900 | SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot); |
---|
901 | |
---|
902 | testperm=0; |
---|
903 | testattr=0; |
---|
904 | for ivar=VarIndex.u |
---|
905 | VarAttribute{ivar}.Role='vector_x'; |
---|
906 | testattr=1; |
---|
907 | if test_grid |
---|
908 | VarDimIndex{ivar}=DimIndex; %permute dimensions |
---|
909 | testperm=1; |
---|
910 | end |
---|
911 | end |
---|
912 | for ivar=VarIndex.v |
---|
913 | VarAttribute{ivar}.Role='vector_y'; |
---|
914 | testattr=1; |
---|
915 | if test_grid |
---|
916 | VarDimIndex{ivar}=DimIndex;%permute dimensions |
---|
917 | testperm=1; |
---|
918 | end |
---|
919 | end |
---|
920 | for ivar=VarIndex.A |
---|
921 | if test_grid |
---|
922 | VarDimIndex{ivar}=DimIndex;%permute dimensions |
---|
923 | testperm=1; |
---|
924 | end |
---|
925 | if isempty(iuA) |
---|
926 | VarAttribute{ivar}.Role='scalar';%Role =scalar |
---|
927 | testattr=1; |
---|
928 | else |
---|
929 | VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable |
---|
930 | nbattr=length(VarAttribute); |
---|
931 | VarAttribute{nbattr}.Role='scalar'; |
---|
932 | testattr=1; |
---|
933 | end |
---|
934 | end |
---|
935 | if testperm |
---|
936 | SubField.VarDimIndex=VarDimIndex(VarIndex_tot); |
---|
937 | end |
---|
938 | if testattr |
---|
939 | SubField.VarAttribute=VarAttribute(VarIndex_tot); |
---|
940 | end |
---|
941 | set(hselect_field,'UserData',Field) |
---|
942 | |
---|
943 | %--------------------------------------------------------- |
---|
944 | % --- Executes on button press in OK. |
---|
945 | |
---|
946 | function OK_Callback(hObject, eventdata, handles) |
---|
947 | %--------------------------------------------------------- |
---|
948 | |
---|
949 | handles.output=read_GUI(handles.get_field); |
---|
950 | guidata(hObject, handles);% Update handles structure |
---|
951 | uiresume(handles.get_field); |
---|
952 | drawnow |
---|
953 | return |
---|
954 | |
---|
955 | %%%% SKIPPED %%%% |
---|
956 | hfield=[]; |
---|
957 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
958 | hseries=findobj(allchild(0),'tag','series'); |
---|
959 | check_series=0; |
---|
960 | % look for the status of the GUI uvmat |
---|
961 | if ~isempty(huvmat) |
---|
962 | hh=guidata(huvmat); |
---|
963 | FieldMenu=get(hh.FieldName,'String'); |
---|
964 | FieldName=FieldMenu{get(hh.FieldName,'Value')}; |
---|
965 | if strcmp(FieldName,'get_field...') |
---|
966 | hfield=hh.FieldName; %FieldName on uvmat |
---|
967 | elseif strcmp(get(hh.FieldName_1,'Visible'),'on') |
---|
968 | FieldMenu=get(hh.FieldName_1,'String'); |
---|
969 | if ~isempty(FieldMenu) |
---|
970 | FieldName=FieldMenu{get(hh.FieldName_1,'Value')}; |
---|
971 | if strcmp(FieldName,'get_field...') |
---|
972 | hfield=hh.FieldName_1; %FieldName_1 on uvmat |
---|
973 | end |
---|
974 | end |
---|
975 | end |
---|
976 | end |
---|
977 | % if no filed data is concerned on uvmat, look at the GUI series |
---|
978 | if isempty(hfield) && ~isempty(hseries) |
---|
979 | check_series=1; |
---|
980 | hh=guidata(hseries); |
---|
981 | FieldMenu=get(hh.FieldName,'String'); |
---|
982 | FieldName=FieldMenu{get(hh.FieldName,'Value')}; |
---|
983 | if strcmp(FieldName,'get_field...') |
---|
984 | hfield=hh.FieldName; %FieldName on series |
---|
985 | else |
---|
986 | FieldMenu=get(hh.FieldName_1,'String'); |
---|
987 | FieldName=FieldMenu{get(hh.FieldName_1,'Value')}; |
---|
988 | if strcmp(FieldName,'get_field...') |
---|
989 | hfield=hh.FieldName_1; %FieldName_1 on series |
---|
990 | end |
---|
991 | end |
---|
992 | end |
---|
993 | if ~isempty(hfield) |
---|
994 | get_field_GUI=read_GUI(handles.get_field); |
---|
995 | if isfield(get_field_GUI,'PanelVectors') |
---|
996 | set(hh.Coord_x,'value',1) |
---|
997 | set(hh.Coord_y,'value',1) |
---|
998 | set(hh.Coord_x,'String',{get_field_GUI.PanelVectors.coord_x_vectors}) |
---|
999 | set(hh.Coord_y,'String',{get_field_GUI.PanelVectors.coord_y_vectors}) |
---|
1000 | UName=get_field_GUI.PanelVectors.vector_x; |
---|
1001 | VName=get_field_GUI.PanelVectors.vector_y; |
---|
1002 | menu_str=[{['vec(' UName ',' VName ')']};{UName};{VName};{['norm(' UName ',' VName ')']};{'get_field...'}]; |
---|
1003 | menu_color=[{''};{UName};{VName};{['norm(' UName ',' VName ')']}]; |
---|
1004 | set(hfield,'Value',1) |
---|
1005 | set(hfield,'String',menu_str) |
---|
1006 | if ~check_series |
---|
1007 | ind_menu=find(strcmp(get_field_GUI.PanelVectors.vec_color,menu_color)); |
---|
1008 | if ~isempty(ind_menu) |
---|
1009 | set(hh.ColorScalar,'Value',ind_menu) |
---|
1010 | else |
---|
1011 | set(hh.ColorScalar,'Value',1) |
---|
1012 | end |
---|
1013 | set(hh.ColorScalar,'String',menu_color) |
---|
1014 | end |
---|
1015 | elseif isfield(get_field_GUI,'PanelScalar') |
---|
1016 | set(hh.Coord_x,'value',1) |
---|
1017 | set(hh.Coord_y,'value',1) |
---|
1018 | set(hh.Coord_x,'String',{get_field_GUI.PanelScalar.coord_x_scalar}) |
---|
1019 | set(hh.Coord_y,'String',{get_field_GUI.PanelScalar.coord_y_scalar}) |
---|
1020 | AName=get_field_GUI.PanelScalar.scalar; |
---|
1021 | menu=get(hfield,'String'); |
---|
1022 | ind_select=find(strcmp(AName,menu)); |
---|
1023 | if isempty(ind_select) |
---|
1024 | menu=[menu(1:end-1);{AName};{'get_field...'}]; |
---|
1025 | ind_select=numel(menu)-1; |
---|
1026 | end |
---|
1027 | set(hfield,'Value',ind_select); |
---|
1028 | set(hfield,'String',menu); |
---|
1029 | elseif isfield(get_field_GUI,'Panel1Dplot') |
---|
1030 | set(hh.Coord_x,'Value',1) |
---|
1031 | set(hh.Coord_x,'String',{get_field_GUI.Panel1Dplot.abscissa}) |
---|
1032 | set(hh.Coord_y,'String',get_field_GUI.Panel1Dplot.ordinate) |
---|
1033 | set(hh.Coord_y,'Max', numel(get_field_GUI.Panel1Dplot.ordinate)) |
---|
1034 | set(hh.Coord_y,'Value',1:numel(get_field_GUI.Panel1Dplot.ordinate)) |
---|
1035 | set(hfield,'Value',1) |
---|
1036 | set(hfield,'String',[{''};{'get_field...'}]) |
---|
1037 | end |
---|
1038 | if ~check_series && strcmp(get(gcbf,'tag'),'get_field')%get_field is not called by another GUI (uvmat) |
---|
1039 | uvmat('run0_Callback',hObject,eventdata,hh); %refresh uvmat |
---|
1040 | end |
---|
1041 | end |
---|
1042 | delete(handles.get_field) |
---|
1043 | |
---|
1044 | |
---|
1045 | |
---|
1046 | %------------------------------------------------- |
---|
1047 | % give index numbers of the strings str in the list ListvarName |
---|
1048 | function VarIndex_y=name2index(cell_str,ListVarName) |
---|
1049 | VarIndex_y=[]; |
---|
1050 | if ischar(cell_str) |
---|
1051 | for ivar=1:length(ListVarName) |
---|
1052 | varlist=ListVarName{ivar}; |
---|
1053 | if isequal(varlist,cell_str) |
---|
1054 | VarIndex_y= ivar; |
---|
1055 | break |
---|
1056 | end |
---|
1057 | end |
---|
1058 | elseif iscell(cell_str) |
---|
1059 | for isel=1:length(cell_str) |
---|
1060 | varsel=cell_str{isel}; |
---|
1061 | for ivar=1:length(ListVarName) |
---|
1062 | varlist=ListVarName{ivar}; |
---|
1063 | if isequal(varlist,varsel) |
---|
1064 | VarIndex_y=[VarIndex_y ivar]; |
---|
1065 | end |
---|
1066 | end |
---|
1067 | end |
---|
1068 | end |
---|
1069 | |
---|
1070 | % -------------------------------------------------------------------- |
---|
1071 | function MenuOpen_Callback(hObject, eventdata, handles) |
---|
1072 | % hObject handle to MenuOpen (see GCBO) |
---|
1073 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1074 | % handles structure with handles and user data (see GUIDATA) |
---|
1075 | |
---|
1076 | |
---|
1077 | % -------------------------------------------------------------------- |
---|
1078 | function MenuExport_Callback(hObject, eventdata, handles) |
---|
1079 | % hObject handle to MenuExport (see GCBO) |
---|
1080 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1081 | % handles structure with handles and user data (see GUIDATA) |
---|
1082 | |
---|
1083 | |
---|
1084 | % -------------------------------------------------------------------- |
---|
1085 | function MenuBrowse_Callback(hObject, eventdata, handles) |
---|
1086 | |
---|
1087 | oldfile=get(handles.inputfile,'String'); |
---|
1088 | testrootfile=0; |
---|
1089 | testsubdir=0; |
---|
1090 | if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box |
---|
1091 | oldfile=''; |
---|
1092 | dir_perso=prefdir; |
---|
1093 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
1094 | if exist(profil_perso,'file') |
---|
1095 | h=load (profil_perso); |
---|
1096 | if isfield(h,'RootPath') |
---|
1097 | RootPath=h.RootPath; |
---|
1098 | end |
---|
1099 | if isfield(h,'SubDir') |
---|
1100 | SubDir=h.SubDir; |
---|
1101 | if ~isempty(SubDir) |
---|
1102 | testsubdir=1; |
---|
1103 | end |
---|
1104 | end |
---|
1105 | if isfield(h,'RootFile') |
---|
1106 | RootFile=h.RootFile; |
---|
1107 | if ~isempty(RootFile) |
---|
1108 | testrootfile=1; |
---|
1109 | end |
---|
1110 | end |
---|
1111 | end |
---|
1112 | end |
---|
1113 | if testrootfile |
---|
1114 | if ~testsubdir |
---|
1115 | oldfile=fullfile(RootPath,RootFile); |
---|
1116 | else |
---|
1117 | oldfile=fullfile(RootPath,SubDir,RootFile); |
---|
1118 | end |
---|
1119 | end |
---|
1120 | [FileName, PathName] = uigetfile( ... |
---|
1121 | {'*.nc', ' *.nc';... |
---|
1122 | '*.cdf', ' *.cdf';... |
---|
1123 | '*.*', 'All Files (*.*)'}, ... |
---|
1124 | 'Pick a file',oldfile); |
---|
1125 | |
---|
1126 | %global inputfile |
---|
1127 | fileinput=[PathName FileName];%complete file name |
---|
1128 | sizf=size(fileinput); |
---|
1129 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
1130 | set(handles.inputfile,'String',fileinput) |
---|
1131 | inputfile_Callback(hObject, eventdata, handles) |
---|
1132 | |
---|
1133 | %update list of recent files in the menubar |
---|
1134 | MenuFile_1=fileinput; |
---|
1135 | MenuFile_2=get(handles.MenuFile_1,'Label'); |
---|
1136 | MenuFile_3=get(handles.MenuFile_2,'Label'); |
---|
1137 | MenuFile_4=get(handles.MenuFile_3,'Label'); |
---|
1138 | MenuFile_5=get(handles.MenuFile_4,'Label'); |
---|
1139 | set(handles.MenuFile_1,'Label',MenuFile_1) |
---|
1140 | set(handles.MenuFile_2,'Label',MenuFile_2) |
---|
1141 | set(handles.MenuFile_3,'Label',MenuFile_3) |
---|
1142 | set(handles.MenuFile_4,'Label',MenuFile_4) |
---|
1143 | set(handles.MenuFile_5,'Label',MenuFile_5) |
---|
1144 | dir_perso=prefdir; |
---|
1145 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
1146 | display(profil_perso) |
---|
1147 | if exist(profil_perso,'file') |
---|
1148 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat |
---|
1149 | else |
---|
1150 | txt=ver('MATLAB'); |
---|
1151 | Release=txt.Release; |
---|
1152 | relnumb=str2double(Release(3:4)); |
---|
1153 | if relnumb >= 14 |
---|
1154 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat |
---|
1155 | else |
---|
1156 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat |
---|
1157 | end |
---|
1158 | end |
---|
1159 | |
---|
1160 | % -------------------------------------------------------------------- |
---|
1161 | function MenuFile_1_Callback(hObject, eventdata, handles) |
---|
1162 | fileinput=get(handles.MenuFile_1,'Label'); |
---|
1163 | set(handles.inputfile,'String',fileinput) |
---|
1164 | inputfile_Callback(hObject, eventdata, handles) |
---|
1165 | |
---|
1166 | % -------------------------------------------------------------------- |
---|
1167 | function MenuFile_2_Callback(hObject, eventdata, handles) |
---|
1168 | fileinput=get(handles.MenuFile_2,'Label'); |
---|
1169 | set(handles.inputfile,'String',fileinput) |
---|
1170 | inputfile_Callback(hObject, eventdata, handles) |
---|
1171 | |
---|
1172 | % ----------------------------------------------------------------------- |
---|
1173 | function MenuFile_3_Callback(hObject, eventdata, handles) |
---|
1174 | % ----------------------------------------------------------------------- |
---|
1175 | fileinput=get(handles.MenuFile_3,'Label'); |
---|
1176 | set(handles.inputfile,'String',fileinput) |
---|
1177 | inputfile_Callback(hObject, eventdata, handles) |
---|
1178 | |
---|
1179 | % ----------------------------------------------------------------------- |
---|
1180 | function MenuFile_4_Callback(hObject, eventdata, handles) |
---|
1181 | % ----------------------------------------------------------------------- |
---|
1182 | fileinput=get(handles.MenuFile_4,'Label'); |
---|
1183 | set(handles.inputfile,'String',fileinput) |
---|
1184 | inputfile_Callback(hObject, eventdata, handles) |
---|
1185 | |
---|
1186 | % ----------------------------------------------------------------------- |
---|
1187 | function MenuFile_5_Callback(hObject, eventdata, handles) |
---|
1188 | % ----------------------------------------------------------------------- |
---|
1189 | fileinput=get(handles.MenuFile_5,'Label'); |
---|
1190 | set(handles.inputfile,'String',fileinput) |
---|
1191 | inputfile_Callback(hObject, eventdata, handles) |
---|
1192 | |
---|
1193 | %------------------------------------------------------------------------ |
---|
1194 | function MenuExportField_Callback(hObject, eventdata, handles) |
---|
1195 | %------------------------------------------------------------------------ |
---|
1196 | global Data_get_field |
---|
1197 | % huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
1198 | inputfile=get(handles.inputfile,'String'); |
---|
1199 | Data_get_field=nc2struct(inputfile); |
---|
1200 | % Data_view_field=UvData.ProjField_2; |
---|
1201 | evalin('base','global Data_get_field')%make CurData global in the workspace |
---|
1202 | display(['content of ' inputfile ':']) |
---|
1203 | evalin('base','Data_get_field') %display CurData in the workspace |
---|
1204 | commandwindow; |
---|
1205 | |
---|
1206 | %------------------------------------------------------------------------ |
---|
1207 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
1208 | %------------------------------------------------------------------------ |
---|
1209 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
1210 | pathelp=fileparts(path_to_uvmat); |
---|
1211 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
1212 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
1213 | else |
---|
1214 | web([helpfile '#get_field']) |
---|
1215 | end |
---|
1216 | |
---|
1217 | % ----------------------------------------------------------------------- |
---|
1218 | function TimeName_Callback(hObject, eventdata, handles) |
---|
1219 | |
---|
1220 | scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates |
---|
1221 | vector_x_Callback(hObject, eventdata, handles) |
---|
1222 | |
---|
1223 | %------------------------------------------------------------------------ |
---|
1224 | % --- Executes on button press in TimeAttribute. |
---|
1225 | function TimeAttribute_Callback(hObject, eventdata, handles) |
---|
1226 | %------------------------------------------------------------------------ |
---|
1227 | val=get(handles.TimeAttribute,'Value'); |
---|
1228 | if val |
---|
1229 | set(handles.TimeAttributeMenu,'Visible','on') |
---|
1230 | Field=get(handles.get_field,'UserData'); |
---|
1231 | time_value=zeros(size(Field.ListGlobalAttribute)); |
---|
1232 | test_time=zeros(size(Field.ListGlobalAttribute)); |
---|
1233 | for ilist=1:numel(Field.ListGlobalAttribute) |
---|
1234 | if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}])) |
---|
1235 | eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';']) |
---|
1236 | if ~isempty(time_val) |
---|
1237 | time_value(ilist)=time_val; |
---|
1238 | test_time(ilist)=1; |
---|
1239 | end |
---|
1240 | end |
---|
1241 | end |
---|
1242 | ListTimeAttribute=Field.ListGlobalAttribute(test_time==1); |
---|
1243 | attr_index=get(handles.TimeAttributeMenu,'Value'); |
---|
1244 | if attr_index>numel(ListTimeAttribute) |
---|
1245 | attr_index=1; |
---|
1246 | set(handles.TimeAttributeMenu,'Value',1); |
---|
1247 | end |
---|
1248 | if isempty(ListTimeAttribute) |
---|
1249 | set(handles.TimeAttributeMenu,'String',{''}) |
---|
1250 | set(handles.TimeValue,'Visible','off') |
---|
1251 | else |
---|
1252 | set(handles.TimeValue,'Visible','on') |
---|
1253 | set(handles.TimeAttributeMenu,'String',ListTimeAttribute) |
---|
1254 | set(handles.TimeValue,'String',num2str(time_value(attr_index))) |
---|
1255 | end |
---|
1256 | set(handles.TimeDimension,'Value',0) |
---|
1257 | TimeDimension_Callback(hObject, eventdata, handles) |
---|
1258 | set(handles.TimeVariable,'Value',0) |
---|
1259 | TimeVariable_Callback(hObject, eventdata, handles) |
---|
1260 | else |
---|
1261 | set(handles.TimeAttributeMenu,'Visible','off') |
---|
1262 | set(handles.TimeValue,'Visible','off') |
---|
1263 | end |
---|
1264 | |
---|
1265 | %------------------------------------------------------------------------ |
---|
1266 | % --- Executes on selection change in TimeAttributeMenu. |
---|
1267 | function TimeAttributeMenu_Callback(hObject, eventdata, handles) |
---|
1268 | ListTimeAttribute=get(handles.TimeAttributeMenu,'String'); |
---|
1269 | index=get(handles.TimeAttributeMenu,'Value'); |
---|
1270 | AttrName=ListTimeAttribute{index}; |
---|
1271 | Field=get(handles.get_field,'UserData'); |
---|
1272 | eval(['time_val=Field.' AttrName ';']) |
---|
1273 | set(handles.TimeValue,'String',num2str(time_val)) |
---|
1274 | %------------------------------------------------------------------------ |
---|
1275 | |
---|
1276 | %------------------------------------------------------------------------ |
---|
1277 | % --- Executes on button press in TimeVariable. |
---|
1278 | function TimeDimension_Callback(hObject, eventdata, handles) |
---|
1279 | %------------------------------------------------------------------------ |
---|
1280 | val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected |
---|
1281 | if val %if check box TimeDimension is selected |
---|
1282 | Field=get(handles.get_field,'UserData');% structure describing the currently opened field |
---|
1283 | previous_menu=get(handles.TimeDimensionMenu,'String'); |
---|
1284 | if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu |
---|
1285 | ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time' |
---|
1286 | if isempty(ind_select) |
---|
1287 | ind_select=1;% select the first item in the list if 'time' is not found |
---|
1288 | end |
---|
1289 | set(handles.TimeDimensionMenu,'Value',ind_select); |
---|
1290 | set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu |
---|
1291 | end |
---|
1292 | set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible |
---|
1293 | set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible |
---|
1294 | TimeDimensionMenu_Callback(hObject, eventdata, handles) |
---|
1295 | set(handles.TimeAttribute,'Value',0) %deselect alternative options for time |
---|
1296 | set(handles.TimeVariable,'Value',0) |
---|
1297 | TimeAttribute_Callback(hObject, eventdata, handles) |
---|
1298 | else |
---|
1299 | set(handles.TimeDimensionMenu,'Visible','off') |
---|
1300 | set(handles.TimeIndexValue,'Visible','off') |
---|
1301 | end |
---|
1302 | % |
---|
1303 | % %------------------------------------------------------------------------ |
---|
1304 | % % --- Executes on selection change in TimeDimensionMenu. |
---|
1305 | % function TimeDimensionMenu_Callback(hObject, eventdata, handles) |
---|
1306 | % %------------------------------------------------------------------------ |
---|
1307 | % index=get(handles.TimeDimensionMenu,'Value'); |
---|
1308 | % DimList=get(handles.TimeDimensionMenu,'String'); |
---|
1309 | % DimName=DimList{index}; |
---|
1310 | % Field=get(handles.get_field,'UserData'); |
---|
1311 | % DimIndex=find(strcmp(DimName,Field.ListDimName),1); |
---|
1312 | % ref_index=round(Field.DimValue(DimIndex)/2); |
---|
1313 | % set(handles.TimeIndexValue,'String',num2str(ref_index)) |
---|
1314 | % scalar_Callback(hObject, eventdata, handles) |
---|
1315 | % vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time) |
---|
1316 | % % look for a corresponding time variable and value |
---|
1317 | % time_test=zeros(size(Field.VarDimName)); |
---|
1318 | % for ilist=1:numel(Field.VarDimName) |
---|
1319 | % if isequal(Field.VarDimName{ilist},{DimName}) |
---|
1320 | % time_test(ilist)=1; |
---|
1321 | % end |
---|
1322 | % end |
---|
1323 | % ListVariable=Field.ListVarName(time_test==1); |
---|
1324 | % set(handles.TimeVariableMenu,'Value',1) |
---|
1325 | % if isempty(ListVariable) |
---|
1326 | % set(handles.TimeVariableMenu,'String',{''}) |
---|
1327 | % set(handles.TimeVarValue,'String','') |
---|
1328 | % else |
---|
1329 | % set(handles.TimeVariableMenu,'String',ListVariable) |
---|
1330 | % TimeVarName=ListVariable{1}; |
---|
1331 | % VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables |
---|
1332 | % inputfile=get(handles.inputfile,'String');% read the input file |
---|
1333 | % SubField=nc2struct(inputfile,{TimeVarName}); |
---|
1334 | % eval(['TimeValue=SubField.' TimeVarName '(ref_index);']) |
---|
1335 | % set(handles.TimeVarValue,'Visible','on') |
---|
1336 | % set(handles.TimeVariableMenu,'Visible','on') |
---|
1337 | % set(handles.TimeVarValue,'String',num2str(TimeValue)) |
---|
1338 | % end |
---|
1339 | % |
---|
1340 | % |
---|
1341 | % % % ----------------------------------------------------------------------- |
---|
1342 | % % % --- Executes on button press in TimeVariable. |
---|
1343 | % % function TimeVariable_Callback(hObject, eventdata, handles) |
---|
1344 | % % % ----------------------------------------------------------------------- |
---|
1345 | % % val=get(handles.TimeVariable,'Value'); |
---|
1346 | % % if val |
---|
1347 | % % Field=get(handles.get_field,'UserData'); |
---|
1348 | % % time_test=zeros(size(Field.VarDimName)); |
---|
1349 | % % for ilist=1:numel(Field.VarDimName) |
---|
1350 | % % if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension |
---|
1351 | % % time_test(ilist)=1; |
---|
1352 | % % end |
---|
1353 | % % end |
---|
1354 | % % ind_test=find(time_test); |
---|
1355 | % % if isempty(time_test) |
---|
1356 | % % set(handles.TimeVariable,'Value',0) |
---|
1357 | % % set(handles.TimeVariableMenu,'Visible','off') |
---|
1358 | % % set(handles.TimeVarValue,'Visible','off') |
---|
1359 | % % else |
---|
1360 | % % set(handles.TimeVariableMenu,'Visible','on') |
---|
1361 | % % set(handles.TimeVarValue,'Visible','on') |
---|
1362 | % % if get(handles.TimeVariableMenu,'Value')>numel(ind_test) |
---|
1363 | % % set(handles.TimeVariableMenu,'Value',1) |
---|
1364 | % % end |
---|
1365 | % % set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test)) |
---|
1366 | % % TimeVariableMenu_Callback(hObject, eventdata, handles) |
---|
1367 | % % set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time |
---|
1368 | % % set(handles.TimeAttribute,'Value',0) |
---|
1369 | % % TimeAttribute_Callback(hObject, eventdata, handles) |
---|
1370 | % % end |
---|
1371 | % % else |
---|
1372 | % % set(handles.TimeVariableMenu,'Visible','off') |
---|
1373 | % % set(handles.TimeVarValue,'Visible','off') |
---|
1374 | % % end |
---|
1375 | % |
---|
1376 | % % ----------------------------------------------------------------------- |
---|
1377 | % % --- Executes on selection change in TimeVariableMenu. |
---|
1378 | % function TimeVariableMenu_Callback(hObject, eventdata, handles) |
---|
1379 | % % ----------------------------------------------------------------------- |
---|
1380 | % ListVar=get(handles.TimeVariableMenu,'String'); |
---|
1381 | % index=get(handles.TimeVariableMenu,'Value'); |
---|
1382 | % TimeVariable=ListVar{index};% name of the selected variable |
---|
1383 | % if isempty(TimeVariable)% case of blank selection |
---|
1384 | % return |
---|
1385 | % end |
---|
1386 | % Field=get(handles.get_field,'UserData'); %index of |
---|
1387 | % VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables |
---|
1388 | % DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable |
---|
1389 | % set(handles.TimeDimensionMenu,'Value',1) |
---|
1390 | % set(handles.TimeDimensionMenu,'String',DimName) |
---|
1391 | % inputfile=get(handles.inputfile,'String');% read the input file |
---|
1392 | % SubField=nc2struct(inputfile,{TimeVariable}); |
---|
1393 | % eval(['TimeDimension=numel(SubField.' TimeVariable ');']) |
---|
1394 | % ref_index=round(TimeDimension/2); |
---|
1395 | % eval(['TimeValue=SubField.' TimeVariable '(ref_index);']) |
---|
1396 | % set(handles.TimeIndexValue,'String',num2str(ref_index)) |
---|
1397 | % set(handles.TimeVarValue,'String',num2str(TimeValue)) |
---|
1398 | |
---|
1399 | |
---|
1400 | % --- Executes on button press in check_rgb. |
---|
1401 | function check_rgb_Callback(hObject, eventdata, handles) |
---|
1402 | |
---|
1403 | |
---|
1404 | % --- Executes when user attempts to close get_field. |
---|
1405 | function get_field_CloseRequestFcn(hObject, eventdata, handles) |
---|
1406 | if isequal(get(handles.get_field, 'waitstatus'), 'waiting') |
---|
1407 | % The GUI is still in UIWAIT, us UIRESUME |
---|
1408 | uiresume(handles.get_field); |
---|
1409 | else |
---|
1410 | % The GUI is no longer waiting, just close it |
---|
1411 | delete(handles.get_field); |
---|
1412 | end |
---|
1413 | |
---|
1414 | |
---|
1415 | |
---|
1416 | |
---|
1417 | |
---|
1418 | % --- Executes on selection change in listbox30. |
---|
1419 | function listbox30_Callback(hObject, eventdata, handles) |
---|
1420 | % hObject handle to listbox30 (see GCBO) |
---|
1421 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1422 | % handles structure with handles and user data (see GUIDATA) |
---|
1423 | |
---|
1424 | % Hints: contents = cellstr(get(hObject,'String')) returns listbox30 contents as cell array |
---|
1425 | % contents{get(hObject,'Value')} returns selected item from listbox30 |
---|
1426 | |
---|
1427 | |
---|
1428 | % --- Executes on selection change in SwitchVarIndexX. |
---|
1429 | function SwitchVarIndexX_Callback(hObject, eventdata, handles) |
---|
1430 | % hObject handle to SwitchVarIndexX (see GCBO) |
---|
1431 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1432 | % handles structure with handles and user data (see GUIDATA) |
---|
1433 | |
---|
1434 | % Hints: contents = cellstr(get(hObject,'String')) returns SwitchVarIndexX contents as cell array |
---|
1435 | % contents{get(hObject,'Value')} returns selected item from SwitchVarIndexX |
---|
1436 | |
---|
1437 | |
---|
1438 | % --- Executes on selection change in SwitchVarIndexTime. |
---|
1439 | function SwitchVarIndexTime_Callback(hObject, eventdata, handles) |
---|
1440 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
1441 | option=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
1442 | Field=get(handles.get_field,'UserData'); |
---|
1443 | switch option |
---|
1444 | case 'file index' |
---|
1445 | set(handles.TimeVarName, 'Visible','off') |
---|
1446 | case 'attribute' |
---|
1447 | set(handles.TimeVarName, 'Visible','on') |
---|
1448 | time_index=[]; |
---|
1449 | PreviousList=get(handles.TimeVarName, 'String'); |
---|
1450 | index=[]; |
---|
1451 | if ~isempty(PreviousList) |
---|
1452 | PreviousAttr=PreviousList{get(handles.TimeVarName, 'Value')}; |
---|
1453 | index=find(strcmp(PreviousAttr,Field.ListNumAttributes)); |
---|
1454 | end |
---|
1455 | if isempty(index) |
---|
1456 | time_index=find(~cellfun('isempty',regexp(Field.ListNumAttributes,'Time')));% index of the attributes containing the string 'Time' |
---|
1457 | end |
---|
1458 | if ~isempty(time_index) |
---|
1459 | set(handles.TimeVarName,'Value',time_index(1)) |
---|
1460 | else |
---|
1461 | set(handles.TimeVarName,'Value',1) |
---|
1462 | end |
---|
1463 | set(handles.TimeVarName, 'String',Field.ListNumAttributes) |
---|
1464 | case 'variable' |
---|
1465 | set(handles.TimeVarName, 'Visible','on') |
---|
1466 | TimeVarName=Field.SingleVarName; |
---|
1467 | List=get(handles.TimeVarName,'String'); |
---|
1468 | option=List{get(handles.TimeVarName,'Value')}; |
---|
1469 | ind=find(strcmp(option,TimeVarName)); |
---|
1470 | if isempty(ind) |
---|
1471 | set(handles.TimeVarName, 'Value',1); |
---|
1472 | else |
---|
1473 | set(handles.TimeVarName, 'Value',ind); |
---|
1474 | end |
---|
1475 | set(handles.TimeVarName, 'String',TimeVarName) |
---|
1476 | case 'dim index' |
---|
1477 | set(handles.TimeVarName, 'Visible','on') |
---|
1478 | TimeVarName=Field.SingleDimName; |
---|
1479 | List=get(handles.TimeVarName,'String'); |
---|
1480 | option=List{get(handles.TimeVarName,'Value')}; |
---|
1481 | ind=find(strcmp(option,TimeVarName)); |
---|
1482 | if isempty(ind) |
---|
1483 | set(handles.TimeVarName, 'Value',1); |
---|
1484 | else |
---|
1485 | set(handles.TimeVarName, 'Value',ind); |
---|
1486 | end |
---|
1487 | set(handles.TimeVarName, 'String',TimeVarName) |
---|
1488 | end |
---|
1489 | |
---|
1490 | |
---|
1491 | % --- Executes on button press in CheckScalar. |
---|
1492 | function checkbox22_Callback(hObject, eventdata, handles) |
---|
1493 | % hObject handle to CheckScalar (see GCBO) |
---|
1494 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1495 | % handles structure with handles and user data (see GUIDATA) |
---|
1496 | |
---|
1497 | % Hint: get(hObject,'Value') returns toggle state of CheckScalar |
---|
1498 | |
---|
1499 | |
---|
1500 | % --- Executes on button press in checkbox23. |
---|
1501 | function checkbox23_Callback(hObject, eventdata, handles) |
---|
1502 | % hObject handle to checkbox23 (see GCBO) |
---|
1503 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
1504 | % handles structure with handles and user data (see GUIDATA) |
---|
1505 | |
---|
1506 | % Hint: get(hObject,'Value') returns toggle state of checkbox23 |
---|