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