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