[204] | 1 | %'get_field': display variables and attributes from a Netcdf file, and RUN selected fields |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | %function varargout = get_field(varargin) |
---|
| 4 | % associated with the GUI get_field.fig |
---|
| 5 | % |
---|
| 6 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 7 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
| 8 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 9 | % This file is part of the toolbox UVMAT. |
---|
| 10 | % |
---|
| 11 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 12 | % it under the terms of the GNU General Public License as published by |
---|
| 13 | % the Free Software Foundation; either version 2 of the License, or |
---|
| 14 | % (at your option) any later version. |
---|
| 15 | % |
---|
| 16 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 17 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 18 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 19 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
| 20 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 21 | |
---|
| 22 | function varargout = get_field(varargin) |
---|
| 23 | |
---|
[503] | 24 | % Last Modified by GUIDE v2.5 26-Jul-2012 09:11:23 |
---|
[204] | 25 | |
---|
| 26 | % Begin initialization code - DO NOT EDIT |
---|
| 27 | gui_Singleton = 0; |
---|
| 28 | gui_State = struct('gui_Name', mfilename, ... |
---|
| 29 | 'gui_Singleton', gui_Singleton, ... |
---|
| 30 | 'gui_OpeningFcn', @get_field_OpeningFcn, ... |
---|
| 31 | 'gui_OutputFcn', @get_field_OutputFcn, ... |
---|
| 32 | 'gui_LayoutFcn', [] , ... |
---|
| 33 | 'gui_Callback', []); |
---|
| 34 | if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
| 35 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
| 36 | end |
---|
| 37 | |
---|
| 38 | if nargout |
---|
| 39 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
| 40 | else |
---|
| 41 | gui_mainfcn(gui_State, varargin{:}); |
---|
| 42 | end |
---|
| 43 | % End initialization code - DO NOT EDIT |
---|
| 44 | |
---|
| 45 | %------------------------------------------------------------------------ |
---|
| 46 | % --- Executes just before get_field is made visible. |
---|
| 47 | function get_field_OpeningFcn(hObject, eventdata, handles,filename,multiple) |
---|
| 48 | %------------------------------------------------------------------------ |
---|
| 49 | global nb_builtin % nbre of functions to include by default in the menu of functions called by RUN |
---|
| 50 | |
---|
| 51 | |
---|
[227] | 52 | |
---|
[204] | 53 | %% Choose default command line output for get_field |
---|
| 54 | handles.output = hObject; |
---|
| 55 | |
---|
| 56 | %% Update handles structure |
---|
| 57 | guidata(hObject, handles); |
---|
[434] | 58 | set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display) |
---|
[204] | 59 | |
---|
| 60 | %% prepare the list of RUN fcts and set their paths |
---|
| 61 | % functions included by default in 'get_field.m |
---|
[213] | 62 | menu_str={'PLOT';'FFT';'filter_band'}; |
---|
[204] | 63 | nb_builtin=numel(menu_str); |
---|
| 64 | path_uvmat=fileparts(which('uvmat'));%path of the function 'uvmat' |
---|
| 65 | addpath(fullfile(path_uvmat,'get_field')) |
---|
| 66 | testexist=zeros(size(menu_str'));%default |
---|
| 67 | for ilist=1:length(menu_str) |
---|
| 68 | if exist(menu_str{ilist},'file') |
---|
| 69 | fct_handle{ilist,1}=str2func(menu_str{ilist}); |
---|
| 70 | testexist(ilist)=1; |
---|
| 71 | else |
---|
| 72 | fct_handle{ilist,1}=[]; |
---|
| 73 | testexist(ilist)=0; |
---|
| 74 | end |
---|
| 75 | end |
---|
| 76 | rmpath(fullfile(path_uvmat,'get_field')) |
---|
| 77 | dir_perso=prefdir; |
---|
| 78 | |
---|
| 79 | % look for functions previously used (names and paths saved in the personal file uvmat_perso.mat): |
---|
| 80 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 81 | if exist(profil_perso,'file') |
---|
| 82 | h=load (profil_perso); |
---|
| 83 | if isfield(h,'get_field_fct') && iscell(h.get_field_fct) |
---|
| 84 | for ilist=1:length(h.get_field_fct) |
---|
| 85 | [path,file]=fileparts(h.get_field_fct{ilist}); |
---|
| 86 | addpath(path) |
---|
| 87 | if exist(file,'file') |
---|
| 88 | h_func=str2func(file); |
---|
| 89 | testexist=[testexist 1]; |
---|
| 90 | else |
---|
| 91 | h_func=[]; |
---|
| 92 | testexist=[testexist 0]; |
---|
| 93 | end |
---|
| 94 | fct_handle=[fct_handle; {h_func}]; %concatene the list of paths |
---|
| 95 | rmpath(path) |
---|
| 96 | menu_str=[menu_str; {file}]; |
---|
| 97 | end |
---|
| 98 | end |
---|
| 99 | end |
---|
| 100 | |
---|
| 101 | menu_str=menu_str(testexist==1);%=menu_str(testexist~=0) |
---|
| 102 | fct_handle=fct_handle(testexist==1); |
---|
| 103 | menu_str=[menu_str;{'more...'}]; |
---|
| 104 | set(handles.ACTION,'String',menu_str) |
---|
| 105 | set(handles.ACTION,'UserData',fct_handle)% store the list of path in UserData of ACTION |
---|
| 106 | set(handles.path_action,'String',fullfile(path_uvmat,'get_field')) |
---|
| 107 | set(handles.ACTION,'Value',1)% PLOT option selected |
---|
| 108 | |
---|
| 109 | %% settings for 'slave' mode, called by uvamt, or 'master' mode |
---|
| 110 | if exist('filename','var') && ischar(filename) %transfer input file name in slave mode |
---|
[227] | 111 | set(handles.inputfile,'String',filename)% prefill the input file name |
---|
[494] | 112 | Field=nc2struct(filename,[]);% reads the field structure, without variables |
---|
[204] | 113 | if isfield(Field,'Txt') |
---|
| 114 | msgbox_uvmat('ERROR',Field.Txt) |
---|
| 115 | else |
---|
[227] | 116 | set(handles.get_field,'UserData',Field); |
---|
[494] | 117 | Field_input(handles,Field); |
---|
[204] | 118 | end |
---|
| 119 | else %master mode |
---|
[227] | 120 | set(handles.inputfile,'String','') |
---|
| 121 | end |
---|
| 122 | |
---|
| 123 | %% load the list of previously browsed files for the upper bar menu Open |
---|
| 124 | dir_perso=prefdir; |
---|
| 125 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% |
---|
| 126 | if exist(profil_perso,'file') |
---|
| 127 | h=load (profil_perso); |
---|
| 128 | if isfield(h,'MenuFile_1') |
---|
| 129 | set(handles.MenuFile_1,'Label',h.MenuFile_1); |
---|
[204] | 130 | end |
---|
[227] | 131 | if isfield(h,'MenuFile_1') |
---|
| 132 | set(handles.MenuFile_2,'Label',h.MenuFile_2); |
---|
| 133 | end |
---|
| 134 | if isfield(h,'MenuFile_1') |
---|
| 135 | set(handles.MenuFile_3,'Label',h.MenuFile_3); |
---|
| 136 | end |
---|
| 137 | if isfield(h,'MenuFile_1') |
---|
| 138 | set(handles.MenuFile_4,'Label',h.MenuFile_4); |
---|
| 139 | end |
---|
| 140 | if isfield(h,'MenuFile_1') |
---|
| 141 | set(handles.MenuFile_5,'Label',h.MenuFile_5); |
---|
| 142 | end |
---|
[204] | 143 | end |
---|
| 144 | |
---|
[434] | 145 | %% put the GUI on the lower right of the sceen |
---|
| 146 | pos_view_field=get(hObject,'Position'); |
---|
| 147 | ScreenSize=get(0,'ScreenSize'); |
---|
| 148 | pos_view_field(1)=ScreenSize(1)+ScreenSize(3)-pos_view_field(3); |
---|
| 149 | pos_view_field(2)=ScreenSize(2); |
---|
| 150 | set(hObject,'Position',pos_view_field) |
---|
| 151 | |
---|
[204] | 152 | %% remove already opened get_field GUI with name get_field |
---|
| 153 | if ~(exist('multiple','var') && isequal(multiple,1)) %set single occurrence |
---|
| 154 | hget_field=findobj(allchild(0),'Name','get_field'); %hget_field(1)= new GUI |
---|
| 155 | if length(hget_field)>1 |
---|
| 156 | delete(hget_field(2)) |
---|
| 157 | end |
---|
| 158 | else |
---|
| 159 | set(hObject,'name','get_field_1') |
---|
| 160 | end |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | %------------------------------------------------------------------------ |
---|
| 164 | % --- Outputs from this function are returned to the command line. |
---|
| 165 | function varargout = get_field_OutputFcn(hObject, eventdata, handles) |
---|
| 166 | %------------------------------------------------------------------------ |
---|
| 167 | varargout{1} = handles.output; |
---|
| 168 | |
---|
| 169 | %------------------------------------------------------------------------ |
---|
| 170 | % --- Executes when a new input file name is introduced. |
---|
| 171 | function inputfile_Callback(hObject, eventdata, handles) |
---|
| 172 | %------------------------------------------------------------------------ |
---|
| 173 | inputfile=get(handles.inputfile,'String'); |
---|
[227] | 174 | Field=nc2struct(inputfile,[]);% reads the field description, without data |
---|
[204] | 175 | if isfield(Field,'Txt') |
---|
| 176 | msgbox_uvmat('ERROR',Field.Txt) |
---|
| 177 | else |
---|
[227] | 178 | set(handles.get_field,'UserData',Field); |
---|
[494] | 179 | Field_input(handles,Field); |
---|
[204] | 180 | end |
---|
| 181 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
| 182 | if ~isempty(huvmat) |
---|
| 183 | delete(huvmat)%delete uvmat for plot reinitialisation |
---|
| 184 | end |
---|
| 185 | |
---|
| 186 | %------------------------------------------------------------------------ |
---|
| 187 | % --- update the display when a new field is introduced. |
---|
[494] | 188 | function Field_input(handles,Field) |
---|
[204] | 189 | %------------------------------------------------------------------------ |
---|
| 190 | if isfield(Field,'ListDimName')&&~isempty(Field.ListDimName) |
---|
| 191 | Tabcell(:,1)=Field.ListDimName; |
---|
| 192 | for iline=1:length(Field.ListDimName) |
---|
| 193 | Tabcell{iline,2}=num2str(Field.DimValue(iline)); |
---|
| 194 | end |
---|
[227] | 195 | Tabchar=cell2tab(Tabcell,' = '); |
---|
[204] | 196 | set(handles.dimensions,'String',Tabchar) |
---|
| 197 | end |
---|
| 198 | if ~isfield(Field,'ListVarName') |
---|
| 199 | return |
---|
| 200 | end |
---|
| 201 | Txt=Field.ListVarName; |
---|
| 202 | set(handles.variables,'Value',1) |
---|
| 203 | set(handles.variables,'String',[{'*'} Txt]) |
---|
| 204 | variables_Callback(handles.variables,[], handles) |
---|
| 205 | set(handles.abscissa,'String',[{''} Txt ]) |
---|
| 206 | set(handles.ordinate,'String',Txt) |
---|
| 207 | set(handles.vector_x,'String',[Txt ]) |
---|
| 208 | set(handles.vector_y,'String',[Txt ]) |
---|
| 209 | set(handles.vector_z,'String',[{''} Txt ]) |
---|
| 210 | set(handles.vec_color,'String',[{''} Txt ]) |
---|
| 211 | set(handles.coord_x_scalar,'String',[{''} Txt ]) |
---|
| 212 | set(handles.coord_y_scalar,'String',[{''} Txt ]) |
---|
| 213 | set(handles.coord_x_vectors,'String',[{''} Txt ]) |
---|
| 214 | set(handles.coord_y_vectors,'String',[{''} Txt ]) |
---|
| 215 | set(handles.coord_z_scalar,'String',[{''} Txt ]) |
---|
| 216 | set(handles.coord_z_vectors,'String',[{''} Txt ]) |
---|
| 217 | set(handles.scalar,'Value',1) |
---|
[227] | 218 | |
---|
[204] | 219 | set(handles.scalar,'String', Txt ) |
---|
[512] | 220 | [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Field); |
---|
[204] | 221 | if ~isempty(errormsg) |
---|
[512] | 222 | msgbox_uvmat('ERROR',['error in get_field/Field_input/find_field_cells: ' errormsg]) |
---|
[204] | 223 | return |
---|
| 224 | end |
---|
[227] | 225 | for icell=1:numel(CellVarIndex) |
---|
| 226 | NbDim(icell)=max(NbDim(icell),numel(CellVarIndex{icell})); |
---|
| 227 | end |
---|
[204] | 228 | [maxdim,imax]=max(NbDim); |
---|
| 229 | |
---|
| 230 | if maxdim>=3 |
---|
| 231 | set(handles.vector_z,'Visible','on') |
---|
| 232 | set(handles.vector_z,'String',[{''} Txt ]) |
---|
| 233 | set(handles.coord_z_vectors,'Visible','on') |
---|
| 234 | set(handles.coord_z_vectors,'String',[{''} Txt ]) |
---|
| 235 | set(handles.coord_z_scalar,'Visible','on') |
---|
| 236 | set(handles.coord_z_scalar,'String',[{''} Txt ]) |
---|
| 237 | else |
---|
| 238 | set(handles.vector_z,'Visible','off') |
---|
| 239 | set(handles.coord_z_vectors,'Visible','off') |
---|
| 240 | set(handles.coord_z_scalar,'Visible','off') |
---|
| 241 | end |
---|
| 242 | if maxdim>=2 |
---|
[503] | 243 | set(handles.CheckPlot1D,'Value',0) |
---|
[204] | 244 | if ~isempty(VarType{imax}.vector_x) && ~isempty(VarType{imax}.vector_y) |
---|
[503] | 245 | set(handles.CheckVector,'Value',1) |
---|
| 246 | set(handles.CheckScalar,'Value',0) |
---|
[236] | 247 | set(handles.vector_x,'Value',VarType{imax}.vector_x(1)) |
---|
| 248 | set(handles.vector_y,'Value',VarType{imax}.vector_y(1)) |
---|
[204] | 249 | if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y) |
---|
| 250 | set(handles.coord_x_vectors,'Value',VarType{imax}.coord_x+1) |
---|
| 251 | set(handles.coord_y_vectors,'Value',VarType{imax}.coord_y+1) |
---|
| 252 | end |
---|
| 253 | if ~isempty(VarType{imax}.coord) |
---|
| 254 | set(handles.coord_y_vectors,'Value',VarType{imax}.coord(1)+1) |
---|
| 255 | if numel(VarType{imax}.coord)>=2 |
---|
| 256 | set(handles.coord_x_vectors,'Value',VarType{imax}.coord(2)+1) |
---|
| 257 | end |
---|
| 258 | end |
---|
| 259 | else |
---|
[503] | 260 | set(handles.CheckScalar,'Value',1) |
---|
| 261 | set(handles.CheckVector,'Value',0) |
---|
[204] | 262 | if isfield(VarType{imax},'scalar') && length(VarType{imax}.scalar)>=1 |
---|
| 263 | set(handles.scalar,'Value',VarType{imax}.scalar(1)) |
---|
| 264 | if ~isempty(VarType{imax}.coord_x) && ~isempty(VarType{imax}.coord_y) |
---|
| 265 | set(handles.coord_x_scalar,'Value',VarType{imax}.coord_x+1) |
---|
| 266 | set(handles.coord_y_scalar,'Value',VarType{imax}.coord_y+1) |
---|
| 267 | end |
---|
| 268 | if ~isempty(VarType{imax}.coord_z) |
---|
| 269 | set(handles.coord_z_scalar,'Value',VarType{imax}.coord_z+1) |
---|
| 270 | end |
---|
| 271 | if ~isempty(VarType{imax}.coord) |
---|
| 272 | if numel(VarType{imax}.coord)>=maxdim-2 && maxdim>=3 |
---|
| 273 | set(handles.coord_z_scalar,'Value',VarType{imax}.coord(maxdim-2)+1) |
---|
| 274 | end |
---|
| 275 | if numel(VarType{imax}.coord)>=maxdim-1 |
---|
| 276 | set(handles.coord_y_scalar,'Value',VarType{imax}.coord(maxdim-1)+1) |
---|
| 277 | end |
---|
| 278 | if numel(VarType{imax}.coord)>=maxdim |
---|
| 279 | set(handles.coord_x_scalar,'Value',VarType{imax}.coord(maxdim)+1) |
---|
| 280 | end |
---|
| 281 | end |
---|
| 282 | end |
---|
| 283 | end |
---|
[503] | 284 | CheckPlot1D_Callback(handles.CheckPlot1D, [], handles) |
---|
| 285 | CheckScalar_Callback(handles.CheckScalar, [], handles) |
---|
| 286 | CheckVector_Callback(handles.CheckVector, [], handles) |
---|
[204] | 287 | end |
---|
[227] | 288 | %scalar_Callback(handles.get_field, eventdata, handles) |
---|
| 289 | %vector_x_Callback(handles.get_field, eventdata, handles) |
---|
[204] | 290 | |
---|
| 291 | %------------------------------------------------------------------------ |
---|
| 292 | function ordinate_Callback(hObject, eventdata, handles) |
---|
| 293 | %------------------------------------------------------------------------ |
---|
| 294 | hselect_field=get(handles.inputfile,'parent'); |
---|
| 295 | Field=get(hselect_field,'UserData'); |
---|
| 296 | list=get(handles.ordinate,'String'); |
---|
| 297 | yindex=get(handles.ordinate,'Value'); |
---|
| 298 | yindex=name2index(list{yindex(1)},Field.ListVarName); |
---|
| 299 | if ~isempty(yindex) |
---|
| 300 | set(handles.variables,'Value',yindex+1) |
---|
| 301 | variables_Callback(hObject, eventdata, handles) |
---|
| 302 | end |
---|
[512] | 303 | [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(Field); |
---|
[204] | 304 | for icell=1:numel(CellVarIndex) |
---|
| 305 | VarIndex=CellVarIndex{icell}; |
---|
| 306 | if ~isempty(find(VarIndex==yindex,1)) && (isempty(VarType{icell}.coord_x)||~isequal(VarType{icell}.coord_x,VarIndex)) |
---|
| 307 | cell_select=icell; |
---|
| 308 | break |
---|
| 309 | end |
---|
| 310 | end |
---|
| 311 | |
---|
| 312 | val=get(handles.abscissa,'Value'); |
---|
| 313 | set(handles.abscissa,'Value',min(val,2)); |
---|
| 314 | coord_x_index=VarType{cell_select}.coord; |
---|
| 315 | coord_x_index=coord_x_index(coord_x_index~=0); |
---|
| 316 | set(handles.abscissa,'String',[{''}; (Field.ListVarName(coord_x_index))'; (Field.ListVarName(VarIndex))']) |
---|
| 317 | |
---|
| 318 | %------------------------------------------------------------------------ |
---|
| 319 | % --- Executes on selection change in abscissa. |
---|
| 320 | function abscissa_Callback(hObject, eventdata, handles) |
---|
| 321 | %------------------------------------------------------------------------ |
---|
| 322 | hselect_field=get(handles.inputfile,'parent'); |
---|
| 323 | Field=get(hselect_field,'UserData');%current input field |
---|
| 324 | xdispindex=get(handles.abscissa,'Value');%index in the list of abscissa |
---|
[503] | 325 | % test_2D=get(handles.CheckVector,'Value');% =1 for vector fields |
---|
| 326 | % test_scalar=get(handles.CheckScalar,'Value');% =1 for scalar fields |
---|
[227] | 327 | %if isequal(xdispindex,1)% blank selection, no selected TimeVariable for abscissa |
---|
[204] | 328 | % Txt=Field.ListVarName; |
---|
| 329 | % set(handles.ordinate,'String',[{''} Txt ])% display all the varaibles in the list of ordinates |
---|
| 330 | % xindex=[]; |
---|
| 331 | % else |
---|
| 332 | xlist=get(handles.abscissa,'String');%list of abscissa |
---|
| 333 | VarName=xlist{xdispindex}; %selected variable name |
---|
| 334 | update_field(hObject, eventdata, handles,VarName) |
---|
| 335 | % xindex=name2index(xname,Field.ListVarName); %index of the selection in the total list of variables |
---|
| 336 | % if ~isempty(xindex) |
---|
| 337 | % set(handles.variables,'Value',xindex+1) |
---|
| 338 | % variables_Callback(hObject, eventdata, handles) |
---|
| 339 | % end |
---|
| 340 | % set(handles.variables,'Value',xindex+1)%outline in the list of variables |
---|
[227] | 341 | % variables_Callback(hObject, eventdata, handles) %display properties of the TimeVariable (dim, attributes) |
---|
[204] | 342 | % if ~test_2D & ~test_scalar% look for possible varaibles to RUN in ordinate |
---|
[227] | 343 | % index=Field.VarDimIndex{xindex};%dimension indices of the TimeVariable selected for abscissa |
---|
[204] | 344 | % VarIndex=[]; |
---|
| 345 | % for ilist=1:length(Field.VarDimIndex)%detect |
---|
| 346 | % index_i=Field.VarDimIndex{ilist}; |
---|
| 347 | % if ~isempty(index_i) |
---|
[227] | 348 | % if isequal(index_i(1),index(1))%if the first dimension of the TimeVariable coincide with the selected one, RUN is possible |
---|
[204] | 349 | % VarIndex=[VarIndex ilist]; |
---|
| 350 | % end |
---|
| 351 | % end |
---|
| 352 | % end |
---|
| 353 | % % set(handles.ordinate,'Value',1) |
---|
| 354 | % set(handles.ordinate,'String',Field.ListVarName(VarIndex)) |
---|
| 355 | % end |
---|
| 356 | % end |
---|
| 357 | % |
---|
| 358 | % update_UserData(handles) |
---|
| 359 | |
---|
| 360 | %------------------------------------------------------------------------ |
---|
| 361 | % --- Executes on selection change in scalar menu. |
---|
| 362 | function scalar_Callback(hObject, eventdata, handles) |
---|
| 363 | %------------------------------------------------------------------------ |
---|
[227] | 364 | index=get(handles.scalar,'Value'); |
---|
| 365 | string=get(handles.scalar,'String'); |
---|
| 366 | VarName=string{index}; |
---|
[204] | 367 | update_field(hObject, eventdata, handles,VarName) |
---|
| 368 | |
---|
[227] | 369 | %eliminate time |
---|
| 370 | TimeDimName='';%default |
---|
| 371 | if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on') |
---|
| 372 | TimeDimList=get(handles.TimeDimensionMenu,'String'); |
---|
| 373 | TimeDimIndex=get(handles.TimeDimensionMenu,'Value'); |
---|
| 374 | TimeDimName=TimeDimList{TimeDimIndex}; |
---|
| 375 | end |
---|
| 376 | |
---|
| 377 | %check possible coordinates |
---|
| 378 | Field=get(handles.get_field,'UserData'); |
---|
| 379 | dim_scalar=Field.VarDimName{index};%list of dimensions of the selected scalar |
---|
| 380 | test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate |
---|
| 381 | for ilist=1:numel(Field.VarDimName) |
---|
| 382 | dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
| 383 | if isequal(dimnames,{TimeDimName}) |
---|
| 384 | test_coord(ilist)=0;%mark time variables fo elimination |
---|
| 385 | end |
---|
| 386 | for idim=1:numel(dimnames) |
---|
| 387 | if isempty(find(strcmp(dimnames{idim},dim_scalar),1))%dimension not found in the scalar variable |
---|
| 388 | test_coord(ilist)=0; |
---|
| 389 | break |
---|
| 390 | end |
---|
| 391 | end |
---|
| 392 | end |
---|
| 393 | test_coord(index)=0;%the coordinate variable must be different from the scalar |
---|
| 394 | |
---|
| 395 | string_coord=[{''};string(test_coord==1)]; |
---|
| 396 | val=get(handles.coord_x_scalar,'Value'); |
---|
| 397 | if val>numel(string_coord) |
---|
| 398 | set(handles.coord_x_scalar,'Value',1) |
---|
| 399 | end |
---|
| 400 | set(handles.coord_x_scalar,'String',string_coord); |
---|
| 401 | val=get(handles.coord_y_scalar,'Value'); |
---|
| 402 | if val>numel(string_coord) |
---|
| 403 | set(handles.coord_y_scalar,'Value',1) |
---|
| 404 | end |
---|
| 405 | set(handles.coord_y_scalar,'String',string_coord); |
---|
| 406 | val=get(handles.coord_y_scalar,'Value'); |
---|
| 407 | if val>numel(string_coord) |
---|
| 408 | set(handles.coord_y_scalar,'Value',1) |
---|
| 409 | end |
---|
| 410 | set(handles.coord_z_scalar,'String',string_coord); |
---|
| 411 | |
---|
| 412 | |
---|
[204] | 413 | %------------------------------------------------------------------------ |
---|
| 414 | % --- Executes on selection change in coord_x_scalar. |
---|
| 415 | function coord_x_scalar_Callback(hObject, eventdata, handles) |
---|
| 416 | %------------------------------------------------------------------------ |
---|
| 417 | index=get(handles.coord_x_scalar,'Value'); |
---|
| 418 | string=get(handles.coord_x_scalar,'String'); |
---|
| 419 | VarName=string{index}; |
---|
| 420 | update_field(hObject, eventdata, handles,VarName) |
---|
| 421 | |
---|
| 422 | %------------------------------------------------------------------------ |
---|
| 423 | % --- Executes on selection change in coord_y_scalar. |
---|
| 424 | function coord_y_scalar_Callback(hObject, eventdata, handles) |
---|
| 425 | %------------------------------------------------------------------------ |
---|
| 426 | index=get(handles.coord_y_scalar,'Value'); |
---|
| 427 | string=get(handles.coord_y_scalar,'String'); |
---|
| 428 | VarName=string{index}; |
---|
| 429 | update_field(hObject, eventdata, handles,VarName) |
---|
| 430 | |
---|
| 431 | %------------------------------------------------------------------------ |
---|
| 432 | % --- Executes on selection change in coord_z_scalar. |
---|
| 433 | function coord_z_scalar_Callback(hObject, eventdata, handles) |
---|
| 434 | %------------------------------------------------------------------------ |
---|
| 435 | index=get(handles.coord_z_scalar,'Value'); |
---|
| 436 | string=get(handles.coord_z_scalar,'String'); |
---|
| 437 | VarName=string{index}; |
---|
| 438 | update_field(hObject, eventdata, handles,VarName) |
---|
| 439 | |
---|
| 440 | %------------------------------------------------------------------------ |
---|
| 441 | % --- Executes on selection change in vector_x. |
---|
| 442 | function vector_x_Callback(hObject, eventdata, handles) |
---|
| 443 | %------------------------------------------------------------------------ |
---|
| 444 | index=get(handles.vector_x,'Value'); |
---|
| 445 | string=get(handles.vector_x,'String'); |
---|
| 446 | VarName=string{index}; |
---|
[227] | 447 | |
---|
| 448 | %check possible coordinates |
---|
| 449 | Field=get(handles.get_field,'UserData'); |
---|
| 450 | dim_var=Field.VarDimName{index};%list of dimensions of the selected scalar |
---|
| 451 | test_coord=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as coordinate |
---|
| 452 | test_component=ones(size(Field.VarDimName)); %=1 when variable #ilist is eligible as other vector component |
---|
| 453 | for ilist=1:numel(Field.VarDimName) |
---|
| 454 | dimnames=Field.VarDimName{ilist}; %list of dimensions for variable #ilist |
---|
| 455 | if ~isequal(dimnames,dim_var) |
---|
| 456 | test_component(ilist)=0; |
---|
| 457 | end |
---|
| 458 | for idim=1:numel(dimnames) |
---|
| 459 | if isempty(find(strcmp(dimnames{idim},dim_var),1))%dimension not found in the scalar variable |
---|
| 460 | test_coord(ilist)=0; |
---|
| 461 | break |
---|
| 462 | end |
---|
| 463 | end |
---|
| 464 | end |
---|
| 465 | %eliminate time |
---|
| 466 | if get(handles.TimeVariable,'Value') |
---|
| 467 | TimeName=get(handles.TimeName,'String'); |
---|
| 468 | index_time=find(strcmp( TimeName,Field.ListVarName)); |
---|
| 469 | test_coord(index_time)=0; |
---|
| 470 | end |
---|
| 471 | vlength=numel(string(test_component==1)); |
---|
| 472 | val=get(handles.vector_y,'Value'); |
---|
| 473 | if val>vlength |
---|
| 474 | set(handles.vector_y,'Value',1) |
---|
| 475 | end |
---|
| 476 | set(handles.vector_y,'String',[string(test_component==1)]) |
---|
| 477 | val=get(handles.vector_z,'Value'); |
---|
| 478 | if val>vlength+1 |
---|
| 479 | set(handles.vector_z,'Value',1) |
---|
| 480 | end |
---|
| 481 | set(handles.vector_z,'String',[{''};string(test_component==1)]) |
---|
| 482 | val=get(handles.vec_color,'Value'); |
---|
| 483 | if val>vlength+1 |
---|
| 484 | set(handles.vec_color,'Value',1) |
---|
| 485 | end |
---|
| 486 | set(handles.vec_color,'String',[{''};string(test_component==1)]) |
---|
| 487 | string_coord=[{''};string(test_coord==1)]; |
---|
| 488 | val=get(handles.coord_x_vectors,'Value'); |
---|
| 489 | if val>numel(string_coord) |
---|
| 490 | set(handles.coord_x_vectors,'Value',1) |
---|
| 491 | end |
---|
| 492 | set(handles.coord_x_vectors,'String',string_coord); |
---|
| 493 | val=get(handles.coord_y_vectors,'Value'); |
---|
| 494 | if val>numel(string_coord) |
---|
| 495 | set(handles.coord_y_vectors,'Value',1) |
---|
| 496 | end |
---|
| 497 | set(handles.coord_y_vectors,'String',string_coord); |
---|
| 498 | val=get(handles.coord_z_vectors,'Value'); |
---|
| 499 | if val>numel(string_coord) |
---|
| 500 | set(handles.coord_z_vectors,'Value',1) |
---|
| 501 | end |
---|
| 502 | set(handles.coord_z_vectors,'String',string_coord); |
---|
| 503 | |
---|
[204] | 504 | update_field(hObject, eventdata, handles,VarName) |
---|
| 505 | |
---|
| 506 | %------------------------------------------------------------------------ |
---|
| 507 | % --- Executes on selection change in vector_y. |
---|
| 508 | function vector_y_Callback(hObject, eventdata, handles) |
---|
| 509 | %------------------------------------------------------------------------ |
---|
| 510 | index=get(handles.vector_y,'Value'); |
---|
| 511 | string=get(handles.vector_y,'String'); |
---|
| 512 | VarName=string{index}; |
---|
| 513 | update_field(hObject, eventdata, handles,VarName) |
---|
| 514 | |
---|
| 515 | %------------------------------------------------------------------------ |
---|
| 516 | % --- Executes on selection change in vector_z. |
---|
| 517 | function vector_z_Callback(hObject, eventdata, handles) |
---|
| 518 | %------------------------------------------------------------------------ |
---|
| 519 | index=get(handles.vector_z,'Value'); |
---|
| 520 | string=get(handles.vector_z,'String'); |
---|
| 521 | VarName=Astring{index}; |
---|
| 522 | update_field(hObject, eventdata, handles,VarName) |
---|
| 523 | |
---|
| 524 | %------------------------------------------------------------------------ |
---|
| 525 | % --- Executes on selection change in coord_x_vectors. |
---|
| 526 | function coord_x_vectors_Callback(hObject, eventdata, handles) |
---|
| 527 | %------------------------------------------------------------------------ |
---|
| 528 | index=get(handles.coord_x_vectors,'Value'); |
---|
| 529 | string=get(handles.coord_x_vectors,'String'); |
---|
| 530 | VarName=string{index}; |
---|
| 531 | update_field(hObject, eventdata, handles,VarName) |
---|
| 532 | |
---|
[227] | 533 | %------------------------------------------------------------------------ |
---|
[204] | 534 | % --- Executes on selection change in coord_y_vectors. |
---|
| 535 | function coord_y_vectors_Callback(hObject, eventdata, handles) |
---|
[227] | 536 | %------------------------------------------------------------------------ |
---|
[204] | 537 | index=get(handles.coord_y_vectors,'Value'); |
---|
| 538 | string=get(handles.coord_y_vectors,'String'); |
---|
| 539 | VarName=string{index}; |
---|
| 540 | update_field(hObject, eventdata, handles,VarName) |
---|
| 541 | |
---|
[227] | 542 | %------------------------------------------------------------------------ |
---|
[204] | 543 | % --- Executes on selection change in coord_z_scalar. |
---|
| 544 | function coord_z_vectors_Callback(hObject, eventdata, handles) |
---|
[227] | 545 | %------------------------------------------------------------------------ |
---|
[204] | 546 | index=get(handles.coord_z_vectors,'Value'); |
---|
| 547 | string=get(handles.coord_z_vectors,'String'); |
---|
| 548 | VarName=string{index}; |
---|
| 549 | update_field(hObject, eventdata, handles,VarName) |
---|
| 550 | |
---|
[227] | 551 | %------------------------------------------------------------------------ |
---|
[204] | 552 | % --- Executes on selection change in vec_color. |
---|
| 553 | function vec_color_Callback(hObject, eventdata, handles) |
---|
[227] | 554 | %------------------------------------------------------------------------ |
---|
[204] | 555 | index=get(handles.vec_color,'Value'); |
---|
| 556 | string=get(handles.vec_color,'String'); |
---|
| 557 | VarName=string{index}; |
---|
| 558 | update_field(hObject, eventdata, handles,VarName) |
---|
| 559 | |
---|
[227] | 560 | %----------------------------------------------------------------------- |
---|
[204] | 561 | function update_field(hObject, eventdata, handles,VarName) |
---|
[227] | 562 | %----------------------------------------------------------------------- |
---|
| 563 | Field=get(handles.get_field,'UserData'); |
---|
[204] | 564 | index=name2index(VarName,Field.ListVarName); |
---|
| 565 | if ~isempty(index) |
---|
| 566 | set(handles.variables,'Value',index+1) |
---|
| 567 | variables_Callback(hObject, eventdata, handles) |
---|
| 568 | end |
---|
| 569 | |
---|
[227] | 570 | %------------------------------------------------------------------------ |
---|
[204] | 571 | % update the UserData Field for use of the selected variables outsde get_field (taken from RUN_Callback) |
---|
| 572 | function update_UserData(handles) |
---|
[227] | 573 | %------------------------------------------------------------------------ |
---|
[204] | 574 | return |
---|
| 575 | % global SubField |
---|
| 576 | hselect_field=get(handles.inputfile,'parent');%handle of the get_field interface |
---|
| 577 | Field=get(hselect_field,'UserData');% read the current field Structure in the get_field interface |
---|
| 578 | if isfield(Field,'VarAttribute') |
---|
| 579 | VarAttribute=Field.VarAttribute; |
---|
| 580 | else |
---|
| 581 | VarAttribute={}; |
---|
| 582 | end |
---|
| 583 | |
---|
| 584 | |
---|
| 585 | % select the indices of field variables for 2D plots |
---|
[503] | 586 | test_CheckPlot1D=get(handles.CheckPlot1D,'Value'); |
---|
| 587 | test_scalar=get(handles.CheckScalar,'Value'); |
---|
| 588 | test_vector=get(handles.CheckVector,'Value'); |
---|
[204] | 589 | |
---|
| 590 | %transform if needed (calibration) |
---|
| 591 | list=get(handles.menu_coord,'String'); |
---|
| 592 | index=get(handles.menu_coord,'Value'); |
---|
| 593 | transform=list{index}; |
---|
| 594 | if ~isequal(transform,'') |
---|
| 595 | Field=feval(transform,Field); |
---|
| 596 | end |
---|
| 597 | VarIndex.u=[]; |
---|
| 598 | VarIndex.v=[]; |
---|
| 599 | VarIndex.w=[]; |
---|
| 600 | VarIndex.A=[]; |
---|
| 601 | VarIndex_tot=[]; |
---|
| 602 | iuA=[]; |
---|
| 603 | if test_scalar |
---|
| 604 | Astring=get(handles.scalar,'String'); |
---|
| 605 | Aindex=get(handles.scalar,'Value');%selected indices in the ordinate listbox |
---|
| 606 | list_var=Astring(Aindex); |
---|
| 607 | VarIndex.A=name2index(list_var,Field.ListVarName);%index of the variable A in ListVarName |
---|
| 608 | VarIndex_tot= [VarIndex_tot VarIndex.A]; |
---|
| 609 | DimIndex=Field.VarDimIndex{VarIndex.A};%dimension indices of the variable |
---|
| 610 | DimValue=Field.DimValue(DimIndex); |
---|
| 611 | ind=find(DimValue==1); |
---|
| 612 | DimIndex(ind)=[];%Mremove singleton |
---|
| 613 | end |
---|
| 614 | if test_vector |
---|
| 615 | Ustring=get(handles.vector_x,'String'); |
---|
| 616 | Uindex=get(handles.vector_x,'Value'); %selected indices in the ordinate listbox |
---|
| 617 | list_var=Ustring{Uindex};%name of the selected scalar |
---|
| 618 | VarIndex.u=name2index(list_var,Field.ListVarName); |
---|
| 619 | Vstring=get(handles.vector_y,'String'); |
---|
| 620 | Vindex=get(handles.vector_y,'Value'); %selected indices in the ordinate listbox |
---|
| 621 | list_var=Ustring{Vindex};%name of the selected scalar |
---|
| 622 | VarIndex.v=name2index(list_var,Field.ListVarName); |
---|
| 623 | if isequal(VarIndex.u,VarIndex.A)|isequal(VarIndex.v,VarIndex.A) |
---|
| 624 | iuA=VarIndex.A; %same variable used for vector and scalar |
---|
| 625 | VarIndex_tot(iuA)=[]; |
---|
| 626 | end |
---|
| 627 | VarIndex_tot=[VarIndex_tot VarIndex.u VarIndex.v]; |
---|
| 628 | %dimensions |
---|
| 629 | DimIndex_u=Field.VarDimIndex{VarIndex.u};%dimension indices of the variable |
---|
| 630 | DimValue=Field.DimValue(DimIndex_u); |
---|
| 631 | ind=find(DimValue==1); |
---|
| 632 | DimIndex_u(ind)=[];%Mremove singleton |
---|
| 633 | DimIndex_v=Field.VarDimIndex{VarIndex.v};%dimension indices of the variable |
---|
| 634 | DimValue=Field.DimValue(DimIndex_v); |
---|
| 635 | ind=find(DimValue==1); |
---|
| 636 | DimIndex_v(ind)=[];%Mremove singleton |
---|
| 637 | if ~isequal(DimIndex_u,DimIndex_v) |
---|
| 638 | msgbox_uvmat('ERROR','inconsistent dimensions for u and v') |
---|
| 639 | set(handles.vector_y,'Value',1); |
---|
| 640 | return |
---|
| 641 | elseif test_scalar & ~isequal(DimIndex_u,DimIndex) |
---|
| 642 | msgbox_uvmat('ERROR','inconsistent dimensions for vector and scalar represented as vector color') |
---|
| 643 | set(handles.scalar,'Value',1); |
---|
| 644 | return |
---|
| 645 | end |
---|
| 646 | DimIndex=DimIndex_u; |
---|
[227] | 647 | %TODO possibility of selecting 3 times the same TimeVariable for u, v, w components |
---|
[204] | 648 | end |
---|
| 649 | |
---|
| 650 | |
---|
[227] | 651 | % select the TimeVariable index (or indices) for z coordinates |
---|
[204] | 652 | test_grid=0; |
---|
| 653 | if test_scalar | test_vector |
---|
| 654 | nbdim=length(DimIndex); |
---|
| 655 | if nbdim > 3 |
---|
| 656 | msgbox_uvmat('ERROR','array with more than three dimensions, not supported') |
---|
| 657 | return |
---|
| 658 | else |
---|
[213] | 659 | perm_ind=1:nbdim; |
---|
[204] | 660 | end |
---|
| 661 | if nbdim==3 |
---|
| 662 | zstring=get(handles.coord_z_vectors_scalar,'String'); |
---|
| 663 | zindex=get(handles.coord_z_vectors_scalar,'Value'); %selected indices in the ordinate listbox |
---|
| 664 | list_var=zstring(zindex); |
---|
| 665 | VarIndex_z=name2index(list_var,Field.ListVarName);%index of the selected variable |
---|
| 666 | if isequal(VarIndex.A,VarIndex_z)|isequal(VarIndex.u,VarIndex_z)|isequal(VarIndex.v,VarIndex_z)|isequal(VarIndex.w,VarIndex_z) |
---|
| 667 | if zindex ~= 1 |
---|
| 668 | set(handles.coord_z_vectors_scalar,'Value',1)%ordinate cannot be the same as scalar or vector components |
---|
| 669 | return |
---|
| 670 | end |
---|
| 671 | else |
---|
| 672 | VarIndex_tot=[VarIndex_tot VarIndex_z]; |
---|
| 673 | DimIndex_z=Field.VarDimIndex{VarIndex_z}; |
---|
| 674 | DimValue=Field.DimValue(DimIndex_z); |
---|
| 675 | ind=find(DimValue==1); |
---|
| 676 | DimIndex_z(ind)=[];%Mremove singleton |
---|
| 677 | if isequal(DimIndex_z,DimIndex) |
---|
| 678 | VarAttribute{VarIndex_z}.Role='coord_z';%unstructured coordinates |
---|
| 679 | elseif length(DimIndex_z)==1 |
---|
| 680 | VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; %dimension variable |
---|
| 681 | ind_z=find(DimIndex==DimIndex_z(1)); |
---|
| 682 | perm_ind(ind_z)=1; |
---|
| 683 | test_grid=1; |
---|
| 684 | else |
---|
| 685 | msgbox_uvmat('ERROR','multiple dimensions for the z coordinate') |
---|
| 686 | return |
---|
| 687 | end |
---|
| 688 | end |
---|
| 689 | % if ~isempty(VarIndex_z) |
---|
[227] | 690 | % DimIndex_z=Field.VarDimIndex{VarIndex_z};%dimension indices of the TimeVariable |
---|
| 691 | % if length(DimIndex_z)==1 & nbdim==3 %dimension TimeVariable |
---|
[204] | 692 | % VarAttribute{VarIndex_z}.Role=Field.ListDimName{DimIndex_z}; |
---|
| 693 | % ind_z=find(DimIndex==DimIndex_z(1)); |
---|
| 694 | % perm_ind(ind_z)=1; |
---|
| 695 | % test_grid=1; |
---|
| 696 | % end |
---|
| 697 | % end |
---|
| 698 | end |
---|
| 699 | end |
---|
| 700 | |
---|
[227] | 701 | % select the TimeVariable index (or indices) for ordinate |
---|
[204] | 702 | ystring=get(handles.ordinate,'String'); |
---|
| 703 | yindex=get(handles.ordinate,'Value'); %selected indices in the ordinate listbox |
---|
| 704 | list_var=ystring(yindex); |
---|
| 705 | VarIndex.y=name2index(list_var,Field.ListVarName); |
---|
| 706 | if isequal(VarIndex.A,VarIndex.y) |
---|
| 707 | set(handles.coord_y_scalar,'Value',1) |
---|
| 708 | elseif isequal(VarIndex.u,VarIndex.y)||isequal(VarIndex.v,VarIndex.y)||isequal(VarIndex.w,VarIndex.y) |
---|
| 709 | set(handles.coord_y_vectors,'Value',1)%ordinate cannot be the same as scalar or vector components |
---|
| 710 | else |
---|
| 711 | for ivar=1:length(VarIndex.y) |
---|
| 712 | VarAttribute{VarIndex.y(ivar)}.Role='coord_y'; |
---|
| 713 | end |
---|
| 714 | VarIndex_tot=[VarIndex_tot VarIndex.y]; |
---|
| 715 | end |
---|
| 716 | if (test_scalar | test_vector) & ~isempty(VarIndex.y) |
---|
| 717 | DimIndex_y=Field.VarDimIndex{VarIndex.y};%dimension indices of the variable |
---|
| 718 | if length(DimIndex_y)==1 |
---|
| 719 | ind_y=find(DimIndex==DimIndex_y(1)); |
---|
| 720 | test_grid=1; |
---|
| 721 | if nbdim==3 |
---|
| 722 | VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y}; |
---|
| 723 | perm_ind(ind_y)=2; |
---|
| 724 | elseif nbdim==2 |
---|
| 725 | VarAttribute{VarIndex.y}.Role=Field.ListDimName{DimIndex_y}; |
---|
| 726 | perm_ind(ind_y)=1; |
---|
| 727 | end |
---|
| 728 | elseif test_grid |
---|
| 729 | msgbox_uvmat('ERROR','the dimension of the y coordinate variable should be 1') |
---|
| 730 | end |
---|
| 731 | end |
---|
| 732 | |
---|
[227] | 733 | %select the TimeVariable index for the abscissa |
---|
[204] | 734 | xstring=get(handles.abscissa,'String'); |
---|
| 735 | xindex=get(handles.abscissa,'Value'); |
---|
| 736 | list_var=xstring(xindex); |
---|
| 737 | VarIndex.x=name2index(list_var,Field.ListVarName);%var index corresponding to var name list_var |
---|
| 738 | if length(VarIndex.x)==1 |
---|
| 739 | DimIndex_x=Field.VarDimIndex{VarIndex.x}; |
---|
| 740 | DimValue=Field.DimValue(DimIndex_x); |
---|
| 741 | ind=find(DimValue==1); |
---|
| 742 | DimIndex_x(ind)=[];%Mremove singleton |
---|
| 743 | VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; %dimension variable |
---|
| 744 | % VarAttribute{VarIndex.x}.Role='coord_x';%default (may be modified) |
---|
| 745 | index_detect=find(VarIndex_tot==VarIndex.x); |
---|
| 746 | else |
---|
| 747 | index_detect=[];%coord x variable not already used |
---|
| 748 | end |
---|
| 749 | if isempty(index_detect) |
---|
| 750 | VarIndex_tot=[VarIndex_tot VarIndex.x]; |
---|
[503] | 751 | elseif ~test_CheckPlot1D |
---|
[204] | 752 | VarIndex.x=[]; |
---|
| 753 | set(handles.abscissa,'Value',1)%vchosen abscissa already chosen, suppres it as abscissa |
---|
| 754 | end |
---|
| 755 | |
---|
| 756 | if (test_scalar | test_vector) & ~isempty(VarIndex.x) |
---|
| 757 | DimIndex_x=Field.VarDimIndex{VarIndex.x};%dimension indices of the variable |
---|
| 758 | if length(DimIndex_x)==1 |
---|
| 759 | ind_x=find(DimIndex==DimIndex_x(1)); |
---|
| 760 | if nbdim==3 |
---|
| 761 | %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; |
---|
| 762 | perm_ind(ind_x)=3; |
---|
| 763 | elseif nbdim==2 |
---|
| 764 | %VarAttribute{VarIndex.x}.Role=Field.ListDimName{DimIndex_x}; |
---|
| 765 | perm_ind(ind_x)=2; |
---|
| 766 | end |
---|
| 767 | if isequal(perm_ind,1:nbdim) |
---|
| 768 | test_grid=0; |
---|
| 769 | end |
---|
| 770 | DimIndex=DimIndex(perm_ind); |
---|
| 771 | elseif test_grid |
---|
| 772 | msgbox_uvmat('ERROR','the dimension of the x coordinate variable should be 1') |
---|
| 773 | end |
---|
| 774 | if isequal(DimIndex_x,DimIndex) |
---|
| 775 | VarAttribute{VarIndex.x}.Role='coord_x';%unstructured coordinates |
---|
| 776 | end |
---|
| 777 | end |
---|
| 778 | |
---|
| 779 | %defined the selected sub-field SubField |
---|
| 780 | SubField.ListGlobalAttribute{1}='InputFile'; |
---|
| 781 | SubField.InputFile=get(handles.inputfile,'String'); |
---|
| 782 | SubField.ListDimName=Field.ListDimName; |
---|
| 783 | SubField.DimValue=Field.DimValue; |
---|
| 784 | SubField.ListVarName=Field.ListVarName(VarIndex_tot); |
---|
| 785 | SubField.VarDimIndex=Field.VarDimIndex(VarIndex_tot); |
---|
| 786 | |
---|
| 787 | testperm=0; |
---|
| 788 | testattr=0; |
---|
| 789 | for ivar=VarIndex.u |
---|
| 790 | VarAttribute{ivar}.Role='vector_x'; |
---|
| 791 | testattr=1; |
---|
| 792 | if test_grid |
---|
| 793 | VarDimIndex{ivar}=DimIndex; %permute dimensions |
---|
| 794 | testperm=1; |
---|
| 795 | end |
---|
| 796 | end |
---|
| 797 | for ivar=VarIndex.v |
---|
| 798 | VarAttribute{ivar}.Role='vector_y'; |
---|
| 799 | testattr=1; |
---|
| 800 | if test_grid |
---|
| 801 | VarDimIndex{ivar}=DimIndex;%permute dimensions |
---|
| 802 | testperm=1; |
---|
| 803 | end |
---|
| 804 | end |
---|
| 805 | for ivar=VarIndex.A |
---|
| 806 | if test_grid |
---|
| 807 | VarDimIndex{ivar}=DimIndex;%permute dimensions |
---|
| 808 | testperm=1; |
---|
| 809 | end |
---|
| 810 | if isempty(iuA) |
---|
| 811 | VarAttribute{ivar}.Role='scalar';%Role =scalar |
---|
| 812 | testattr=1; |
---|
| 813 | else |
---|
| 814 | VarAttribute=[VarAttribute VarAttribute(ivar)]; %duplicate the attribute for a new variable |
---|
| 815 | nbattr=length(VarAttribute); |
---|
| 816 | VarAttribute{nbattr}.Role='scalar'; |
---|
| 817 | testattr=1; |
---|
| 818 | end |
---|
| 819 | end |
---|
| 820 | if testperm |
---|
| 821 | SubField.VarDimIndex=VarDimIndex(VarIndex_tot); |
---|
| 822 | end |
---|
| 823 | if testattr |
---|
| 824 | SubField.VarAttribute=VarAttribute(VarIndex_tot); |
---|
| 825 | end |
---|
| 826 | set(hselect_field,'UserData',Field) |
---|
| 827 | |
---|
| 828 | %--------------------------------------------------------- |
---|
| 829 | % --- Executes on button press in RUN. |
---|
| 830 | |
---|
| 831 | function RUN_Callback(hObject, eventdata, handles) |
---|
| 832 | %--------------------------------------------------------- |
---|
[227] | 833 | set(handles.RUN,'BackgroundColor',[1 1 0])% mark use of RUN action |
---|
| 834 | test_fig=get(handles.SelectFigure,'Value'); |
---|
[204] | 835 | |
---|
| 836 | % plot requested in uvmat |
---|
[227] | 837 | if ~test_fig |
---|
[204] | 838 | inputfile=get(handles.inputfile,'String'); |
---|
| 839 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
| 840 | if isempty(huvmat) |
---|
[231] | 841 | input.InputFile=inputfile; |
---|
| 842 | input.FieldsString={'get_field...'}; |
---|
| 843 | uvmat(input) |
---|
[204] | 844 | else |
---|
| 845 | set(huvmat,'Visible','on')%make uvmat visible (bugs can hide it in some cases) |
---|
| 846 | hhuvmat=guidata(huvmat); |
---|
[227] | 847 | set(hhuvmat.Fields,'Value',1) |
---|
| 848 | set(hhuvmat.Fields,'String',{'get_field...'}) |
---|
[204] | 849 | uvmat('run0_Callback',hObject,eventdata,hhuvmat); % display field in uvmat |
---|
| 850 | end |
---|
| 851 | |
---|
| 852 | % other kind of plot |
---|
[227] | 853 | else %TODO: check and update: add plot on an existing axes |
---|
| 854 | figcell=get(handles.list_fig,'String'); |
---|
| 855 | index=get(handles.list_fig,'value'); |
---|
| 856 | figstring=figcell{index}; |
---|
[204] | 857 | index=get(handles.ACTION,'Value'); |
---|
| 858 | list_func=get(handles.ACTION,'UserData'); |
---|
| 859 | h_fun=list_func{index}; |
---|
| 860 | set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784]) |
---|
| 861 | drawnow |
---|
[227] | 862 | SubField=h_fun(handles.get_field);%handles.figure1 =handles of the GUI get_field |
---|
[204] | 863 | if ~isempty(SubField) |
---|
| 864 | plot_get_field(SubField,handles) |
---|
| 865 | end |
---|
| 866 | browse_fig(handles.list_fig); %update the list of new existing figures |
---|
| 867 | end |
---|
| 868 | set(handles.RUN,'BackgroundColor',[1 0 0]) |
---|
| 869 | |
---|
| 870 | %------------------------------------------------------------------------ |
---|
| 871 | % --- Function for plotting the current subfield |
---|
| 872 | function plot_get_field(SubField,handles) |
---|
| 873 | %------------------------------------------------------------------------ |
---|
[213] | 874 | list_fig=get(handles.list_fig,'String'); |
---|
[204] | 875 | val=get(handles.list_fig,'Value'); |
---|
| 876 | if strcmp(list_fig{val},'uvmat') |
---|
| 877 | set(handles.inputfile,'Enable','off')% desactivate the input file edit box |
---|
| 878 | set(handles.RUN,'Visible','off')% RUN button not visible (passive mode, get_field used to define the field for uvamt) |
---|
| 879 | set(handles.MenuOpen,'Visible','off') |
---|
| 880 | set(handles.MenuExport,'Visible','off') |
---|
| 881 | uvmat(get(handles.inputfile,'String')) |
---|
| 882 | elseif strcmp(list_fig{val},'view_field') |
---|
| 883 | view_field(SubField) |
---|
| 884 | else |
---|
| 885 | hfig=str2double(list_fig{val});% chosen figure number from tyhe GUI |
---|
| 886 | if isnan(hfig) |
---|
| 887 | hfig=figure; |
---|
| 888 | list_fig=[list_fig;num2str(hfig)]; |
---|
| 889 | set(handles.list_fig,'String',list_fig); |
---|
| 890 | haxes=axes; |
---|
| 891 | else |
---|
| 892 | figure(hfig); |
---|
| 893 | end |
---|
| 894 | haxes=findobj(hfig,'Type','axes'); |
---|
| 895 | plot_field(SubField,haxes) |
---|
| 896 | end |
---|
| 897 | |
---|
| 898 | % %------------------------------------------------ |
---|
| 899 | % % --- Executes on button press in Plot_histo. |
---|
| 900 | % %RUN global histograms |
---|
| 901 | % %------------------------------------------------- |
---|
| 902 | % function RUN_histo_Callback(hObject, eventdata, handles) |
---|
| 903 | % % hObject handle to RUN (see GCBO) |
---|
| 904 | % % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 905 | % % handles structure with handles and user data (see GUIDATA) |
---|
| 906 | % |
---|
[227] | 907 | % %timename plots |
---|
[204] | 908 | % leg={}; |
---|
| 909 | % n=0; |
---|
| 910 | % if (get(handles.cm_switch,'Value')==1) |
---|
| 911 | % Uval_p=Uval_cm; |
---|
| 912 | % Vval_p=Vval_cm; |
---|
| 913 | % Uhist_p=Uhist_cm; |
---|
| 914 | % Vhist_p=Vhist_cm; |
---|
| 915 | % xlab='velocity (cm/s)'; |
---|
| 916 | % else |
---|
| 917 | % Uval_p=Uval; |
---|
| 918 | % Vval_p=Vval; |
---|
| 919 | % Uhist_p=Uhist; |
---|
| 920 | % Vhist_p=Vhist; |
---|
| 921 | % xlab='velocity (pixels)'; |
---|
| 922 | % end |
---|
| 923 | % if (get(handles.vector_y,'Value') == 1) |
---|
| 924 | % hhh=figure(2); |
---|
| 925 | % hold on |
---|
| 926 | % title([filebase ', ' strindex ', ' fieldtitle]) |
---|
| 927 | % plot(Uval_p,Uhist_p,'b-') |
---|
| 928 | % n=n+1; |
---|
| 929 | % leg{n}='Uhist'; |
---|
| 930 | % xlabel(xlab) |
---|
| 931 | % end |
---|
| 932 | % if (get(handles.Vhist_input,'Value') == 1) |
---|
| 933 | % hhh=figure(2); |
---|
| 934 | % hold on |
---|
| 935 | % title([filebase ', ' strindex ', ' fieldtitle]) |
---|
| 936 | % plot(Vval_p,Vhist_p,'r-') |
---|
| 937 | % n=n+1; |
---|
| 938 | % leg{n}='Vhist'; |
---|
| 939 | % xlabel(xlab); |
---|
| 940 | % end |
---|
| 941 | % if (get(handles.Chist_input,'Value') == 1) |
---|
| 942 | % hhhh=figure(3); |
---|
| 943 | % hold on |
---|
| 944 | % title([filebase ', ' strindex ', ' fieldtitle]) |
---|
| 945 | % plot(Cval,Chist,'k-') |
---|
| 946 | % leg{1}='Chist'; |
---|
| 947 | % end |
---|
| 948 | % % hold off |
---|
| 949 | % grid on |
---|
| 950 | % legend(leg); |
---|
| 951 | |
---|
| 952 | % %------------------------------------------------------------- |
---|
| 953 | % % --- Executes on button press in Save_input. |
---|
| 954 | % function Save_input_Callback(hObject, eventdata, handles) |
---|
| 955 | % list_str=get(handles.abscissa,'String'); |
---|
| 956 | % val=get(handles.abscissa,'Value'); |
---|
| 957 | % var=list_str{val}; |
---|
| 958 | % hselect_field=get(handles.Save_input,'parent') |
---|
| 959 | % set(hselect_field,'UserData',var); |
---|
| 960 | % set(hselect_field,'Tag','idle') |
---|
| 961 | |
---|
| 962 | % |
---|
| 963 | % %------------------------------------------------------------- |
---|
| 964 | % % --- Executes on button press in save_histo. |
---|
| 965 | % function save_histo_Callback(hObject, eventdata, handles) |
---|
| 966 | % global filebase |
---|
| 967 | % |
---|
| 968 | % pathstr = fileparts(filebase) |
---|
| 969 | % if (get(handles.Chist_input,'Value') == 1) |
---|
| 970 | % def = {[pathstr pathstr(1) 'PIV_corr_histo.fig']}; |
---|
| 971 | % else |
---|
| 972 | |
---|
| 973 | % def = {[pathstr pathstr(1) 'vel_histo.fig']}; |
---|
| 974 | % end |
---|
| 975 | % prompt={'save figure(2) as'} |
---|
| 976 | % dlg_title = 'save figure'; |
---|
| 977 | % num_lines= 1; |
---|
| 978 | % answer = inputdlg(prompt,dlg_title,num_lines,def) |
---|
| 979 | % saveas(2,answer{1}) |
---|
| 980 | |
---|
| 981 | |
---|
| 982 | %%------------------------------------------------------- |
---|
| 983 | % --- Executes on button press in peaklocking. |
---|
| 984 | %------------------------------------------------- |
---|
| 985 | function peaklocking(handles) |
---|
| 986 | %evaluation of peacklocking errors |
---|
| 987 | %use splinhist: give spline coeff cc for a smooth histo (call spline4) |
---|
| 988 | %use histsmooth(x,cc): calculate the smooth histo for any value x |
---|
| 989 | %use histder(x,cc): calculate the derivative of the smooth histo |
---|
| 990 | global hfig1 hfig2 hfig3 |
---|
| 991 | global nbb Uval Vval Uhist Vhist % nbb resolution of the histogram nbb=10: 10 values in unity interval |
---|
| 992 | global xval xerror yval yerror |
---|
| 993 | |
---|
| 994 | set(handles.vector_y,'Value',1)% trigger the option Uhist on the interface |
---|
| 995 | set(handles.Vhist_input,'Value',1) |
---|
| 996 | set(handles.cm_switch,'Value',0) % put the switch to 'pixel' |
---|
| 997 | |
---|
| 998 | %adjust the extremal values of the histogram in U with respect to integer |
---|
| 999 | %values |
---|
| 1000 | minimU=round(min(Uval)-0.5)+0.5; %first value of the histogram with integer bins |
---|
| 1001 | maximU=round(max(Uval)-0.5)+0.5; |
---|
| 1002 | minim_fin=(minimU-0.5+1/(2*nbb)); % first bin valueat the beginning of an integer interval |
---|
| 1003 | maxim_fin=(maximU+0.5-1/(2*nbb)); % last integer value |
---|
| 1004 | nb_bin_min= round(-(minim_fin - min(Uval))*nbb); % nbre of bins added below |
---|
| 1005 | nb_bin_max=round((maxim_fin -max(Uval))*nbb); %nbre of bins added above |
---|
| 1006 | Uval=[minim_fin:(1/nbb):maxim_fin]; |
---|
| 1007 | histu_min=zeros(nb_bin_min,1); |
---|
| 1008 | histu_max=zeros(nb_bin_max,1); |
---|
| 1009 | Uhist=[histu_min; Uhist ;histu_max]; % column vector |
---|
| 1010 | |
---|
| 1011 | %adjust the extremal values of the histogram in V |
---|
| 1012 | minimV=round(min(Vval-0.5)+0.5); |
---|
| 1013 | maximV=round(max(Vval-0.5)+0.5); |
---|
| 1014 | minim_fin=minimV-0.5+1/(2*nbb); % first bin valueat the beginning of an integer interval |
---|
| 1015 | maxim_fin=maximV+0.5-1/(2*nbb); % last integer value |
---|
| 1016 | nb_bin_min=round((min(Vval) - minim_fin)*nbb); % nbre of bins added below |
---|
| 1017 | nb_bin_max=round((maxim_fin -max(Vval))*nbb); |
---|
| 1018 | Vval=[minim_fin:(1/nbb):maxim_fin]; |
---|
| 1019 | histu_min=zeros(nb_bin_min,1); |
---|
| 1020 | histu_max=zeros(nb_bin_max,1); |
---|
| 1021 | Vhist=[histu_min; Vhist ;histu_max]; % column vector |
---|
| 1022 | |
---|
| 1023 | % RUN_histo_Callback(hObject, eventdata, handles) |
---|
| 1024 | % %adjust the histogram to integer values: |
---|
| 1025 | |
---|
| 1026 | %histoU and V |
---|
| 1027 | [Uhistinter,xval,xerror]=peaklock(nbb,minimU,maximU,Uhist); |
---|
| 1028 | [Vhistinter,yval,yerror]=peaklock(nbb,minimV,maximV,Vhist); |
---|
| 1029 | |
---|
| 1030 | % selection of value ranges such that histo>=10 (enough statistics) |
---|
| 1031 | Uval_ind=find(Uhist>=10); |
---|
| 1032 | ind_min=min(Uval_ind); |
---|
| 1033 | ind_max=max(Uval_ind); |
---|
| 1034 | U_min=Uval(ind_min);% minimum allowed value |
---|
| 1035 | U_max=Uval(ind_max);%maximum allowed value |
---|
| 1036 | |
---|
| 1037 | % selection of value ranges such that histo>=10 (enough statistics) |
---|
| 1038 | Vval_ind=find(Vhist>=10); |
---|
| 1039 | ind_min=min(Vval_ind); |
---|
| 1040 | ind_max=max(Vval_ind); |
---|
| 1041 | V_min=Vval(ind_min);% minimum allowed value |
---|
| 1042 | V_max=Vval(ind_max);%maximum allowed value |
---|
| 1043 | |
---|
| 1044 | figure(4)% plot U histogram with smoothed one |
---|
| 1045 | plot(Uval,Uhist,'b') |
---|
| 1046 | grid on |
---|
| 1047 | hold on |
---|
| 1048 | plot(Uval,Uhistinter,'r'); |
---|
| 1049 | hold off |
---|
| 1050 | |
---|
| 1051 | figure(5)% plot V histogram with smoothed one |
---|
| 1052 | plot(Vval,Vhist,'b') |
---|
| 1053 | grid on |
---|
| 1054 | hold on |
---|
| 1055 | plot(Vval,Vhistinter,'r'); |
---|
| 1056 | hold off |
---|
| 1057 | |
---|
| 1058 | figure(6)% plot pixel error in two subplots |
---|
| 1059 | hfig4=subplot(2,1,1); |
---|
| 1060 | hfig5=subplot(2,1,2); |
---|
| 1061 | axes(hfig4) |
---|
| 1062 | plot(xval,xerror) |
---|
| 1063 | axis([U_min U_max -0.4 0.4]) |
---|
| 1064 | xlabel('velocity u (pix)') |
---|
| 1065 | ylabel('peaklocking error (pix)') |
---|
| 1066 | grid on |
---|
| 1067 | axes(hfig5) |
---|
| 1068 | plot(yval,yerror) |
---|
| 1069 | axis([V_min V_max -0.4 0.4]); |
---|
| 1070 | xlabel('velocity v (pix)') |
---|
| 1071 | ylabel('peaklocking error (pix)') |
---|
| 1072 | grid on |
---|
| 1073 | |
---|
| 1074 | |
---|
| 1075 | % ------------------------------------------------------------------ |
---|
| 1076 | function variables_Callback(hObject, eventdata, handles) |
---|
| 1077 | Tabchar={''};%default |
---|
| 1078 | Tabcell=[]; |
---|
| 1079 | hselect_field=get(handles.variables,'parent'); |
---|
[227] | 1080 | Field=get(handles.get_field,'UserData'); |
---|
[204] | 1081 | index=get(handles.variables,'Value');%index in the list 'variables' |
---|
[363] | 1082 | |
---|
| 1083 | %% list global TimeAttribute names and values if index=1 (blank TimeVariable display) is selected |
---|
[204] | 1084 | if isequal(index,1) |
---|
| 1085 | set(handles.attributes_txt,'String','global attributes') |
---|
| 1086 | if isfield(Field,'ListGlobalAttribute') && ~isempty(Field.ListGlobalAttribute) |
---|
| 1087 | for iline=1:length(Field.ListGlobalAttribute) |
---|
| 1088 | Tabcell{iline,1}=Field.ListGlobalAttribute{iline}; |
---|
| 1089 | if isfield(Field, Field.ListGlobalAttribute{iline}) |
---|
| 1090 | eval(['val=Field.' Field.ListGlobalAttribute{iline} ';']) |
---|
| 1091 | if ischar(val);% attribute value is char string |
---|
| 1092 | Tabcell{iline,2}=val; |
---|
| 1093 | elseif size(val,1)==1 %attribute value is a number or matlab vector |
---|
| 1094 | Tabcell{iline,2}=num2str(val); |
---|
| 1095 | end |
---|
| 1096 | end |
---|
| 1097 | end |
---|
| 1098 | Tabchar=cell2tab(Tabcell,'='); |
---|
| 1099 | end |
---|
[363] | 1100 | %% list Attribute names and values associated to the Variable # index-1 |
---|
[204] | 1101 | else |
---|
| 1102 | list_var=get(handles.variables,'String'); |
---|
| 1103 | var_select=list_var{index}; |
---|
| 1104 | set(handles.attributes_txt,'String', ['attributes of ' var_select]) |
---|
| 1105 | if isfield(Field,'VarAttribute')&& length(Field.VarAttribute)>=index-1 |
---|
| 1106 | % nbline=0; |
---|
| 1107 | VarAttr=Field.VarAttribute{index-1}; |
---|
| 1108 | if isstruct(VarAttr) |
---|
| 1109 | attr_list=fieldnames(VarAttr); |
---|
| 1110 | for iline=1:length(attr_list) |
---|
| 1111 | Tabcell{iline,1}=attr_list{iline}; |
---|
| 1112 | eval(['val=VarAttr.' attr_list{iline} ';']) |
---|
| 1113 | if ischar(val); |
---|
| 1114 | Tabcell{iline,2}=val; |
---|
| 1115 | else |
---|
| 1116 | Tabcell{iline,2}=num2str(val); |
---|
| 1117 | end |
---|
| 1118 | end |
---|
| 1119 | end |
---|
| 1120 | end |
---|
| 1121 | |
---|
| 1122 | end |
---|
| 1123 | if ~isempty(Tabcell) |
---|
| 1124 | Tabchar=cell2tab(Tabcell,'='); |
---|
| 1125 | Tabchar=[{''};Tabchar]; |
---|
| 1126 | end |
---|
| 1127 | set(handles.attributes,'Value',1);% select the first item |
---|
| 1128 | set(handles.attributes,'String',Tabchar); |
---|
| 1129 | |
---|
[363] | 1130 | %% update dimensions; |
---|
[204] | 1131 | if isfield(Field,'ListDimName') |
---|
| 1132 | Tabdim={};%default |
---|
| 1133 | if isequal(index,1)%list all dimensions |
---|
| 1134 | dim_indices=1:length(Field.ListDimName); |
---|
| 1135 | set(handles.dimensions_txt,'String', 'dimensions') |
---|
| 1136 | else |
---|
| 1137 | DimCell=Field.VarDimName{index-1}; |
---|
| 1138 | if ischar(DimCell) |
---|
| 1139 | DimCell={DimCell}; |
---|
| 1140 | end |
---|
| 1141 | dim_indices=[]; |
---|
| 1142 | for idim=1:length(DimCell) |
---|
| 1143 | dim_index=strcmp(DimCell{idim},Field.ListDimName);%vector with size of Field.ListDimName, =0 |
---|
| 1144 | dim_index=find(dim_index,1); |
---|
| 1145 | dim_indices=[dim_indices dim_index]; |
---|
| 1146 | end |
---|
| 1147 | set(handles.dimensions_txt,'String', ['dimensions of ' var_select]) |
---|
| 1148 | end |
---|
| 1149 | for iline=1:length(dim_indices) |
---|
| 1150 | Tabdim{iline,1}=Field.ListDimName{dim_indices(iline)}; |
---|
| 1151 | Tabdim{iline,2}=num2str(Field.DimValue(dim_indices(iline))); |
---|
| 1152 | end |
---|
[227] | 1153 | Tabchar=cell2tab(Tabdim,' = '); |
---|
[204] | 1154 | Tabchar=[{''} ;Tabchar]; |
---|
[227] | 1155 | set(handles.dimensions,'Value',1) |
---|
[204] | 1156 | set(handles.dimensions,'String',Tabchar) |
---|
| 1157 | end |
---|
| 1158 | |
---|
| 1159 | %------------------------------------------------------------------------ |
---|
[503] | 1160 | % --- Executes on button press in CheckPlot1D. |
---|
| 1161 | function CheckPlot1D_Callback(hObject, eventdata, handles) |
---|
[204] | 1162 | %------------------------------------------------------------------------ |
---|
[503] | 1163 | val=get(handles.CheckPlot1D,'Value'); |
---|
[204] | 1164 | if isequal(val,0) |
---|
| 1165 | set(handles.Panel1Dplot,'Visible','off') |
---|
| 1166 | else |
---|
| 1167 | set(handles.Panel1Dplot,'Visible','on') |
---|
| 1168 | end |
---|
| 1169 | |
---|
| 1170 | %------------------------------------------------------------------------ |
---|
[503] | 1171 | % --- Executes on button press in CheckScalar. |
---|
| 1172 | function CheckScalar_Callback(hObject, eventdata, handles) |
---|
[204] | 1173 | %------------------------------------------------------------------------ |
---|
[503] | 1174 | val=get(handles.CheckScalar,'Value'); |
---|
[204] | 1175 | if isequal(val,0) |
---|
| 1176 | set(handles.PanelScalar,'Visible','off') |
---|
| 1177 | else |
---|
| 1178 | set(handles.PanelScalar,'Visible','on') |
---|
| 1179 | end |
---|
| 1180 | |
---|
| 1181 | %------------------------------------------------------------------------ |
---|
[503] | 1182 | % --- Executes on button press in CheckVector. |
---|
| 1183 | function CheckVector_Callback(hObject, eventdata, handles) |
---|
[204] | 1184 | %------------------------------------------------------------------------ |
---|
[503] | 1185 | val=get(handles.CheckVector,'Value'); |
---|
[204] | 1186 | if isequal(val,0) |
---|
| 1187 | set(handles.PanelVectors,'Visible','off') |
---|
| 1188 | else |
---|
| 1189 | set(handles.PanelVectors,'Visible','on') |
---|
| 1190 | end |
---|
| 1191 | |
---|
[227] | 1192 | % %------------------------------------------------------------------------ |
---|
| 1193 | % function mouse_up_gui(ggg,eventdata,handles) |
---|
| 1194 | % %------------------------------------------------------------------------ |
---|
| 1195 | % if isequal(get(ggg,'SelectionType'),'alt') |
---|
| 1196 | % message=''; |
---|
| 1197 | % global CurData |
---|
| 1198 | % inputfield=get(handles.inputfile,'String'); |
---|
| 1199 | % if exist(inputfield,'file') |
---|
| 1200 | % CurData=nc2struct(inputfield); |
---|
| 1201 | % else |
---|
| 1202 | % CurData=get(ggg,'UserData');% get_field opened from a input field, not a file |
---|
| 1203 | % end |
---|
| 1204 | % %%%% TODO: put the matalb command window in front |
---|
| 1205 | % evalin('base','global CurData')%make CurData global in the workspace |
---|
| 1206 | % evalin('base','CurData') %display CurData in the workspace |
---|
| 1207 | % end |
---|
[204] | 1208 | |
---|
| 1209 | %------------------------------------------------------------------------ |
---|
| 1210 | % --- Executes on selection change in ACTION. |
---|
| 1211 | %------------------------------------------------------------------------ |
---|
| 1212 | function ACTION_Callback(hObject, eventdata, handles) |
---|
| 1213 | global nb_builtin |
---|
| 1214 | list_ACTION=get(handles.ACTION,'String');% list menu fields |
---|
| 1215 | index_ACTION=get(handles.ACTION,'Value');% selected string index |
---|
| 1216 | ACTION= list_ACTION{index_ACTION}; % selected string |
---|
| 1217 | list_func_handles=get(handles.ACTION,'UserData');% get list of function handles (full address of the function, including name and path) |
---|
| 1218 | ff=functions(list_func_handles{end}); |
---|
| 1219 | % add a new function to the menu |
---|
| 1220 | if isequal(ACTION,'more...') |
---|
| 1221 | [FileName, PathName] = uigetfile( ... |
---|
| 1222 | {'*.m', ' (*.m)'; |
---|
| 1223 | '*.m', '.m files '; ... |
---|
| 1224 | '*.*', 'All Files (*.*)'}, ... |
---|
| 1225 | 'Pick a file',ff.file); |
---|
| 1226 | if length(FileName)<2 |
---|
| 1227 | return |
---|
| 1228 | end |
---|
| 1229 | [pp,ACTION,ext_fct]=fileparts(FileName); |
---|
| 1230 | if ~isequal(ext_fct,'.m') |
---|
| 1231 | msgbox_uvmat('ERROR','a Matlab function .m must be introduced'); |
---|
| 1232 | return |
---|
| 1233 | end |
---|
| 1234 | |
---|
| 1235 | % insert the choice in the action menu |
---|
| 1236 | menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed |
---|
| 1237 | index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list |
---|
| 1238 | addpath(PathName) |
---|
| 1239 | list_func_handles{index_ACTION}=str2func(ACTION);% create the function handle corresponding to the newly seleced function |
---|
| 1240 | set(handles.ACTION,'UserData',list_func_handles) |
---|
| 1241 | set(handles.path_action,'enable','inactive')% indicate that the current path is accessible (not 'off') |
---|
| 1242 | %list_path{index_ACTION}=PathName; |
---|
| 1243 | if length(menu_str)>nb_builtin+5; |
---|
| 1244 | nbremove=length(menu_str)-nb_builtin-5; |
---|
| 1245 | menu_str(nb_builtin+1:end-5)=[]; |
---|
| 1246 | list_func_handles(nb_builtin+1:end-4)=[]; |
---|
| 1247 | index_ACTION=index_ACTION-nbremove; |
---|
| 1248 | set(handles.ACTION,'Value',index_ACTION) |
---|
| 1249 | set(handles.ACTION,'String',menu_str) |
---|
| 1250 | end |
---|
| 1251 | %record the current menu in personal file profil_perso |
---|
| 1252 | dir_perso=prefdir; |
---|
| 1253 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 1254 | get_field_fct={}; |
---|
| 1255 | for ilist=nb_builtin+1:length(menu_str)-1 |
---|
| 1256 | ff=functions(list_func_handles{ilist}); |
---|
| 1257 | get_field_fct{ilist-nb_builtin}=ff.file; |
---|
| 1258 | end |
---|
| 1259 | if exist(profil_perso,'file') |
---|
| 1260 | save(profil_perso,'get_field_fct','-append') |
---|
| 1261 | else |
---|
| 1262 | txt=ver('MATLAB'); |
---|
| 1263 | Release=txt.Release; |
---|
| 1264 | relnumb=str2num(Release(3:4)); |
---|
| 1265 | if relnumb >= 14 |
---|
| 1266 | save(profil_perso,'get_field_fct','-V6') |
---|
| 1267 | else |
---|
| 1268 | save(profil_perso, 'get_field_fct') |
---|
| 1269 | end |
---|
| 1270 | end |
---|
| 1271 | end |
---|
| 1272 | |
---|
| 1273 | %check the current path to the selected function |
---|
| 1274 | h_fun=list_func_handles{index_ACTION}; |
---|
| 1275 | if isa(h_fun,'function_handle') |
---|
| 1276 | func=functions(h_fun); |
---|
| 1277 | set(handles.path_action,'String',fileparts(func.file)); %show the path to the senlected function |
---|
| 1278 | GUI_input=h_fun();%handles.figure1 =handles of the GUI get_field |
---|
| 1279 | else |
---|
| 1280 | set(handles.path_action,'String','') |
---|
| 1281 | msgbox_uvmat('ERROR','unknown path to ACTION function, reload it') |
---|
| 1282 | return |
---|
| 1283 | end |
---|
| 1284 | |
---|
| 1285 | %prepare the GUI options for the selected ACTION |
---|
| 1286 | test_1Dplot=0; |
---|
| 1287 | test_scalar=0; |
---|
| 1288 | test_vector=0; |
---|
| 1289 | if iscell(GUI_input) |
---|
[503] | 1290 | for ilist=1:size(GUI_input,1) |
---|
| 1291 | switch GUI_input{ilist,1} |
---|
[204] | 1292 | %RootFile always visible |
---|
[503] | 1293 | case 'CheckPlot1D' |
---|
| 1294 | test_1Dplot=isequal(GUI_input{ilist,2},'on'); |
---|
| 1295 | case 'CheckScalar' |
---|
| 1296 | test_scalar=isequal(GUI_input{ilist,2},'on'); |
---|
| 1297 | case 'CheckVector' |
---|
| 1298 | test_vector=isequal(GUI_input{ilist,2},'on'); |
---|
[204] | 1299 | end |
---|
| 1300 | end |
---|
| 1301 | end |
---|
[503] | 1302 | set(handles.CheckPlot1D,'Value',test_1Dplot); |
---|
| 1303 | set(handles.CheckScalar,'Value',test_scalar); |
---|
| 1304 | set(handles.CheckVector,'Value',test_vector); |
---|
| 1305 | CheckPlot1D_Callback(hObject, eventdata, handles) |
---|
| 1306 | CheckScalar_Callback(hObject, eventdata, handles) |
---|
| 1307 | CheckVector_Callback(hObject, eventdata, handles) |
---|
[204] | 1308 | |
---|
| 1309 | |
---|
| 1310 | %----------------------------------------------------- |
---|
| 1311 | % --- browse existing figures |
---|
| 1312 | %----------------------------------------------------- |
---|
| 1313 | function browse_fig(menu_handle) |
---|
| 1314 | hh=findobj(allchild(0),'Type','figure'); |
---|
| 1315 | ilist=0; |
---|
| 1316 | list={}; |
---|
| 1317 | for ifig=1:length(hh) %look for all existing figures |
---|
| 1318 | name=get(hh(ifig),'Name'); |
---|
| 1319 | if ~strcmp(name,'uvmat')&& ~strcmp(name,'view_field') %case of uvmat GUI |
---|
| 1320 | hchild=get(hh(ifig),'children');% look for axes contained in each figure |
---|
| 1321 | nbaxe=0; |
---|
| 1322 | for ichild=1:length(hchild) |
---|
| 1323 | Type=get(hchild(ichild),'Type'); |
---|
| 1324 | Tag=get(hchild(ichild),'Tag'); |
---|
| 1325 | if isequal(Type,'axes') |
---|
| 1326 | if ~isequal(Tag,'Colorbar')& ~isequal(Tag,'legend')% don't select colorbars for plotting |
---|
| 1327 | nbaxe=nbaxe+1;%count the existing axis |
---|
| 1328 | end |
---|
| 1329 | end |
---|
| 1330 | end |
---|
| 1331 | if nbaxe==1 |
---|
| 1332 | ilist=ilist+1;%add a line in the list of axis |
---|
| 1333 | list{ilist,1}=num2str(hh(ifig)); |
---|
| 1334 | elseif nbaxe>1 |
---|
| 1335 | for iaxe=1:nbaxe |
---|
| 1336 | ilist=ilist+1;%add a line in the list of axis |
---|
| 1337 | list{ilist,1}=[num2str(hh(ifig)) '_' num2str(iaxe)]; |
---|
| 1338 | end |
---|
| 1339 | end |
---|
| 1340 | end |
---|
| 1341 | end |
---|
| 1342 | list=['uvmat';list]; |
---|
| 1343 | set(menu_handle,'Value',1) |
---|
| 1344 | set(menu_handle,'String',list) |
---|
| 1345 | |
---|
| 1346 | |
---|
| 1347 | %----------------------------------------------------- |
---|
| 1348 | function list_fig_Callback(hObject, eventdata, handles) |
---|
| 1349 | %----------------------------------------------------- |
---|
| 1350 | list_fig=get(handles.list_fig,'String'); |
---|
| 1351 | fig_val=get(handles.list_fig,'Value'); |
---|
| 1352 | plot_fig=list_fig{fig_val}; |
---|
| 1353 | if strcmp(plot_fig,'view_field') |
---|
| 1354 | % huvmat=findobj(allchild(0),'name','uvmat'); |
---|
| 1355 | % if ~isempty(huvmat) |
---|
| 1356 | % uistack(huvmat,'top') |
---|
| 1357 | % end |
---|
| 1358 | else%if ~isequal(plot_fig,'new fig...') & ~isequal(plot_fig,'uvmat') |
---|
| 1359 | sep=regexp(plot_fig,'_'); |
---|
| 1360 | if ~isempty(sep) |
---|
| 1361 | plot_fig=plot_fig([1:sep-1]); |
---|
| 1362 | end |
---|
| 1363 | if ishandle(str2num(plot_fig)) |
---|
| 1364 | figure(str2num(plot_fig))% display existing figure |
---|
| 1365 | else |
---|
| 1366 | browse_fig(handles.list_fig); %reset the current list of figures |
---|
| 1367 | end |
---|
| 1368 | end |
---|
| 1369 | |
---|
| 1370 | |
---|
| 1371 | %------------------------------------------------- |
---|
| 1372 | % give index numbers of the strings str in the list ListvarName |
---|
| 1373 | function VarIndex_y=name2index(cell_str,ListVarName) |
---|
| 1374 | VarIndex_y=[]; |
---|
| 1375 | if ischar(cell_str) |
---|
| 1376 | for ivar=1:length(ListVarName) |
---|
| 1377 | varlist=ListVarName{ivar}; |
---|
| 1378 | if isequal(varlist,cell_str) |
---|
| 1379 | VarIndex_y= ivar; |
---|
| 1380 | break |
---|
| 1381 | end |
---|
| 1382 | end |
---|
| 1383 | elseif iscell(cell_str) |
---|
| 1384 | for isel=1:length(cell_str) |
---|
| 1385 | varsel=cell_str{isel}; |
---|
| 1386 | for ivar=1:length(ListVarName) |
---|
| 1387 | varlist=ListVarName{ivar}; |
---|
| 1388 | if isequal(varlist,varsel) |
---|
| 1389 | VarIndex_y=[VarIndex_y ivar]; |
---|
| 1390 | end |
---|
| 1391 | end |
---|
| 1392 | end |
---|
| 1393 | end |
---|
| 1394 | |
---|
| 1395 | % -------------------------------------------------------------------- |
---|
| 1396 | function MenuOpen_Callback(hObject, eventdata, handles) |
---|
| 1397 | % hObject handle to MenuOpen (see GCBO) |
---|
| 1398 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 1399 | % handles structure with handles and user data (see GUIDATA) |
---|
| 1400 | |
---|
| 1401 | |
---|
| 1402 | % -------------------------------------------------------------------- |
---|
| 1403 | function MenuExport_Callback(hObject, eventdata, handles) |
---|
| 1404 | % hObject handle to MenuExport (see GCBO) |
---|
| 1405 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 1406 | % handles structure with handles and user data (see GUIDATA) |
---|
| 1407 | |
---|
| 1408 | |
---|
| 1409 | % -------------------------------------------------------------------- |
---|
| 1410 | function MenuBrowse_Callback(hObject, eventdata, handles) |
---|
| 1411 | |
---|
| 1412 | oldfile=get(handles.inputfile,'String'); |
---|
| 1413 | testrootfile=0; |
---|
| 1414 | testsubdir=0; |
---|
| 1415 | if isempty(oldfile)|isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box |
---|
| 1416 | oldfile=''; |
---|
| 1417 | dir_perso=prefdir; |
---|
| 1418 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 1419 | if exist(profil_perso,'file') |
---|
| 1420 | h=load (profil_perso); |
---|
| 1421 | if isfield(h,'RootPath') |
---|
| 1422 | RootPath=h.RootPath; |
---|
| 1423 | end |
---|
| 1424 | if isfield(h,'SubDir') |
---|
| 1425 | SubDir=h.SubDir; |
---|
| 1426 | if ~isempty(SubDir) |
---|
| 1427 | testsubdir=1; |
---|
| 1428 | end |
---|
| 1429 | end |
---|
| 1430 | if isfield(h,'RootFile') |
---|
| 1431 | RootFile=h.RootFile; |
---|
| 1432 | if ~isempty(RootFile) |
---|
| 1433 | testrootfile=1; |
---|
| 1434 | end |
---|
| 1435 | end |
---|
| 1436 | end |
---|
| 1437 | end |
---|
| 1438 | if testrootfile |
---|
| 1439 | if ~testsubdir |
---|
| 1440 | oldfile=fullfile(RootPath,RootFile); |
---|
| 1441 | else |
---|
| 1442 | oldfile=fullfile(RootPath,SubDir,RootFile); |
---|
| 1443 | end |
---|
| 1444 | end |
---|
| 1445 | [FileName, PathName] = uigetfile( ... |
---|
| 1446 | {'*.nc', ' *.nc';... |
---|
| 1447 | '*.cdf', ' *.cdf';... |
---|
| 1448 | '*.*', 'All Files (*.*)'}, ... |
---|
| 1449 | 'Pick a file',oldfile); |
---|
| 1450 | |
---|
| 1451 | %global inputfile |
---|
| 1452 | fileinput=[PathName FileName];%complete file name |
---|
| 1453 | sizf=size(fileinput); |
---|
[227] | 1454 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
[204] | 1455 | set(handles.inputfile,'String',fileinput) |
---|
| 1456 | inputfile_Callback(hObject, eventdata, handles) |
---|
| 1457 | |
---|
| 1458 | %update list of recent files in the menubar |
---|
| 1459 | MenuFile_1=fileinput; |
---|
| 1460 | MenuFile_2=get(handles.MenuFile_1,'Label'); |
---|
| 1461 | MenuFile_3=get(handles.MenuFile_2,'Label'); |
---|
| 1462 | MenuFile_4=get(handles.MenuFile_3,'Label'); |
---|
| 1463 | MenuFile_5=get(handles.MenuFile_4,'Label'); |
---|
| 1464 | set(handles.MenuFile_1,'Label',MenuFile_1) |
---|
| 1465 | set(handles.MenuFile_2,'Label',MenuFile_2) |
---|
| 1466 | set(handles.MenuFile_3,'Label',MenuFile_3) |
---|
| 1467 | set(handles.MenuFile_4,'Label',MenuFile_4) |
---|
| 1468 | set(handles.MenuFile_5,'Label',MenuFile_5) |
---|
| 1469 | dir_perso=prefdir; |
---|
| 1470 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
| 1471 | display(profil_perso) |
---|
| 1472 | if exist(profil_perso,'file') |
---|
| 1473 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat |
---|
| 1474 | else |
---|
| 1475 | txt=ver('MATLAB'); |
---|
| 1476 | Release=txt.Release; |
---|
| 1477 | relnumb=str2double(Release(3:4)); |
---|
| 1478 | if relnumb >= 14 |
---|
| 1479 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat |
---|
| 1480 | else |
---|
| 1481 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat |
---|
| 1482 | end |
---|
| 1483 | end |
---|
| 1484 | |
---|
| 1485 | % -------------------------------------------------------------------- |
---|
| 1486 | function MenuFile_1_Callback(hObject, eventdata, handles) |
---|
| 1487 | fileinput=get(handles.MenuFile_1,'Label'); |
---|
| 1488 | set(handles.inputfile,'String',fileinput) |
---|
| 1489 | inputfile_Callback(hObject, eventdata, handles) |
---|
| 1490 | |
---|
| 1491 | % -------------------------------------------------------------------- |
---|
| 1492 | function MenuFile_2_Callback(hObject, eventdata, handles) |
---|
| 1493 | fileinput=get(handles.MenuFile_2,'Label'); |
---|
| 1494 | set(handles.inputfile,'String',fileinput) |
---|
| 1495 | inputfile_Callback(hObject, eventdata, handles) |
---|
| 1496 | |
---|
[227] | 1497 | % ----------------------------------------------------------------------- |
---|
[204] | 1498 | function MenuFile_3_Callback(hObject, eventdata, handles) |
---|
[227] | 1499 | % ----------------------------------------------------------------------- |
---|
[204] | 1500 | fileinput=get(handles.MenuFile_3,'Label'); |
---|
| 1501 | set(handles.inputfile,'String',fileinput) |
---|
| 1502 | inputfile_Callback(hObject, eventdata, handles) |
---|
| 1503 | |
---|
[227] | 1504 | % ----------------------------------------------------------------------- |
---|
[204] | 1505 | function MenuFile_4_Callback(hObject, eventdata, handles) |
---|
[227] | 1506 | % ----------------------------------------------------------------------- |
---|
[204] | 1507 | fileinput=get(handles.MenuFile_4,'Label'); |
---|
| 1508 | set(handles.inputfile,'String',fileinput) |
---|
| 1509 | inputfile_Callback(hObject, eventdata, handles) |
---|
| 1510 | |
---|
[227] | 1511 | % ----------------------------------------------------------------------- |
---|
[204] | 1512 | function MenuFile_5_Callback(hObject, eventdata, handles) |
---|
[227] | 1513 | % ----------------------------------------------------------------------- |
---|
[204] | 1514 | fileinput=get(handles.MenuFile_5,'Label'); |
---|
| 1515 | set(handles.inputfile,'String',fileinput) |
---|
| 1516 | inputfile_Callback(hObject, eventdata, handles) |
---|
| 1517 | |
---|
[227] | 1518 | %------------------------------------------------------------------------ |
---|
[204] | 1519 | function MenuExportField_Callback(hObject, eventdata, handles) |
---|
[227] | 1520 | %------------------------------------------------------------------------ |
---|
[204] | 1521 | global Data_get_field |
---|
| 1522 | % huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
| 1523 | inputfile=get(handles.inputfile,'String'); |
---|
| 1524 | Data_get_field=nc2struct(inputfile); |
---|
| 1525 | % Data_view_field=UvData.ProjField_2; |
---|
| 1526 | evalin('base','global Data_get_field')%make CurData global in the workspace |
---|
| 1527 | display(['content of ' inputfile ':']) |
---|
| 1528 | evalin('base','Data_get_field') %display CurData in the workspace |
---|
| 1529 | commandwindow; |
---|
| 1530 | |
---|
[227] | 1531 | %------------------------------------------------------------------------ |
---|
[204] | 1532 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
[227] | 1533 | %------------------------------------------------------------------------ |
---|
[204] | 1534 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
| 1535 | pathelp=fileparts(path_to_uvmat); |
---|
| 1536 | helpfile=fullfile(pathelp,'UVMAT_DOC','uvmat_doc.html'); |
---|
| 1537 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the directory UVMAT/UVMAT_DOC') |
---|
| 1538 | else |
---|
| 1539 | web([helpfile '#get_field']) |
---|
| 1540 | end |
---|
| 1541 | |
---|
[227] | 1542 | % ----------------------------------------------------------------------- |
---|
| 1543 | function TimeName_Callback(hObject, eventdata, handles) |
---|
| 1544 | |
---|
| 1545 | scalar_Callback(hObject, eventdata, handles)% suppress time variable from possible spatial coordinates |
---|
| 1546 | vector_x_Callback(hObject, eventdata, handles) |
---|
| 1547 | |
---|
| 1548 | %------------------------------------------------------------------------ |
---|
| 1549 | % --- Executes on button press in TimeAttribute. |
---|
| 1550 | function TimeAttribute_Callback(hObject, eventdata, handles) |
---|
| 1551 | %------------------------------------------------------------------------ |
---|
| 1552 | val=get(handles.TimeAttribute,'Value'); |
---|
| 1553 | if val |
---|
| 1554 | set(handles.TimeAttributeMenu,'Visible','on') |
---|
| 1555 | Field=get(handles.get_field,'UserData'); |
---|
| 1556 | time_value=zeros(size(Field.ListGlobalAttribute)); |
---|
| 1557 | test_time=zeros(size(Field.ListGlobalAttribute)); |
---|
| 1558 | for ilist=1:numel(Field.ListGlobalAttribute) |
---|
| 1559 | if isnumeric(eval(['Field.' Field.ListGlobalAttribute{ilist}])) |
---|
| 1560 | eval(['time_val=Field.' Field.ListGlobalAttribute{ilist} ';']) |
---|
| 1561 | if ~isempty(time_val) |
---|
| 1562 | time_value(ilist)=time_val; |
---|
| 1563 | test_time(ilist)=1; |
---|
| 1564 | end |
---|
| 1565 | end |
---|
| 1566 | end |
---|
| 1567 | ListTimeAttribute=Field.ListGlobalAttribute(test_time==1); |
---|
| 1568 | attr_index=get(handles.TimeAttributeMenu,'Value'); |
---|
| 1569 | if attr_index>numel(ListTimeAttribute) |
---|
| 1570 | attr_index=1; |
---|
| 1571 | set(handles.TimeAttributeMenu,'Value',1); |
---|
| 1572 | end |
---|
| 1573 | if isempty(ListTimeAttribute) |
---|
| 1574 | set(handles.TimeAttributeMenu,'String',{''}) |
---|
| 1575 | set(handles.TimeValue,'Visible','off') |
---|
| 1576 | else |
---|
| 1577 | set(handles.TimeValue,'Visible','on') |
---|
| 1578 | set(handles.TimeAttributeMenu,'String',ListTimeAttribute) |
---|
| 1579 | set(handles.TimeValue,'String',num2str(time_value(attr_index))) |
---|
| 1580 | end |
---|
| 1581 | set(handles.TimeDimension,'Value',0) |
---|
| 1582 | TimeDimension_Callback(hObject, eventdata, handles) |
---|
| 1583 | set(handles.TimeVariable,'Value',0) |
---|
| 1584 | TimeVariable_Callback(hObject, eventdata, handles) |
---|
| 1585 | else |
---|
| 1586 | set(handles.TimeAttributeMenu,'Visible','off') |
---|
| 1587 | set(handles.TimeValue,'Visible','off') |
---|
| 1588 | end |
---|
| 1589 | |
---|
| 1590 | %------------------------------------------------------------------------ |
---|
| 1591 | % --- Executes on selection change in TimeAttributeMenu. |
---|
| 1592 | function TimeAttributeMenu_Callback(hObject, eventdata, handles) |
---|
| 1593 | ListTimeAttribute=get(handles.TimeAttributeMenu,'String'); |
---|
| 1594 | index=get(handles.TimeAttributeMenu,'Value'); |
---|
| 1595 | AttrName=ListTimeAttribute{index}; |
---|
| 1596 | Field=get(handles.get_field,'UserData'); |
---|
| 1597 | eval(['time_val=Field.' AttrName ';']) |
---|
| 1598 | set(handles.TimeValue,'String',num2str(time_val)) |
---|
| 1599 | %------------------------------------------------------------------------ |
---|
| 1600 | |
---|
| 1601 | %------------------------------------------------------------------------ |
---|
| 1602 | % --- Executes on button press in TimeVariable. |
---|
| 1603 | function TimeDimension_Callback(hObject, eventdata, handles) |
---|
| 1604 | %------------------------------------------------------------------------ |
---|
| 1605 | val=get(handles.TimeDimension,'Value');%=1 if check box TimeDimension is selected |
---|
| 1606 | if val %if check box TimeDimension is selected |
---|
| 1607 | Field=get(handles.get_field,'UserData');% structure describing the currently opened field |
---|
| 1608 | previous_menu=get(handles.TimeDimensionMenu,'String'); |
---|
| 1609 | if ~isequal(previous_menu,Field.ListDimName)%update the list of available dimensions in the menu |
---|
| 1610 | ind_select=find(strcmpi('time',Field.ListDimName),1);% look for a dimension named 'time' or 'Time' |
---|
| 1611 | if isempty(ind_select) |
---|
| 1612 | ind_select=1;% select the first item in the list if 'time' is not found |
---|
| 1613 | end |
---|
| 1614 | set(handles.TimeDimensionMenu,'Value',ind_select); |
---|
| 1615 | set(handles.TimeDimensionMenu,'String',Field.ListDimName)% put the list of available dimensions in the menu |
---|
| 1616 | end |
---|
| 1617 | set(handles.TimeDimensionMenu,'Visible','on')% the menu is made visible |
---|
| 1618 | set(handles.TimeIndexValue,'Visible','on')% the time matrix index value selected is made visible |
---|
| 1619 | TimeDimensionMenu_Callback(hObject, eventdata, handles) |
---|
| 1620 | set(handles.TimeAttribute,'Value',0) %deselect alternative options for time |
---|
| 1621 | set(handles.TimeVariable,'Value',0) |
---|
| 1622 | TimeAttribute_Callback(hObject, eventdata, handles) |
---|
| 1623 | else |
---|
| 1624 | set(handles.TimeDimensionMenu,'Visible','off') |
---|
| 1625 | set(handles.TimeIndexValue,'Visible','off') |
---|
| 1626 | end |
---|
| 1627 | |
---|
| 1628 | %------------------------------------------------------------------------ |
---|
| 1629 | % --- Executes on selection change in TimeDimensionMenu. |
---|
| 1630 | function TimeDimensionMenu_Callback(hObject, eventdata, handles) |
---|
| 1631 | %------------------------------------------------------------------------ |
---|
| 1632 | index=get(handles.TimeDimensionMenu,'Value'); |
---|
| 1633 | DimList=get(handles.TimeDimensionMenu,'String'); |
---|
| 1634 | DimName=DimList{index}; |
---|
| 1635 | Field=get(handles.get_field,'UserData'); |
---|
| 1636 | DimIndex=find(strcmp(DimName,Field.ListDimName),1); |
---|
| 1637 | ref_index=round(Field.DimValue(DimIndex)/2); |
---|
| 1638 | set(handles.TimeIndexValue,'String',num2str(ref_index)) |
---|
| 1639 | scalar_Callback(hObject, eventdata, handles) |
---|
| 1640 | vector_x_Callback(hObject, eventdata, handles)% update menus of coordinates (remove time) |
---|
| 1641 | % look for a corresponding time variable and value |
---|
| 1642 | time_test=zeros(size(Field.VarDimName)); |
---|
| 1643 | for ilist=1:numel(Field.VarDimName) |
---|
| 1644 | if isequal(Field.VarDimName{ilist},{DimName}) |
---|
| 1645 | time_test(ilist)=1; |
---|
| 1646 | end |
---|
| 1647 | end |
---|
| 1648 | ListVariable=Field.ListVarName(time_test==1); |
---|
| 1649 | set(handles.TimeVariableMenu,'Value',1) |
---|
| 1650 | if isempty(ListVariable) |
---|
| 1651 | set(handles.TimeVariableMenu,'String',{''}) |
---|
| 1652 | set(handles.TimeVarValue,'String','') |
---|
| 1653 | else |
---|
| 1654 | set(handles.TimeVariableMenu,'String',ListVariable) |
---|
| 1655 | TimeVarName=ListVariable{1}; |
---|
| 1656 | VarIndex=find(strcmp(TimeVarName,Field.ListVarName),1);%index in the list of variables |
---|
| 1657 | inputfile=get(handles.inputfile,'String');% read the input file |
---|
| 1658 | SubField=nc2struct(inputfile,{TimeVarName}); |
---|
| 1659 | eval(['TimeValue=SubField.' TimeVarName '(ref_index);']) |
---|
| 1660 | set(handles.TimeVarValue,'Visible','on') |
---|
| 1661 | set(handles.TimeVariableMenu,'Visible','on') |
---|
| 1662 | set(handles.TimeVarValue,'String',num2str(TimeValue)) |
---|
| 1663 | end |
---|
| 1664 | |
---|
| 1665 | |
---|
| 1666 | % % ----------------------------------------------------------------------- |
---|
| 1667 | % % --- Executes on button press in TimeVariable. |
---|
| 1668 | % function TimeVariable_Callback(hObject, eventdata, handles) |
---|
| 1669 | % % ----------------------------------------------------------------------- |
---|
| 1670 | % val=get(handles.TimeVariable,'Value'); |
---|
| 1671 | % if val |
---|
| 1672 | % Field=get(handles.get_field,'UserData'); |
---|
| 1673 | % time_test=zeros(size(Field.VarDimName)); |
---|
| 1674 | % for ilist=1:numel(Field.VarDimName) |
---|
| 1675 | % if isequal(numel(Field.VarDimName{ilist}),1)%select variables with a single dimension |
---|
| 1676 | % time_test(ilist)=1; |
---|
| 1677 | % end |
---|
| 1678 | % end |
---|
| 1679 | % ind_test=find(time_test); |
---|
| 1680 | % if isempty(time_test) |
---|
| 1681 | % set(handles.TimeVariable,'Value',0) |
---|
| 1682 | % set(handles.TimeVariableMenu,'Visible','off') |
---|
| 1683 | % set(handles.TimeVarValue,'Visible','off') |
---|
| 1684 | % else |
---|
| 1685 | % set(handles.TimeVariableMenu,'Visible','on') |
---|
| 1686 | % set(handles.TimeVarValue,'Visible','on') |
---|
| 1687 | % if get(handles.TimeVariableMenu,'Value')>numel(ind_test) |
---|
| 1688 | % set(handles.TimeVariableMenu,'Value',1) |
---|
| 1689 | % end |
---|
| 1690 | % set(handles.TimeVariableMenu,'String',Field.ListVarName(ind_test)) |
---|
| 1691 | % TimeVariableMenu_Callback(hObject, eventdata, handles) |
---|
| 1692 | % set(handles.TimeDimension,'Value',0) %deseselect alternative option sfor time |
---|
| 1693 | % set(handles.TimeAttribute,'Value',0) |
---|
| 1694 | % TimeAttribute_Callback(hObject, eventdata, handles) |
---|
| 1695 | % end |
---|
| 1696 | % else |
---|
| 1697 | % set(handles.TimeVariableMenu,'Visible','off') |
---|
| 1698 | % set(handles.TimeVarValue,'Visible','off') |
---|
| 1699 | % end |
---|
| 1700 | |
---|
| 1701 | % ----------------------------------------------------------------------- |
---|
| 1702 | % --- Executes on selection change in TimeVariableMenu. |
---|
| 1703 | function TimeVariableMenu_Callback(hObject, eventdata, handles) |
---|
| 1704 | % ----------------------------------------------------------------------- |
---|
| 1705 | ListVar=get(handles.TimeVariableMenu,'String'); |
---|
| 1706 | index=get(handles.TimeVariableMenu,'Value'); |
---|
| 1707 | TimeVariable=ListVar{index};% name of the selected variable |
---|
| 1708 | if isempty(TimeVariable)% case of blank selection |
---|
| 1709 | return |
---|
| 1710 | end |
---|
| 1711 | Field=get(handles.get_field,'UserData'); %index of |
---|
| 1712 | VarIndex=find(strcmp(TimeVariable,Field.ListVarName),1);%index in the list of variables |
---|
| 1713 | DimName=Field.VarDimName{VarIndex}; % dimension corresponding to the variable |
---|
| 1714 | set(handles.TimeDimensionMenu,'Value',1) |
---|
| 1715 | set(handles.TimeDimensionMenu,'String',DimName) |
---|
| 1716 | inputfile=get(handles.inputfile,'String');% read the input file |
---|
| 1717 | SubField=nc2struct(inputfile,{TimeVariable}); |
---|
| 1718 | eval(['TimeDimension=numel(SubField.' TimeVariable ');']) |
---|
| 1719 | ref_index=round(TimeDimension/2); |
---|
| 1720 | eval(['TimeValue=SubField.' TimeVariable '(ref_index);']) |
---|
| 1721 | set(handles.TimeIndexValue,'String',num2str(ref_index)) |
---|
| 1722 | set(handles.TimeVarValue,'String',num2str(TimeValue)) |
---|
| 1723 | |
---|
| 1724 | |
---|
| 1725 | function TimeValue_Callback(hObject, eventdata, handles) |
---|
| 1726 | %TO suppress |
---|
| 1727 | |
---|
| 1728 | % ----------------------------------------------------------------------- |
---|
| 1729 | function TimeIndexValue_Callback(hObject, eventdata, handles) |
---|
| 1730 | % ----------------------------------------------------------------------- |
---|
| 1731 | TimeIndex=str2double(get(handles.TimeIndexValue,'String')); |
---|
| 1732 | TimeVarName=Field.ListVarName{time_index}; |
---|
| 1733 | set(handles.TimeVariable,'Value',1) |
---|
| 1734 | set(handles.TimeName,'String',TimeVarName) |
---|
| 1735 | fileinput=get(handles.inputfile,'String'); |
---|
| 1736 | SubField=nc2struct(fileinput,{TimeVarName}); |
---|
| 1737 | eval(['TimeValue=SubField.' TimeVarName '(ref_index);']); |
---|
| 1738 | set(handles.TimeValue,'Visible','on') |
---|
| 1739 | set(handles.TimeValue,'String',num2str(TimeValue)) |
---|
| 1740 | |
---|
| 1741 | % ----------------------------------------------------------------------- |
---|
| 1742 | function SelectFigure_Callback(hObject, eventdata, handles) |
---|
| 1743 | % ----------------------------------------------------------------------- |
---|
| 1744 | val=get(handles.SelectFigure,'Value'); |
---|
| 1745 | if val |
---|
| 1746 | set(handles.list_fig,'Visible','on') |
---|
| 1747 | %% look at the existing figures in the work space |
---|
| 1748 | browse_fig(handles.list_fig) |
---|
| 1749 | else |
---|
| 1750 | set(handles.list_fig,'Visible','off') |
---|
| 1751 | end |
---|
| 1752 | |
---|
| 1753 | |
---|
| 1754 | function TimeVarValue_Callback(hObject, eventdata, handles) |
---|
| 1755 | |
---|
| 1756 | |
---|
| 1757 | |
---|
| 1758 | % --- Executes on button press in check_rgb. |
---|
| 1759 | function check_rgb_Callback(hObject, eventdata, handles) |
---|