| 1 | 
function [] = plotcube(XX,YY,C) | 
| 2 | 
% plotcube(x,y,c) | 
| 3 | 
% | 
| 4 | 
% Plots cubed-sphere data in 3D on sphere. (x,y) are | 
| 5 | 
% coordinates, c is cell-centered scalar to be plotted. | 
| 6 | 
% Dimensions should be N+1 x N+1 x 6 for (x,y) | 
| 7 | 
% and                   N  x  N  x 6 for c | 
| 8 | 
% | 
| 9 | 
% The default plotting mode is shading faceted. Using this or | 
| 10 | 
% shading flat, (x,y) should be the coordinates of grid-corners | 
| 11 | 
% and can legitimately have dimension (N+1)x(N+1)x6. | 
| 12 | 
% | 
| 13 | 
% If using shading interp, then (x,y) must be the coordinates of | 
| 14 | 
% the cell centers with same dimensions as c. | 
| 15 | 
% | 
| 16 | 
% e.g. | 
| 17 | 
% | 
| 18 | 
% xg=rdmds('XG'); | 
| 19 | 
% yg=rdmds('YG'); | 
| 20 | 
% ps=rdmds('Eta.0000000000'); | 
| 21 | 
% plotube(xg,yg,ps); | 
| 22 | 
% | 
| 23 | 
% xc=rdmds('XC'); | 
| 24 | 
% yc=rdmds('YC'); | 
| 25 | 
% plotube(xg,yg,ps);shading interp | 
| 26 | 
 | 
| 27 | 
if max(max(max(YY)))-min(min(min(YY))) < 3*pi | 
| 28 | 
 X=tiles(XX*180/pi,1:6); | 
| 29 | 
 Y=tiles(YY*180/pi,1:6); | 
| 30 | 
else | 
| 31 | 
 X=tiles(XX,1:6); | 
| 32 | 
 Y=tiles(YY,1:6); | 
| 33 | 
end | 
| 34 | 
Q=tiles(C,1:6); | 
| 35 | 
 | 
| 36 | 
% Assume model grid corner coordinates were provided. | 
| 37 | 
if size(X,1)==size(Q,1) | 
| 38 | 
 X(end+1,:,:)=NaN; | 
| 39 | 
 X(:,end+1,:)=NaN; | 
| 40 | 
 X(end,:,[1 3 5])=X(1,:,[2 4 6]); | 
| 41 | 
 X(:,end,[2 4 6])=X(:,1,[3 5 1]); | 
| 42 | 
 X(:,end,[1 3 5])=squeeze(X(1,end:-1:1,[3 5 1])); | 
| 43 | 
 X(end,:,[2 4 6])=squeeze(X(end:-1:1,1,[4 6 2])); | 
| 44 | 
 Y(end+1,:,:)=NaN; | 
| 45 | 
 Y(:,end+1,:)=NaN; | 
| 46 | 
 Y(end,:,[1 3 5])=Y(1,:,[2 4 6]); | 
| 47 | 
 Y(:,end,[2 4 6])=Y(:,1,[3 5 1]); | 
| 48 | 
 Y(:,end,[1 3 5])=squeeze(Y(1,end:-1:1,[3 5 1])); | 
| 49 | 
 Y(end,:,[2 4 6])=squeeze(Y(end:-1:1,1,[4 6 2])); | 
| 50 | 
end | 
| 51 | 
[nx ny nt]=size(X); | 
| 52 | 
 | 
| 53 | 
z=sin(Y*pi/180); | 
| 54 | 
x=cos(Y*pi/180).*cos(X*pi/180); | 
| 55 | 
y=cos(Y*pi/180).*sin(X*pi/180); | 
| 56 | 
 | 
| 57 | 
surf(x(:,:,1),y(:,:,1),z(:,:,1),Q(:,:,1)) | 
| 58 | 
hold on | 
| 59 | 
for j=2:6 | 
| 60 | 
 surf(x(:,:,j),y(:,:,j),z(:,:,j),Q(:,:,j)) | 
| 61 | 
end | 
| 62 | 
hold off | 
| 63 | 
xlabel('X'); | 
| 64 | 
ylabel('Y'); | 
| 65 | 
zlabel('Z'); |