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