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