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