1 | %'get_field': display variables and attributes from a Netcdf file, and OK selected fields |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % GetFieldData=get_field(FileName,ParamIn) |
---|
4 | % associated with the GUI get_field.fig |
---|
5 | % |
---|
6 | % OUTPUT: |
---|
7 | % GetFieldData: structure containing the information on the selected |
---|
8 | % fields, obtained by applying the fct red_GUI to the GUI get_field |
---|
9 | % .FieldOption='vectors': variables are used for vector plot |
---|
10 | % 'scalar': variables are used for scalar plot, |
---|
11 | % '1Dplot': variables are used for usual x-y plot, |
---|
12 | % 'civdata...': go back to automatic reading of civ data |
---|
13 | % .PanelVectors: sub-structure variables used as vector components |
---|
14 | % .PanelScalar: |
---|
15 | % INPUT: |
---|
16 | % FileName: name (including path) of the netcdf file to open |
---|
17 | % ParmIn: structure containing parameters for preselecting menus: |
---|
18 | % .Title: set the title of the GUI get_field |
---|
19 | % .SwitchVarIndexTime='file index','variable' or 'matrix index': select the default option for 'time' |
---|
20 | % .TimeAttrName: preselect the name of a global attribute for time |
---|
21 | % .SeriesInput=1 if get_field is called by the GUI series,=0 otherwise (plot options provided in the latter case) |
---|
22 | % .Coord_x,.Coord_y,.Coord_z, names of the variables used as the three coordinates |
---|
23 | % .scalar : set the default choise of the scale variable |
---|
24 | % .vector_x, .vector_y : set the default choise for the variables used for the x and y vector components |
---|
25 | |
---|
26 | %======================================================================= |
---|
27 | % Copyright 2008-2020, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
28 | % http://www.legi.grenoble-inp.fr |
---|
29 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
30 | % |
---|
31 | % This file is part of the toolbox UVMAT. |
---|
32 | % |
---|
33 | % UVMAT is free software; you can redistribute it and/or modify |
---|
34 | % it under the terms of the GNU General Public License as published |
---|
35 | % by the Free Software Foundation; either version 2 of the license, |
---|
36 | % or (at your option) any later version. |
---|
37 | % |
---|
38 | % UVMAT is distributed in the hope that it will be useful, |
---|
39 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
40 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
41 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
42 | %======================================================================= |
---|
43 | |
---|
44 | function varargout = get_field(varargin) |
---|
45 | |
---|
46 | % Last Modified by GUIDE v2.5 18-Feb-2015 23:42:12 |
---|
47 | |
---|
48 | % Begin initialization code - DO NOT EDIT |
---|
49 | gui_Singleton = 1; |
---|
50 | gui_State = struct('gui_Name', mfilename, ... |
---|
51 | 'gui_Singleton', gui_Singleton, ... |
---|
52 | 'gui_OpeningFcn', @get_field_OpeningFcn, ... |
---|
53 | 'gui_OutputFcn', @get_field_OutputFcn, ... |
---|
54 | 'gui_LayoutFcn', [] , ... |
---|
55 | 'gui_Callback', []); |
---|
56 | if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
57 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
58 | end |
---|
59 | |
---|
60 | if nargout |
---|
61 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
62 | else |
---|
63 | gui_mainfcn(gui_State, varargin{:}); |
---|
64 | end |
---|
65 | % End initialization code - DO NOT EDIT |
---|
66 | |
---|
67 | %------------------------------------------------------------------------ |
---|
68 | % --- Executes just before get_field is made visible. |
---|
69 | %------------------------------------------------------------------------ |
---|
70 | function get_field_OpeningFcn(hObject, eventdata, handles,filename,ParamIn) |
---|
71 | |
---|
72 | %% GUI settings |
---|
73 | handles.output = 'Cancel'; |
---|
74 | guidata(hObject, handles); |
---|
75 | set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display) |
---|
76 | set(hObject,'CloseRequestFcn',{@closefcn,handles}) |
---|
77 | |
---|
78 | %% enter input data |
---|
79 | if ischar(filename) % input file name |
---|
80 | set(handles.inputfile,'String',filename)% fill the input file name |
---|
81 | [Field,tild,tild,errormsg]=nc2struct(filename,[]);% reads the field structure, without the variables |
---|
82 | else |
---|
83 | msgbox_uvmat('ERROR','get_field requires a file name as input')% display error message for input file reading |
---|
84 | return |
---|
85 | end |
---|
86 | if ~isempty(errormsg) |
---|
87 | msgbox_uvmat('ERROR',['get_field/nc2struct/' errormsg])% display error message for input file reading |
---|
88 | return |
---|
89 | end |
---|
90 | if ~isfield(Field,'ListVarName') |
---|
91 | msgbox_uvmat('ERROR',['no variable found in ' filename])% display error message for input file reading |
---|
92 | return |
---|
93 | end |
---|
94 | if ~exist('ParamIn','var') |
---|
95 | ParamIn.Coord_z=''; |
---|
96 | end |
---|
97 | |
---|
98 | %% look at singletons and variables with a single dimension |
---|
99 | Field.Display=Field; |
---|
100 | Field.Check0D=zeros(size(Field.ListVarName));% =1 for arrays with a single value |
---|
101 | NbVar=numel(Field.VarDimName);%nbre of variables in the input data |
---|
102 | for ilist=1:NbVar |
---|
103 | if ischar(Field.VarDimName{ilist}) |
---|
104 | Field.VarDimName{ilist}={Field.VarDimName{ilist}}; %transform string into cell |
---|
105 | end |
---|
106 | NbDim=numel(Field.VarDimName{ilist}); |
---|
107 | check_singleton=false(1,NbDim);% check singleton, false by default |
---|
108 | for idim=1:NbDim |
---|
109 | dim_index=strcmp(Field.VarDimName{ilist}{idim},Field.ListDimName);%index in the list of dimensions |
---|
110 | check_singleton(idim)=isequal(Field.DimValue(dim_index),1);%check_singleton=1 for singleton |
---|
111 | end |
---|
112 | Field.Check0D(ilist)=(isequal(check_singleton,ones(1,NbDim)))||(~isequal(Field.VarType(ilist),4)&&~isequal(Field.VarType(ilist),5)&&~isequal(Field.VarType(ilist),6));% =1 if the variable reduces to a single value |
---|
113 | if ~Field.Check0D(ilist) |
---|
114 | Field.Display.VarDimName{ilist}=Field.VarDimName{ilist}(~check_singleton);% eliminate singletons in the list of variable dimensions |
---|
115 | end |
---|
116 | end |
---|
117 | if ~isfield(Field,'VarAttribute') |
---|
118 | Field.VarAttribute={}; |
---|
119 | end |
---|
120 | if numel(Field.VarAttribute)<NbVar% complement VarAttribute by blanjs if neded |
---|
121 | Field.VarAttribute(numel(Field.VarAttribute)+1:NbVar)=cell(1,NbVar-numel(Field.VarAttribute)); |
---|
122 | end |
---|
123 | % Field.Display = list of variables and corresponding properties obtained after removal of variables with a single value and singleton dimensions |
---|
124 | Field.Display.ListVarName=Field.ListVarName(~Field.Check0D); %list of variables available for plots, after eliminating variables with a single value |
---|
125 | Field.Display.VarAttribute=Field.VarAttribute(~Field.Check0D); |
---|
126 | Field.Display.VarDimName=Field.Display.VarDimName(~Field.Check0D); |
---|
127 | Field.Display.ListDimName=Field.ListDimName(Field.DimValue~=1);% list of non singleton dimension names |
---|
128 | Field.Display.DimValue=Field.DimValue(Field.DimValue~=1);% corresponding list of non singleton dimension values |
---|
129 | |
---|
130 | |
---|
131 | %% analyse the input field cells |
---|
132 | [CellInfo,NbDim,errormsg]=find_field_cells(Field.Display); |
---|
133 | if ~isempty(errormsg) |
---|
134 | msgbox_uvmat('ERROR',['get_field / Field_input / find_field_cells: ' errormsg]) |
---|
135 | return |
---|
136 | end |
---|
137 | if isempty(CellInfo) |
---|
138 | [Field.MaxDim,imax]=max(cellfun(@numel,Field.Display.VarDimName));% maximum number of dimensions for the input fields |
---|
139 | ListDim=Field.Display.VarDimName{imax}; |
---|
140 | check_cellinfo=false; |
---|
141 | else |
---|
142 | [Field.MaxDim,imax]=max(NbDim);% maximum number of dimensions for the input fields identified by attributes |
---|
143 | check_cellinfo=true; |
---|
144 | end |
---|
145 | |
---|
146 | %% set time mode |
---|
147 | ListSwitchVarIndexTime={'file index'};% default setting: the time is the file index |
---|
148 | % look at global attributes with numerical values |
---|
149 | check_numvalue=false(1,numel(Field.ListGlobalAttribute)); |
---|
150 | for ilist=1:numel(Field.ListGlobalAttribute) |
---|
151 | Value=Field.(Field.ListGlobalAttribute{ilist}); |
---|
152 | check_numvalue(ilist)=isnumeric(Value); |
---|
153 | end |
---|
154 | Field.Display.ListGlobalAttribute=Field.ListGlobalAttribute(check_numvalue);% select the attributes with float numerical value |
---|
155 | if ~isempty(Field.Display.ListGlobalAttribute) |
---|
156 | ListSwitchVarIndexTime=[ListSwitchVarIndexTime; {'attribute'}];% the time can be chosen as a global attribute |
---|
157 | end |
---|
158 | |
---|
159 | Check_index=0; |
---|
160 | if Field.MaxDim>=2 |
---|
161 | ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'variable'};{'matrix index'}];% the time can be chosen as a dim index |
---|
162 | else |
---|
163 | for ilist=1:numel(Field.Display.VarDimName) |
---|
164 | NbComponent=numel(Field.Display.VarDimName{ilist}); |
---|
165 | if NbComponent>=2% multicomponent matrices without coordinate variables (thus not considered in the fct find_field_cell) |
---|
166 | ListSwitchVarIndexTime=[ListSwitchVarIndexTime;{'matrix index'}];% the time can be chosen as a dim index |
---|
167 | Check_index=1; |
---|
168 | break |
---|
169 | end |
---|
170 | end |
---|
171 | end |
---|
172 | |
---|
173 | %% select the Time attribute from input |
---|
174 | if Field.MaxDim >2 |
---|
175 | variable_index=find(strcmp('variable',ListSwitchVarIndexTime),1); |
---|
176 | set(handles.SwitchVarIndexTime,'Value',variable_index); |
---|
177 | else |
---|
178 | if isfield(ParamIn,'TimeAttrName')&& ~isempty(ParamIn.TimeAttrName) |
---|
179 | time_index=find(strcmp(ParamIn.TimeAttrName,Field.Display.ListGlobalAttribute),1); |
---|
180 | else |
---|
181 | time_index=find(strcmp('Time',Field.Display.ListGlobalAttribute));% look for global attribute containing name 'Time' |
---|
182 | end |
---|
183 | if isempty(time_index) |
---|
184 | set(handles.SwitchVarIndexTime,'Value',1); |
---|
185 | else |
---|
186 | set(handles.SwitchVarIndexTime,'Value',2); |
---|
187 | set(handles.TimeName,'UserData',time_index) |
---|
188 | end |
---|
189 | end |
---|
190 | set(handles.SwitchVarIndexTime,'String',ListSwitchVarIndexTime) |
---|
191 | set(handles.SwitchVarIndexTime,'UserData',ListSwitchVarIndexTime); % keep string in memory for check3D |
---|
192 | set(handles.get_field,'UserData',Field);% record the finput field structure |
---|
193 | SwitchVarIndexTime_Callback([], [], handles) |
---|
194 | |
---|
195 | %% set vector menu (priority) if detected or scalar menu for space dim >=2, or usual (x,y) plot for 1D fields |
---|
196 | set(handles.vector_x,'String',Field.Display.ListVarName)% fill the menu of x vector components |
---|
197 | set(handles.vector_y,'String',Field.Display.ListVarName)% fill the menu of y vector components |
---|
198 | set(handles.vector_z,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components |
---|
199 | set(handles.vec_color,'String',[{''} Field.Display.ListVarName])% fill the menu of y vector components |
---|
200 | set(handles.scalar,'Value',1)% fill the menu of y vector components |
---|
201 | set(handles.scalar,'String',Field.Display.ListVarName)% fill the menu for scalar |
---|
202 | %set(handles.ordinate,'Value',1)% fill the menu of y vector components |
---|
203 | %set(handles.ordinate,'String',Field.Display.ListVarName)% fill the menu of y coordinate for 1D plots |
---|
204 | checkseries=0; |
---|
205 | if isfield(ParamIn,'SeriesInput') && ParamIn.SeriesInput% case of call by series |
---|
206 | set(handles.FieldOption,'value',1) |
---|
207 | if isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata') |
---|
208 | set(handles.FieldOption,'String',{'scalar';'vectors';'civdata...'}) |
---|
209 | else |
---|
210 | set(handles.FieldOption,'String',{'scalar';'vectors'}) |
---|
211 | end |
---|
212 | checkseries=1; |
---|
213 | set(handles.scalar,'Max',2) |
---|
214 | elseif isfield(Field,'Conventions')&& strcmp(Field.Conventions,'uvmat/civdata') |
---|
215 | set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors';'civdata...'})% provides the possibility to come back to civdata |
---|
216 | set(handles.scalar,'Max',1) |
---|
217 | else |
---|
218 | set(handles.FieldOption,'String',{'1D plot';'scalar';'vectors'}) |
---|
219 | set(handles.scalar,'Max',1) |
---|
220 | end |
---|
221 | |
---|
222 | %% set default field options |
---|
223 | checknbdim=cellfun('size',Field.Display.VarDimName,2); |
---|
224 | % if max(checknbdim)<=1 |
---|
225 | % Field.MaxDim=1;% only 1D fields, considered as a time series by default |
---|
226 | % end |
---|
227 | if Field.MaxDim>=2 && ~checkseries% case of 2D (or 3D) fields |
---|
228 | check_vec_input=0; |
---|
229 | % case of vector initially selected from uvmat input |
---|
230 | if isfield(ParamIn,'vector_x')&& isfield(ParamIn,'vector_y') |
---|
231 | ichoice_x=find(strcmp(ParamIn.vector_x,Field.Display.ListVarName),1); |
---|
232 | ichoice_y=find(strcmp(ParamIn.vector_y,Field.Display.ListVarName),1); |
---|
233 | if ~isempty(ichoice_x)&&~isempty(ichoice_y) |
---|
234 | set(handles.vector_x,'UserData',ichoice_x) |
---|
235 | set(handles.vector_y,'UserData',ichoice_y) |
---|
236 | check_vec_input=1; |
---|
237 | end |
---|
238 | end |
---|
239 | % otherwise select vectors marked as attributes in the input field |
---|
240 | if check_cellinfo && ~check_vec_input && isfield(CellInfo{imax},'VarIndex_vector_x') && isfield(CellInfo{imax},'VarIndex_vector_y') |
---|
241 | set(handles.vector_x,'UserData',CellInfo{imax}.VarIndex_vector_x(1)) |
---|
242 | set(handles.vector_y,'UserData',CellInfo{imax}.VarIndex_vector_y(1)) |
---|
243 | check_vec_input=1; |
---|
244 | end |
---|
245 | if check_vec_input |
---|
246 | set(handles.FieldOption,'Value',3)% set vector selection option |
---|
247 | else |
---|
248 | set(handles.FieldOption,'Value',2)% set scalar selection option |
---|
249 | end |
---|
250 | else % case of 1D fields |
---|
251 | set(handles.FieldOption,'Value',1) |
---|
252 | end |
---|
253 | |
---|
254 | %% fill the general list of dimensions, variables, attributes |
---|
255 | if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName) |
---|
256 | Tabcell(:,1)=Field.ListDimName; |
---|
257 | for iline=1:length(Field.ListDimName) |
---|
258 | Tabcell{iline,2}=num2str(Field.DimValue(iline)); |
---|
259 | end |
---|
260 | Tabchar=cell2tab(Tabcell,' = '); |
---|
261 | set(handles.dimensions,'String',Tabchar) |
---|
262 | end |
---|
263 | |
---|
264 | %% fill menus for coordinates and time |
---|
265 | FieldOption_Callback(handles.variables,[], handles)% list the global attributes |
---|
266 | |
---|
267 | %% put the GUI on the lower right of the sceen |
---|
268 | set(hObject,'Unit','pixels') |
---|
269 | %pos_view_field=get(hObject,'Position'); |
---|
270 | set(0,'Unit','pixels') |
---|
271 | ScreenSize=get(0,'ScreenSize'); |
---|
272 | pos_view_field(3:4)=[955 648]; |
---|
273 | pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3); |
---|
274 | pos_view_field(2)=ScreenSize(2); |
---|
275 | set(hObject,'Position',pos_view_field) |
---|
276 | set(handles.get_field,'WindowStyle','modal')% Make the GUI modal |
---|
277 | if isfield(ParamIn,'Title') |
---|
278 | set(hObject,'Name',ParamIn.Title) |
---|
279 | end |
---|
280 | |
---|
281 | %% set z coordinate menu if relevant |
---|
282 | if Field.MaxDim>=3 && prod(Field.DimValue)<10^8 && ~(isfield(ParamIn,'Coord_z') && isempty(ParamIn.Coord_z)) % 3D field (with memory content smaller than 400 Mo) |
---|
283 | set(handles.Check3D,'Value',1) |
---|
284 | else |
---|
285 | set(handles.Check3D,'Value',0) |
---|
286 | end |
---|
287 | Check3D_Callback(hObject, eventdata, handles) |
---|
288 | set(handles.variables,'Value',1) |
---|
289 | set(handles.variables,'String',[{'*'} Field.ListVarName]) |
---|
290 | variables_Callback(handles.variables,[], handles)% list the global attributes |
---|
291 | drawnow |
---|
292 | uiwait(handles.get_field); |
---|
293 | |
---|
294 | % ----------------------------------------------------------------------- |
---|
295 | % --- Activated by selection in the list of variables |
---|
296 | % ---------------------------------------------------------------------- |
---|
297 | function variables_Callback(hObject, VarName, handles) |
---|
298 | |
---|
299 | Tabchar={''};%default |
---|
300 | Tabcell=[]; |
---|
301 | hselect_field=get(handles.variables,'parent'); |
---|
302 | Field=get(handles.get_field,'UserData'); |
---|
303 | index=get(handles.variables,'Value');%index in the list 'variables' |
---|
304 | |
---|
305 | %% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected |
---|
306 | if isequal(index,1) |
---|
307 | set(handles.attributes_txt,'String','global attributes') |
---|
308 | if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute) |
---|
309 | for iline=1:length(Field.ListGlobalAttribute) |
---|
310 | Tabcell{iline,1}=Field.ListGlobalAttribute{iline}; |
---|
311 | if isfield(Field, Field.ListGlobalAttribute{iline}) |
---|
312 | val=Field.(Field.ListGlobalAttribute{iline}); |
---|
313 | if ischar(val);% attribute value is char string |
---|
314 | Tabcell{iline,2}=val; |
---|
315 | elseif size(val,1)==1 %attribute value is a number or matlab vector |
---|
316 | Tabcell{iline,2}=num2str(val); |
---|
317 | end |
---|
318 | end |
---|
319 | end |
---|
320 | Tabchar=cell2tab(Tabcell,'='); |
---|
321 | end |
---|
322 | %% list Attribute names and values associated to the Variable # index-1 |
---|
323 | else |
---|
324 | list_var=get(handles.variables,'String'); |
---|
325 | if index>numel(list_var) |
---|
326 | return |
---|
327 | end |
---|
328 | VarName=list_var{index}; |
---|
329 | set(handles.attributes_txt,'String', ['attributes of ' VarName]) |
---|
330 | if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1 |
---|
331 | VarAttr=Field.VarAttribute{index-1}; |
---|
332 | if isstruct(VarAttr) |
---|
333 | attr_list=fieldnames(VarAttr); |
---|
334 | for iline=1:length(attr_list) |
---|
335 | Tabcell{iline,1}=attr_list{iline}; |
---|
336 | val=VarAttr.(attr_list{iline}) ; |
---|
337 | if ischar(val); |
---|
338 | Tabcell{iline,2}=val; |
---|
339 | else |
---|
340 | Tabcell{iline,2}=num2str(val); |
---|
341 | end |
---|
342 | end |
---|
343 | end |
---|
344 | end |
---|
345 | end |
---|
346 | if ~isempty(Tabcell) |
---|
347 | Tabchar=cell2tab(Tabcell,'='); |
---|
348 | end |
---|
349 | set(handles.attributes,'Value',1);% select the first item |
---|
350 | set(handles.attributes,'String',Tabchar); |
---|
351 | |
---|
352 | %% update dimensions; |
---|
353 | if isfield(Field,'ListDimName') |
---|
354 | Tabdim={};%default |
---|
355 | if isequal(index,1)%list all dimensions if '*' is selected as the variable |
---|
356 | dim_indices=1:length(Field.ListDimName); |
---|
357 | set(handles.dimensions_txt,'String', 'dimensions') |
---|
358 | else % a specific variable has been selected |
---|
359 | DimCell=Field.VarDimName{index-1}; |
---|
360 | if ischar(DimCell) |
---|
361 | DimCell={DimCell};% transform into a cell for a single dimension defined by a char string |
---|
362 | end |
---|
363 | dim_indices=[]; |
---|
364 | for idim=1:length(DimCell) |
---|
365 | dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0 |
---|
366 | dim_index=find(dim_index,1); |
---|
367 | dim_indices=[dim_indices dim_index]; |
---|
368 | end |
---|
369 | set(handles.dimensions_txt,'String', ['dimensions of ' VarName]) |
---|
370 | end |
---|
371 | for iline=1:length(dim_indices) |
---|
372 | Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)}; |
---|
373 | Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline))); |
---|
374 | end |
---|
375 | Tabchar=cell2tab(Tabdim,' = '); |
---|
376 | Tabchar=[{''} ;Tabchar]; |
---|
377 | set(handles.dimensions,'Value',1) |
---|
378 | set(handles.dimensions,'String',Tabchar) |
---|
379 | end |
---|
380 | |
---|
381 | %% propose a plot by default if variables_Callback has not been already called by FieldOption_Callback (VarName is not a char string) |
---|
382 | if ~ischar(VarName) && ~isequal(index,1) |
---|
383 | if numel(DimCell)==1 |
---|
384 | set(handles.FieldOption,'Value',1)%propose 1D plot |
---|
385 | else |
---|
386 | set(handles.FieldOption,'Value',2)%propose scalar plot |
---|
387 | end |
---|
388 | if numel(DimCell)<=2 |
---|
389 | set(handles.Check3D,'Value',0) |
---|
390 | else |
---|
391 | set(handles.Check3D,'Value',1) |
---|
392 | end |
---|
393 | FieldOption_Callback(hObject, VarName, handles) |
---|
394 | end |
---|
395 | |
---|
396 | %------------------------------------------------------------------------ |
---|
397 | % --- Executes on selection change in FieldOption. |
---|
398 | %------------------------------------------------------------------------ |
---|
399 | function FieldOption_Callback(hObject, VarName, handles) |
---|
400 | |
---|
401 | Field=get(handles.get_field,'UserData'); |
---|
402 | FieldList=get(handles.FieldOption,'String'); |
---|
403 | FieldOption=FieldList{get(handles.FieldOption,'Value')}; |
---|
404 | switch FieldOption |
---|
405 | case '1D plot' |
---|
406 | set(handles.Coordinates,'Visible','on') |
---|
407 | %set(handles.PanelOrdinate,'Visible','on') |
---|
408 | %pos=get(handles.PanelOrdinate,'Position'); |
---|
409 | % pos(1)=2; |
---|
410 | % pos_coord=get(handles.Coordinates,'Position'); |
---|
411 | % pos(2)=pos_coord(2)-pos(4)-2; |
---|
412 | %set(handles.PanelOrdinate,'Position',pos) |
---|
413 | set(handles.PanelScalar,'Visible','off') |
---|
414 | set(handles.PanelVectors,'Visible','off') |
---|
415 | set(handles.Coord_y,'Visible','on') |
---|
416 | set(handles.Coord_y,'Max',2)%allow multiple selection |
---|
417 | set(handles.Y_title,'Visible','on') |
---|
418 | set(handles.Coord_z,'Visible','off') |
---|
419 | set(handles.Z_title,'Visible','off') |
---|
420 | set(handles.Coord_x,'String',Field.Display.ListVarName') |
---|
421 | Coord_x_Callback(hObject, VarName, handles) |
---|
422 | %set(handles.Coord_y,'String',Field.Display.ListVarName') |
---|
423 | %Coord_x_Callback(hObject, VarName, handles) |
---|
424 | case {'scalar'} |
---|
425 | set(handles.Coordinates,'Visible','on') |
---|
426 | %set(handles.PanelOrdinate,'Visible','off') |
---|
427 | set(handles.PanelScalar,'Visible','on') |
---|
428 | set(handles.PanelVectors,'Visible','off') |
---|
429 | pos=get(handles.PanelScalar,'Position'); |
---|
430 | pos(1)=2; |
---|
431 | pos_coord=get(handles.Coordinates,'Position'); |
---|
432 | pos(2)=pos_coord(2)-pos(4)-2; |
---|
433 | set(handles.PanelScalar,'Position',pos) |
---|
434 | set(handles.Coord_y,'Visible','on') |
---|
435 | set(handles.Y_title,'Visible','on') |
---|
436 | if ~ischar(VarName) |
---|
437 | %default scalar selection |
---|
438 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante |
---|
439 | for ilist=1:numel(Field.Display.VarDimName) |
---|
440 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') |
---|
441 | Role=Field.Display.VarAttribute{ilist}.Role; |
---|
442 | if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') |
---|
443 | test_coord(ilist)=1; |
---|
444 | end |
---|
445 | end |
---|
446 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
447 | if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable |
---|
448 | test_coord(ilist)=1; |
---|
449 | end |
---|
450 | end |
---|
451 | scalar_index=find(~test_coord,1);%get the first variable not a coordinate |
---|
452 | if isempty(scalar_index) |
---|
453 | set(handles.scalar,'Value',1) |
---|
454 | else |
---|
455 | set(handles.scalar,'Value',scalar_index) |
---|
456 | end |
---|
457 | end |
---|
458 | scalar_Callback(hObject,VarName, handles) |
---|
459 | case 'vectors' |
---|
460 | set(handles.PanelVectors,'Visible','on') |
---|
461 | set(handles.Coordinates,'Visible','on') |
---|
462 | %set(handles.PanelOrdinate,'Visible','off') |
---|
463 | set(handles.PanelScalar,'Visible','off') |
---|
464 | pos=get(handles.PanelVectors,'Position'); |
---|
465 | pos(1)=2; |
---|
466 | pos_coord=get(handles.Coordinates,'Position'); |
---|
467 | pos(2)=pos_coord(2)-pos(4)-2; |
---|
468 | set(handles.PanelVectors,'Position',pos) |
---|
469 | set(handles.Coord_y,'Visible','on') |
---|
470 | set(handles.Y_title,'Visible','on') |
---|
471 | %default vector selection |
---|
472 | vector_x_value=get(handles.vector_x,'UserData'); |
---|
473 | vector_y_value=get(handles.vector_y,'UserData'); |
---|
474 | if ~isempty(vector_x_value)&&~isempty(vector_y_value) |
---|
475 | set(handles.vector_x,'Value',vector_x_value) |
---|
476 | set(handles.vector_y,'Value',vector_y_value) |
---|
477 | else |
---|
478 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate |
---|
479 | for ilist=1:numel(Field.Display.VarDimName) |
---|
480 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') |
---|
481 | Role=Field.Display.VarAttribute{ilist}.Role; |
---|
482 | if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') |
---|
483 | test_coord(ilist)=1; |
---|
484 | end |
---|
485 | end |
---|
486 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
487 | if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable |
---|
488 | test_coord(ilist)=1; |
---|
489 | end |
---|
490 | end |
---|
491 | vector_index=find(~test_coord,2);%get the two first variables not a coordinate |
---|
492 | if isempty(vector_index) |
---|
493 | set(handles.vector_x,'Value',1) |
---|
494 | set(handles.vector_y,'Value',2) |
---|
495 | else |
---|
496 | set(handles.vector_x,'Value',vector_index(1)) |
---|
497 | set(handles.vector_y,'Value',vector_index(2)) |
---|
498 | end |
---|
499 | end |
---|
500 | vector_Callback(handles) |
---|
501 | case 'civdata...' |
---|
502 | %set(handles.PanelOrdinate,'Visible','off') |
---|
503 | set(handles.PanelScalar,'Visible','off') |
---|
504 | set(handles.PanelVectors,'Visible','off') |
---|
505 | set(handles.Coordinates,'Visible','off') |
---|
506 | end |
---|
507 | |
---|
508 | |
---|
509 | function set_coord_y_options(handles,VarName) |
---|
510 | %------------------------------------------------------------------------ |
---|
511 | Field=get(handles.get_field,'UserData'); |
---|
512 | VarIndex=find(strcmp(VarName,Field.Display.ListVarName),1); |
---|
513 | DimCell=Field.Display.VarDimName{VarIndex}; |
---|
514 | % y_index=get(handles.Coord_y,'Value'); |
---|
515 | % y_menu=get(handles.Coord_y,'String'); |
---|
516 | % if isempty(y_menu) |
---|
517 | % return |
---|
518 | % else |
---|
519 | % YName=y_menu{y_index}; |
---|
520 | % end |
---|
521 | |
---|
522 | %% set list of possible coordinates |
---|
523 | % test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate |
---|
524 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante |
---|
525 | % ListCoord={''}; |
---|
526 | % dim_var=Field.Display.VarDimName{y_index};%list of dimensions of the selected variable |
---|
527 | |
---|
528 | for ilist=1:numel(Field.Display.VarDimName) |
---|
529 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
530 | if isequal(dimnames,DimCell)||isequal(dimnames(1:end-1),DimCell)||isequal(dimnames(2:end),DimCell) |
---|
531 | test_coord(ilist)=1; |
---|
532 | end |
---|
533 | end |
---|
534 | ListCoord=Field.Display.ListVarName(find(test_coord)); |
---|
535 | set(handles.Coord_y,'String',ListCoord) |
---|
536 | val_y=1; |
---|
537 | if strcmp(VarName,ListCoord{1})&& numel(ListCoord)>=2 |
---|
538 | val_y=2; |
---|
539 | end |
---|
540 | set(handles.Coord_y,'Value',val_y) |
---|
541 | |
---|
542 | %% set default coord selection |
---|
543 | % if numel(find(test_coord))>3 |
---|
544 | % SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String'); |
---|
545 | % if numel(SwitchVarIndexTime)<3 |
---|
546 | % SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index']; |
---|
547 | % set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime) |
---|
548 | % end |
---|
549 | % set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time |
---|
550 | % SwitchVarIndexTime_Callback([], [], handles) |
---|
551 | % end |
---|
552 | % if numel(var_component)<2 |
---|
553 | % if numel(test_coord)<2 |
---|
554 | % ListCoord={''}; |
---|
555 | % else |
---|
556 | % set(handles.Coord_x,'Value',2) |
---|
557 | % set(handles.Coord_y,'Value',1) |
---|
558 | % end |
---|
559 | % else |
---|
560 | % coord_val=1; |
---|
561 | % for ilist=1:numel(var_component) |
---|
562 | % ivar=var_component(ilist); |
---|
563 | % if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role') |
---|
564 | % Role=Field.Display.VarAttribute{ivar}.Role; |
---|
565 | % if strcmp(Role,'coord_x') |
---|
566 | % coord_val=ilist; |
---|
567 | % end |
---|
568 | % end |
---|
569 | % end |
---|
570 | % set(handles.Coord_x,'Value',coord_val+1) |
---|
571 | % end |
---|
572 | % set(handles.Coord_x,'String',[{''}; ListCoord]) |
---|
573 | |
---|
574 | |
---|
575 | % %% set list of time coordinates |
---|
576 | % menu=get(handles.SwitchVarIndexTime,'String'); |
---|
577 | % TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
578 | % switch TimeOption |
---|
579 | % case 'variable' |
---|
580 | % if numel(find(test_coord))<3 |
---|
581 | % ListTime={''}; |
---|
582 | % else |
---|
583 | % ListTime=Field.Display.ListVarName(find(test_coord,end)); |
---|
584 | % end |
---|
585 | % set(handles.TimeName,'Value',1) |
---|
586 | % set(handles.TimeName,'String',ListTime) |
---|
587 | % case 'matrix index' |
---|
588 | % if numel(find(test_coord))<3 |
---|
589 | % ListTime={''}; |
---|
590 | % else |
---|
591 | % ListTime=Field.Display.VarDimName{find(test_coord,end)}; |
---|
592 | % end |
---|
593 | % set(handles.TimeName,'Value',1) |
---|
594 | % set(handles.TimeName,'String',ListTime) |
---|
595 | % end |
---|
596 | % if ~ischar(DimCell) |
---|
597 | % update_field(handles,YName) |
---|
598 | % end |
---|
599 | |
---|
600 | %------------------------------------------------------------------------ |
---|
601 | % --- Executes on selection change in scalar menu. |
---|
602 | %------------------------------------------------------------------------ |
---|
603 | function scalar_Callback(hObject, VarName, handles) |
---|
604 | |
---|
605 | Field=get(handles.get_field,'UserData');% get the input field info stored in UserData of the GUI |
---|
606 | scalar_menu=get(handles.scalar,'String');% read the menu for scalar selection |
---|
607 | if ischar(VarName)% case of a call with input variable |
---|
608 | ScalarName=VarName; |
---|
609 | scalar_index=find(strcmp(VarName,scalar_menu)); |
---|
610 | set(handles.scalar,'Value',scalar_index)% select the input variable field in the menu |
---|
611 | else % no input variable, the variable ScalarName is selected from the menu |
---|
612 | scalar_index=get(handles.scalar,'Value'); |
---|
613 | ScalarName=scalar_menu{scalar_index}; |
---|
614 | end |
---|
615 | |
---|
616 | %% set list of possible coordinates |
---|
617 | test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate |
---|
618 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante |
---|
619 | dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable |
---|
620 | %if ~get(handles.CheckDimensionX,'Value') |
---|
621 | %look for coordinate variables among the other variables |
---|
622 | for ilist=1:numel(Field.Display.VarDimName) |
---|
623 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
624 | if isequal(dimnames,dim_var) |
---|
625 | test_component(ilist)=1;% the listed variable has the same dimension as the selected scalar-> possibly chosen as unstructured coordinate |
---|
626 | elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var), 1))%variable ilist is a 1D array which can be coordinate variable |
---|
627 | test_coord(ilist)=1; |
---|
628 | end |
---|
629 | end |
---|
630 | %end |
---|
631 | var_component=find(test_component);% list of variable indices elligible as unstructured coordinates |
---|
632 | var_coord=find(test_coord);% % list of variable indices elligible as gridded coordinates |
---|
633 | index_coord=[]; |
---|
634 | index_component=[]; |
---|
635 | for iscalar=1:numel(scalar_index) |
---|
636 | index_component=[index_component find(var_component==scalar_index(iscalar),1)]; |
---|
637 | index_coord=[index_coord find(var_coord==scalar_index(iscalar),1)]; |
---|
638 | end |
---|
639 | var_component(index_component)=[]; |
---|
640 | var_coord(index_coord)=[]; |
---|
641 | ListCoord=Field.Display.ListVarName([var_coord var_component]); |
---|
642 | coord_val=zeros(size(ListCoord)); |
---|
643 | |
---|
644 | %% set default selection for grid coordinates |
---|
645 | if numel(var_coord)>=2 |
---|
646 | coord_val(1)=var_coord(end); |
---|
647 | coord_val(2)=var_coord(end-1); |
---|
648 | if numel(var_coord)>=3 |
---|
649 | coord_val(3)=var_coord(end-2); |
---|
650 | end |
---|
651 | end |
---|
652 | % if numel(find(test_coord))>3 |
---|
653 | % SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String'); |
---|
654 | % if numel(SwitchVarIndexTime)<3 |
---|
655 | % SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index']; |
---|
656 | % set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime) |
---|
657 | % end |
---|
658 | % set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time |
---|
659 | % SwitchVarIndexTime_Callback([], [], handles) |
---|
660 | % end |
---|
661 | |
---|
662 | %% default selection for labelled unstructured coordinates |
---|
663 | for ilist=1:numel(var_component) |
---|
664 | ivar=var_component(ilist); |
---|
665 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role') |
---|
666 | Role=Field.Display.VarAttribute{ivar}.Role; |
---|
667 | if strcmp(Role,'coord_x') |
---|
668 | coord_val(1)=ilist; |
---|
669 | elseif strcmp(Role,'coord_y') |
---|
670 | coord_val(2)=ilist; |
---|
671 | elseif strcmp(Role,'coord_z') |
---|
672 | coord_val(3)=ilist; |
---|
673 | end |
---|
674 | end |
---|
675 | end |
---|
676 | if numel(find(coord_val))<2 % no predefiend components |
---|
677 | if numel(var_coord)>=3 |
---|
678 | coord_val(3)=3; |
---|
679 | end |
---|
680 | coord_val([1 2])=[1 2]; |
---|
681 | end |
---|
682 | |
---|
683 | %% set menu and default selection for coordinates |
---|
684 | set(handles.Coord_x,'Value',coord_val(1)) |
---|
685 | set(handles.Coord_x,'String',ListCoord) |
---|
686 | set(handles.Coord_y,'Value',coord_val(2)) |
---|
687 | set(handles.Coord_y,'String',ListCoord) |
---|
688 | if numel(find(coord_val))>=3 |
---|
689 | set(handles.Coord_z,'Value',coord_val(3)) |
---|
690 | set(handles.Coord_z,'String',ListCoord) |
---|
691 | set(handles.Coord_z,'Visible','on') |
---|
692 | set(handles.Check3D,'Value', 1) |
---|
693 | end |
---|
694 | |
---|
695 | %% set list of time coordinates |
---|
696 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
697 | TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
698 | switch TimeOption |
---|
699 | case 'variable' |
---|
700 | if numel(find(test_coord))<3 |
---|
701 | ListTime={''}; |
---|
702 | else |
---|
703 | ListTime=Field.Display.ListVarName(find(test_coord,end)); |
---|
704 | end |
---|
705 | set(handles.TimeName,'Value',1) |
---|
706 | set(handles.TimeName,'String',ListTime) |
---|
707 | case 'dim index' |
---|
708 | if numel(find(test_coord))<3 |
---|
709 | ListTime={''}; |
---|
710 | else |
---|
711 | ListTime=Field.Display.VarDimName{find(test_coord,end)}; |
---|
712 | end |
---|
713 | set(handles.TimeName,'Value',1) |
---|
714 | set(handles.TimeName,'String',ListTime) |
---|
715 | end |
---|
716 | if ~ischar(VarName) |
---|
717 | update_field(handles,ScalarName) |
---|
718 | end |
---|
719 | |
---|
720 | % --- Executes on button press in check_rgb. |
---|
721 | function check_rgb_Callback(hObject, eventdata, handles) |
---|
722 | |
---|
723 | |
---|
724 | %------------------------------------------------------------------------ |
---|
725 | % --- Executes on selection change in vector_x. |
---|
726 | %------------------------------------------------------------------------ |
---|
727 | function vector_x_Callback(hObject, DimCell, handles) |
---|
728 | |
---|
729 | vector_x_menu=get(handles.vector_x,'String'); |
---|
730 | vector_x_index=get(handles.vector_x,'Value'); |
---|
731 | vector_x=vector_x_menu{vector_x_index}; |
---|
732 | vector_Callback(handles) |
---|
733 | if ~ischar(DimCell) |
---|
734 | update_field(handles,vector_x) |
---|
735 | end |
---|
736 | |
---|
737 | %------------------------------------------------------------------------ |
---|
738 | % --- Executes on selection change in vector_x. |
---|
739 | %------------------------------------------------------------------------ |
---|
740 | function vector_y_Callback(hObject, DimCell, handles) |
---|
741 | |
---|
742 | vector_y_menu=get(handles.vector_x,'String'); |
---|
743 | vector_y_index=get(handles.vector_x,'Value'); |
---|
744 | vector_y=vector_y_menu{vector_y_index}; |
---|
745 | vector_Callback(handles) |
---|
746 | if ~ischar(DimCell) |
---|
747 | update_field(handles,vector_y) |
---|
748 | end |
---|
749 | |
---|
750 | %------------------------------------------------------------------------ |
---|
751 | % --- Executes on selection change in vector_z. |
---|
752 | function vector_z_Callback(hObject, DimCell, handles) |
---|
753 | %------------------------------------------------------------------------ |
---|
754 | vector_z_menu=get(handles.vector_z,'String'); |
---|
755 | vector_z_index=get(handles.vector_z,'Value'); |
---|
756 | vector_z=vector_z_menu{vector_z_index}; |
---|
757 | vector_Callback(handles) |
---|
758 | if ~ischar(DimCell) |
---|
759 | update_field(handles,vector_z) |
---|
760 | end |
---|
761 | %------------------------------------------------------------------------ |
---|
762 | % --- Executes on selection change in vec_color. |
---|
763 | function vec_color_Callback(hObject, DimCell, handles) |
---|
764 | %------------------------------------------------------------------------ |
---|
765 | index=get(handles.vec_color,'Value'); |
---|
766 | string=get(handles.vec_color,'String'); |
---|
767 | VarName=string{index}; |
---|
768 | vector_Callback(handles) |
---|
769 | if ~ischar(DimCell) |
---|
770 | update_field(handles,VarName) |
---|
771 | end |
---|
772 | %------------------------------------------------------------------------ |
---|
773 | % --- Executes on selection change in vector_x or vector_y |
---|
774 | function vector_Callback( handles) |
---|
775 | %------------------------------------------------------------------------ |
---|
776 | Field=get(handles.get_field,'UserData'); |
---|
777 | vector_x_index=get(handles.vector_x,'Value'); |
---|
778 | vector_y_index=get(handles.vector_y,'Value'); |
---|
779 | vec_color_index=get(handles.vec_color,'Value'); |
---|
780 | |
---|
781 | %% set list of possible coordinates |
---|
782 | test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate |
---|
783 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate |
---|
784 | check_consistent=1;%check that the selected vector components (and possibly color var) have the same dimensiosn |
---|
785 | ListCoord={''}; |
---|
786 | dim_var=Field.Display.VarDimName{vector_x_index};%list of dimensions of the selected variable |
---|
787 | if ~isequal(dim_var,Field.Display.VarDimName{vector_y_index}) |
---|
788 | check_consistent=0; |
---|
789 | elseif vec_color_index~=1 && ~isequal(dim_var,Field.Display.VarDimName{vec_color_index}) |
---|
790 | check_consistent=0; |
---|
791 | end |
---|
792 | % the two vector components have consistent dimensions |
---|
793 | if check_consistent |
---|
794 | for ilist=1:numel(Field.Display.VarDimName) |
---|
795 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
796 | if isequal(dimnames,dim_var) |
---|
797 | test_component(ilist)=1; |
---|
798 | elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable |
---|
799 | test_coord(ilist)=1; |
---|
800 | end |
---|
801 | end |
---|
802 | var_component=find(test_component);% list of variable indices elligible as unstructured coordinates |
---|
803 | var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates |
---|
804 | var_component(var_component==vector_x_index|var_component==vector_y_index)=[]; |
---|
805 | var_coord(var_coord==vector_x_index|var_coord==vector_y_index)=[];% remove vector components form te possible list of coordinates |
---|
806 | ListCoord=Field.Display.ListVarName([var_coord var_component]); |
---|
807 | |
---|
808 | %% set default coord selection |
---|
809 | if numel(find(test_coord))>3 |
---|
810 | set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time |
---|
811 | end |
---|
812 | if numel(var_component)<2 %unstructured coordinates excluded |
---|
813 | if numel(find(test_coord))<2 |
---|
814 | ListCoord={''}; |
---|
815 | else |
---|
816 | if numel(find(test_coord))>=3 |
---|
817 | set(handles.Coord_x,'Value',3) |
---|
818 | set(handles.Coord_y,'Value',2) |
---|
819 | set(handles.Coord_z,'Value',1) |
---|
820 | else |
---|
821 | set(handles.Coord_x,'Value',2) |
---|
822 | set(handles.Coord_y,'Value',1) |
---|
823 | end |
---|
824 | end |
---|
825 | else |
---|
826 | coord_val=[0 0 0]; |
---|
827 | for ilist=1:numel(var_component) |
---|
828 | ivar=var_component(ilist); |
---|
829 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role') |
---|
830 | Role=Field.Display.VarAttribute{ivar}.Role; |
---|
831 | if strcmp(Role,'coord_x') |
---|
832 | coord_val(1)=ilist; |
---|
833 | elseif strcmp(Role,'coord_y') |
---|
834 | coord_val(2)=ilist; |
---|
835 | elseif strcmp(Role,'coord_z') |
---|
836 | coord_val(3)=ilist; |
---|
837 | end |
---|
838 | end |
---|
839 | end |
---|
840 | if isempty(find(coord_val)) |
---|
841 | coord_val=var_coord;% case of dimension coordinates |
---|
842 | end |
---|
843 | if numel(find(coord_val))<2 |
---|
844 | coord_val=[1 2 3]; |
---|
845 | end |
---|
846 | set(handles.Coord_x,'Value',coord_val(end)) |
---|
847 | set(handles.Coord_y,'Value',coord_val(end-1)) |
---|
848 | if numel(coord_val)>=3 |
---|
849 | set(handles.Coord_z,'Value',coord_val(end-2)) |
---|
850 | end |
---|
851 | end |
---|
852 | end |
---|
853 | set(handles.Coord_z,'String',ListCoord) |
---|
854 | set(handles.Coord_y,'String',ListCoord) |
---|
855 | set(handles.Coord_x,'String',ListCoord) |
---|
856 | |
---|
857 | |
---|
858 | %% set list of time coordinates |
---|
859 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
860 | TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
861 | switch TimeOption |
---|
862 | case 'variable' |
---|
863 | if numel(find(test_coord))<3 |
---|
864 | ListTime={''}; |
---|
865 | else |
---|
866 | ListTime=Field.Display.ListVarName(find(test_coord,end)); |
---|
867 | end |
---|
868 | set(handles.TimeName,'Value',1) |
---|
869 | set(handles.TimeName,'String',ListTime) |
---|
870 | case 'dim index' |
---|
871 | if numel(find(test_coord))<3 |
---|
872 | ListTime={''}; |
---|
873 | else |
---|
874 | ListTime=Field.Display.VarDimName{find(test_coord,end)}; |
---|
875 | end |
---|
876 | set(handles.TimeName,'Value',1) |
---|
877 | set(handles.TimeName,'String',ListTime) |
---|
878 | end |
---|
879 | |
---|
880 | %------------------------------------------------------------------------ |
---|
881 | % --- Executes on selection change in SwitchVarIndexX. |
---|
882 | %------------------------------------------------------------------------ |
---|
883 | function SwitchVarIndexX_Callback(hObject, eventdata, handles) |
---|
884 | |
---|
885 | %------------------------------------------------------------------------ |
---|
886 | % --- Executes on selection change in Coord_x. |
---|
887 | %------------------------------------------------------------------------ |
---|
888 | function Coord_x_Callback(hObject, DimCell, handles) |
---|
889 | DimCell |
---|
890 | index=get(handles.Coord_x,'Value'); |
---|
891 | string=get(handles.Coord_x,'String'); |
---|
892 | VarName=string{index}; |
---|
893 | if ~ischar(DimCell) |
---|
894 | update_field(handles,VarName) |
---|
895 | end |
---|
896 | if isequal(get(handles.FieldOption,'Value'),1) |
---|
897 | set_coord_y_options(handles,VarName) |
---|
898 | end |
---|
899 | |
---|
900 | %------------------------------------------------------------------------ |
---|
901 | % --- Executes on selection change in Coord_y. |
---|
902 | %------------------------------------------------------------------------ |
---|
903 | function Coord_y_Callback(hObject, DimCell, handles) |
---|
904 | |
---|
905 | index=get(handles.Coord_y,'Value'); |
---|
906 | string=get(handles.Coord_y,'String'); |
---|
907 | VarName=string{index}; |
---|
908 | |
---|
909 | if ~ischar(DimCell) |
---|
910 | update_field(handles,VarName) |
---|
911 | end |
---|
912 | |
---|
913 | %------------------------------------------------------------------------ |
---|
914 | % --- Executes on selection change in Coord_z. |
---|
915 | %------------------------------------------------------------------------ |
---|
916 | function Coord_z_Callback(hObject, DimCell, handles) |
---|
917 | |
---|
918 | index=get(handles.Coord_z,'Value'); |
---|
919 | string=get(handles.Coord_z,'String'); |
---|
920 | VarName=string{index}; |
---|
921 | if ~ischar(DimCell) |
---|
922 | update_field(handles,VarName) |
---|
923 | end |
---|
924 | |
---|
925 | %------------------------------------------------------------------------ |
---|
926 | % --- Executes on selection change in SwitchVarIndexTime. |
---|
927 | %------------------------------------------------------------------------ |
---|
928 | |
---|
929 | function SwitchVarIndexTime_Callback(hObject, eventdata, handles) |
---|
930 | |
---|
931 | Field=get(handles.get_field,'UserData'); |
---|
932 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
933 | option=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
934 | |
---|
935 | switch option |
---|
936 | case 'file index' |
---|
937 | set(handles.TimeName, 'Visible','off')% the time is taken as the file index |
---|
938 | case 'attribute' |
---|
939 | set(handles.TimeName, 'Visible','on')% timeName menu represents the available attributes |
---|
940 | time_index=get(handles.TimeName,'UserData'); %select the input data |
---|
941 | if isempty(time_index) |
---|
942 | PreviousList=get(handles.TimeName, 'String'); |
---|
943 | if ~isempty(PreviousList) |
---|
944 | PreviousAttr=PreviousList{get(handles.TimeName, 'Value')}; |
---|
945 | index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttribute),1); |
---|
946 | end |
---|
947 | end |
---|
948 | if isempty(time_index) |
---|
949 | time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% index of the attributes containing the string 'Time' |
---|
950 | end |
---|
951 | if ~isempty(time_index) |
---|
952 | set(handles.TimeName,'Value',time_index) |
---|
953 | else |
---|
954 | set(handles.TimeName,'Value',1) |
---|
955 | end |
---|
956 | set(handles.TimeName, 'String',Field.Display.ListGlobalAttribute) |
---|
957 | |
---|
958 | case 'variable'% TimeName menu represents the available variables |
---|
959 | set(handles.TimeName, 'Visible','on') |
---|
960 | VarNbDim=cellfun('length',Field.Display.VarDimName); % check the nbre of dimensions of each input variable |
---|
961 | TimeVarName=Field.Display.ListVarName(VarNbDim==1);% list of variables with a single dimension (candidate for time) |
---|
962 | List=get(handles.TimeName,'String');% list of names on the menu for time |
---|
963 | if isempty(List) |
---|
964 | ind=1; |
---|
965 | else |
---|
966 | option=List{get(handles.TimeName,'Value')};% previous selected option |
---|
967 | ind=find(strcmp(option,TimeVarName)); %check whether the previous selection is available in the newlist |
---|
968 | if isempty(ind) |
---|
969 | ind=1; |
---|
970 | end |
---|
971 | end |
---|
972 | if ~isempty(TimeVarName) |
---|
973 | set(handles.TimeName, 'Value',ind);% select first value in the menu if the option is not found |
---|
974 | set(handles.TimeName, 'String',TimeVarName)% update the menu for time name |
---|
975 | end |
---|
976 | case 'matrix index'% TimeName menu represents the available dimensions |
---|
977 | set(handles.TimeName, 'Visible','on') |
---|
978 | set(handles.TimeName, 'Value',1); |
---|
979 | set(handles.TimeName, 'String',Field.Display.ListDimName) |
---|
980 | end |
---|
981 | TimeName_Callback(hObject, [], handles) |
---|
982 | |
---|
983 | %----------------------------------------------------------------------- |
---|
984 | % update the display of the variable 'VarName' and its dimensions in the list of variables |
---|
985 | function update_field(handles,VarName) |
---|
986 | %----------------------------------------------------------------------- |
---|
987 | Field=get(handles.get_field,'UserData'); |
---|
988 | index=name2index(VarName,Field.ListVarName); |
---|
989 | if ~isempty(index) |
---|
990 | set(handles.variables,'Value',index+1) |
---|
991 | variables_Callback(handles.variables, VarName, handles) |
---|
992 | end |
---|
993 | |
---|
994 | %------------------------------------------------------------------------ |
---|
995 | % --- give index numbers of the strings str in the list ListvarName |
---|
996 | % ----------------------------------------------------------------------- |
---|
997 | function VarIndex_y=name2index(cell_str,ListVarName) |
---|
998 | |
---|
999 | VarIndex_y=[]; |
---|
1000 | if ischar(cell_str) |
---|
1001 | VarIndex_y=find(strcmp(cell_str,ListVarName),1); |
---|
1002 | elseif iscell(cell_str) |
---|
1003 | for isel=1:length(cell_str) |
---|
1004 | varsel=cell_str{isel}; |
---|
1005 | for ivar=1:length(ListVarName) |
---|
1006 | varlist=ListVarName{ivar}; |
---|
1007 | if isequal(varlist,varsel) |
---|
1008 | VarIndex_y=[VarIndex_y ivar]; |
---|
1009 | end |
---|
1010 | end |
---|
1011 | end |
---|
1012 | end |
---|
1013 | |
---|
1014 | |
---|
1015 | |
---|
1016 | % % --- Executes on button press in CheckDimensionY. |
---|
1017 | % function CheckDimensionY_Callback(hObject, eventdata, handles) |
---|
1018 | % FieldList=get(handles.FieldOption,'String'); |
---|
1019 | % FieldOption=FieldList{get(handles.FieldOption,'Value')}; |
---|
1020 | % switch FieldOption |
---|
1021 | % case '1D plot' |
---|
1022 | % |
---|
1023 | % case {'scalar','pick variables'} |
---|
1024 | % scalar_Callback(hObject, eventdata, handles) |
---|
1025 | % case 'vectors' |
---|
1026 | % end |
---|
1027 | % |
---|
1028 | % |
---|
1029 | % % --- Executes on button press in CheckDimensionZ. |
---|
1030 | % function CheckDimensionZ_Callback(hObject, eventdata, handles) |
---|
1031 | % FieldList=get(handles.FieldOption,'String'); |
---|
1032 | % FieldOption=FieldList{get(handles.FieldOption,'Value')}; |
---|
1033 | % switch FieldOption |
---|
1034 | % case '1D plot' |
---|
1035 | % |
---|
1036 | % case 'scalar' |
---|
1037 | % scalar_Callback(hObject, eventdata, handles) |
---|
1038 | % case 'vectors' |
---|
1039 | % end |
---|
1040 | |
---|
1041 | % --- Executes on selection change in TimeName. |
---|
1042 | function TimeName_Callback(hObject, eventdata, handles) |
---|
1043 | Field=get(handles.get_field,'UserData'); |
---|
1044 | index=get(handles.SwitchVarIndexTime,'Value'); |
---|
1045 | MenuIndex=get(handles.TimeName,'Value'); |
---|
1046 | string=get(handles.TimeName,'String'); |
---|
1047 | TimeName='';%default |
---|
1048 | if ~isempty(string)&&iscell(string) |
---|
1049 | TimeName=string{MenuIndex}; |
---|
1050 | end |
---|
1051 | switch index |
---|
1052 | case 1 |
---|
1053 | set(handles.num_TimeDimension,'String','') |
---|
1054 | set(handles.TimeUnit,'String','index') |
---|
1055 | case 2 |
---|
1056 | set(handles.num_TimeDimension,'String','') |
---|
1057 | attr_index=find(strcmpi([TimeName 'Unit'],Field.ListGlobalAttribute));% look for time unit |
---|
1058 | if ~isempty(attr_index) |
---|
1059 | AttrName=Field.ListGlobalAttribute{attr_index}; |
---|
1060 | set(handles.TimeUnit,'String',Field.(AttrName)) |
---|
1061 | else |
---|
1062 | set(handles.TimeUnit,'String','') |
---|
1063 | end |
---|
1064 | case {3 ,4} |
---|
1065 | if index==3 % TimeName is used to chose a variable |
---|
1066 | VarIndex=name2index(TimeName,Field.ListVarName); |
---|
1067 | DimName=Field.VarDimName{VarIndex}; |
---|
1068 | DimIndex=name2index(DimName,Field.ListDimName); |
---|
1069 | DimValue=Field.DimValue(DimIndex); |
---|
1070 | set(handles.num_TimeDimension,'String',num2str(DimValue)) |
---|
1071 | unit=''; |
---|
1072 | if isfield(Field,'VarAttribute')&& isfield(Field.VarAttribute{VarIndex},'Unit') |
---|
1073 | unit=Field.VarAttribute{VarIndex}.Unit; |
---|
1074 | end |
---|
1075 | set(handles.TimeUnit,'String',unit) |
---|
1076 | update_field(handles,TimeName) |
---|
1077 | elseif index==4% TimeName is used to chose a dimension |
---|
1078 | DimName=string{MenuIndex}; |
---|
1079 | DimIndex=name2index(DimName,Field.ListDimName); |
---|
1080 | DimValue=Field.DimValue(DimIndex); |
---|
1081 | set(handles.num_TimeDimension,'String',num2str(DimValue)) |
---|
1082 | set(handles.TimeUnit,'String','index') |
---|
1083 | end |
---|
1084 | end |
---|
1085 | |
---|
1086 | %----------------------------------------------------------------------- |
---|
1087 | % --- Executes on button press in Check3D. |
---|
1088 | %----------------------------------------------------------------------- |
---|
1089 | function Check3D_Callback(hObject, eventdata, handles) |
---|
1090 | if get(handles.Check3D,'Value')% 3D fields |
---|
1091 | status='on'; |
---|
1092 | else% fields studied as 2D |
---|
1093 | status='off'; |
---|
1094 | end |
---|
1095 | |
---|
1096 | set(handles.Coord_z,'Visible',status) |
---|
1097 | % set(handles.CheckDimensionZ,'Visible',status) |
---|
1098 | set(handles.Z_title,'Visible',status) |
---|
1099 | set(handles.vector_z,'Visible',status) |
---|
1100 | set(handles.W_title,'Visible',status) |
---|
1101 | Field=get(handles.get_field,'UserData'); |
---|
1102 | if strcmp(status,'on')% ask for 3D input |
---|
1103 | if Field.MaxDim>3% for 4D fields, propose to use the fourth variable as time |
---|
1104 | %set(handles.Time,'Visible','on') |
---|
1105 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
1106 | val=find(strcmp('variable',menu)); |
---|
1107 | if ~isempty(val) |
---|
1108 | set(handles.SwitchVarIndexTime,'Value',val) |
---|
1109 | end |
---|
1110 | else |
---|
1111 | set(handles.SwitchVarIndexTime,'Value',1) |
---|
1112 | set(handles.SwitchVarIndexTime,'String',{'file index';'attribute'}) |
---|
1113 | end |
---|
1114 | else |
---|
1115 | set(handles.SwitchVarIndexTime,'String',get(handles.SwitchVarIndexTime,'UserData')) |
---|
1116 | if Field.MaxDim >=3 |
---|
1117 | var_index=find(strcmp('variable',get(handles.SwitchVarIndexTime,'UserData'))); |
---|
1118 | set(handles.SwitchVarIndexTime,'Value',var_index) |
---|
1119 | end |
---|
1120 | end |
---|
1121 | SwitchVarIndexTime_Callback(handles.SwitchVarIndexTime,[], handles) |
---|
1122 | |
---|
1123 | %------------------------------------------------------------------------ |
---|
1124 | % --- Executes on button press in OK. |
---|
1125 | %------------------------------------------------------------------------ |
---|
1126 | function OK_Callback(hObject, eventdata, handles) |
---|
1127 | handles.output=read_GUI(handles.get_field); |
---|
1128 | guidata(hObject, handles);% Update handles structure |
---|
1129 | uiresume(handles.get_field); |
---|
1130 | drawnow |
---|
1131 | % this function then activate get_field_OutputFcn |
---|
1132 | |
---|
1133 | %------------------------------------------------------------------------ |
---|
1134 | % --- Executes when the GUI is closed by the mouse on upper right corner. |
---|
1135 | %------------------------------------------------------------------------ |
---|
1136 | function closefcn(hObject, eventdata, handles) |
---|
1137 | handles.output=[]; |
---|
1138 | guidata(hObject, handles);% Update handles structure |
---|
1139 | uiresume(handles.get_field); |
---|
1140 | drawnow |
---|
1141 | |
---|
1142 | %------------------------------------------------------------------------ |
---|
1143 | % --- Outputs from this function are returned to the command line. |
---|
1144 | %------------------------------------------------------------------------ |
---|
1145 | function varargout = get_field_OutputFcn(hObject, eventdata, handles) |
---|
1146 | |
---|
1147 | varargout{1} =handles.output; |
---|
1148 | delete(handles.get_field) |
---|