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