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