Changeset 684 for trunk/src/proj_field.m
- Timestamp:
- Sep 8, 2013, 10:24:51 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/proj_field.m
r675 r684 249 249 if numel(Coord{idim})==2 250 250 DCoord_min(idim)= (Coord{idim}(2)-Coord{idim}(1))/(npxy(idim)-1); 251 test_direct(idim)=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise 251 252 else 252 253 DCoord=diff(Coord{idim}); … … 924 925 XMin=min(ObjectData.RangeX); 925 926 XMax=max(ObjectData.RangeX); 926 testXMin=XMax>XMin; 927 testXMin=XMax>XMin;%=1 if XMin defined (i.e. RangeY has tow distinct elements) 927 928 testXMax=1;% range restriction along X 928 929 end … … 930 931 YMin=min(ObjectData.RangeY); 931 932 YMax=max(ObjectData.RangeY); 932 testYMin=YMax>YMin; 933 testYMin=YMax>YMin;%=1 if YMin defined (i.e. RangeY has tow distinct elements) 933 934 testYMax=1; 934 935 end … … 1041 1042 AYName='coord_y'; 1042 1043 AXName='coord_x'; 1043 if ~strcmp(ObjectData.ProjMode,'projection') 1044 if strcmp(ObjectData.ProjMode,'projection') 1045 ProjData.coord_y=[FieldData.YMin FieldData.YMax];%note that if projection is done on a grid, the Min and Max along each direction must have been defined 1046 ProjData.coord_x=[FieldData.XMin FieldData.XMax]; 1047 coord_x_proj=FieldData.XMin:FieldData.CoordMesh:FieldData.XMax; 1048 coord_y_proj=FieldData.YMin:FieldData.CoordMesh:FieldData.YMax; 1049 else 1044 1050 ProjData.coord_y=[ObjectData.RangeY(1) ObjectData.RangeY(2)];%note that if projection is done on a grid, the Min and Max along each direction must have been defined 1045 ProjData.coord_x=[ObjectData.RangeX(1) ObjectData.RangeX(2)]; 1046 coord_x_proj=ObjectData.RangeX(1):ObjectData.DX:ObjectData.RangeX(2); 1047 coord_y_proj=ObjectData.RangeY(1):ObjectData.DY:ObjectData.RangeY(2); 1048 else 1049 ProjData.coord_y=[FieldData.YMin FieldData.YMax];%note that if projection is done on a grid, the Min and Max along each direction must have been defined 1050 ProjData.coord_x=[FieldData.XMin FieldData.XMax]; 1051 coord_x_proj=FieldData.XMin:FieldData.CoordMesh:FieldData.XMax; 1052 coord_y_proj=FieldData.YMin:FieldData.CoordMesh:FieldData.YMax; 1053 end 1054 [X,YI]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates 1055 XI=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-YI*sin(PlaneAngle(3));%corresponding coordinates in the original system 1056 YI=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+YI*cos(PlaneAngle(3)); 1051 ProjData.coord_x=[ObjectData.RangeX(1) ObjectData.RangeX(2)]; 1052 coord_x_proj=ObjectData.RangeX(1):ObjectData.DX:ObjectData.RangeX(2); 1053 coord_y_proj=ObjectData.RangeY(1):ObjectData.DY:ObjectData.RangeY(2); 1054 end 1055 [XI,YI]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates 1056 % XI=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-YI*sin(PlaneAngle(3));%corresponding coordinates in the original system 1057 % YI=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+YI*cos(PlaneAngle(3)); 1057 1058 else% we use the existing grid from field cell #icell_grid 1058 1059 NbDim=NbDimArray(icell_grid); … … 1062 1063 ProjData.(AXName)=FieldData.(AXName); % new (projected ) y coordinates 1063 1064 end 1064 1065 1066 1065 ProjData.ListVarName={AYName,AXName}; 1066 ProjData.VarDimName={AYName,AXName}; 1067 ProjData.VarAttribute={[],[]}; 1067 1068 end 1068 1069 … … 1276 1277 ProjMode{icell}='interp_lin'; %request linear interpolation for projection on a tilted plane 1277 1278 end 1278 1279 1279 1280 if isequal(ProjMode{icell},'projection')% && (~testangle || test90y || test90x) 1280 1281 if NbDim==2 && ~testXMin && ~testXMax && ~testYMin && ~testYMax% no range restriction … … 1284 1285 VarAttribute=[VarAttribute FieldData.VarAttribute(VarIndex)]; 1285 1286 end 1286 1287 1287 ProjData.(AYName)=FieldData.(AYName); 1288 1288 ProjData.(AXName)=FieldData.(AXName); … … 1292 1292 end 1293 1293 else 1294 indY=NbDim-1; 1295 if test_direct(indY) 1296 min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1; 1297 max_indy=floor((YMax-Coord{indY}(1))/DYinit)+1; 1298 Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1); 1299 Ybound(2)=Coord{indY}(1)+DYinit*(max_indy-1); 1294 Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)}); 1295 Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)}); 1296 if numel(Coord{NbDim-1})==2 1297 DY=(Coord{NbDim-1}(2)-Coord{NbDim-1}(1))/(DimValue(1)-1); 1298 end 1299 if numel(Coord{NbDim})==2 1300 DX=(Coord{NbDim}(2)-Coord{NbDim}(1))/(DimValue(2)-1); 1301 end 1302 if testYMin%test_direct(indY) 1303 YIndexMin=(YMin-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the min y value for the new field 1304 YIndexMax=(YMax-Coord{NbDim-1}(1))/DY+1;% matrix index corresponding to the max y value for the new field 1300 1305 else 1301 min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;1302 max_indy=floor((Coord{indY}(1)-YMin)/DYinit)+1;1303 Ybound(2)=Coord{ indY}(1)-DYinit*(max_indy-1);1304 Ybound(1)=Coord{ indY}(1)-DYinit*(min_indy-1);1305 end 1306 if test _direct(NbDim)==11307 min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;1308 max_indx=floor((XMax-Coord{NbDim}(1))/DXinit)+1;1309 Xbound(1)=Coord{NbDim}(1)+DX init*(min_indx-1);1310 Xbound(2)=Coord{NbDim}(1)+DX init*(max_indx-1);1306 YIndexMin=(Coord{NbDim-1}(1)-YMax)/DY+1; 1307 YIndexMax=(Coord{NbDim-1}(1)-YMin)/DY+1; 1308 Ybound(2)=Coord{NbDim-1}(1)-DY*(YIndexMax-1); 1309 Ybound(1)=Coord{NbDim-1}(1)-DY*(YIndexMin-1); 1310 end 1311 if testXMin%test_direct(NbDim)==1 1312 XIndexMin=(XMin-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the min x value for the new field 1313 XIndexMax=(XMax-Coord{NbDim}(1))/DX+1;% matrix index corresponding to the max x value for the new field 1314 Xbound(1)=Coord{NbDim}(1)+DX*(XIndexMin-1);% x value corresponding to XIndexMin 1315 Xbound(2)=Coord{NbDim}(1)+DX*(XIndexMax-1);% x value corresponding to XIndexMax 1311 1316 else 1312 min_indx=ceil((Coord{NbDim}(1)-XMax)/DXinit)+1; 1313 max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1; 1314 Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1); 1315 Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1); 1316 end 1317 min_indy=max(min_indy,1);% deals with margin (bound lower than the first index) 1318 min_indx=max(min_indx,1); 1317 XIndexMin=(Coord{NbDim}(1)-XMax)/DX+1; 1318 XIndexMax=(Coord{NbDim}(1)-XMin)/DX+1; 1319 Xbound(2)=Coord{NbDim}(1)+DX*(XIndexMax-1); 1320 Xbound(1)=Coord{NbDim}(1)+DX*(XIndexMin-1); 1321 end 1322 YIndexRange(1)=ceil(min(YIndexMin,YIndexMax));%first y index to select from the previous field 1323 YIndexRange(1)=max(YIndexRange(1),1);% avoid bound lower than the first index 1324 YIndexRange(2)=floor(max(YIndexMin,YIndexMax));%last y index to select from the previous field 1325 YIndexRange(2)=min(YIndexRange(2),DimValue(NbDim-1));% limit to the last available index 1326 XIndexRange(1)=ceil(min(XIndexMin,XIndexMax));%first x index to select from the previous field 1327 XIndexRange(1)=max(XIndexRange(1),1);% avoid bound lower than the first index 1328 XIndexRange(2)=floor(max(XIndexMin,XIndexMax));%last x index to select from the previous field 1329 XIndexRange(2)=min(XIndexRange(2),DimValue(NbDim));% limit to the last available index 1319 1330 if test90y 1320 1331 ind_new=[3 2 1]; … … 1329 1340 eval(['ProjData.' VarName '=squeeze(ProjData.' VarName '(iz,:,:));'])% select the z index iz 1330 1341 end 1331 eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];'])%record the new (projected ) y coordinates1332 eval(['ProjData.' AXName '=[Coord{1}(end),Coord{1}(1)];'])%record the new (projected ) x coordinates1342 ProjData.(AYName)=[Ybound(1) Ybound(2)]; %record the new (projected ) y coordinates 1343 ProjData.(AXName)=[Coord{1}(end),Coord{1}(1)]; %record the new (projected ) x coordinates 1333 1344 else 1334 1345 if NbDim==3 … … 1341 1352 end 1342 1353 end 1343 max_indy=min(max_indy,DimValue(1));%introduce bounds in y and x indices1344 max_indx=min(max_indx,DimValue(2));1345 1354 for ivar=VarIndex% loop on non coordinate variables 1346 1355 VarName=FieldData.ListVarName{ivar}; … … 1351 1360 end 1352 1361 if NbDim==3 1353 eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']);1362 ProjData.(VarName)=squeeze(FieldData.(VarName)(iz,YIndexRange(1):YIndexRange(end),XIndexRange(1):XIndexRange(end))); 1354 1363 else 1355 eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']);1364 ProjData.(VarName)=FieldData.(VarName)(YIndexRange(1):YIndexRange(end),XIndexRange(1):XIndexRange(end),:); 1356 1365 end 1357 1366 end 1358 eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];'])%record the new (projected ) y coordinates1359 eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];'])%record the new (projected ) x coordinates1367 ProjData.(AYName)=Coord{NbDim-1}(1)+DY*(YIndexRange-1); %record the new (projected ) y coordinates 1368 ProjData.(AXName)=Coord{NbDim}(1)+DX*(XIndexRange-1); %record the new (projected ) x coordinates 1360 1369 end 1361 1370 end … … 1370 1379 test_interp_tps=0; 1371 1380 end 1372 coord_x_proj=XMin:DX:XMax; 1373 coord_y_proj=YMin:DY:YMax; 1381 Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)}); 1382 Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)}); 1383 xcorner=[min(Coord{NbDim}) max(Coord{NbDim}) max(Coord{NbDim}) min(Coord{NbDim})]-ObjectData.Coord(1,1);% corner absissa of the original grid with respect to the new origin 1384 ycorner=[min(Coord{NbDim-1}) min(Coord{NbDim-1}) max(Coord{NbDim-1}) max(Coord{NbDim-1})]-ObjectData.Coord(1,2);% corner ordinates of the original grid 1385 xcor_new=xcorner*cos(PlaneAngle(3))+ycorner*sin(PlaneAngle(3));%coordinates of the corners in new frame 1386 ycor_new=-xcorner*sin(PlaneAngle(3))+ycorner*cos(PlaneAngle(3)); 1387 if testXMin 1388 xcor_new=max(xcor_new,XMin); 1389 end 1390 if testXMax 1391 xcor_new=min(xcor_new,XMax); 1392 end 1393 if testYMin 1394 ycor_new=max(ycor_new,YMin); 1395 end 1396 if testYMax 1397 ycor_new=min(ycor_new,YMax); 1398 end 1399 coord_x_proj=min(xcor_new):DX:max(xcor_new); 1400 coord_y_proj=min(ycor_new):DY:max(ycor_new); 1401 ProjData.(AYName)=[coord_y_proj(1) coord_y_proj(end)]; %record the new (projected ) y coordinates 1402 ProjData.(AXName)=[coord_x_proj(1) coord_x_proj(end)]; %record the new (projected ) x coordinates 1374 1403 [X,YI]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates 1375 1404 XI=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-YI*sin(PlaneAngle(3));%corresponding coordinates in the original system 1376 1405 YI=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+YI*cos(PlaneAngle(3)); 1377 Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});1378 Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)});1379 1406 if numel(Coord{1})==2% x coordiante defiend by its bounds, get the whole set 1380 1407 Coord{1}=linspace(Coord{1}(1),Coord{1}(2),CellInfo{icell}.CoordSize(1)); … … 1392 1419 end 1393 1420 FFName=['FF_' num2str(ind)];% append an index to the name of error flag, FF_1,FF_2... 1394 end 1421 end 1395 1422 % project all variables in the cell 1396 1423 for ivar=VarIndex … … 1947 1974 if test_direct(indY) 1948 1975 min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1; 1949 max_indy=floor((YMax-Coord{indY}(1))/DYinit)+1;1976 YIndexFirst=floor((YMax-Coord{indY}(1))/DYinit)+1; 1950 1977 Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1); 1951 Ybound(2)=Coord{indY}(1)+DYinit*( max_indy-1);1978 Ybound(2)=Coord{indY}(1)+DYinit*(YIndexFirst-1); 1952 1979 else 1953 1980 min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;
Note: See TracChangeset
for help on using the changeset viewer.