[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) |
---|
[206] | 390 | %scalar w variable |
---|
[8] | 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 |
---|
[206] | 394 | VarIndex=name2index(VarNameW,Field.ListVarName);%index of the variable in ListVarName |
---|
| 395 | %check consistency of dimensions with u |
---|
| 396 | if ~isempty( VarIndex) |
---|
| 397 | dimname_w=Field.VarDimName{VarIndex}; |
---|
| 398 | if ~isequal(dimname_w,dimname_u) |
---|
| 399 | errormsg='inconsistent dimensions for u and w'; |
---|
| 400 | return |
---|
| 401 | end |
---|
| 402 | nbvar=nbvar+1; |
---|
| 403 | % w_index=nbvar; |
---|
| 404 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 405 | VarDimName{nbvar}=dimname_u; |
---|
| 406 | if numel(VarAttribute)>=VarIndex |
---|
| 407 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 408 | end |
---|
| 409 | SubVarAttribute{nbvar}.Role='vector_z'; |
---|
[8] | 410 | end |
---|
| 411 | end |
---|
| 412 | |
---|
| 413 | % select color variable |
---|
| 414 | inputlist=get(handles.vec_color,'String'); |
---|
| 415 | val=get(handles.vec_color,'Value');% a single selection is expected for abscissa |
---|
| 416 | VarNameC=inputlist{val}; %name of the variable in the list |
---|
| 417 | VarIndex=name2index(VarNameC,Field.ListVarName);%index of the variable in ListVarName |
---|
| 418 | %check consistency of dimensions with u |
---|
| 419 | if ~isempty(VarIndex) |
---|
| 420 | if ~isequal(Field.VarDimName{VarIndex},dimname_u) |
---|
| 421 | errormsg='inconsistent dimensions for u and v'; |
---|
| 422 | return |
---|
| 423 | end |
---|
| 424 | nbvar=nbvar+1; |
---|
[34] | 425 | % c_index=nbvar; |
---|
[8] | 426 | ListVarName{nbvar}=Field.ListVarName{VarIndex}; |
---|
| 427 | VarDimName{nbvar}=Field.VarDimName{VarIndex}; |
---|
| 428 | if numel(VarAttribute)>=VarIndex |
---|
| 429 | SubVarAttribute{nbvar}=VarAttribute{VarIndex}; |
---|
| 430 | end |
---|
| 431 | SubVarAttribute{nbvar}.Role='scalar'; |
---|
| 432 | end |
---|
| 433 | end |
---|
[32] | 434 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
[8] | 435 | |
---|
| 436 | % get the input field |
---|
| 437 | inputfield=get(handles.inputfile,'String'); |
---|
| 438 | if exist(inputfield,'file')% read the input data corresponding to the list of selected varaibles |
---|
| 439 | SubField=nc2struct(inputfield,ListVarName); |
---|
| 440 | else % subfield stored in memory |
---|
[32] | 441 | SubField.ListGlobalAttribute={}; |
---|
[8] | 442 | SubField.ListVarName=ListVarName; |
---|
| 443 | SubField.VarDimName=VarDimName; |
---|
| 444 | end |
---|
| 445 | SubField.ListGlobalAttribute=['InputFile' SubField.ListGlobalAttribute]; |
---|
| 446 | SubField.InputFile=get(handles.inputfile,'String'); |
---|
| 447 | SubField.VarAttribute=SubVarAttribute; |
---|
| 448 | |
---|
[32] | 449 | %permute indices if coord_y is not the first matrix index: scalar case |
---|
[206] | 450 | NbDim=2; %default |
---|
[8] | 451 | if test_scalar |
---|
[179] | 452 | VarNameA=Field.ListVarName{VarIndexA};%name of the scalar variable |
---|
| 453 | DimCellA=Field.VarDimName{VarIndexA}; %dimension names for the scalar variable |
---|
| 454 | eval(['npxy=size(SubField.' VarNameA ');'])%zize of the scalar variable |
---|
[8] | 455 | SingleCellA={}; |
---|
| 456 | if numel(npxy) < numel(DimCellA) |
---|
| 457 | SingleCellA=DimCellA(1:end-numel(npxy)); |
---|
| 458 | DimCellA=DimCellA(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 459 | end |
---|
| 460 | ind_select=find(npxy~=1);%look for non singleton dimensions |
---|
[179] | 461 | DimCellA=DimCellA(ind_select);%dimension names for the scalar variable, after removing singletons |
---|
[8] | 462 | npxy=npxy(ind_select); |
---|
| 463 | dimA=[]; |
---|
| 464 | if test_zdimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
[206] | 465 | NbDim=3;% field considered as 3D if a z coordinate is defined (to distinguish for instance from 2D color images with 3 components) |
---|
[179] | 466 | ind_singleton=find(strcmp(dimname_z,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions |
---|
| 467 | if ~isempty(ind_singleton) |
---|
| 468 | errormsg=['the singleton dimension ' dimname_z ' has been selected for z']; |
---|
| 469 | return |
---|
[8] | 470 | end |
---|
[179] | 471 | icoord=find(strcmp(dimname_z,DimCellA),1);% a dimension variable |
---|
| 472 | dimA=[dimA icoord]; |
---|
[8] | 473 | end |
---|
| 474 | if test_ydimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
[179] | 475 | ind_singleton=find(strcmp(dimname_y,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions |
---|
| 476 | if ~isempty(ind_singleton) |
---|
| 477 | errormsg=['the singleton dimension ' dimname_y ' has been selected for ordinate']; |
---|
| 478 | return |
---|
[8] | 479 | end |
---|
[179] | 480 | icoord=find(strcmp(dimname_y,DimCellA),1);% a dimension variable |
---|
| 481 | dimA=[dimA icoord]; |
---|
[8] | 482 | end |
---|
[179] | 483 | if test_xdimvar |
---|
| 484 | ind_singleton=find(strcmp(dimname_x,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions |
---|
| 485 | if ~isempty(ind_singleton) |
---|
| 486 | errormsg=['the singleton dimension ' dimname_x ' has been selected for ordinate']; |
---|
| 487 | return |
---|
[8] | 488 | end |
---|
[179] | 489 | icoord=find(strcmp(dimname_x,DimCellA),1);% a dimension variable |
---|
| 490 | dimA=[dimA icoord]; |
---|
[8] | 491 | end |
---|
| 492 | dimextra=(1:numel(DimCellA)); |
---|
| 493 | dimextra(dimA)=[]; %list of unselected dimension indices |
---|
| 494 | DimCellA=DimCellA([dimA dimextra]); |
---|
[105] | 495 | eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra]);']) |
---|
[8] | 496 | SubField.VarDimName{VarSubIndexA}=DimCellA; |
---|
| 497 | %add default coord_x and/or coord_y if empty |
---|
| 498 | if empty_coord_x || empty_coord_y |
---|
| 499 | VarName=Field.ListVarName{field_var_index}; |
---|
| 500 | DimCell=Field.VarDimName{field_var_index}; |
---|
[105] | 501 | eval(['npxy=size(SubField.' VarName ');']) |
---|
[8] | 502 | if numel(npxy) < numel(DimCell) |
---|
| 503 | DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 504 | end |
---|
| 505 | ind_select=find(npxy~=1) ;%look for non singleton dimensions |
---|
[206] | 506 | DimCell=DimCell(ind_select);%list of dimension names for the scalar, after singleton removal |
---|
[8] | 507 | npxy=npxy(ind_select); |
---|
| 508 | testold=0; |
---|
| 509 | %old convention; use of coord_1 and Coord_2 |
---|
| 510 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=field_var_index |
---|
| 511 | if isfield(Field.VarAttribute{field_var_index},'Coord_2')&& isfield(Field.VarAttribute{field_var_index},'Coord_1') |
---|
[56] | 512 | Coord_2=Field.VarAttribute{field_var_index}.Coord_2; |
---|
| 513 | Coord_1=Field.VarAttribute{field_var_index}.Coord_1; |
---|
[8] | 514 | testold=1; |
---|
| 515 | end |
---|
| 516 | end |
---|
| 517 | if empty_coord_x |
---|
[206] | 518 | coord_x_name=DimCell{NbDim}; |
---|
[8] | 519 | SubField.ListVarName=[{coord_x_name} SubField.ListVarName]; |
---|
| 520 | SubField.VarDimName=[{coord_x_name} SubField.VarDimName]; |
---|
| 521 | if testold |
---|
| 522 | eval(['SubField.' coord_x_name '=linspace(Coord_2(1),Coord_2(end),npxy(2));']) |
---|
| 523 | else |
---|
[206] | 524 | eval(['SubField.' coord_x_name '=[0.5 npxy(NbDim)-0.5];']) |
---|
[8] | 525 | end |
---|
| 526 | |
---|
| 527 | if ~testold |
---|
| 528 | coord_x_attr.units='index'; |
---|
| 529 | else |
---|
| 530 | coord_x_attr.units='cm'; |
---|
| 531 | end |
---|
| 532 | SubField.VarAttribute=[{coord_x_attr} SubField.VarAttribute]; |
---|
| 533 | end |
---|
| 534 | if empty_coord_y |
---|
[206] | 535 | coord_y_name=DimCell{NbDim-1}; |
---|
[8] | 536 | SubField.ListVarName=[{coord_y_name} SubField.ListVarName]; |
---|
| 537 | SubField.VarDimName=[{coord_y_name} SubField.VarDimName]; |
---|
| 538 | if testold |
---|
| 539 | eval(['SubField.' coord_y_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));']) |
---|
| 540 | else |
---|
[206] | 541 | eval(['SubField.' coord_y_name '=[npxy(NbDim-1)-0.5 0.5];']) |
---|
[8] | 542 | end |
---|
| 543 | if ~testold |
---|
| 544 | coord_y_attr.units='index'; |
---|
| 545 | else |
---|
| 546 | coord_y_attr.units='cm'; |
---|
| 547 | end |
---|
| 548 | SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute]; |
---|
| 549 | end |
---|
| 550 | end |
---|
| 551 | end |
---|
| 552 | |
---|
[32] | 553 | %permute indices if coord_y is not the first matrix index: vector case |
---|
[8] | 554 | if test_vector |
---|
[34] | 555 | VarNameU=Field.ListVarName{VarIndexU}; % name of u component variable |
---|
| 556 | DimCellU=Field.VarDimName{VarIndexU}; % list of dimensions for u component |
---|
[105] | 557 | eval(['npxy=size(SubField.' VarNameU ');']) % npxy= dimension values for the u component |
---|
[8] | 558 | SingleCellU={}; |
---|
| 559 | if numel(npxy) < numel(DimCellU) |
---|
| 560 | SingleCellU=DimCellU(1:end-numel(npxy)); |
---|
| 561 | DimCellU=DimCellU(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 562 | end |
---|
[34] | 563 | ind_single=find(npxy==1);%indices of singleton dimensions |
---|
| 564 | if ind_single<=numel(DimCellU) |
---|
| 565 | SingleCellU=[SingleCellU DimCellU(ind_single)]; |
---|
| 566 | end |
---|
[8] | 567 | ind_select=find(npxy~=1);%look for non singleton dimensions |
---|
[47] | 568 | if numel(DimCellU)>=ind_select |
---|
| 569 | DimCellU=DimCellU(ind_select); |
---|
| 570 | end |
---|
[8] | 571 | npxy=npxy(ind_select); |
---|
| 572 | dimU=[]; |
---|
| 573 | if test_zdimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
| 574 | for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 575 | if strcmp(dimname_vec_z,SingleCellU{icoord})% a singleton dimension |
---|
| 576 | errormsg=['the singleton dimension ' dimname_vec_z ' has been selected for z']; |
---|
| 577 | return |
---|
| 578 | end |
---|
| 579 | end |
---|
| 580 | for icoord=1:numel(DimCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 581 | if strcmp(dimname_vec_z,DimCellU{icoord})% a dimension variable |
---|
| 582 | dimU=[dimU icoord]; |
---|
| 583 | break |
---|
| 584 | end |
---|
| 585 | end |
---|
| 586 | end |
---|
[105] | 587 | if test_vec_y_dimvar%dim_x && dim_y && ~isempty(VarSubIndexA) |
---|
[8] | 588 | for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 589 | if strcmp(dimname_vec_y,SingleCellU{icoord})% a singleton dimension |
---|
| 590 | errormsg=['the singleton dimension ' dimname_vec_y ' has been selected for ordinate']; |
---|
| 591 | return |
---|
| 592 | end |
---|
| 593 | end |
---|
| 594 | for icoord=1:numel(DimCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 595 | if strcmp(dimname_vec_y,DimCellU{icoord})% a dimension variable |
---|
| 596 | dimU=[dimU icoord]; |
---|
| 597 | break |
---|
| 598 | end |
---|
| 599 | end |
---|
| 600 | end |
---|
| 601 | if test_xdimvar |
---|
| 602 | for icoord=1:numel(SingleCellU)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 603 | if strcmp(dimname_x,SingleCellU{icoord})% a singleton dimension |
---|
| 604 | errormsg=['the singleton dimension ' dimname_vec_x ' has been selected for abscissa']; |
---|
| 605 | return |
---|
| 606 | end |
---|
| 607 | end |
---|
| 608 | for icoord=1:numel(DimCellA)% look for coincidence of dimension with one of the dimensions of the scalar |
---|
| 609 | if strcmp(dimname_vec_x,DimCellU{icoord})% a dimension variable |
---|
| 610 | dimU=[dimU icoord]; |
---|
| 611 | break |
---|
| 612 | end |
---|
| 613 | end |
---|
| 614 | end |
---|
[34] | 615 | if numel(DimCellU)>1 |
---|
| 616 | dimextra=(1:numel(DimCellU)); |
---|
| 617 | dimextra(dimU)=[]; %list of unselected dimension indices |
---|
| 618 | DimCellU=DimCellU([dimU dimextra]); |
---|
| 619 | eval(['SubField.' VarNameU '=permute(squeeze(SubField.' VarNameU '),[dimU dimextra]);']) |
---|
| 620 | eval(['SubField.' VarNameV '=permute(squeeze(SubField.' VarNameV '),[dimU dimextra]);']) |
---|
| 621 | SubField.VarDimName{VarSubIndexU}=DimCellU; |
---|
| 622 | SubField.VarDimName{VarSubIndexV}=DimCellU; |
---|
| 623 | end |
---|
[8] | 624 | %add default coord_x and/or coord_y if empty |
---|
| 625 | if empty_coord_vec_x || empty_coord_vec_y |
---|
| 626 | VarName=Field.ListVarName{field_var_index}; |
---|
| 627 | DimCell=Field.VarDimName{field_var_index}; |
---|
[105] | 628 | eval(['npxy=size(SubField.' VarName ');']) |
---|
[8] | 629 | if numel(npxy) < numel(DimCell) |
---|
| 630 | DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
| 631 | end |
---|
| 632 | ind_select=find(npxy~=1) ;%look for non singleton dimensions |
---|
| 633 | DimCell=DimCell(ind_select); |
---|
| 634 | npxy=npxy(ind_select); |
---|
| 635 | testold=0; |
---|
| 636 | %old convention; use of coord_1 and Coord_2 |
---|
| 637 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=field_var_index |
---|
| 638 | if isfield(Field.VarAttribute{field_var_index},'Coord_2')&& isfield(Field.VarAttribute{field_var_index},'Coord_1') |
---|
[56] | 639 | Coord_2=Field.VarAttribute{field_var_index}.Coord_2; |
---|
| 640 | Coord_1=Field.VarAttribute{field_var_index}.Coord_1; |
---|
[8] | 641 | testold=1; |
---|
| 642 | end |
---|
| 643 | end |
---|
[89] | 644 | if empty_coord_vec_x |
---|
| 645 | if numel(DimCell)<2 |
---|
| 646 | errormsg='undefined x coordinate'; |
---|
| 647 | return |
---|
| 648 | end |
---|
| 649 | coord_x_name=DimCell{2}; |
---|
| 650 | SubField.ListVarName=[{coord_x_name} SubField.ListVarName]; |
---|
| 651 | SubField.VarDimName=[{coord_x_name} SubField.VarDimName]; |
---|
| 652 | if testold |
---|
| 653 | eval(['SubField.' coord_x_name '=linspace(Coord_2(1),Coord_2(end),npxy(2));']) |
---|
| 654 | else |
---|
| 655 | eval(['SubField.' coord_x_name '=[0.5 npxy(2)-0.5];']) |
---|
| 656 | end |
---|
[8] | 657 | |
---|
| 658 | if ~testold |
---|
| 659 | coord_x_attr.units='index'; |
---|
| 660 | else |
---|
| 661 | coord_x_attr.units='cm'; |
---|
| 662 | end |
---|
| 663 | SubField.VarAttribute=[{coord_x_attr} SubField.VarAttribute]; |
---|
| 664 | end |
---|
| 665 | if empty_coord_vec_y |
---|
| 666 | coord_y_name=DimCell{1}; |
---|
| 667 | SubField.ListVarName=[{coord_y_name} SubField.ListVarName]; |
---|
| 668 | SubField.VarDimName=[{coord_y_name} SubField.VarDimName]; |
---|
| 669 | if testold |
---|
| 670 | eval(['SubField.' coord_y_name '=linspace(Coord_1(1),Coord_1(end),npxy(1));']) |
---|
| 671 | else |
---|
| 672 | eval(['SubField.' coord_y_name '=[npxy(1)-0.5 0.5];']) |
---|
| 673 | end |
---|
| 674 | if ~testold |
---|
| 675 | coord_y_attr.units='index'; |
---|
| 676 | else |
---|
| 677 | coord_y_attr.units='cm'; |
---|
| 678 | end |
---|
| 679 | SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute]; |
---|
| 680 | end |
---|
| 681 | end |
---|
| 682 | end |
---|
| 683 | if test_1Dplot |
---|
| 684 | for ilist=1:numel(VarIndex_y) |
---|
| 685 | VarName=Field.ListVarName{VarIndex_y(ilist)}; |
---|
| 686 | eval(['npxy=size(SubField.' VarName ');']) |
---|
| 687 | ind_select=find(npxy~=1); |
---|
| 688 | SubField.VarDimName{subvarindex(ilist)}=SubField.VarDimName{subvarindex(ilist)}(ind_select); |
---|
| 689 | eval(['SubField.' VarName '=squeeze(SubField.' VarName ');'])%remove singleton dimensions |
---|
| 690 | if testpermute(ilist) |
---|
| 691 | eval(['SubField.' VarName '=permute(SubField.' VarName ',[2 1]);']) |
---|
| 692 | SubField.VarDimName{subvarindex(ilist)}=SubField.VarDimName{subvarindex(ilist)}([2 1]); |
---|
| 693 | end |
---|
| 694 | end |
---|
| 695 | if empty_coord_x |
---|
| 696 | SubField.ListVarName=[{[coord_x_name '_index']} SubField.ListVarName]; |
---|
| 697 | SubField.VarDimName=[{coord_x_name } SubField.VarDimName]; |
---|
| 698 | VarName=Field.ListVarName{VarIndex_y(1)}; |
---|
| 699 | DimCell=Field.VarDimName{VarIndex_y(1)}; |
---|
[105] | 700 | eval(['npxy=size(SubField.' VarName ');']) |
---|
[8] | 701 | if numel(npxy) < numel(DimCell) |
---|
[34] | 702 | % DimCell=DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions |
---|
[8] | 703 | end |
---|
| 704 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=VarIndex_y(1) ... |
---|
| 705 | && isfield(Field.VarAttribute{VarIndex_y(1)},'Coord_1') |
---|
[34] | 706 | % Coord_1=Field.VarAttribute{VarIndex_y(1)}.Coord_1;%old convention; use of coord_1 |
---|
[8] | 707 | eval(['SubField.' coord_x_name '_index=linspace(Coord_1(1),Coord_1(end),npxy(1));']) |
---|
| 708 | else |
---|
| 709 | eval(['SubField.' coord_x_name '_index=linspace(0.5,npxy(1)-0.5,npxy(1));']) |
---|
| 710 | end |
---|
| 711 | struct.Role='coord_x'; |
---|
| 712 | SubField.VarAttribute=[{struct} SubField.VarAttribute]; |
---|
| 713 | end |
---|
| 714 | end |
---|
| 715 | |
---|
| 716 | %------------------------------------------------- |
---|
| 717 | % give index numbers of the strings str in the list ListvarName |
---|
| 718 | function VarIndex_y=name2index(cell_str,ListVarName) |
---|
| 719 | VarIndex_y=[]; |
---|
| 720 | if ischar(cell_str) |
---|
| 721 | for ivar=1:length(ListVarName) |
---|
| 722 | varlist=ListVarName{ivar}; |
---|
| 723 | if isequal(varlist,cell_str) |
---|
| 724 | VarIndex_y= ivar; |
---|
| 725 | break |
---|
| 726 | end |
---|
| 727 | end |
---|
| 728 | elseif iscell(cell_str) |
---|
| 729 | for isel=1:length(cell_str) |
---|
| 730 | varsel=cell_str{isel}; |
---|
| 731 | for ivar=1:length(ListVarName) |
---|
| 732 | varlist=ListVarName{ivar}; |
---|
| 733 | if isequal(varlist,varsel) |
---|
| 734 | VarIndex_y=[VarIndex_y ivar]; |
---|
| 735 | end |
---|
| 736 | end |
---|
| 737 | end |
---|
| 738 | end |
---|