function [z] = cyl2cart(c,xi,yi,varargin) % z=cyl2cart(c,xi,yi); % % Re-grids model output in cylindrical coords to cartesian. % c is a 2-D or 3-D scalar or z-vector field % xi,yi are vectors of the new regular lat-lon grid to interpolate to. % z is the interpolated data with dimensions of size(xi) by size(yi). % theta=0 is at 12 o'clock. % % e.g. % >> t=rdmds('Ttave.0000513360'); % >> xi=-179:2:180;yi=-89:2:90; % >> ti=cyl2cart(t,xi,yi); % NN=size(c); [theta rho nz]=size(c); [RHO,THETA] = meshgrid(1:rho,-pi+2*pi/theta:2*pi/theta:pi); [x,y] = pol2cart(THETA,RHO); nx=theta;ny=rho; X=reshape(x,[1 nx*ny]); Y=reshape(y,[1 nx*ny]); del=griddata_preprocess(Y,X,yi,xi',varargin{:}); for k=1:nz; C=reshape(c(:,:,k),[1 nx*ny]); z(:,:,k)=griddata(Y,X,C,yi,xi',varargin{:}); end % k % Split vertical and time dimensions if size(NN,2)>2 z=reshape(z,[size(z,1) size(z,2) NN(3:end)]); end