| 1 |
afe |
1.1 |
function [z] = cart2cyl(c,thetai,rhoi,varargin) |
| 2 |
|
|
% z=cart2cyl(c,xi,yi); |
| 3 |
|
|
% |
| 4 |
|
|
% Re-grids model output in cylindrical coords to cartesian. |
| 5 |
|
|
% c is a 2-D or 3-D scalar or z-vector field |
| 6 |
|
|
% xi,yi are vectors of the new regular lat-lon grid to interpolate to. |
| 7 |
|
|
% z is the interpolated data with dimensions of size(xi) by size(yi). |
| 8 |
|
|
% |
| 9 |
|
|
% e.g. |
| 10 |
|
|
% >> t=rdmds('Ttave.0000513360'); |
| 11 |
|
|
% >> xi=-179:2:180;yi=-89:2:90; |
| 12 |
|
|
% >> ti=cyl2cart(t,xi,yi); |
| 13 |
|
|
% |
| 14 |
|
|
|
| 15 |
|
|
NN=size(c); |
| 16 |
|
|
%[theta rho nz]=size(c); |
| 17 |
|
|
[x y nz]=size(c); |
| 18 |
|
|
%[RHO,THETA] = meshgrid(1:rho,-pi+2*pi/theta:2*pi/theta:pi); |
| 19 |
|
|
[Y,X] = meshgrid(-(x-1)/2:(x-1)/2,-(y-1)/2:(y-1)/2); |
| 20 |
|
|
%[x,y] = pol2cart(THETA,RHO); |
| 21 |
|
|
[theta,rho] = cart2pol(X,Y); |
| 22 |
|
|
theta=(theta./(pi*2)+0.5).*size(thetai,2); |
| 23 |
|
|
%theta=rot90(theta.*180./pi,-1); |
| 24 |
|
|
%[nx ny nz]=size(c); |
| 25 |
|
|
%nx=theta;ny=rho; |
| 26 |
|
|
ntheta=x;nrho=y; |
| 27 |
|
|
|
| 28 |
|
|
%X=reshape(x,[1 nx*ny]); |
| 29 |
|
|
%Y=reshape(y,[1 nx*ny]); |
| 30 |
|
|
THETA=reshape(theta,[1 ntheta*nrho]); |
| 31 |
|
|
RHO=reshape(rho,[1 ntheta*nrho]); |
| 32 |
|
|
%del=griddata_preprocess(Y,X,yi,xi',varargin{:}); |
| 33 |
|
|
del=griddata_preprocess(RHO,THETA,rhoi,thetai',varargin{:}); |
| 34 |
|
|
|
| 35 |
|
|
for k=1:nz; |
| 36 |
|
|
C=reshape(c(:,:,k),[1 ntheta*nrho]); |
| 37 |
|
|
z(:,:,k)=griddata(RHO,THETA,C,rhoi,thetai',varargin{:}); |
| 38 |
|
|
%z(:,:,k)=griddata(Y,X,C,yi,xi',varargin{:}); |
| 39 |
|
|
% z(:,:,k)=griddata_fast(del,[C C(il) C(ig)],varargin{:}); |
| 40 |
|
|
end % k |
| 41 |
|
|
|
| 42 |
|
|
% Split vertical and time dimensions |
| 43 |
|
|
if size(NN,2)>2 |
| 44 |
|
|
z=reshape(z,[size(z,1) size(z,2) NN(3:end)]); |
| 45 |
|
|
end |