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