Changeset 227 for trunk/src/read_get_field.m
- Timestamp:
- Mar 31, 2011, 1:42:51 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/read_get_field.m
r206 r227 124 124 return 125 125 end 126 val=get(handles.scalar,'Value');%selected ind ices in the ordinate listbox127 VarNameScalar=inputlist{val}; %name of the variable in the list126 val=get(handles.scalar,'Value');%selected index for the scalar variable 127 VarNameScalar=inputlist{val}; %name of the variable 128 128 VarIndexA=name2index(VarNameScalar,Field.ListVarName);%index of the variable in ListVarName 129 dimname_A=Field.VarDimName{VarIndexA}; 129 dimname_A=Field.VarDimName{VarIndexA};% list of dimension names for the scalar variable (cell array) 130 %remove time dimension if defined 131 TimeVarIndex=[]; %default 132 if strcmp(get(handles.TimeDimensionMenu,'Visible'),'on') 133 dim_list=get(handles.TimeDimensionMenu,'String'); 134 dim_index=get(handles.TimeDimensionMenu,'Value'); 135 Time_dim=dim_list{dim_index}; 136 TimeVarIndex=find(strcmp(Time_dim,dimname_A),1); 137 if ~isempty(TimeVarIndex) 138 dimname_A(TimeVarIndex)=[]; 139 end 140 end 130 141 nbvar=nbvar+1; 131 142 ListVarName{nbvar}=Field.ListVarName{VarIndexA}; … … 157 168 if iscell(dimname_x) 158 169 if numel(dimname_x)==1 159 dimname_x=dimname_x{1};%transform to char chain 170 %dimname_x=dimname_x{1};%transform to char chain 171 elseif numel(dimname_x)==2 172 index1_x = find(strcmp(dimname_x{1},dimname_A));%index of diname_x(1) in dimname_A 173 index2_x = find(strcmp(dimname_x{2},dimname_A));%index of diname_x(2) in dimname_A 160 174 else 161 175 errormsg='invalid x coordinate selection in get_field'; … … 190 204 if numel(dimname_y)==1 191 205 dimname_y=dimname_y{1};%transform to char chain 206 elseif numel(dimname_y)==2 207 index1_y = find(strcmp(dimname_y{1},dimname_A));%index of diname_x(1) in dimname_A 208 index2_y = find(strcmp(dimname_y{2},dimname_A));%index of diname_x(2) in dimname_A 192 209 else 193 210 errormsg='invalid y coordinate selection in get_field'; … … 214 231 nbvar=nbvar+1; 215 232 ListVarName{nbvar}=Field.ListVarName{VarIndex}; 216 VarDimName{nbvar}=dimname_ y;233 VarDimName{nbvar}=dimname_z; 217 234 if numel(VarAttribute)>=VarIndex 218 235 SubVarAttribute{nbvar}=VarAttribute{VarIndex}; 219 236 end 220 237 %check consistency of dimensions 221 if ~isequal(dimname_ y,dimname_A)% case of dimension variables222 if iscell(dimname_ y)223 if numel(dimname_ y)==1224 dimname_ y=dimname_y{1};%transform to char chain238 if ~isequal(dimname_z,dimname_A)% case of dimension variables 239 if iscell(dimname_z) 240 if numel(dimname_z)==1 241 dimname_z=dimname_z{1};%transform to char chain 225 242 else 226 errormsg='invalid ycoordinate selection in get_field';243 errormsg='invalid z coordinate selection in get_field'; 227 244 return 228 245 end … … 432 449 end 433 450 end 451 452 453 434 454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 435 436 % get the input field 455 %% get the input field 437 456 inputfield=get(handles.inputfile,'String'); 438 457 if exist(inputfield,'file')% read the input data corresponding to the list of selected varaibles … … 443 462 SubField.VarDimName=VarDimName; 444 463 end 445 SubField.ListGlobalAttribute=['InputFile' SubField.ListGlobalAttribute]; 464 if strcmp(get(handles.TimeIndexValue,'Visible'),'on') && ~isempty(get(handles.TimeIndexValue,'String')) 465 SubField.ListGlobalAttribute=[{'TimeIndex'} SubField.ListGlobalAttribute]; 466 SubField.TimeIndex=str2double(get(handles.TimeIndexValue,'String')); 467 end 468 TimeValue=NaN; 469 if strcmp(get(handles.TimeVarValue,'Visible'),'on') 470 TimeValue=str2double(get(handles.TimeVarValue,'String')); 471 elseif strcmp(get(handles.TimeValue,'Visible'),'on') 472 TimeValue=str2double(get(handles.TimeValue,'String')); 473 end 474 if ~isnan(TimeValue) 475 SubField.ListGlobalAttribute=[{'TimeValue'} SubField.ListGlobalAttribute]; 476 SubField.TimeValue=str2double(get(handles.TimeVarValue,'String')); 477 end 478 SubField.ListGlobalAttribute=[{'InputFile'} SubField.ListGlobalAttribute]; 446 479 SubField.InputFile=get(handles.inputfile,'String'); 447 480 SubField.VarAttribute=SubVarAttribute; … … 453 486 DimCellA=Field.VarDimName{VarIndexA}; %dimension names for the scalar variable 454 487 eval(['npxy=size(SubField.' VarNameA ');'])%zize of the scalar variable 488 % if ~isempty(TimeVarIndex)% 489 % DimCellA(TimeVarIndex)=[];%suppress the time dimension 490 % npxy(TimeVarIndex)=[]; 491 % end 455 492 SingleCellA={}; 456 493 if numel(npxy) < numel(DimCellA) … … 461 498 DimCellA=DimCellA(ind_select);%dimension names for the scalar variable, after removing singletons 462 499 npxy=npxy(ind_select); 500 % if ~isempty(TimeVarIndex)% 501 % DimCellA(TimeVarIndex)=[];%suppress the time dimension 502 % npxy(TimeVarIndex)=[]; 503 % end 504 NbDim=numel(npxy); 463 505 dimA=[]; 464 if test_zdimvar %dim_x && dim_y && ~isempty(VarSubIndexA)506 if test_zdimvar 465 507 NbDim=3;% field considered as 3D if a z coordinate is defined (to distinguish for instance from 2D color images with 3 components) 466 508 ind_singleton=find(strcmp(dimname_z,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions … … 472 514 dimA=[dimA icoord]; 473 515 end 474 if test_ydimvar %dim_x && dim_y && ~isempty(VarSubIndexA)516 if test_ydimvar 475 517 ind_singleton=find(strcmp(dimname_y,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions 476 518 if ~isempty(ind_singleton) … … 481 523 dimA=[dimA icoord]; 482 524 end 483 if test_xdimvar 484 ind_singleton=find(strcmp(dimname_x ,SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions485 if ~isempty(ind_singleton) 525 if test_xdimvar% a varible has been selected for x coordinate 526 ind_singleton=find(strcmp(dimname_x{1},SingleCellA),1);% look for coincidence of dimension with one of the singleton dimensions 527 if ~isempty(ind_singleton) 486 528 errormsg=['the singleton dimension ' dimname_x ' has been selected for ordinate']; 487 529 return 488 530 end 489 icoord=find(strcmp(dimname_x ,DimCellA),1);% a dimension variable531 icoord=find(strcmp(dimname_x{1},DimCellA),1);% a dimension variable 490 532 dimA=[dimA icoord]; 491 533 end 492 dimextra=(1:numel(DimCellA)); 493 dimextra(dimA)=[]; %list of unselected dimension indices 534 dimextra=(1:numel(DimCellA)); %list of initial dimension indices 535 if isempty(TimeVarIndex)% 536 dimextra(dimA)=[]; %list of unselected dimension indices 537 DimCellA=DimCellA([dimA dimextra]); 538 eval(['SubField.' VarNameA '=squeeze(SubField.' VarNameA ');']) 539 if ~isempty(dimA)&& ~isempty(dimextra) 540 eval(['SubField.' VarNameA '=permute(SubField.' VarNameA ',[dimA dimextra]);']) 541 end 542 else 543 time_index=str2double(get(handles.TimeIndexValue,'String')); 544 dimextra([dimA TimeVarIndex])=[]; 545 %DimCellA=DimCellA([dimA dimextra TimeVarIndex])%put the time dimension at the end 546 eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra TimeVarIndex]);'])%put time variable as the last dimension 547 nbdimA=numel(dimA)+numel(dimextra); 548 switch nbdimA 549 case 1 550 colon_str='(:'; 551 case 2 552 colon_str='(:,:'; 553 case 3 554 colon_str='(:,:,:'; 555 end 556 eval(['SubField.' VarNameA '=SubField.' VarNameA colon_str ',time_index);']) 557 NbDim=NbDim-1; 558 end 494 559 DimCellA=DimCellA([dimA dimextra]); 495 eval(['SubField.' VarNameA '=permute(squeeze(SubField.' VarNameA '),[dimA dimextra]);'])496 560 SubField.VarDimName{VarSubIndexA}=DimCellA; 497 561 %add default coord_x and/or coord_y if empty 498 562 if empty_coord_x || empty_coord_y 499 VarName=Field.ListVarName{field_var_index};500 DimCell=Field.VarDimName{field_var_index};501 eval(['npxy=size(SubField.' VarName ');'])502 if numel(npxy) < numel(DimCell )503 DimCell =DimCell(end-numel(npxy)+1:end); %suppress the first singletons) dimensions563 %VarName=Field.ListVarName{field_var_index} 564 %DimCell=Field.VarDimName{field_var_index} 565 eval(['npxy=size(SubField.' VarNameA ')']) 566 if numel(npxy) < numel(DimCellA) 567 DimCellA=DimCellA(end-numel(npxy)+1:end); %suppress the first singletons) dimensions 504 568 end 505 569 ind_select=find(npxy~=1) ;%look for non singleton dimensions 506 DimCell =DimCell(ind_select);%list of dimension names for the scalar, after singleton removal570 DimCellA=DimCellA(ind_select);%list of dimension names for the scalar, after singleton removal 507 571 npxy=npxy(ind_select); 508 572 testold=0; … … 516 580 end 517 581 if empty_coord_x 518 coord_x_name=DimCell {NbDim};582 coord_x_name=DimCellA{NbDim}; 519 583 SubField.ListVarName=[{coord_x_name} SubField.ListVarName]; 520 584 SubField.VarDimName=[{coord_x_name} SubField.VarDimName]; … … 533 597 end 534 598 if empty_coord_y 535 coord_y_name=DimCell {NbDim-1};599 coord_y_name=DimCellA{NbDim-1}; 536 600 SubField.ListVarName=[{coord_y_name} SubField.ListVarName]; 537 601 SubField.VarDimName=[{coord_y_name} SubField.VarDimName]; … … 547 611 end 548 612 SubField.VarAttribute=[{coord_y_attr} SubField.VarAttribute]; 613 end 614 if empty_coord_z && NbDim==3 615 coord_z_name=DimCellA{NbDim-2}; 616 SubField.ListVarName=[{coord_z_name} SubField.ListVarName]; 617 SubField.VarDimName=[{coord_z_name} SubField.VarDimName]; 618 if testold 619 eval(['SubField.' coord_z_name '=linspace(Coord_3(1),Coord_3(end),npxy(1));']) 620 else 621 eval(['SubField.' coord_z_name '=[0.5 npxy(NbDim-2)-0.5];']) 622 end 623 if ~testold 624 coord_z_attr.units='index'; 625 else 626 coord_z_attr.units='cm'; 627 end 628 SubField.VarAttribute=[{coord_z_attr} SubField.VarAttribute]; 549 629 end 550 630 end … … 714 794 end 715 795 796 %% remove time variable 797 if get(handles.TimeDimension,'Value') 798 799 % TimeName=get(handles.TimeName,'String'); 800 % time_index=find(strcmp(TimeName,SubField.ListVarName),1); 801 % SubField.ListVarName(TimeVarIndex)=[]; 802 % SubField.VarDimName(TimeVarIndex)=[]; 803 % SubField.VarAttribute(TimeVarIndex)=[]; 804 end 805 806 716 807 %------------------------------------------------- 717 808 % give index numbers of the strings str in the list ListvarName
Note: See TracChangeset
for help on using the changeset viewer.