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