[32] | 1 | %'read_get_field': read the list of selected variables from the GUI get_field |
---|
| 2 | |
---|
| 3 | % OUTPUT: |
---|
| 4 | % SubField: structure with fields |
---|
| 5 | % .ListVarName: list of selected variables |
---|
| 6 | % .VarDimName: cells with the corresponding dimension names |
---|
| 7 | % .Field1, 2...: if an input file has been opened by get_field |
---|
| 8 | % errormsg: error message (=[] when no error) |
---|
| 9 | |
---|
[8] | 10 | % INPUT: |
---|
| 11 | % hget_field: handles of the GUI get_field |
---|
| 12 | |
---|
| 13 | function [SubField,errormsg]=read_get_field(hget_field) |
---|
| 14 | %--------------------------------------------------------- |
---|
| 15 | SubField=[];%default |
---|
| 16 | errormsg=[]; %default |
---|
| 17 | handles=guidata(hget_field);%handles of GUI elements in get_field |
---|
| 18 | Field=get(hget_field,'UserData');% read the current field Structure in the get_field interface |
---|
| 19 | if isfield(Field,'VarAttribute') |
---|
| 20 | VarAttribute=Field.VarAttribute; |
---|
| 21 | else |
---|
| 22 | VarAttribute={}; |
---|
| 23 | end |
---|
| 24 | |
---|
| 25 | % select the indices of field variables for 2D plots |
---|
| 26 | test_1Dplot=get(handles.check_1Dplot,'Value'); |
---|
| 27 | test_scalar=get(handles.check_scalar,'Value'); |
---|
| 28 | test_vector=get(handles.check_vector,'Value'); |
---|
| 29 | |
---|
| 30 | nbvar=0; |
---|
| 31 | empty_coord_x=0; |
---|
| 32 | empty_coord_y=0; |
---|
[34] | 33 | %dimname_y={}; |
---|
[8] | 34 | ListVarName={}; |
---|
| 35 | VarDimName={}; |
---|
| 36 | SubVarAttribute={}; |
---|
[34] | 37 | %dim_x=0; |
---|
| 38 | %dim_y=0; |
---|
[8] | 39 | dim_z=0; |
---|
[34] | 40 | %dim_vec_x=0; |
---|
| 41 | %dim_vec_y=0; |
---|
| 42 | %dim_vec_z=0; |
---|
| 43 | %c_index=[]; |
---|
[32] | 44 | |
---|
| 45 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 46 | % ordinary (1D) plot |
---|
[8] | 47 | if test_1Dplot |
---|
[32] | 48 | % select ordinate variable(s) |
---|
[8] | 49 | inputlist=get(handles.ordinate,'String'); |
---|
| 50 | val=get(handles.ordinate,'Value');% selection(s) for ordinate |
---|
| 51 | VarNameCell=inputlist(val); %names of the variable(s) in the list |
---|
[34] | 52 | VarIndex_y=[]; |
---|
| 53 | dim_ordinate={}; |
---|
| 54 | testpermute=[]; |
---|
| 55 | subvarindex=[]; |
---|
[8] | 56 | for ilist=1:length(VarNameCell) |
---|
| 57 | VarIndex_y(ilist)=name2index(VarNameCell{ilist},Field.ListVarName);%index of the variable in ListVarName |
---|
| 58 | dim_ordinate{ilist}=Field.VarDimName{VarIndex_y(ilist)};% name of the corresponding dimension |
---|
| 59 | testpermute(ilist)=0;%default |
---|
| 60 | nbvar=nbvar+1; |
---|
| 61 | ListVarName{nbvar}=Field.ListVarName{VarIndex_y(ilist)}; |
---|
| 62 | VarDimName{nbvar}=Field.VarDimName{VarIndex_y(ilist)}; |
---|
| 63 | subvarindex(ilist)=nbvar; |
---|
| 64 | if numel(VarAttribute)>=VarIndex_y(ilist) |
---|
| 65 | SubVarAttribute{nbvar}=VarAttribute{VarIndex_y(ilist)}; |
---|
| 66 | end |
---|
| 67 | SubVarAttribute{nbvar}.Role='scalar'; |
---|
| 68 | end |
---|
| 69 | |
---|
[32] | 70 | % select abscissa variable |
---|
[8] | 71 | inputlist=get(handles.abscissa,'String'); |
---|
| 72 | val=get(handles.abscissa,'Value');% a single selection is expected for abscissa |
---|
| 73 | VarName=inputlist{val}; %name of the variable in the list |
---|
| 74 | VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName |
---|
| 75 | if isempty(VarIndex)% default abscissa = matrix index |
---|
| 76 | coord_x_name=dim_ordinate{1};% name of the x coordinate = dimension of the plotted quantity |
---|
| 77 | if iscell(coord_x_name) |
---|
| 78 | coord_x_name=coord_x_name{1}; |
---|
| 79 | end |
---|
| 80 | empty_coord_x=1; |
---|
| 81 | else |
---|
| 82 | dimname_x=Field.VarDimName{VarIndex}; |
---|
[80] | 83 | if iscell(dimname_x) && numel(dimname_x)~=1 |
---|
[8] | 84 | errormsg='abscissa must be a one-dimensional variable'; |
---|
| 85 | return |
---|
| 86 | end |
---|
| 87 | nbvar=nbvar+1; |
---|
| 88 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 89 | VarDimName{nbvar}=Field.VarDimName{VarIndex}; |
---|
| 90 | if numel(VarAttribute)>=VarIndex |
---|
| 91 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 92 | end |
---|
| 93 | SubVarAttribute{nbvar}.Role='coord_x'; |
---|
| 94 | %check consistency of ordinate dimensions |
---|
| 95 | for ilist=1:length(VarNameCell) |
---|
| 96 | if iscell(dim_ordinate{ilist}) |
---|
| 97 | if ~strcmp(dim_ordinate{ilist}{1},dimname_x) |
---|
| 98 | if strcmp(dim_ordinate{ilist}{2},dimname_x) |
---|
| 99 | testpermute(ilist)=1; |
---|
| 100 | else |
---|
| 101 | errormsg='inconsistent dimensions for ordinate and abscissa'; |
---|
| 102 | return |
---|
| 103 | end |
---|
| 104 | end |
---|
| 105 | end |
---|
| 106 | end |
---|
| 107 | end |
---|
| 108 | end |
---|
| 109 | test3D=strcmp(get(handles.coord_z_scalar,'Visible'),'on')||strcmp(get(handles.coord_z_vectors,'Visible'),'on'); |
---|
| 110 | VarSubIndexA=[]; |
---|
| 111 | |
---|
[32] | 112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 113 | %scalar field |
---|
[8] | 114 | test_xdimvar=0;%default |
---|
| 115 | test_ydimvar=0;%default |
---|
| 116 | test_zdimvar=0;%defaul |
---|
| 117 | dimname_x=[]; |
---|
| 118 | dimname_y=[]; |
---|
| 119 | dimname_z=[]; |
---|
| 120 | if test_scalar |
---|
| 121 | inputlist=get(handles.scalar,'String'); |
---|
| 122 | if isempty(inputlist) |
---|
| 123 | errormsg='empty input field'; |
---|
| 124 | return |
---|
| 125 | end |
---|
| 126 | val=get(handles.scalar,'Value');%selected indices in the ordinate listbox |
---|
| 127 | VarNameScalar=inputlist{val}; %name of the variable in the list |
---|
| 128 | VarIndexA=name2index(VarNameScalar,Field.ListVarName);%index of the variable in ListVarName |
---|
| 129 | dimname_A=Field.VarDimName{VarIndexA}; |
---|
| 130 | nbvar=nbvar+1; |
---|
| 131 | ListVarName{nbvar}=Field.ListVarName{VarIndexA}; |
---|
| 132 | VarSubIndexA=nbvar; |
---|
| 133 | VarDimName{nbvar}=dimname_A; |
---|
| 134 | if numel(VarAttribute)>=VarIndexA |
---|
| 135 | SubVarAttribute{nbvar}=VarAttribute{VarIndexA}; |
---|
| 136 | end |
---|
| 137 | SubVarAttribute{nbvar}.Role='scalar'; |
---|
| 138 | field_var_index=VarIndexA; %store the last variable index to determine the absissa dimension if not defiend |
---|
| 139 | |
---|
| 140 | % select x variable |
---|
| 141 | inputlist=get(handles.coord_x_scalar,'String'); |
---|
| 142 | val=get(handles.coord_x_scalar,'Value');% a single selection is expected for abscissa |
---|
| 143 | VarName=inputlist{val}; %name of the variable in the list |
---|
| 144 | VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName |
---|
| 145 | if isempty(VarIndex)% default abscissa = matrix index |
---|
| 146 | empty_coord_x=1; |
---|
| 147 | else |
---|
| 148 | dimname_x=Field.VarDimName{VarIndex}; |
---|
| 149 | nbvar=nbvar+1; |
---|
| 150 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 151 | VarDimName{nbvar}=dimname_x; |
---|
| 152 | if numel(VarAttribute)>=VarIndex |
---|
| 153 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 154 | end |
---|
| 155 | %check consistency of dimensions |
---|
| 156 | if ~isequal(dimname_x,dimname_A)% case of dimension variables |
---|
| 157 | if iscell(dimname_x) |
---|
| 158 | if numel(dimname_x)==1 |
---|
| 159 | dimname_x=dimname_x{1};%transform to char chain |
---|
| 160 | else |
---|
| 161 | errormsg='invalid x coordinate selection in get_field'; |
---|
| 162 | return |
---|
| 163 | end |
---|
| 164 | end |
---|
| 165 | test_xdimvar=1; |
---|
| 166 | SubVarAttribute{nbvar}.Role='dimvar';% dimension variable |
---|
| 167 | else |
---|
| 168 | SubVarAttribute{nbvar}.Role='coord_x';%abcissa with unstructured coordinates |
---|
| 169 | end |
---|
| 170 | end |
---|
| 171 | |
---|
| 172 | % select y variable |
---|
| 173 | inputlist=get(handles.coord_y_scalar,'String'); |
---|
| 174 | val=get(handles.coord_y_scalar,'Value');% a single selection is expected for abscissa |
---|
| 175 | VarName=inputlist{val}; %name of the variable in the list |
---|
| 176 | VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName |
---|
| 177 | if isempty(VarIndex)% default abscissa = matrix index |
---|
| 178 | empty_coord_y=1; |
---|
| 179 | else |
---|
| 180 | dimname_y=Field.VarDimName{VarIndex}; |
---|
| 181 | nbvar=nbvar+1; |
---|
| 182 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 183 | VarDimName{nbvar}=dimname_y; |
---|
| 184 | if numel(VarAttribute)>=VarIndex |
---|
| 185 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 186 | end |
---|
| 187 | %check consistency of dimensions |
---|
| 188 | if ~isequal(dimname_y,dimname_A)% case of dimension variables |
---|
| 189 | if iscell(dimname_y) |
---|
| 190 | if numel(dimname_y)==1 |
---|
| 191 | dimname_y=dimname_y{1};%transform to char chain |
---|
| 192 | else |
---|
| 193 | errormsg='invalid y coordinate selection in get_field'; |
---|
| 194 | return |
---|
| 195 | end |
---|
| 196 | end |
---|
| 197 | test_ydimvar=1; |
---|
| 198 | SubVarAttribute{nbvar}.Role='dimvar';% dimension variable |
---|
| 199 | else |
---|
| 200 | SubVarAttribute{nbvar}.Role='coord_y';%abcissa with unstructured coordinates |
---|
| 201 | end |
---|
| 202 | end |
---|
| 203 | |
---|
| 204 | % select z variable |
---|
| 205 | if test3D % TODO: Lire z comme x et y |
---|
| 206 | inputlist=get(handles.coord_z_scalar,'String'); |
---|
| 207 | val=get(handles.coord_z_scalar,'Value');% a single selection is expected for abscissa |
---|
| 208 | VarName=inputlist{val}; %name of the variable in the list |
---|
| 209 | VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName |
---|
| 210 | if isempty(VarIndex)% default abscissa = matrix index |
---|
[179] | 211 | empty_coord_z=1; |
---|
[8] | 212 | else |
---|
| 213 | dimname_z=Field.VarDimName{VarIndex}; |
---|
| 214 | nbvar=nbvar+1; |
---|
| 215 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
[179] | 216 | VarDimName{nbvar}=dimname_y; |
---|
[8] | 217 | if numel(VarAttribute)>=VarIndex |
---|
| 218 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 219 | end |
---|
[179] | 220 | %check consistency of dimensions |
---|
| 221 | if ~isequal(dimname_y,dimname_A)% case of dimension variables |
---|
| 222 | if iscell(dimname_y) |
---|
| 223 | if numel(dimname_y)==1 |
---|
| 224 | dimname_y=dimname_y{1};%transform to char chain |
---|
| 225 | else |
---|
| 226 | errormsg='invalid y coordinate selection in get_field'; |
---|
| 227 | return |
---|
| 228 | end |
---|
| 229 | end |
---|
| 230 | test_zdimvar=1; |
---|
[8] | 231 | SubVarAttribute{nbvar}.Role='dimvar';% dimension variable |
---|
| 232 | else |
---|
[179] | 233 | SubVarAttribute{nbvar}.Role='coord_z';%abcissa with unstructured coordinates |
---|
[8] | 234 | end |
---|
| 235 | end |
---|
| 236 | end |
---|
| 237 | end |
---|
[32] | 238 | |
---|
| 239 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 240 | % vectors |
---|
[105] | 241 | test_vec_x_dimvar=0;%default |
---|
| 242 | test_vec_y_dimvar=0;%default |
---|
[34] | 243 | % test_vec_z_dimvar=0;%defaul |
---|
[8] | 244 | dimname_vec_x=[]; |
---|
| 245 | dimname_vec_y=[]; |
---|
| 246 | dimname_vec_z=[]; |
---|
| 247 | if test_vector |
---|
| 248 | %select u variable |
---|
| 249 | inputlist=get(handles.vector_x,'String'); |
---|
| 250 | if isempty(inputlist) |
---|
| 251 | errormsg='empty input field'; |
---|
| 252 | return |
---|
| 253 | end |
---|
| 254 | val=get(handles.vector_x,'Value');%selected indices in the ordinate listbox |
---|
| 255 | VarNameU=inputlist{val}; %name of the variable in the list |
---|
| 256 | VarIndexU=name2index(VarNameU,Field.ListVarName);%index of the variable in ListVarName |
---|
| 257 | nbvar=nbvar+1; |
---|
| 258 | VarSubIndexU=nbvar; |
---|
| 259 | ListVarName{nbvar}=Field.ListVarName{VarIndexU}; |
---|
| 260 | dimname_u=Field.VarDimName{VarIndexU}; |
---|
| 261 | VarDimName{nbvar}=dimname_u; |
---|
| 262 | if numel(VarAttribute)>=VarIndexU |
---|
| 263 | SubVarAttribute{nbvar}=VarAttribute{VarIndexU}; |
---|
| 264 | end |
---|
| 265 | SubVarAttribute{nbvar}.Role='vector_x'; |
---|
| 266 | field_var_index=VarIndexU; %store the last variable index to determine the absissa dimension if not defiend |
---|
| 267 | |
---|
| 268 | %scalar v variable |
---|
| 269 | inputlist=get(handles.vector_y,'String'); |
---|
| 270 | val=get(handles.vector_y,'Value');%selected indices in the ordinate listbox |
---|
| 271 | VarNameV=inputlist{val}; %name of the variable in the list |
---|
| 272 | VarIndexV=name2index(VarNameV,Field.ListVarName);%index of the variable in ListVarName |
---|
| 273 | %check consistency of dimensions with u |
---|
| 274 | dimname_v=Field.VarDimName{VarIndexV}; |
---|
| 275 | if ~isequal(dimname_v,dimname_u) |
---|
| 276 | errormsg='inconsistent dimensions for u and v'; |
---|
| 277 | return |
---|
| 278 | end |
---|
| 279 | nbvar=nbvar+1; |
---|
| 280 | VarSubIndexV=nbvar; |
---|
| 281 | ListVarName{nbvar}=Field.ListVarName{VarIndexV}; |
---|
| 282 | VarDimName{nbvar}=dimname_u; |
---|
| 283 | if numel(VarAttribute)>=VarIndexV |
---|
| 284 | SubVarAttribute{nbvar}=VarAttribute{VarIndexV}; |
---|
| 285 | end |
---|
[32] | 286 | SubVarAttribute{nbvar}.Role='vector_y'; |
---|
[8] | 287 | |
---|
[32] | 288 | % select x variable for vector |
---|
[8] | 289 | inputlist=get(handles.coord_x_vectors,'String'); |
---|
| 290 | val=get(handles.coord_x_vectors,'Value');% a single selection is expected for abscissa |
---|
| 291 | VarName=inputlist{val}; %name of the variable in the list |
---|
| 292 | VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName |
---|
| 293 | if isempty(VarIndex)% default abscissa = matrix indexTODO like scalar |
---|
| 294 | empty_coord_vec_x=1; |
---|
| 295 | else |
---|
| 296 | empty_coord_vec_x=0; |
---|
| 297 | dimname_vec_x=Field.VarDimName{VarIndex}; |
---|
| 298 | nbvar=nbvar+1; |
---|
| 299 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 300 | VarDimName{nbvar}=dimname_vec_x; |
---|
| 301 | if numel(VarAttribute)>=VarIndex |
---|
| 302 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 303 | end |
---|
| 304 | %check consistency of dimensions |
---|
| 305 | if ~isequal(dimname_vec_x,dimname_u)% case of dimension variables |
---|
| 306 | if iscell(dimname_vec_x) |
---|
| 307 | if numel(dimname_vec_x)==1 |
---|
| 308 | dimname_vec_x=dimname_vec_x{1};%transform to char chain |
---|
| 309 | else |
---|
| 310 | errormsg='invalid x coordinate selection in get_field'; |
---|
| 311 | return |
---|
| 312 | end |
---|
| 313 | end |
---|
[105] | 314 | test_vec_x_dimvar=1; |
---|
[8] | 315 | SubVarAttribute{nbvar}.Role='dimvar';% dimension variable |
---|
| 316 | else |
---|
| 317 | SubVarAttribute{nbvar}.Role='coord_x';%abcissa with unstructured coordinates |
---|
| 318 | end |
---|
| 319 | end |
---|
| 320 | |
---|
[32] | 321 | % select y variable for vector |
---|
[8] | 322 | inputlist=get(handles.coord_y_vectors,'String'); |
---|
| 323 | val=get(handles.coord_y_vectors,'Value');% a single selection is expected for abscissa |
---|
| 324 | VarName=inputlist{val}; %name of the variable in the list |
---|
| 325 | VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName |
---|
| 326 | if isempty(VarIndex)% default abscissa = matrix indexTODO like scalar |
---|
| 327 | empty_coord_vec_y=1; |
---|
| 328 | else |
---|
| 329 | empty_coord_vec_y=0; |
---|
| 330 | dimname_vec_y=Field.VarDimName{VarIndex}; |
---|
| 331 | nbvar=nbvar+1; |
---|
| 332 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 333 | VarDimName{nbvar}=dimname_vec_y; |
---|
| 334 | if numel(VarAttribute)>=VarIndex |
---|
| 335 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 336 | end |
---|
| 337 | %check consistency of dimensions |
---|
| 338 | if ~isequal(dimname_vec_y,dimname_u)% case of dimension variables |
---|
| 339 | if iscell(dimname_vec_y) |
---|
| 340 | if numel(dimname_vec_y)==1 |
---|
| 341 | dimname_vec_y=dimname_vec_y{1};%transform to char chain |
---|
| 342 | else |
---|
| 343 | errormsg='invalid y coordinate selection in get_field'; |
---|
| 344 | return |
---|
| 345 | end |
---|
| 346 | end |
---|
[105] | 347 | test_vec_y_dimvar=1; |
---|
[8] | 348 | SubVarAttribute{nbvar}.Role='dimvar';% dimension variable |
---|
| 349 | else |
---|
| 350 | SubVarAttribute{nbvar}.Role='coord_y';%abcissa with unstructured coordinates |
---|
| 351 | end |
---|
| 352 | end |
---|
| 353 | |
---|
| 354 | % select z variable for vector |
---|
| 355 | if test3D |
---|
| 356 | inputlist=get(handles.coord_z_vectors,'String'); |
---|
| 357 | val=get(handles.coord_z_vectors,'Value');% a single selection is expected for abscissa |
---|
| 358 | VarName=inputlist{val}; %name of the variable in the list |
---|
| 359 | VarIndex=name2index(VarName,Field.ListVarName);%index of the variable in ListVarName |
---|
| 360 | if isempty(VarIndex)% default abscissa = matrix indexTODO like scalar |
---|
| 361 | % coord_x_name=dimname_u{2};% name of the x coordinate = dimension of the plotted quantity |
---|
[34] | 362 | % empty_coord_vec_z=1; |
---|
[8] | 363 | else |
---|
| 364 | dimname_vec_z=Field.VarDimName{VarIndex}; |
---|
| 365 | nbvar=nbvar+1; |
---|
| 366 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 367 | VarDimName{nbvar}=dimname_vec_z; |
---|
| 368 | if numel(VarAttribute)>=VarIndex |
---|
| 369 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 370 | end |
---|
| 371 | %check consistency of dimensions |
---|
| 372 | if ~isequal(dimname_vec_z,dimname_u)% case of dimension variables |
---|
| 373 | if iscell(dimname_vec_z) |
---|
| 374 | if numel(dimname_vec_z)==1 |
---|
| 375 | dimname_vec_z=dimname_vec_y{1};%transform to char chain |
---|
| 376 | else |
---|
| 377 | errormsg='invalid y coordinate selection in get_field'; |
---|
| 378 | return |
---|
| 379 | end |
---|
| 380 | end |
---|
[34] | 381 | % test_vec_z_dimvar=1; |
---|
[8] | 382 | SubVarAttribute{nbvar}.Role='dimvar';% dimension variable |
---|
| 383 | else |
---|
| 384 | SubVarAttribute{nbvar}.Role='coord_z';%abcissa with unstructured coordinates |
---|
| 385 | end |
---|
| 386 | end |
---|
| 387 | end |
---|
[32] | 388 | |
---|
| 389 | if test3D % (a revoir) |
---|
[8] | 390 | %scalar w variable |
---|
| 391 | inputlist=get(handles.vector_z,'String'); |
---|
| 392 | val=get(handles.vector_z,'Value');%selected indices in the ordinate listbox |
---|
| 393 | VarNameW=inputlist{val}; %name of the variable in the list |
---|
| 394 | VarIndex=name2index(VarNameW,Field.ListVarName);%index of the variable in ListVarName |
---|
| 395 | %check consistency of dimensions with u |
---|
| 396 | dimname_w=Field.VarDimName{VarIndex}; |
---|
| 397 | if ~isequal(dimname_w,dimname_u) |
---|
| 398 | errormsg='inconsistent dimensions for u and v'; |
---|
| 399 | return |
---|
| 400 | end |
---|
| 401 | nbvar=nbvar+1; |
---|
[34] | 402 | % w_index=nbvar; |
---|
[8] | 403 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 404 | VarDimName{nbvar}=dimname_u; |
---|
| 405 | if numel(VarAttribute)>=VarIndex |
---|
| 406 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 407 | end |
---|
| 408 | SubVarAttribute{nbvar}.Role='vector_z'; |
---|
| 409 | end |
---|
| 410 | |
---|
| 411 | % select color variable |
---|
| 412 | inputlist=get(handles.vec_color,'String'); |
---|
| 413 | val=get(handles.vec_color,'Value');% a single selection is expected for abscissa |
---|
| 414 | VarNameC=inputlist{val}; %name of the variable in the list |
---|
| 415 | VarIndex=name2index(VarNameC,Field.ListVarName);%index of the variable in ListVarName |
---|
| 416 | %check consistency of dimensions with u |
---|
| 417 | if ~isempty(VarIndex) |
---|
| 418 | if ~isequal(Field.VarDimName{VarIndex},dimname_u) |
---|
| 419 | errormsg='inconsistent dimensions for u and v'; |
---|
| 420 | return |
---|
| 421 | end |
---|
| 422 | nbvar=nbvar+1; |
---|
[34] | 423 | % c_index=nbvar; |
---|
[8] | 424 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 425 | VarDimName{nbvar}=Field.VarDimName{VarIndex}; |
---|
| 426 | if numel(VarAttribute)>=VarIndex |
---|
| 427 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 428 | end |
---|
| 429 | SubVarAttribute{nbvar}.Role='scalar'; |
---|
| 430 | end |
---|
| 431 | end |
---|
[32] | 432 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
[8] | 433 | |
---|
| 434 | % get the input field |
---|
| 435 | inputfield=get(handles.inputfile,'String'); |
---|
| 436 | if exist(inputfield,'file')% read the input data corresponding to the list of selected varaibles |
---|
| 437 | SubField=nc2struct(inputfield,ListVarName); |
---|
| 438 | else % subfield stored in memory |
---|
[32] | 439 | SubField.ListGlobalAttribute={}; |
---|
[8] | 440 | SubField.ListVarName=ListVarName; |
---|
| 441 | SubField.VarDimName=VarDimName; |
---|
| 442 | end |
---|
| 443 | SubField.ListGlobalAttribute=['InputFile' SubField.ListGlobalAttribute]; |
---|
| 444 | SubField.InputFile=get(handles.inputfile,'String'); |
---|
| 445 | SubField.VarAttribute=SubVarAttribute; |
---|
| 446 | |
---|
[32] | 447 | %permute indices if coord_y is not the first matrix index: scalar case |
---|
[8] | 448 | if test_scalar |
---|
[179] | 449 | VarNameA=Field.ListVarName{VarIndexA};%name of the scalar variable |
---|
| 450 | DimCellA=Field.VarDimName{VarIndexA}; %dimension names for the scalar variable |
---|
| 451 | eval(['npxy=size(SubField.' VarNameA ');'])%zize of the scalar variable |
---|
[8] | 452 | SingleCellA={}; |
---|
| 453 | if numel(npxy) < numel(DimCellA) |
---|
| 454 | SingleCellA=DimCellA(1:end-numel(npxy)); |
---|
| 455 | DimCellA=DimCellA(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 456 | end |
---|
[179] | 457 | %ind_single=find(npxy==1); |
---|
[8] | 458 | ind_select=find(npxy~=1);%look for non singleton dimensions |
---|
[179] | 459 | DimCellA=DimCellA(ind_select);%dimension names for the scalar variable, after removing singletons |
---|
[8] | 460 | npxy=npxy(ind_select); |
---|
| 461 | dimA=[]; |
---|
| 462 | if test_zdimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
[179] | 463 | ind_singleton=find(strcmp(dimname_z,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions |
---|
| 464 | if ~isempty(ind_singleton) |
---|
| 465 | errormsg=['the singleton dimension ' dimname_z ' has been selected for z']; |
---|
| 466 | return |
---|
[8] | 467 | end |
---|
[179] | 468 | icoord=find(strcmp(dimname_z,DimCellA),1);% a dimension variable |
---|
| 469 | dimA=[dimA icoord]; |
---|
| 470 | % for icoord=1:numel(DimCellA)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 471 | % if strcmp(dimname_z,DimCellA{icoord})% a dimension variable |
---|
| 472 | % dimA=[dimA icoord]; |
---|
| 473 | % break |
---|
| 474 | % end |
---|
| 475 | % end |
---|
[8] | 476 | end |
---|
| 477 | if test_ydimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
[179] | 478 | ind_singleton=find(strcmp(dimname_y,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions |
---|
| 479 | if ~isempty(ind_singleton) |
---|
| 480 | errormsg=['the singleton dimension ' dimname_y ' has been selected for ordinate']; |
---|
| 481 | return |
---|
[8] | 482 | end |
---|
[179] | 483 | icoord=find(strcmp(dimname_y,DimCellA),1);% a dimension variable |
---|
| 484 | dimA=[dimA icoord]; |
---|
[8] | 485 | end |
---|
[179] | 486 | if test_xdimvar |
---|
| 487 | ind_singleton=find(strcmp(dimname_x,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions |
---|
| 488 | if ~isempty(ind_singleton) |
---|
| 489 | errormsg=['the singleton dimension ' dimname_x ' has been selected for ordinate']; |
---|
| 490 | return |
---|
[8] | 491 | end |
---|
[179] | 492 | icoord=find(strcmp(dimname_x,DimCellA),1);% a dimension variable |
---|
| 493 | dimA=[dimA icoord]; |
---|
[8] | 494 | end |
---|
| 495 | dimextra=(1:numel(DimCellA)); |
---|
| 496 | dimextra(dimA)=[]; %list of unselected dimension indices |
---|
| 497 | DimCellA=DimCellA([dimA dimextra]); |
---|
[105] | 498 | eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra]);']) |
---|
[8] | 499 | SubField.VarDimName{VarSubIndexA}=DimCellA; |
---|
| 500 | %add default coord_x and/or coord_y if empty |
---|
| 501 | if empty_coord_x || empty_coord_y |
---|
| 502 | VarName=Field.ListVarName{field_var_index}; |
---|
| 503 | DimCell=Field.VarDimName{field_var_index}; |
---|
[105] | 504 | eval(['npxy=size(SubField.' VarName ');']) |
---|
[8] | 505 | if numel(npxy) < numel(DimCell) |
---|
| 506 | DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 507 | end |
---|
| 508 | ind_select=find(npxy~=1) ;%look for non singleton dimensions |
---|
| 509 | DimCell=DimCell(ind_select); |
---|
| 510 | npxy=npxy(ind_select); |
---|
| 511 | testold=0; |
---|
| 512 | %old convention; use of coord_1 and Coord_2 |
---|
| 513 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=field_var_index |
---|
| 514 | if isfield(Field.VarAttribute{field_var_index},'Coord_2')&& isfield(Field.VarAttribute{field_var_index},'Coord_1') |
---|
[56] | 515 | Coord_2=Field.VarAttribute{field_var_index}.Coord_2; |
---|
| 516 | Coord_1=Field.VarAttribute{field_var_index}.Coord_1; |
---|
[8] | 517 | testold=1; |
---|
| 518 | end |
---|
| 519 | end |
---|
| 520 | if empty_coord_x |
---|
| 521 | coord_x_name=DimCell{2}; |
---|
| 522 | SubField.ListVarName=[{coord_x_name} SubField.ListVarName]; |
---|
| 523 | SubField.VarDimName=[{coord_x_name} SubField.VarDimName]; |
---|
| 524 | if testold |
---|
| 525 | eval(['SubField.' coord_x_name '=linspace(Coord_2(1),Coord_2(end),npxy(2));']) |
---|
| 526 | else |
---|
| 527 | eval(['SubField.' coord_x_name '=[0.5 npxy(2)-0.5];']) |
---|
| 528 | end |
---|
| 529 | |
---|
| 530 | if ~testold |
---|
| 531 | coord_x_attr.units='index'; |
---|
| 532 | else |
---|
| 533 | coord_x_attr.units='cm'; |
---|
| 534 | end |
---|
| 535 | SubField.VarAttribute=[{coord_x_attr} SubField.VarAttribute]; |
---|
| 536 | end |
---|
| 537 | if empty_coord_y |
---|
| 538 | coord_y_name=DimCell{1}; |
---|
| 539 | SubField.ListVarName=[{coord_y_name} SubField.ListVarName]; |
---|
| 540 | SubField.VarDimName=[{coord_y_name} SubField.VarDimName]; |
---|
| 541 | if testold |
---|
| 542 | eval(['SubField.' coord_y_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));']) |
---|
| 543 | else |
---|
| 544 | eval(['SubField.' coord_y_name '=[npxy(1)-0.5 0.5];']) |
---|
| 545 | end |
---|
| 546 | if ~testold |
---|
| 547 | coord_y_attr.units='index'; |
---|
| 548 | else |
---|
| 549 | coord_y_attr.units='cm'; |
---|
| 550 | end |
---|
| 551 | SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute]; |
---|
| 552 | end |
---|
| 553 | end |
---|
| 554 | end |
---|
| 555 | |
---|
[32] | 556 | %permute indices if coord_y is not the first matrix index: vector case |
---|
[8] | 557 | if test_vector |
---|
[34] | 558 | VarNameU=Field.ListVarName{VarIndexU}; % name of u component variable |
---|
| 559 | DimCellU=Field.VarDimName{VarIndexU}; % list of dimensions for u component |
---|
[105] | 560 | eval(['npxy=size(SubField.' VarNameU ');']) % npxy= dimension values for the u component |
---|
[8] | 561 | SingleCellU={}; |
---|
| 562 | if numel(npxy) < numel(DimCellU) |
---|
| 563 | SingleCellU=DimCellU(1:end-numel(npxy)); |
---|
| 564 | DimCellU=DimCellU(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 565 | end |
---|
[34] | 566 | ind_single=find(npxy==1);%indices of singleton dimensions |
---|
| 567 | if ind_single<=numel(DimCellU) |
---|
| 568 | SingleCellU=[SingleCellU DimCellU(ind_single)]; |
---|
| 569 | end |
---|
[8] | 570 | ind_select=find(npxy~=1);%look for non singleton dimensions |
---|
[47] | 571 | if numel(DimCellU)>=ind_select |
---|
| 572 | DimCellU=DimCellU(ind_select); |
---|
| 573 | end |
---|
[8] | 574 | npxy=npxy(ind_select); |
---|
| 575 | dimU=[]; |
---|
| 576 | if test_zdimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
| 577 | for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 578 | if strcmp(dimname_vec_z,SingleCellU{icoord})% a singleton dimension |
---|
| 579 | errormsg=['the singleton dimension ' dimname_vec_z ' has been selected for z']; |
---|
| 580 | return |
---|
| 581 | end |
---|
| 582 | end |
---|
| 583 | for icoord=1:numel(DimCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 584 | if strcmp(dimname_vec_z,DimCellU{icoord})% a dimension variable |
---|
| 585 | dimU=[dimU icoord]; |
---|
| 586 | break |
---|
| 587 | end |
---|
| 588 | end |
---|
| 589 | end |
---|
[105] | 590 | if test_vec_y_dimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
[8] | 591 | for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 592 | if strcmp(dimname_vec_y,SingleCellU{icoord})% a singleton dimension |
---|
| 593 | errormsg=['the singleton dimension ' dimname_vec_y ' has been selected for ordinate']; |
---|
| 594 | return |
---|
| 595 | end |
---|
| 596 | end |
---|
| 597 | for icoord=1:numel(DimCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 598 | if strcmp(dimname_vec_y,DimCellU{icoord})% a dimension variable |
---|
| 599 | dimU=[dimU icoord]; |
---|
| 600 | break |
---|
| 601 | end |
---|
| 602 | end |
---|
| 603 | end |
---|
| 604 | if test_xdimvar |
---|
| 605 | for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 606 | if strcmp(dimname_x,SingleCellU{icoord})% a singleton dimension |
---|
| 607 | errormsg=['the singleton dimension ' dimname_vec_x ' has been selected for abscissa']; |
---|
| 608 | return |
---|
| 609 | end |
---|
| 610 | end |
---|
| 611 | for icoord=1:numel(DimCellA)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 612 | if strcmp(dimname_vec_x,DimCellU{icoord})% a dimension variable |
---|
| 613 | dimU=[dimU icoord]; |
---|
| 614 | break |
---|
| 615 | end |
---|
| 616 | end |
---|
| 617 | end |
---|
[34] | 618 | if numel(DimCellU)>1 |
---|
| 619 | dimextra=(1:numel(DimCellU)); |
---|
| 620 | dimextra(dimU)=[]; %list of unselected dimension indices |
---|
| 621 | DimCellU=DimCellU([dimU dimextra]); |
---|
| 622 | eval(['SubField.' VarNameU '=permute(squeeze(SubField.' VarNameU '),[dimU dimextra]);']) |
---|
| 623 | eval(['SubField.' VarNameV '=permute(squeeze(SubField.' VarNameV '),[dimU dimextra]);']) |
---|
| 624 | SubField.VarDimName{VarSubIndexU}=DimCellU; |
---|
| 625 | SubField.VarDimName{VarSubIndexV}=DimCellU; |
---|
| 626 | end |
---|
[8] | 627 | %add default coord_x and/or coord_y if empty |
---|
| 628 | if empty_coord_vec_x || empty_coord_vec_y |
---|
| 629 | VarName=Field.ListVarName{field_var_index}; |
---|
| 630 | DimCell=Field.VarDimName{field_var_index}; |
---|
[105] | 631 | eval(['npxy=size(SubField.' VarName ');']) |
---|
[8] | 632 | if numel(npxy) < numel(DimCell) |
---|
| 633 | DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 634 | end |
---|
| 635 | ind_select=find(npxy~=1) ;%look for non singleton dimensions |
---|
| 636 | DimCell=DimCell(ind_select); |
---|
| 637 | npxy=npxy(ind_select); |
---|
| 638 | testold=0; |
---|
| 639 | %old convention; use of coord_1 and Coord_2 |
---|
| 640 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=field_var_index |
---|
| 641 | if isfield(Field.VarAttribute{field_var_index},'Coord_2')&& isfield(Field.VarAttribute{field_var_index},'Coord_1') |
---|
[56] | 642 | Coord_2=Field.VarAttribute{field_var_index}.Coord_2; |
---|
| 643 | Coord_1=Field.VarAttribute{field_var_index}.Coord_1; |
---|
[8] | 644 | testold=1; |
---|
| 645 | end |
---|
| 646 | end |
---|
[89] | 647 | if empty_coord_vec_x |
---|
| 648 | if numel(DimCell)<2 |
---|
| 649 | errormsg='undefined x coordinate'; |
---|
| 650 | return |
---|
| 651 | end |
---|
| 652 | coord_x_name=DimCell{2}; |
---|
| 653 | SubField.ListVarName=[{coord_x_name} SubField.ListVarName]; |
---|
| 654 | SubField.VarDimName=[{coord_x_name} SubField.VarDimName]; |
---|
| 655 | if testold |
---|
| 656 | eval(['SubField.' coord_x_name '=linspace(Coord_2(1),Coord_2(end),npxy(2));']) |
---|
| 657 | else |
---|
| 658 | eval(['SubField.' coord_x_name '=[0.5 npxy(2)-0.5];']) |
---|
| 659 | end |
---|
[8] | 660 | |
---|
| 661 | if ~testold |
---|
| 662 | coord_x_attr.units='index'; |
---|
| 663 | else |
---|
| 664 | coord_x_attr.units='cm'; |
---|
| 665 | end |
---|
| 666 | SubField.VarAttribute=[{coord_x_attr} SubField.VarAttribute]; |
---|
| 667 | end |
---|
| 668 | if empty_coord_vec_y |
---|
| 669 | coord_y_name=DimCell{1}; |
---|
| 670 | SubField.ListVarName=[{coord_y_name} SubField.ListVarName]; |
---|
| 671 | SubField.VarDimName=[{coord_y_name} SubField.VarDimName]; |
---|
| 672 | if testold |
---|
| 673 | eval(['SubField.' coord_y_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));']) |
---|
| 674 | else |
---|
| 675 | eval(['SubField.' coord_y_name '=[npxy(1)-0.5 0.5];']) |
---|
| 676 | end |
---|
| 677 | if ~testold |
---|
| 678 | coord_y_attr.units='index'; |
---|
| 679 | else |
---|
| 680 | coord_y_attr.units='cm'; |
---|
| 681 | end |
---|
| 682 | SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute]; |
---|
| 683 | end |
---|
| 684 | end |
---|
| 685 | end |
---|
| 686 | if test_1Dplot |
---|
| 687 | for ilist=1:numel(VarIndex_y) |
---|
| 688 | VarName=Field.ListVarName{VarIndex_y(ilist)}; |
---|
| 689 | eval(['npxy=size(SubField.' VarName ');']) |
---|
| 690 | ind_select=find(npxy~=1); |
---|
| 691 | SubField.VarDimName{subvarindex(ilist)}=SubField.VarDimName{subvarindex(ilist)}(ind_select); |
---|
| 692 | eval(['SubField.' VarName '=squeeze(SubField.' VarName ');'])%remove singleton dimensions |
---|
| 693 | if testpermute(ilist) |
---|
| 694 | eval(['SubField.' VarName '=permute(SubField.' VarName ',[2 1]);']) |
---|
| 695 | SubField.VarDimName{subvarindex(ilist)}=SubField.VarDimName{subvarindex(ilist)}([2 1]); |
---|
| 696 | end |
---|
| 697 | end |
---|
| 698 | if empty_coord_x |
---|
| 699 | SubField.ListVarName=[{[coord_x_name '_index']} SubField.ListVarName]; |
---|
| 700 | SubField.VarDimName=[{coord_x_name } SubField.VarDimName]; |
---|
| 701 | VarName=Field.ListVarName{VarIndex_y(1)}; |
---|
| 702 | DimCell=Field.VarDimName{VarIndex_y(1)}; |
---|
[105] | 703 | eval(['npxy=size(SubField.' VarName ');']) |
---|
[8] | 704 | if numel(npxy) < numel(DimCell) |
---|
[34] | 705 | % DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
[8] | 706 | end |
---|
| 707 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=VarIndex_y(1) ... |
---|
| 708 | && isfield(Field.VarAttribute{VarIndex_y(1)},'Coord_1') |
---|
[34] | 709 | % Coord_1=Field.VarAttribute{VarIndex_y(1)}.Coord_1;%old convention; use of coord_1 |
---|
[8] | 710 | eval(['SubField.' coord_x_name '_index=linspace(Coord_1(1),Coord_1(end),npxy(1));']) |
---|
| 711 | else |
---|
| 712 | eval(['SubField.' coord_x_name '_index=linspace(0.5,npxy(1)-0.5,npxy(1));']) |
---|
| 713 | end |
---|
| 714 | struct.Role='coord_x'; |
---|
| 715 | SubField.VarAttribute=[{struct} SubField.VarAttribute]; |
---|
| 716 | end |
---|
| 717 | end |
---|
| 718 | |
---|
| 719 | %------------------------------------------------- |
---|
| 720 | % give index numbers of the strings str in the list ListvarName |
---|
| 721 | function VarIndex_y=name2index(cell_str,ListVarName) |
---|
| 722 | VarIndex_y=[]; |
---|
| 723 | if ischar(cell_str) |
---|
| 724 | for ivar=1:length(ListVarName) |
---|
| 725 | varlist=ListVarName{ivar}; |
---|
| 726 | if isequal(varlist,cell_str) |
---|
| 727 | VarIndex_y= ivar; |
---|
| 728 | break |
---|
| 729 | end |
---|
| 730 | end |
---|
| 731 | elseif iscell(cell_str) |
---|
| 732 | for isel=1:length(cell_str) |
---|
| 733 | varsel=cell_str{isel}; |
---|
| 734 | for ivar=1:length(ListVarName) |
---|
| 735 | varlist=ListVarName{ivar}; |
---|
| 736 | if isequal(varlist,varsel) |
---|
| 737 | VarIndex_y=[VarIndex_y ivar]; |
---|
| 738 | end |
---|
| 739 | end |
---|
| 740 | end |
---|
| 741 | end |
---|