Changeset 530 for trunk/src/proj_field.m
- Timestamp:
- Aug 27, 2012, 4:38:41 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/proj_field.m
r521 r530 148 148 [ProjData,errormsg]=proj_heading(FieldData,ObjectData); 149 149 ProjData.NbDim=0; 150 [CellVarIndex,NbDimCell,VarTypeCell,errormsg]=find_field_cells(FieldData); 150 [CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData); 151 %[CellVarIndex,NbDimCell,VarTypeCell,errormsg]=find_field_cells(FieldData); 151 152 if ~isempty(errormsg) 152 153 errormsg=['error in proj_field/proj_points:' errormsg]; … … 154 155 end 155 156 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 156 for icell=1:length(CellVarIndex) 157 if NbDimCell(icell)==1 158 continue 159 end 160 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 161 VarType=VarTypeCell{icell};% structure defining the types of variables in the cell 162 ivar_X=VarType.coord_x; 163 ivar_Y=VarType.coord_y; 164 ivar_Z=VarType.coord_z; 165 ivar_Anc=VarType.ancillary; 166 test_anc(ivar_Anc)=ones(size(ivar_Anc)); 167 ivar_F=VarType.warnflag; 168 ivar_FF=VarType.errorflag; 169 VarIndex([ivar_X ivar_Y ivar_Z ivar_Anc ivar_F ivar_FF])=[];% not projected variables removed frlom list 170 if isempty(ivar_X) 171 test_grid=1;%test for input data on regular grid (e.g. image)coordinates 172 else 173 if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1 174 errormsg='multiple coordinate input in proj_field.m'; 175 return 176 end 177 if length(ivar_Y)~=1 178 errormsg='y coordinate not defined in proj_field.m'; 179 return 180 end 181 test_grid=0; 182 end 157 for icell=1:length(CellInfo) 158 if NbDimArray(icell)<=1 159 continue %projection only for multidimensional fields 160 end 161 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 162 % VarType=CellInfo{icell}.VarType;% structure defining the types of variables in the cell 163 ivar_X=CellInfo{icell}.CoordIndex(end); 164 ivar_Y=CellInfo{icell}.CoordIndex(end-1); 165 ivar_Z=[]; 166 if NbDimArray(icell)==3 167 ivar_Z=CellInfo{icell}.CoordIndex(1); 168 end 169 % ivar_rem=[]; 170 % if isfield(CellInfo{icell},'VarIndex_ancillary') 171 % ivar_rem=CellInfo{icell}.VarIndex_ancillary; 172 % end 173 % if isfield(CellInfo{icell},'VarIndex_warnflag') 174 % ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_warnflag]; 175 % end 176 ivar_FF=[]; 177 if isfield(CellInfo{icell},'VarIndex_errorflag') 178 ivar_FF=CellInfo{icell}.VarIndex_errorflag; 179 if numel(ivar_FF)>1 180 errormsg='multiple error flag input'; 181 return 182 end 183 end 184 % 185 % select types of variables to be projected 186 ListProject={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 187 check_project=false(size(VarIndex)); 188 for ilist=1:numel(ListProject) 189 if isfield(CellInfo{icell},ListProject{ilist}) 190 check_project(CellInfo{icell}.(ListProject{ilist}))=1; 191 end 192 end 193 VarIndex=VarIndex(check_project); 194 195 % if isempty(ivar_X) 196 % test_grid=1;%test for input data on regular grid (e.g. image)coordinates 197 % else 198 % if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1 199 % errormsg='multiple coordinate input in proj_field.m'; 200 % return 201 % end 202 % if length(ivar_Y)~=1 203 % errormsg='y coordinate not defined in proj_field.m'; 204 % return 205 % end 206 % test_grid=0; 207 % end 183 208 ProjData.ListVarName={'Y','X','NbVal'}; 184 209 ProjData.VarDimName={'nb_points','nb_points','nb_points'}; … … 190 215 ProjData.ListVarName=[ProjData.ListVarName {VarName}];% add the current variable to the list of projected variables 191 216 ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}]; % projected VarName has a single dimension called 'nb_points' (set of projection points) 192 end 193 if ~test_grid 194 eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';']) 195 eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';']) 217 218 end 219 if strcmp( CellInfo{icell}.CoordType,'scattered') 220 coord_x=FieldData.(FieldData.ListVarName{ivar_X}); 221 coord_y=FieldData.(FieldData.ListVarName{ivar_Y}); 196 222 test3D=0;% TEST 3D CASE : NOT COMPLETED , 3D CASE : NOT COMPLETED 197 223 if length(ivar_Z)==1 198 eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])224 coord_z=FieldData.(FieldData.ListVarName{ivar_Z}); 199 225 test3D=1; 200 226 end 201 if length(ivar_F)>1 || length(ivar_FF)>1 202 msgbox_uvmat('ERROR','multiple flag input in proj_field.m') 203 return 204 end 227 205 228 for ipoint=1:siz(1) 206 229 Xpoint=ObjectData.Coord(ipoint,:); … … 231 254 end 232 255 else %case of structured coordinates 233 if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;234 AYName=FieldData.ListVarName{ VarType.coord(1)};235 AXName=FieldData.ListVarName{ VarType.coord(2)};256 if strcmp( CellInfo{icell}.CoordType,'grid') 257 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 258 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 236 259 eval(['AX=FieldData.' AXName ';']);% set of x positions 237 260 eval(['AY=FieldData.' AYName ';']);% set of y positions 238 261 AName=FieldData.ListVarName{VarIndex(1)};% a single variable assumed in the current cell 239 262 eval(['A=FieldData.' AName ';']);% scalar 240 npxy=size(A); 241 NbDim=numel(VarType.coord(VarType.coord>0));%number of space dimensions 263 npxy=size(A); 242 264 %update VarDimName in case of components (non coordinate dimensions e;g. color components) 243 if numel(npxy)>NbDim 265 if numel(npxy)>NbDimArray(icell) 244 266 ProjData.VarDimName{end}={'nb_points','component'}; 245 267 end 246 for idim=1:NbDim %loop on space dimensions268 for idim=1:NbDimArray(icell) %loop on space dimensions 247 269 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default 248 270 test_coord(idim)=0;%test for defined coordinates, =0 by default 249 ivar= VarType.coord(idim);271 ivar=CellInfo{icell}.CoordIndex(idim); 250 272 Coord{idim}=FieldData.(FieldData.ListVarName{ivar}); % position for the first index 251 273 if numel(Coord{idim})==2 … … 342 364 % DimVarIndex=0;%initilise list of indices for dimension variables 343 365 idimvar=0; 344 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 366 [CellInfo,NbDim,errormsg]=find_field_cells(FieldData); 367 %[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 345 368 if ~isempty(errormsg) 346 369 errormsg=['error in proj_field/proj_patch:' errormsg]; … … 350 373 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 351 374 dimcounter=0; 352 for icell=1:length(Cell VarIndex)375 for icell=1:length(CellInfo) 353 376 testX=0; 354 377 testY=0; 355 378 test_Amat=0; 356 379 testfalse=0; 357 VarIndex=Cell VarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName358 VarType=VarTypeCell{icell};380 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 381 % VarType=VarTypeCell{icell}; 359 382 % DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell) 360 383 if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2 361 384 continue 362 385 end 363 testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);364 testfalse= ~isempty(VarType.errorflag);386 %testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y); 387 testfalse=isfield(CellInfo{icell},'VarIndex_errorflag'); 365 388 testproj(VarIndex)=zeros(size(VarIndex));%default 366 testproj(VarType.scalar)=1; 367 testproj(VarType.vector_x)=1; 368 testproj(VarType.vector_y)=1; 369 testproj(VarType.vector_z)=1; 370 testproj(VarType.image)=1; 371 testproj(VarType.color)=1; 372 VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables 373 if check_unstructured%case of unstructured coordinates 389 ivar_X=CellInfo{icell}.CoordIndex(end); 390 ivar_Y=CellInfo{icell}.CoordIndex(end-1); 391 ivar_Z=[]; 392 if NbDimArray(icell)==3 393 ivar_Z=CellInfo{icell}.CoordIndex(1); 394 end 395 ivar_rem=[]; 396 if isfield(CellInfo{icell},'VarIndex_ancillary') 397 ivar_rem=CellInfo{icell}.VarIndex_ancillary; 398 end 399 if isfield(CellInfo{icell},'VarIndex_warnflag') 400 ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_warnflag]; 401 end 402 if isfield(CellInfo{icell},'VarIndex_errorflag') 403 ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_errorflag]; 404 ivar_FF=CellInfo{icell}.VarIndex_errorflag; 405 end 406 VarIndex([ivar_X ivar_Y ivar_Z ivar_rem])=[];% not projected variables removed frlom list 407 408 if strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured coordinates 374 409 eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');']) 375 410 for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag] … … 377 412 eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);']) 378 413 end 379 XName=FieldData.ListVarName{ VarType.coord_x};380 YName=FieldData.ListVarName{ VarType.coord_y};414 XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 415 YName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 381 416 eval(['coord_x=FieldData.' XName ';']) 382 417 eval(['coord_y=FieldData.' YName ';']) … … 387 422 end 388 423 % image or 2D matrix 389 if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;424 if strcmp(CellInfo{icell}.CoordType,'grid')%case of structured coordinates 390 425 test_Amat=1;% test for image or 2D matrix 391 AYName=FieldData.ListVarName{ VarType.coord(1)};392 AXName=FieldData.ListVarName{ VarType.coord(2)};426 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 427 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 393 428 eval(['AX=FieldData.' AXName ';'])% x coordinate 394 429 eval(['AY=FieldData.' AYName ';'])% y coordinate … … 562 597 563 598 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions 564 [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 599 %[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData); 600 [CellInfo,NbDim,errormsg]=find_field_cells(FieldData); 565 601 if ~isempty(errormsg) 566 602 errormsg=['error in proj_field/proj_line:' errormsg]; … … 571 607 ProjData.ListVarName={}; 572 608 ProjData.VarDimName={}; 573 testproj=zeros(size(FieldData.ListVarName)); 574 for icell=1:length(CellVarIndex) 575 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 576 VarType=VarTypeCell{icell}; %types of variables 609 for icell=1:length(CellInfo) 610 %VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 611 % VarType=VarTypeCell{icell}; %types of variables 577 612 if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case 578 613 continue 579 614 end 580 check_unstructured=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates 581 test_tps=~isempty(VarType.coord_tps); 582 testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors 583 testfalse=~isempty(VarType.errorflag);% test for error flag 584 testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0 585 %=0 for vector components, treated separately 586 testproj([VarType.scalar VarType.image VarType.color VarType.vector_x VarType.vector_y])=1; 587 VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables 615 616 % select types of variables to be projected 617 ListProject={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 618 check_project=false(size(FieldData.ListVarName)); 619 for ilist=1:numel(ListProject) 620 if isfield(CellInfo{icell},ListProject{ilist}) 621 check_project(CellInfo{icell}.(ListProject{ilist}))=1; 622 end 623 end 624 VarIndex=find(check_project); 588 625 589 626 %identify vector components 627 testU=isfield(CellInfo{icell},'VarIndex_vector_x') &&isfield(CellInfo{icell},'VarIndex_vector_y') ;% test for vectors 590 628 if testU 591 UName=FieldData.ListVarName{ VarType.vector_x};592 VName=FieldData.ListVarName{ VarType.vector_y};629 UName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}; 630 VName=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}; 593 631 vector_x=FieldData.(UName); 594 632 vector_y=FieldData.(VName); 595 633 end 596 634 %identify error flag 635 testfalse=isfield(CellInfo{icell},'VarIndex_errorflag');% test for error flag 597 636 if testfalse 598 FFName=FieldData.ListVarName{ VarType.errorflag};637 FFName=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag}; 599 638 errorflag=FieldData.(FFName); 600 639 end 601 640 % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y 602 if check_unstructured641 if strcmp(CellInfo{icell}.CoordType,'scattered') 603 642 if ~isequal(ProjMode,'interp') 604 643 if width==0 … … 617 656 end 618 657 end 619 XName= FieldData.ListVarName{ VarType.coord_x};620 YName= FieldData.ListVarName{ VarType.coord_y};658 XName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 659 YName= FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 621 660 coord_x=FieldData.(XName); 622 661 coord_y=FieldData.(YName); … … 633 672 %%%%%%% % A FAIRE CALCULER MEAN DES QUANTITES %%%%%% 634 673 %case of unstructured coordinates 635 if check_unstructured674 if strcmp(CellInfo{icell}.CoordType,'scattered') 636 675 for ip=1:siz_line(1)-1 %Loop on the segments of the polyline 637 676 linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip)); … … 725 764 726 765 %case of structured coordinates 727 elseif numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;766 elseif strcmp(CellInfo{icell}.CoordType,'grid') 728 767 if ~isequal(ObjectData.Type,'line')% exclude polyline 729 768 errormsg=['no projection available on ' ObjectData.Type 'for structured coordinates']; % … … 732 771 test_interp2=0;%default 733 772 % if ~isempty(VarType.coord_y) 734 AYName=FieldData.ListVarName{ VarType.coord(1)};735 AXName=FieldData.ListVarName{ VarType.coord(2)};773 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 774 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 736 775 eval(['AX=FieldData.' AXName ';']);% set of x positions 737 776 eval(['AY=FieldData.' AYName ';']);% set of y positions … … 832 871 end 833 872 if testU 834 vector_x =ProjData.(FieldData.ListVarName{ VarType.vector_x});835 vector_y =ProjData.(FieldData.ListVarName{ VarType.vector_y});836 ProjData.(FieldData.ListVarName{ VarType.vector_x}) =cos(theta)*vector_x+sin(theta)*vector_y;837 ProjData.(FieldData.ListVarName{ VarType.vector_y}) =-sin(theta)*vector_x+cos(theta)*vector_y;873 vector_x =ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}); 874 vector_y =ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}); 875 ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}) =cos(theta)*vector_x+sin(theta)*vector_y; 876 ProjData.(FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}) =-sin(theta)*vector_x+cos(theta)*vector_y; 838 877 end 839 878 ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line'; … … 842 881 end 843 882 end 844 elseif test_tps883 elseif strcmp(CellInfo{icell}.CoordType,'tps') 845 884 if isfield(ObjectData,'DX')&~isempty(ObjectData.DX) 846 885 DX=abs(ObjectData.DX);%mesh of interpolation points along the line … … 972 1011 %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions 973 1012 % CellVarIndex=cells of variable index arrays 974 [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData); 1013 %[CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData); 1014 [CellInfo,NbDimArray,errormsg]=find_field_cells(FieldData); 975 1015 if ~isempty(errormsg) 976 1016 errormsg=['error in proj_field/proj_plane:' errormsg]; … … 980 1020 %% projection modes 981 1021 check_grid=0; 982 ProjMode=cell(size( VarTypeCell));983 for icell=1:numel( VarTypeCell)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates1022 ProjMode=cell(size(CellInfo)); 1023 for icell=1:numel(CellInfo)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates 984 1024 ProjMode{icell}=ObjectData.ProjMode; 985 if isfield( VarTypeCell{icell},'FieldRequest')986 switch VarTypeCell{icell}.FieldRequest1025 if isfield(CellInfo{icell},'FieldRequest') 1026 switch CellInfo{icell}.FieldRequest 987 1027 case 'interp_lin' 988 1028 ProjMode{icell}='interp'; … … 1014 1054 vector_x_proj=[]; 1015 1055 vector_y_proj=[]; 1016 for icell=1:length(Cell VarIndex)1017 NbDim=NbDim Vec(icell);1056 for icell=1:length(CellInfo) 1057 NbDim=NbDimArray(icell); 1018 1058 if NbDim<2 1019 1059 continue % only cells represnting 2D or 3D fields are involved 1020 1060 end 1021 VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName 1022 VarType=VarTypeCell{icell}; 1023 ivar_U=VarType.vector_x; 1024 ivar_V=VarType.vector_y; 1025 if ~isempty(VarType.vector_x_tps)&&~isempty(VarType.vector_y_tps) 1026 ivar_U=VarType.vector_x_tps; 1027 ivar_V=VarType.vector_y_tps; 1028 end 1029 ivar_W=VarType.vector_z; 1030 1031 %type of coordinates 1032 if ~isempty(VarType.coord_x) && ~isempty(VarType.coord_y) 1033 CoordType='unstructured'; 1034 elseif ~isempty(VarType.coord_tps) 1035 CoordType='tps'; 1036 else 1037 CoordType='structured'; 1038 end 1039 1061 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName 1062 ivar_U=[];ivar_V=[];ivar_W=[]; 1063 if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps') 1064 ivar_U=CellInfo{icell}.VarIndex_vector_x_tps; 1065 ivar_V=CellInfo{icell}.VarIndex_vector_y_tps; 1066 elseif isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') 1067 ivar_U=CellInfo{icell}.VarIndex_vector_x; 1068 ivar_V=CellInfo{icell}.VarIndex_vector_y; 1069 end 1070 % if ~isempty(VarType.vector_x_tps)&&~isempty(VarType.vector_y_tps) 1071 % ivar_U=VarType.vector_x_tps; 1072 % ivar_V=VarType.vector_y_tps; 1073 % end 1074 if isfield(CellInfo{icell},'VarIndex_vector_z') 1075 ivar_W=CellInfo{icell}.VarIndex_vector_z; 1076 end 1077 % %type of coordinates 1078 % if ~isempty(VarType.coord_x) && ~isempty(VarType.coord_y) 1079 % CoordType='unstructured'; 1080 % elseif ~isempty(VarType.coord_tps) 1081 % CoordType='tps'; 1082 % else 1083 % CoordType='structured'; 1084 % end 1085 % 1040 1086 %dimensions 1041 1087 DimCell=FieldData.VarDimName{VarIndex(1)}; … … 1046 1092 1047 1093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1048 switch C oordType1094 switch CellInfo{icell}.CoordType 1049 1095 1050 1096 %% case of input fields with unstructured coordinates 1051 case ' unstructured'1097 case 'scattered' 1052 1098 if strcmp(ProjMode{icell},'filter') 1053 1099 continue %skip for filter (needs tps field cell) 1054 1100 end 1055 coord_x=FieldData.(FieldData.ListVarName{VarType.coord_x});% initial x coordinates 1056 coord_y=FieldData.(FieldData.ListVarName{VarType.coord_y});% initial y coordinates 1057 if ~isempty(VarType.coord_z) 1058 coord_z=FieldData.(FieldData.ListVarName{VarType.coord_z});% initial z coordinates 1101 coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});% initial x coordinates 1102 coord_y=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)});% initial y coordinates 1103 check3D=(numel(CellInfo{icell}.CoordIndex)==3); 1104 if check3D 1105 coord_z=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)}); 1059 1106 end 1060 1107 … … 1062 1109 coord_x=coord_x-ObjectData.Coord(1,1); 1063 1110 coord_y=coord_y-ObjectData.Coord(1,2); 1064 if ~isempty(VarType.coord_z)1111 if check3D 1065 1112 coord_z=coord_z-ObjectData.Coord(1,3); 1066 1113 end 1067 1114 1068 1115 % selection of the vectors in the projection range (3D case) 1069 if ~isempty(VarType.coord_z)&& width > 01116 if check3D&& width > 0 1070 1117 %components of the unitiy vector normal to the projection plane 1071 1118 fieldZ=norm_plane(1)*coord_x + norm_plane(2)*coord_y+ norm_plane(3)*coord_z;% distance to the plane … … 1127 1174 coord_X=coord_X(indcut); 1128 1175 coord_Y=coord_Y(indcut); 1129 if ~isempty(VarType.coord_z)1176 if check3D 1130 1177 coord_Z=coord_Z(indcut); 1131 1178 end … … 1138 1185 for ivar=VarIndex %transfer variables to the projection plane 1139 1186 VarName=FieldData.ListVarName{ivar}; 1140 if ivar== VarType.coord_x %x coordinate1187 if ivar==CellInfo{icell}.CoordIndex(end) 1141 1188 ProjData.(VarName)=coord_X; 1142 elseif ivar== VarType.coord_y% y coordinate1189 elseif ivar==CellInfo{icell}.CoordIndex(end-1) % y coordinate 1143 1190 ProjData.(VarName)=coord_Y; 1144 elseif isempty(VarType.coord_z) || ivar~=VarType.coord_z% other variables (except Z coordinate wyhich is not reproduced)1191 elseif ~(check3D && ivar==CellInfo{icell}.CoordIndex(1)) % other variables (except Z coordinate wyhich is not reproduced) 1145 1192 ProjData.(VarName)=FieldData.(VarName); 1146 1193 end 1147 if isempty(VarType.coord_z) || ivar~=VarType.coord_z1194 if ~(check3D && ivar==CellInfo{icell}.CoordIndex(1)) 1148 1195 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1149 1196 ProjData.VarDimName=[ProjData.VarDimName DimCell]; … … 1158 1205 coord_y_proj=YMin:DY:YMax; 1159 1206 [XI,YI]=meshgrid(coord_x_proj,coord_y_proj); 1160 if ~isempty(VarType.errorflag)1161 VarName_FF=FieldData.ListVarName{ VarType.errorflag};1207 if isfield(CellInfo{icell},'VarIndex_errorflag') 1208 VarName_FF=FieldData.ListVarName{CellInfo{icell}.VarIndex_errorflag}; 1162 1209 indsel=find(FieldData.(VarName_FF)==0); 1163 1210 coord_X=coord_X(indsel); … … 1166 1213 % testFF=0; 1167 1214 % nbvar=numel(ProjData.ListVarName); 1168 if isfield( VarType,'vector_x')&&isfield(VarType,'vector_y')&&~isempty(VarType.vector_x)1169 VarName_x=FieldData.ListVarName{ VarType.vector_x};1170 VarName_y=FieldData.ListVarName{ VarType.vector_y};1171 if ~isempty(VarType.errorflag)1215 if isfield(CellInfo{icell},'VarIndex_vector_x')&&isfield(CellInfo{icell},'VarIndex_vector_y') 1216 VarName_x=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_x}; 1217 VarName_y=FieldData.ListVarName{CellInfo{icell}.VarIndex_vector_y}; 1218 if isfield(CellInfo{icell},'VarIndex_errorflag') 1172 1219 FieldData.(VarName_x)=FieldData.(VarName_x)(indsel); 1173 1220 FieldData.(VarName_y)=FieldData.(VarName_y)(indsel); 1174 1221 end 1175 1222 %FieldVar=cat(2,FieldData.(VarName_x),FieldData.(VarName_y)); 1176 if ~isfield( VarType,'CheckSub') || ~VarType.CheckSub1223 if ~isfield(CellInfo{icell},'CheckSub') || ~CellInfo{icell}.CheckSub 1177 1224 vector_x_proj=numel(ProjData.ListVarName)+1; 1178 1225 vector_y_proj=numel(ProjData.ListVarName)+2; 1179 1226 end 1180 1227 end 1181 if ~isempty(VarType.scalar)1182 VarName_scalar=FieldData.ListVarName{ VarType.scalar};1228 if isfield(CellInfo{icell},'VarIndex_scalar') 1229 VarName_scalar=FieldData.ListVarName{CellInfo{icell}.VarIndex_scalar}; 1183 1230 if ~isempty(VarType.errorflag) 1184 1231 FieldData.(VarName_scalar)=FieldData.(VarName_scalar)(indsel); 1185 1232 end 1186 % FieldVar=FieldData.(VarName_scalar); 1187 end 1188 if ~isempty(VarType.ancillary)% do not project ancillary data with interp 1189 FieldData=rmfield(FieldData,FieldData.ListVarName{VarType.ancillary}); 1190 end 1191 if ~isempty(VarType.warnflag)% do not project ancillary data with interp 1192 FieldData=rmfield(FieldData,FieldData.ListVarName{VarType.warnflag}); 1193 end 1194 [VarVal,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_X coord_Y],FieldData,VarType.Operation,XI,YI); 1195 if isfield(VarType,'CheckSub') && VarType.CheckSub && ~isempty(vector_x_proj) 1233 end 1234 if isfield(CellInfo{icell},'VarIndex_ancillary')% do not project ancillary data with interp 1235 FieldData=rmfield(FieldData,FieldData.ListVarName{CellInfo{icell}.VarIndex_ancillary}); 1236 end 1237 if isfield(CellInfo{icell},'VarIndex_warnflag')% do not project ancillary data with interp 1238 FieldData=rmfield(FieldData,FieldData.ListVarName{CellInfo{icell}.VarIndex_warnflag}); 1239 end 1240 [VarVal,ListFieldProj,VarAttribute,errormsg]=calc_field_interp([coord_X coord_Y],FieldData,CellInfo{icell}.Operation,XI,YI); 1241 if isfield(CellInfo{icell},'CheckSub') && CellInfo{icell}.CheckSub && ~isempty(vector_x_proj) 1196 1242 ProjData.(ProjData.ListVarName{vector_x_proj})=ProjData.(ProjData.ListVarName{vector_x_proj})-VarVal{1}; 1197 1243 ProjData.(ProjData.ListVarName{vector_y_proj})=ProjData.(ProjData.ListVarName{vector_y_proj})-VarVal{2}; … … 1242 1288 1243 1289 %% case of input fields defined on a structured grid 1244 case ' structured'1290 case 'grid' 1245 1291 1246 1292 VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions … … 1261 1307 end 1262 1308 end 1263 AYName=FieldData.ListVarName{ VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection)1264 AXName=FieldData.ListVarName{ VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection)1309 AYName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(NbDim-1)};%name of input x coordinate (name preserved on projection) 1310 AXName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(NbDim)};%name of input y coordinate (name preserved on projection) 1265 1311 if testangle% TODO modify name also in case of origin shift in x or y 1266 1312 AYProjName='Y'; … … 1287 1333 for idim=1:NbDim %loop on space dimensions 1288 1334 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default 1289 ivar= VarType.coord(idim);% index of the variable corresponding to the current dimension1335 ivar=CellInfo{icell}.CoordIndex(idim);% index of the variable corresponding to the current dimension 1290 1336 if ~isequal(ivar,0)% a variable corresponds to the dimension #idim 1291 eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']);% coord values for the input field1337 Coord{idim}=FieldData.(FieldData.ListVarName{ivar});% coord values for the input field 1292 1338 if numel(Coord{idim})==2 %input array defined on a regular grid 1293 1339 DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim); … … 1296 1342 DCoord_min(idim)=min(DCoord); 1297 1343 DCoord_max=max(DCoord); 1298 % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise1299 1344 if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000) 1300 1345 msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m']) … … 1383 1428 ProjData.ListVarName=[ProjData.ListVarName FieldData.ListVarName(VarIndex)]; 1384 1429 ProjData.VarDimName=[ProjData.VarDimName FieldData.VarDimName(VarIndex)]; 1430 if isfield(FieldData,'VarAttribute') 1385 1431 ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute(VarIndex)]; 1432 end 1386 1433 ProjData.(AYProjName)=FieldData.(AYName); 1387 1434 ProjData.(AXProjName)=FieldData.(AXName); … … 1680 1727 %----------------------------------------------------------------- 1681 1728 idimvar=0; 1682 [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData);1683 if ~isempty(errormsg)1684 errormsg=['error in proj_field/proj_plane:' errormsg];1685 return1686 end1729 % [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_cells(FieldData); 1730 % if ~isempty(errormsg) 1731 % errormsg=['error in proj_field/proj_plane:' errormsg]; 1732 % return 1733 % end 1687 1734 1688 1735 % LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
Note: See TracChangeset
for help on using the changeset viewer.