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-2015, 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','pixels') |
---|
247 | %pos_view_field=get(hObject,'Position'); |
---|
248 | set(0,'Unit','pixels') |
---|
249 | ScreenSize=get(0,'ScreenSize'); |
---|
250 | pos_view_field(3:4)=[955 648]; |
---|
251 | pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3); |
---|
252 | pos_view_field(2)=ScreenSize(2); |
---|
253 | set(hObject,'Position',pos_view_field) |
---|
254 | set(handles.get_field,'WindowStyle','modal')% Make the GUI modal |
---|
255 | if isfield(ParamIn,'Title') |
---|
256 | set(hObject,'Name',ParamIn.Title) |
---|
257 | end |
---|
258 | |
---|
259 | %% set z coordinate menu if relevant |
---|
260 | if Field.MaxDim>=3 && prod(Field.DimValue)<10^8; % 3D field (with memory content smaller than 400 Mo) |
---|
261 | set(handles.Check3D,'Value',1) |
---|
262 | else |
---|
263 | set(handles.Check3D,'Value',0) |
---|
264 | end |
---|
265 | Check3D_Callback(hObject, eventdata, handles) |
---|
266 | set(handles.variables,'Value',1) |
---|
267 | set(handles.variables,'String',[{'*'} Field.ListVarName]) |
---|
268 | variables_Callback(handles.variables,[], handles)% list the global attributes |
---|
269 | drawnow |
---|
270 | uiwait(handles.get_field); |
---|
271 | |
---|
272 | % ----------------------------------------------------------------------- |
---|
273 | % --- Activated by selection in the list of variables |
---|
274 | % ---------------------------------------------------------------------- |
---|
275 | function variables_Callback(hObject, eventdata, handles) |
---|
276 | |
---|
277 | Tabchar={''};%default |
---|
278 | Tabcell=[]; |
---|
279 | hselect_field=get(handles.variables,'parent'); |
---|
280 | Field=get(handles.get_field,'UserData'); |
---|
281 | index=get(handles.variables,'Value');%index in the list 'variables' |
---|
282 | |
---|
283 | %% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected |
---|
284 | if isequal(index,1) |
---|
285 | set(handles.attributes_txt,'String','global attributes') |
---|
286 | if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute) |
---|
287 | for iline=1:length(Field.ListGlobalAttribute) |
---|
288 | Tabcell{iline,1}=Field.ListGlobalAttribute{iline}; |
---|
289 | if isfield(Field, Field.ListGlobalAttribute{iline}) |
---|
290 | val=Field.(Field.ListGlobalAttribute{iline}); |
---|
291 | if ischar(val);% attribute value is char string |
---|
292 | Tabcell{iline,2}=val; |
---|
293 | elseif size(val,1)==1 %attribute value is a number or matlab vector |
---|
294 | Tabcell{iline,2}=num2str(val); |
---|
295 | end |
---|
296 | end |
---|
297 | end |
---|
298 | Tabchar=cell2tab(Tabcell,'='); |
---|
299 | end |
---|
300 | %% list Attribute names and values associated to the Variable # index-1 |
---|
301 | else |
---|
302 | list_var=get(handles.variables,'String'); |
---|
303 | if index>numel(list_var) |
---|
304 | return |
---|
305 | end |
---|
306 | var_select=list_var{index}; |
---|
307 | set(handles.attributes_txt,'String', ['attributes of ' var_select]) |
---|
308 | if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1 |
---|
309 | % nbline=0; |
---|
310 | VarAttr=Field.VarAttribute{index-1}; |
---|
311 | if isstruct(VarAttr) |
---|
312 | attr_list=fieldnames(VarAttr); |
---|
313 | for iline=1:length(attr_list) |
---|
314 | Tabcell{iline,1}=attr_list{iline}; |
---|
315 | val=VarAttr.(attr_list{iline}) ; |
---|
316 | if ischar(val); |
---|
317 | Tabcell{iline,2}=val; |
---|
318 | else |
---|
319 | Tabcell{iline,2}=num2str(val); |
---|
320 | end |
---|
321 | end |
---|
322 | end |
---|
323 | end |
---|
324 | end |
---|
325 | if ~isempty(Tabcell) |
---|
326 | Tabchar=cell2tab(Tabcell,'='); |
---|
327 | % Tabchar=[{''};Tabchar]; |
---|
328 | end |
---|
329 | set(handles.attributes,'Value',1);% select the first item |
---|
330 | set(handles.attributes,'String',Tabchar); |
---|
331 | |
---|
332 | %% update dimensions; |
---|
333 | if isfield(Field,'ListDimName') |
---|
334 | Tabdim={};%default |
---|
335 | if isequal(index,1)%list all dimensions |
---|
336 | dim_indices=1:length(Field.ListDimName); |
---|
337 | set(handles.dimensions_txt,'String', 'dimensions') |
---|
338 | else |
---|
339 | DimCell=Field.VarDimName{index-1}; |
---|
340 | if ischar(DimCell) |
---|
341 | DimCell={DimCell}; |
---|
342 | end |
---|
343 | dim_indices=[]; |
---|
344 | for idim=1:length(DimCell) |
---|
345 | dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0 |
---|
346 | dim_index=find(dim_index,1); |
---|
347 | dim_indices=[dim_indices dim_index]; |
---|
348 | end |
---|
349 | set(handles.dimensions_txt,'String', ['dimensions of ' var_select]) |
---|
350 | end |
---|
351 | for iline=1:length(dim_indices) |
---|
352 | Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)}; |
---|
353 | Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline))); |
---|
354 | end |
---|
355 | Tabchar=cell2tab(Tabdim,' = '); |
---|
356 | Tabchar=[{''} ;Tabchar]; |
---|
357 | set(handles.dimensions,'Value',1) |
---|
358 | set(handles.dimensions,'String',Tabchar) |
---|
359 | end |
---|
360 | |
---|
361 | %------------------------------------------------------------------------ |
---|
362 | % --- Executes on selection change in FieldOption. |
---|
363 | %------------------------------------------------------------------------ |
---|
364 | function FieldOption_Callback(hObject, eventdata, handles) |
---|
365 | |
---|
366 | Field=get(handles.get_field,'UserData'); |
---|
367 | FieldList=get(handles.FieldOption,'String'); |
---|
368 | FieldOption=FieldList{get(handles.FieldOption,'Value')}; |
---|
369 | switch FieldOption |
---|
370 | |
---|
371 | case '1D plot' |
---|
372 | set(handles.Coordinates,'Visible','on') |
---|
373 | set(handles.PanelOrdinate,'Visible','on') |
---|
374 | pos=get(handles.PanelOrdinate,'Position'); |
---|
375 | pos(1)=2; |
---|
376 | pos_coord=get(handles.Coordinates,'Position'); |
---|
377 | pos(2)=pos_coord(2)-pos(4)-2; |
---|
378 | set(handles.PanelOrdinate,'Position',pos) |
---|
379 | set(handles.PanelScalar,'Visible','off') |
---|
380 | set(handles.PanelVectors,'Visible','off') |
---|
381 | set(handles.Coord_y,'Visible','off') |
---|
382 | set(handles.Y_title,'Visible','off') |
---|
383 | set(handles.Coord_z,'Visible','off') |
---|
384 | set(handles.Z_title,'Visible','off') |
---|
385 | ordinate_Callback(hObject, eventdata, handles) |
---|
386 | |
---|
387 | case {'scalar'} |
---|
388 | set(handles.Coordinates,'Visible','on') |
---|
389 | set(handles.PanelOrdinate,'Visible','off') |
---|
390 | set(handles.PanelScalar,'Visible','on') |
---|
391 | set(handles.PanelVectors,'Visible','off') |
---|
392 | pos=get(handles.PanelScalar,'Position'); |
---|
393 | pos(1)=2; |
---|
394 | pos_coord=get(handles.Coordinates,'Position'); |
---|
395 | pos(2)=pos_coord(2)-pos(4)-2; |
---|
396 | set(handles.PanelScalar,'Position',pos) |
---|
397 | set(handles.Coord_y,'Visible','on') |
---|
398 | set(handles.Y_title,'Visible','on') |
---|
399 | %default scalar selection |
---|
400 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante |
---|
401 | for ilist=1:numel(Field.Display.VarDimName) |
---|
402 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') |
---|
403 | Role=Field.Display.VarAttribute{ilist}.Role; |
---|
404 | if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') |
---|
405 | test_coord(ilist)=1; |
---|
406 | end |
---|
407 | end |
---|
408 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
409 | if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable |
---|
410 | test_coord(ilist)=1; |
---|
411 | end |
---|
412 | end |
---|
413 | scalar_index=find(~test_coord,1);%get the first variable not a coordinate |
---|
414 | if isempty(scalar_index) |
---|
415 | set(handles.scalar,'Value',1) |
---|
416 | else |
---|
417 | set(handles.scalar,'Value',scalar_index) |
---|
418 | end |
---|
419 | scalar_Callback(hObject, eventdata, handles) |
---|
420 | |
---|
421 | case 'vectors' |
---|
422 | set(handles.PanelVectors,'Visible','on') |
---|
423 | set(handles.Coordinates,'Visible','on') |
---|
424 | set(handles.PanelOrdinate,'Visible','off') |
---|
425 | set(handles.PanelScalar,'Visible','off') |
---|
426 | pos=get(handles.PanelVectors,'Position'); |
---|
427 | pos(1)=2; |
---|
428 | pos_coord=get(handles.Coordinates,'Position'); |
---|
429 | pos(2)=pos_coord(2)-pos(4)-2; |
---|
430 | set(handles.PanelVectors,'Position',pos) |
---|
431 | set(handles.Coord_y,'Visible','on') |
---|
432 | set(handles.Y_title,'Visible','on') |
---|
433 | %default vector selection |
---|
434 | vector_x_value=get(handles.vector_x,'UserData'); |
---|
435 | vector_y_value=get(handles.vector_y,'UserData'); |
---|
436 | if ~isempty(vector_x_value)&&~isempty(vector_y_value) |
---|
437 | set(handles.vector_x,'Value',vector_x_value) |
---|
438 | set(handles.vector_y,'Value',vector_y_value) |
---|
439 | else |
---|
440 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate |
---|
441 | for ilist=1:numel(Field.Display.VarDimName) |
---|
442 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ilist && isfield(Field.Display.VarAttribute{ilist},'Role') |
---|
443 | Role=Field.Display.VarAttribute{ilist}.Role; |
---|
444 | if strcmp(Role,'coord_x')||strcmp(Role,'coord_y') |
---|
445 | test_coord(ilist)=1; |
---|
446 | end |
---|
447 | end |
---|
448 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
449 | if numel(dimnames)==1 && strcmp(dimnames{1},Field.Display.ListVarName{ilist})%dimension variable |
---|
450 | test_coord(ilist)=1; |
---|
451 | end |
---|
452 | end |
---|
453 | vector_index=find(~test_coord,2);%get the two first variables not a coordinate |
---|
454 | if isempty(vector_index) |
---|
455 | set(handles.vector_x,'Value',1) |
---|
456 | set(handles.vector_y,'Value',2) |
---|
457 | else |
---|
458 | set(handles.vector_x,'Value',vector_index(1)) |
---|
459 | set(handles.vector_y,'Value',vector_index(2)) |
---|
460 | end |
---|
461 | end |
---|
462 | vector_Callback(handles) |
---|
463 | |
---|
464 | case 'civdata...' |
---|
465 | set(handles.PanelOrdinate,'Visible','off') |
---|
466 | set(handles.PanelScalar,'Visible','off') |
---|
467 | set(handles.PanelVectors,'Visible','off') |
---|
468 | set(handles.Coordinates,'Visible','off') |
---|
469 | end |
---|
470 | |
---|
471 | %------------------------------------------------------------------------ |
---|
472 | function ordinate_Callback(hObject, eventdata, handles) |
---|
473 | %------------------------------------------------------------------------ |
---|
474 | Field=get(handles.get_field,'UserData'); |
---|
475 | y_index=get(handles.ordinate,'Value'); |
---|
476 | y_menu=get(handles.ordinate,'String'); |
---|
477 | if isempty(y_menu) |
---|
478 | return |
---|
479 | else |
---|
480 | YName=y_menu{y_index}; |
---|
481 | end |
---|
482 | |
---|
483 | %% set list of possible coordinates |
---|
484 | test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate |
---|
485 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante |
---|
486 | ListCoord={''}; |
---|
487 | dim_var=Field.Display.VarDimName{y_index};%list of dimensions of the selected variable |
---|
488 | |
---|
489 | for ilist=1:numel(Field.Display.VarDimName) |
---|
490 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
491 | if isequal(dimnames,dim_var) |
---|
492 | test_component(ilist)=1; |
---|
493 | elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable |
---|
494 | test_coord(ilist)=1; |
---|
495 | end |
---|
496 | end |
---|
497 | var_component=find(test_component);% list of variable indices elligible as unstructured coordinates |
---|
498 | var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates |
---|
499 | ListCoord=Field.Display.ListVarName([var_component var_coord]); |
---|
500 | |
---|
501 | %% set default coord selection |
---|
502 | if numel(find(test_coord))>3 |
---|
503 | SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String'); |
---|
504 | if numel(SwitchVarIndexTime)<3 |
---|
505 | SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index']; |
---|
506 | set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime) |
---|
507 | end |
---|
508 | set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time |
---|
509 | SwitchVarIndexTime_Callback([], [], handles) |
---|
510 | end |
---|
511 | if numel(var_component)<2 |
---|
512 | if numel(test_coord)<2 |
---|
513 | ListCoord={''}; |
---|
514 | else |
---|
515 | set(handles.Coord_x,'Value',2) |
---|
516 | set(handles.Coord_y,'Value',1) |
---|
517 | end |
---|
518 | else |
---|
519 | coord_val=1; |
---|
520 | for ilist=1:numel(var_component) |
---|
521 | ivar=var_component(ilist); |
---|
522 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role') |
---|
523 | Role=Field.Display.VarAttribute{ivar}.Role; |
---|
524 | if strcmp(Role,'coord_x') |
---|
525 | coord_val=ilist; |
---|
526 | end |
---|
527 | end |
---|
528 | end |
---|
529 | set(handles.Coord_x,'Value',coord_val) |
---|
530 | end |
---|
531 | set(handles.Coord_x,'String',ListCoord) |
---|
532 | |
---|
533 | |
---|
534 | %% set list of time coordinates |
---|
535 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
536 | TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
537 | switch TimeOption |
---|
538 | case 'variable' |
---|
539 | if numel(find(test_coord))<3 |
---|
540 | ListTime={''}; |
---|
541 | else |
---|
542 | ListTime=Field.Display.ListVarName(find(test_coord,end)); |
---|
543 | end |
---|
544 | set(handles.TimeName,'Value',1) |
---|
545 | set(handles.TimeName,'String',ListTime) |
---|
546 | case 'matrix index' |
---|
547 | if numel(find(test_coord))<3 |
---|
548 | ListTime={''}; |
---|
549 | else |
---|
550 | ListTime=Field.Display.VarDimName{find(test_coord,end)}; |
---|
551 | end |
---|
552 | set(handles.TimeName,'Value',1) |
---|
553 | set(handles.TimeName,'String',ListTime) |
---|
554 | end |
---|
555 | update_field(handles,YName) |
---|
556 | |
---|
557 | %------------------------------------------------------------------------ |
---|
558 | % --- Executes on selection change in scalar menu. |
---|
559 | %------------------------------------------------------------------------ |
---|
560 | function scalar_Callback(hObject, eventdata, handles) |
---|
561 | |
---|
562 | Field=get(handles.get_field,'UserData'); |
---|
563 | scalar_index=get(handles.scalar,'Value'); |
---|
564 | scalar_menu=get(handles.scalar,'String'); |
---|
565 | ScalarName=scalar_menu{scalar_index}; |
---|
566 | |
---|
567 | %% set list of possible coordinates |
---|
568 | test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate |
---|
569 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordiante |
---|
570 | dim_var=Field.Display.VarDimName{scalar_index};%list of dimensions of the selected variable |
---|
571 | if ~get(handles.CheckDimensionX,'Value') |
---|
572 | %look for coordinate variables among the other variables |
---|
573 | for ilist=1:numel(Field.Display.VarDimName) |
---|
574 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
575 | if isequal(dimnames,dim_var) |
---|
576 | test_component(ilist)=1;% the listed variable has the same dimension as the selected scalar-> possibly chosen as unstructured coordinate |
---|
577 | elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var), 1))%variable ilist is a 1D array which can be coordinate variable |
---|
578 | test_coord(ilist)=1; |
---|
579 | end |
---|
580 | end |
---|
581 | end |
---|
582 | var_component=find(test_component);% list of variable indices elligible as unstructured coordinates |
---|
583 | var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates |
---|
584 | var_coord(var_coord==scalar_index)=[]; |
---|
585 | var_component(var_component==scalar_index)=[]; |
---|
586 | ListCoord=Field.Display.ListVarName([var_coord var_component]); |
---|
587 | |
---|
588 | %% set default coord selection |
---|
589 | % if numel(find(test_coord))>3 |
---|
590 | % SwitchVarIndexTime=get(handles.SwitchVarIndexTime,'String'); |
---|
591 | % if numel(SwitchVarIndexTime)<3 |
---|
592 | % SwitchVarIndexTime=[SwitchVarIndexTime;'matrix_index']; |
---|
593 | % set(handles.SwitchVarIndexTime,'String',SwitchVarIndexTime) |
---|
594 | % end |
---|
595 | % set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time |
---|
596 | % SwitchVarIndexTime_Callback([], [], handles) |
---|
597 | % end |
---|
598 | |
---|
599 | coord_val=[0 0]; |
---|
600 | % look for labelled unstructured coordinates |
---|
601 | for ilist=1:numel(var_component) |
---|
602 | ivar=var_component(ilist); |
---|
603 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role') |
---|
604 | Role=Field.Display.VarAttribute{ivar}.Role; |
---|
605 | if strcmp(Role,'coord_x') |
---|
606 | coord_val(1)=ilist; |
---|
607 | elseif strcmp(Role,'coord_y') |
---|
608 | coord_val(2)=ilist; |
---|
609 | elseif strcmp(Role,'coord_z') |
---|
610 | coord_val(3)=ilist; |
---|
611 | end |
---|
612 | end |
---|
613 | end |
---|
614 | if numel(find(coord_val))<2 |
---|
615 | if numel(var_coord)>=3 |
---|
616 | coord_val=[3 2 1]; |
---|
617 | elseif numel(var_coord)>=2 |
---|
618 | % coord_val=[numel(var_component)+2 numel(var_component)+1]; |
---|
619 | coord_val=[2 1]; |
---|
620 | else |
---|
621 | coord_val=[1 2]; |
---|
622 | end |
---|
623 | end |
---|
624 | if get(handles.CheckDimensionX,'Value') |
---|
625 | set(handles.Coord_x,'Value',2) |
---|
626 | set(handles.Coord_x,'String',dim_var') |
---|
627 | else |
---|
628 | set(handles.Coord_x,'Value',coord_val(1)) |
---|
629 | set(handles.Coord_x,'String',ListCoord) |
---|
630 | end |
---|
631 | if get(handles.CheckDimensionX,'Value') |
---|
632 | set(handles.Coord_y,'Value',1) |
---|
633 | set(handles.Coord_y,'String',dim_var') |
---|
634 | else |
---|
635 | set(handles.Coord_y,'Value',coord_val(2)) |
---|
636 | set(handles.Coord_y,'String',ListCoord) |
---|
637 | end |
---|
638 | if get(handles.CheckDimensionX,'Value') |
---|
639 | set(handles.Coord_z,'Value',1) |
---|
640 | set(handles.Coord_z,'String',dim_var') |
---|
641 | else |
---|
642 | set(handles.Coord_z,'Value',coord_val(2)) |
---|
643 | set(handles.Coord_z,'String',ListCoord) |
---|
644 | end |
---|
645 | |
---|
646 | %% set list of time coordinates |
---|
647 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
648 | TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
649 | switch TimeOption |
---|
650 | case 'variable' |
---|
651 | if numel(find(test_coord))<3 |
---|
652 | ListTime={''}; |
---|
653 | else |
---|
654 | ListTime=Field.Display.ListVarName(find(test_coord,end)); |
---|
655 | end |
---|
656 | set(handles.TimeName,'Value',1) |
---|
657 | set(handles.TimeName,'String',ListTime) |
---|
658 | case 'dim index' |
---|
659 | if numel(find(test_coord))<3 |
---|
660 | ListTime={''}; |
---|
661 | else |
---|
662 | ListTime=Field.Display.VarDimName{find(test_coord,end)}; |
---|
663 | end |
---|
664 | set(handles.TimeName,'Value',1) |
---|
665 | set(handles.TimeName,'String',ListTime) |
---|
666 | end |
---|
667 | update_field(handles,ScalarName) |
---|
668 | |
---|
669 | % --- Executes on button press in check_rgb. |
---|
670 | function check_rgb_Callback(hObject, eventdata, handles) |
---|
671 | |
---|
672 | |
---|
673 | %------------------------------------------------------------------------ |
---|
674 | % --- Executes on selection change in vector_x. |
---|
675 | %------------------------------------------------------------------------ |
---|
676 | function vector_x_Callback(hObject, eventdata, handles) |
---|
677 | |
---|
678 | vector_x_menu=get(handles.vector_x,'String'); |
---|
679 | vector_x_index=get(handles.vector_x,'Value'); |
---|
680 | vector_x=vector_x_menu{vector_x_index}; |
---|
681 | vector_Callback(handles) |
---|
682 | update_field(handles,vector_x) |
---|
683 | |
---|
684 | %------------------------------------------------------------------------ |
---|
685 | % --- Executes on selection change in vector_x. |
---|
686 | function vector_y_Callback(hObject, eventdata, handles) |
---|
687 | %------------------------------------------------------------------------ |
---|
688 | vector_y_menu=get(handles.vector_x,'String'); |
---|
689 | vector_y_index=get(handles.vector_x,'Value'); |
---|
690 | vector_y=vector_y_menu{vector_y_index}; |
---|
691 | vector_Callback(handles) |
---|
692 | update_field(handles,vector_y) |
---|
693 | |
---|
694 | %------------------------------------------------------------------------ |
---|
695 | % --- Executes on selection change in vector_z. |
---|
696 | function vector_z_Callback(hObject, eventdata, handles) |
---|
697 | %------------------------------------------------------------------------ |
---|
698 | vector_z_menu=get(handles.vector_z,'String'); |
---|
699 | vector_z_index=get(handles.vector_z,'Value'); |
---|
700 | vector_z=vector_z_menu{vector_z_index}; |
---|
701 | vector_Callback(handles) |
---|
702 | update_field(handles,vector_z) |
---|
703 | |
---|
704 | %------------------------------------------------------------------------ |
---|
705 | % --- Executes on selection change in vec_color. |
---|
706 | function vec_color_Callback(hObject, eventdata, handles) |
---|
707 | %------------------------------------------------------------------------ |
---|
708 | index=get(handles.vec_color,'Value'); |
---|
709 | string=get(handles.vec_color,'String'); |
---|
710 | VarName=string{index}; |
---|
711 | vector_Callback(handles) |
---|
712 | update_field(handles,VarName) |
---|
713 | |
---|
714 | %------------------------------------------------------------------------ |
---|
715 | % --- Executes on selection change in vector_x or vector_y |
---|
716 | function vector_Callback( handles) |
---|
717 | %------------------------------------------------------------------------ |
---|
718 | Field=get(handles.get_field,'UserData'); |
---|
719 | vector_x_index=get(handles.vector_x,'Value'); |
---|
720 | vector_y_index=get(handles.vector_y,'Value'); |
---|
721 | vec_color_index=get(handles.vec_color,'Value'); |
---|
722 | |
---|
723 | %% set list of possible coordinates |
---|
724 | test_component=zeros(size(Field.Display.VarDimName));%=1 when variable #ilist is eligible as unstructured coordinate |
---|
725 | test_coord=zeros(size(Field.Display.VarDimName)); %=1 when variable #ilist is eligible as structured coordinate |
---|
726 | check_consistent=1;%check that the selected vector components (and possibly color var) have the same dimensiosn |
---|
727 | ListCoord={''}; |
---|
728 | dim_var=Field.Display.VarDimName{vector_x_index};%list of dimensions of the selected variable |
---|
729 | if ~isequal(dim_var,Field.Display.VarDimName{vector_y_index}) |
---|
730 | check_consistent=0; |
---|
731 | elseif vec_color_index~=1 && ~isequal(dim_var,Field.Display.VarDimName{vec_color_index}) |
---|
732 | check_consistent=0; |
---|
733 | end |
---|
734 | % the two vector components have consistent dimensions |
---|
735 | if check_consistent |
---|
736 | for ilist=1:numel(Field.Display.VarDimName) |
---|
737 | dimnames=Field.Display.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
738 | if isequal(dimnames,dim_var) |
---|
739 | test_component(ilist)=1; |
---|
740 | elseif numel(dimnames)==1 && ~isempty(find(strcmp(dimnames{1},dim_var)))%variable ilist is a 1D array which can be coordinate variable |
---|
741 | test_coord(ilist)=1; |
---|
742 | end |
---|
743 | end |
---|
744 | var_component=find(test_component);% list of variable indices elligible as unstructured coordinates |
---|
745 | var_coord=find(test_coord);% % list of variable indices elligible as structured coordinates |
---|
746 | var_component(var_component==vector_x_index|var_component==vector_y_index)=[]; |
---|
747 | var_coord(var_coord==vector_x_index|var_coord==vector_y_index)=[];% remove vector components form te possible list of coordinates |
---|
748 | ListCoord=Field.Display.ListVarName([var_coord var_component]); |
---|
749 | |
---|
750 | %% set default coord selection |
---|
751 | if numel(find(test_coord))>3 |
---|
752 | set(handles.SwitchVarIndexTime,'Value',3)% the last dim must be considered as time |
---|
753 | end |
---|
754 | if numel(var_component)<2 |
---|
755 | if numel(find(test_coord))<2 |
---|
756 | ListCoord={''}; |
---|
757 | else |
---|
758 | if numel(find(test_coord))>=3 |
---|
759 | set(handles.Coord_x,'Value',3) |
---|
760 | set(handles.Coord_y,'Value',2) |
---|
761 | set(handles.Coord_z,'Value',1) |
---|
762 | else |
---|
763 | set(handles.Coord_x,'Value',2) |
---|
764 | set(handles.Coord_y,'Value',1) |
---|
765 | end |
---|
766 | end |
---|
767 | else |
---|
768 | coord_val=[0 0 0]; |
---|
769 | for ilist=1:numel(var_component) |
---|
770 | ivar=var_component(ilist); |
---|
771 | if isfield(Field.Display,'VarAttribute') && numel(Field.Display.VarAttribute)>=ivar && isfield(Field.Display.VarAttribute{ivar},'Role') |
---|
772 | Role=Field.Display.VarAttribute{ivar}.Role; |
---|
773 | if strcmp(Role,'coord_x') |
---|
774 | coord_val(1)=ilist; |
---|
775 | elseif strcmp(Role,'coord_y') |
---|
776 | coord_val(2)=ilist; |
---|
777 | elseif strcmp(Role,'coord_z') |
---|
778 | coord_val(3)=ilist; |
---|
779 | end |
---|
780 | end |
---|
781 | end |
---|
782 | if isempty(find(coord_val)) |
---|
783 | coord_val=var_coord;% case of dimension coordinates |
---|
784 | end |
---|
785 | if numel(find(coord_val))<2 |
---|
786 | %coord_val=[numel(var_component)+2 numel(var_component)+1]; |
---|
787 | coord_val=[1 2 3]; |
---|
788 | end |
---|
789 | set(handles.Coord_x,'Value',coord_val(1)) |
---|
790 | set(handles.Coord_y,'Value',coord_val(2)) |
---|
791 | if numel(coord_val)>=3 |
---|
792 | set(handles.Coord_z,'Value',coord_val(3)) |
---|
793 | end |
---|
794 | end |
---|
795 | end |
---|
796 | set(handles.Coord_z,'String',ListCoord) |
---|
797 | set(handles.Coord_y,'String',ListCoord) |
---|
798 | set(handles.Coord_x,'String',ListCoord) |
---|
799 | |
---|
800 | |
---|
801 | %% set list of time coordinates |
---|
802 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
803 | TimeOption=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
804 | switch TimeOption |
---|
805 | case 'variable' |
---|
806 | if numel(find(test_coord))<3 |
---|
807 | ListTime={''}; |
---|
808 | else |
---|
809 | ListTime=Field.Display.ListVarName(find(test_coord,end)); |
---|
810 | end |
---|
811 | set(handles.TimeName,'Value',1) |
---|
812 | set(handles.TimeName,'String',ListTime) |
---|
813 | case 'dim index' |
---|
814 | if numel(find(test_coord))<3 |
---|
815 | ListTime={''}; |
---|
816 | else |
---|
817 | ListTime=Field.Display.VarDimName{find(test_coord,end)}; |
---|
818 | end |
---|
819 | set(handles.TimeName,'Value',1) |
---|
820 | set(handles.TimeName,'String',ListTime) |
---|
821 | end |
---|
822 | |
---|
823 | %------------------------------------------------------------------------ |
---|
824 | % --- Executes on selection change in SwitchVarIndexX. |
---|
825 | %------------------------------------------------------------------------ |
---|
826 | function SwitchVarIndexX_Callback(hObject, eventdata, handles) |
---|
827 | |
---|
828 | %------------------------------------------------------------------------ |
---|
829 | % --- Executes on selection change in Coord_x. |
---|
830 | %------------------------------------------------------------------------ |
---|
831 | function Coord_x_Callback(hObject, eventdata, handles) |
---|
832 | |
---|
833 | index=get(handles.Coord_x,'Value'); |
---|
834 | string=get(handles.Coord_x,'String'); |
---|
835 | VarName=string{index}; |
---|
836 | update_field(handles,VarName) |
---|
837 | |
---|
838 | %------------------------------------------------------------------------ |
---|
839 | % --- Executes on selection change in Coord_y. |
---|
840 | %------------------------------------------------------------------------ |
---|
841 | function Coord_y_Callback(hObject, eventdata, handles) |
---|
842 | |
---|
843 | index=get(handles.Coord_y,'Value'); |
---|
844 | string=get(handles.Coord_y,'String'); |
---|
845 | VarName=string{index}; |
---|
846 | update_field(handles,VarName) |
---|
847 | |
---|
848 | %------------------------------------------------------------------------ |
---|
849 | % --- Executes on selection change in Coord_z. |
---|
850 | %------------------------------------------------------------------------ |
---|
851 | function Coord_z_Callback(hObject, eventdata, handles) |
---|
852 | |
---|
853 | index=get(handles.Coord_z,'Value'); |
---|
854 | string=get(handles.Coord_z,'String'); |
---|
855 | VarName=string{index}; |
---|
856 | update_field(handles,VarName) |
---|
857 | |
---|
858 | %------------------------------------------------------------------------ |
---|
859 | % --- Executes on selection change in SwitchVarIndexTime. |
---|
860 | %------------------------------------------------------------------------ |
---|
861 | |
---|
862 | function SwitchVarIndexTime_Callback(hObject, eventdata, handles) |
---|
863 | |
---|
864 | Field=get(handles.get_field,'UserData'); |
---|
865 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
866 | option=menu{get(handles.SwitchVarIndexTime,'Value')}; |
---|
867 | |
---|
868 | switch option |
---|
869 | case 'file index' |
---|
870 | set(handles.TimeName, 'Visible','off')% the time is taken as the file index |
---|
871 | case 'attribute' |
---|
872 | set(handles.TimeName, 'Visible','on')% timeName menu represents the available attributes |
---|
873 | time_index=get(handles.TimeName,'UserData'); %select the input data |
---|
874 | if isempty(time_index) |
---|
875 | PreviousList=get(handles.TimeName, 'String'); |
---|
876 | if ~isempty(PreviousList) |
---|
877 | PreviousAttr=PreviousList{get(handles.TimeName, 'Value')}; |
---|
878 | index=find(strcmp(PreviousAttr,Field.Display.ListGlobalAttributes),1); |
---|
879 | end |
---|
880 | end |
---|
881 | if isempty(time_index) |
---|
882 | time_index=find(~cellfun('isempty',regexp(Field.Display.ListGlobalAttribute,'Time')),1);% index of the attributes containing the string 'Time' |
---|
883 | end |
---|
884 | if ~isempty(time_index) |
---|
885 | set(handles.TimeName,'Value',time_index) |
---|
886 | else |
---|
887 | set(handles.TimeName,'Value',1) |
---|
888 | end |
---|
889 | set(handles.TimeName, 'String',Field.Display.ListGlobalAttribute) |
---|
890 | |
---|
891 | case 'variable'% TimeName menu represents the available variables |
---|
892 | set(handles.TimeName, 'Visible','on') |
---|
893 | VarNbDim=cellfun('length',Field.Display.VarDimName); % check the nbre of dimensions of each input variable |
---|
894 | TimeVarName=Field.Display.ListVarName(VarNbDim==1);% list of variables with a single dimension (candidate for time) |
---|
895 | List=get(handles.TimeName,'String');% list of names on the menu for time |
---|
896 | if isempty(List) |
---|
897 | ind=1; |
---|
898 | else |
---|
899 | option=List{get(handles.TimeName,'Value')};% previous selected option |
---|
900 | ind=find(strcmp(option,TimeVarName)); %check whether the previous selection is available in the newlist |
---|
901 | if isempty(ind) |
---|
902 | ind=1; |
---|
903 | end |
---|
904 | end |
---|
905 | if ~isempty(TimeVarName) |
---|
906 | set(handles.TimeName, 'Value',ind);% select first value in the menu if the option is not found |
---|
907 | set(handles.TimeName, 'String',TimeVarName)% update the menu for time name |
---|
908 | end |
---|
909 | case 'matrix index'% TimeName menu represents the available dimensions |
---|
910 | set(handles.TimeName, 'Visible','on') |
---|
911 | set(handles.TimeName, 'Value',1); |
---|
912 | set(handles.TimeName, 'String',Field.Display.ListDimName) |
---|
913 | end |
---|
914 | TimeName_Callback(hObject, [], handles) |
---|
915 | |
---|
916 | %----------------------------------------------------------------------- |
---|
917 | function update_field(handles,VarName) |
---|
918 | %----------------------------------------------------------------------- |
---|
919 | Field=get(handles.get_field,'UserData'); |
---|
920 | index=name2index(VarName,Field.ListVarName); |
---|
921 | if ~isempty(index) |
---|
922 | set(handles.variables,'Value',index+1) |
---|
923 | variables_Callback(handles.variables, [], handles) |
---|
924 | end |
---|
925 | |
---|
926 | %------------------------------------------------------------------------ |
---|
927 | % --- give index numbers of the strings str in the list ListvarName |
---|
928 | % ----------------------------------------------------------------------- |
---|
929 | function VarIndex_y=name2index(cell_str,ListVarName) |
---|
930 | |
---|
931 | VarIndex_y=[]; |
---|
932 | if ischar(cell_str) |
---|
933 | for ivar=1:length(ListVarName) |
---|
934 | varlist=ListVarName{ivar}; |
---|
935 | if isequal(varlist,cell_str) |
---|
936 | VarIndex_y= ivar; |
---|
937 | break |
---|
938 | end |
---|
939 | end |
---|
940 | elseif iscell(cell_str) |
---|
941 | for isel=1:length(cell_str) |
---|
942 | varsel=cell_str{isel}; |
---|
943 | for ivar=1:length(ListVarName) |
---|
944 | varlist=ListVarName{ivar}; |
---|
945 | if isequal(varlist,varsel) |
---|
946 | VarIndex_y=[VarIndex_y ivar]; |
---|
947 | end |
---|
948 | end |
---|
949 | end |
---|
950 | end |
---|
951 | |
---|
952 | % --- Executes on button press in CheckDimensionY. |
---|
953 | function CheckDimensionX_Callback(hObject, eventdata, handles) |
---|
954 | CheckDimensionX=get(handles.CheckDimensionX,'value') |
---|
955 | if CheckDimensionX |
---|
956 | set(handles.Coordinates,'visible','off') |
---|
957 | else |
---|
958 | set(handles.Coordinates,'visible','on') |
---|
959 | end |
---|
960 | % FieldList=get(handles.FieldOption,'String'); |
---|
961 | % FieldOption=FieldList{get(handles.FieldOption,'Value')}; |
---|
962 | % switch FieldOption |
---|
963 | % case '1D plot' |
---|
964 | % |
---|
965 | % case {'scalar'} |
---|
966 | % scalar_Callback(hObject, eventdata, handles) |
---|
967 | % case 'vectors' |
---|
968 | % end |
---|
969 | |
---|
970 | % % --- Executes on button press in CheckDimensionY. |
---|
971 | % function CheckDimensionY_Callback(hObject, eventdata, handles) |
---|
972 | % FieldList=get(handles.FieldOption,'String'); |
---|
973 | % FieldOption=FieldList{get(handles.FieldOption,'Value')}; |
---|
974 | % switch FieldOption |
---|
975 | % case '1D plot' |
---|
976 | % |
---|
977 | % case {'scalar','pick variables'} |
---|
978 | % scalar_Callback(hObject, eventdata, handles) |
---|
979 | % case 'vectors' |
---|
980 | % end |
---|
981 | % |
---|
982 | % |
---|
983 | % % --- Executes on button press in CheckDimensionZ. |
---|
984 | % function CheckDimensionZ_Callback(hObject, eventdata, handles) |
---|
985 | % FieldList=get(handles.FieldOption,'String'); |
---|
986 | % FieldOption=FieldList{get(handles.FieldOption,'Value')}; |
---|
987 | % switch FieldOption |
---|
988 | % case '1D plot' |
---|
989 | % |
---|
990 | % case 'scalar' |
---|
991 | % scalar_Callback(hObject, eventdata, handles) |
---|
992 | % case 'vectors' |
---|
993 | % end |
---|
994 | |
---|
995 | % --- Executes on selection change in TimeName. |
---|
996 | function TimeName_Callback(hObject, eventdata, handles) |
---|
997 | Field=get(handles.get_field,'UserData'); |
---|
998 | index=get(handles.SwitchVarIndexTime,'Value'); |
---|
999 | MenuIndex=get(handles.TimeName,'Value'); |
---|
1000 | string=get(handles.TimeName,'String'); |
---|
1001 | TimeName='';%default |
---|
1002 | if ~isempty(string)&&iscell(string) |
---|
1003 | TimeName=string{MenuIndex}; |
---|
1004 | end |
---|
1005 | switch index |
---|
1006 | case 1 |
---|
1007 | set(handles.num_TimeDimension,'String','') |
---|
1008 | set(handles.TimeUnit,'String','index') |
---|
1009 | case 2 |
---|
1010 | set(handles.num_TimeDimension,'String','') |
---|
1011 | attr_index=find(strcmpi([TimeName 'Unit'],Field.ListGlobalAttribute));% look for time unit |
---|
1012 | if ~isempty(attr_index) |
---|
1013 | AttrName=Field.ListGlobalAttribute{attr_index}; |
---|
1014 | set(handles.TimeUnit,'String',Field.(AttrName)) |
---|
1015 | else |
---|
1016 | set(handles.TimeUnit,'String','') |
---|
1017 | end |
---|
1018 | case {3 ,4} |
---|
1019 | if index==3 % TimeName is used to chose a variable |
---|
1020 | VarIndex=name2index(TimeName,Field.ListVarName); |
---|
1021 | DimName=Field.VarDimName{VarIndex}; |
---|
1022 | DimIndex=name2index(DimName,Field.ListDimName); |
---|
1023 | DimValue=Field.DimValue(DimIndex); |
---|
1024 | set(handles.num_TimeDimension,'String',num2str(DimValue)) |
---|
1025 | unit=''; |
---|
1026 | if isfield(Field,'VarAttribute')&& isfield(Field.VarAttribute{VarIndex},'Unit') |
---|
1027 | unit=Field.VarAttribute{VarIndex}.Unit; |
---|
1028 | end |
---|
1029 | set(handles.TimeUnit,'String',unit) |
---|
1030 | update_field(handles,TimeName) |
---|
1031 | elseif index==4% TimeName is used to chose a dimension |
---|
1032 | DimName=string{MenuIndex}; |
---|
1033 | DimIndex=name2index(DimName,Field.ListDimName); |
---|
1034 | DimValue=Field.DimValue(DimIndex); |
---|
1035 | set(handles.num_TimeDimension,'String',num2str(DimValue)) |
---|
1036 | set(handles.TimeUnit,'String','index') |
---|
1037 | end |
---|
1038 | end |
---|
1039 | |
---|
1040 | |
---|
1041 | % --- Executes on button press in Check3D. |
---|
1042 | function Check3D_Callback(hObject, eventdata, handles) |
---|
1043 | if get(handles.Check3D,'Value')% 3D fields |
---|
1044 | status='on'; |
---|
1045 | else% fields studied as 2D |
---|
1046 | status='off'; |
---|
1047 | |
---|
1048 | end |
---|
1049 | set(handles.Coord_z,'Visible',status) |
---|
1050 | % set(handles.CheckDimensionZ,'Visible',status) |
---|
1051 | set(handles.Z_title,'Visible',status) |
---|
1052 | set(handles.vector_z,'Visible',status) |
---|
1053 | set(handles.W_title,'Visible',status) |
---|
1054 | if strcmp(status,'on') |
---|
1055 | Field=get(handles.get_field,'UserData'); |
---|
1056 | if Field.MaxDim>=3% for 3D fields, propose to use the third variable as time |
---|
1057 | menu=get(handles.SwitchVarIndexTime,'String'); |
---|
1058 | val=find(strcmp('variable',menu)); |
---|
1059 | if ~isempty(val) |
---|
1060 | set(handles.SwitchVarIndexTime,'Value',val) |
---|
1061 | SwitchVarIndexTime_Callback(handles.SwitchVarIndexTime,[], handles) |
---|
1062 | end |
---|
1063 | end |
---|
1064 | end |
---|
1065 | %------------------------------------------------------------------------ |
---|
1066 | % --- Executes on button press in OK. |
---|
1067 | %------------------------------------------------------------------------ |
---|
1068 | function OK_Callback(hObject, eventdata, handles) |
---|
1069 | handles.output=read_GUI(handles.get_field); |
---|
1070 | guidata(hObject, handles);% Update handles structure |
---|
1071 | uiresume(handles.get_field); |
---|
1072 | drawnow |
---|
1073 | % this function then activate get_field_OutputFcn |
---|
1074 | |
---|
1075 | %------------------------------------------------------------------------ |
---|
1076 | % --- Executes when the GUI is closed by the mouse on upper right corner. |
---|
1077 | %------------------------------------------------------------------------ |
---|
1078 | function closefcn(hObject, eventdata, handles) |
---|
1079 | handles.output=[]; |
---|
1080 | guidata(hObject, handles);% Update handles structure |
---|
1081 | uiresume(handles.get_field); |
---|
1082 | drawnow |
---|
1083 | |
---|
1084 | %------------------------------------------------------------------------ |
---|
1085 | % --- Outputs from this function are returned to the command line. |
---|
1086 | %------------------------------------------------------------------------ |
---|
1087 | function varargout = get_field_OutputFcn(hObject, eventdata, handles) |
---|
1088 | |
---|
1089 | varargout{1} =handles.output; |
---|
1090 | delete(handles.get_field) |
---|