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