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