function [u,v] = cyl2cartuv(thetav,rhov,xi,yi,varargin) % [u,v]=cyl2cartuv(thetav,rhov,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). % % e.g. % >> t=rdmds('Ttave.0000513360'); % >> xi=-179:2:180;yi=-89:2:90; % >> ti=cyl2cart(x,y,t,xi,yi); % % $Header: /home/ubuntu/mnt/e9_copy/MITgcm_contrib/osse/Attic/cyl2cartuv.m,v 1.2 2004/06/08 14:14:44 afe dead $ if ~isequal(size(thetav),size(rhov)) error('Theta and rho vector arrays must be same size'); end %work out mappings of polar to cartesian NN=size(thetav); [ntheta nrho nz]=size(thetav); [RHO,THETA,NZ] = meshgrid(1:nrho,-pi+2*pi/ntheta:2*pi/ntheta:pi,1:nz); [x,y] = pol2cart(THETA(:,:,1),RHO(:,:,1)); %[nx ny nz]=size(c); nx=ntheta;ny=nrho; % break out components %vv=-(thetav.*-cos(THETA)+rhov.*sin(THETA)); %uv=-(thetav.*-sin(THETA)+rhov.*cos(THETA)); uv=thetav.*cos(THETA)+rhov.*sin(THETA); vv=thetav.*-sin(THETA)+rhov.*cos(THETA); %uv=thetav.*cos(THETA); %+rhov.*sin(THETA); %vv=thetav.*-sin(THETA); %+rhov.*cos(THETA); %uv=rhov.*sin(THETA); %vv=rhov.*cos(THETA); X=reshape(x,[1 nx*ny]); Y=reshape(y,[1 nx*ny]); del=griddata_preprocess(Y,X,yi,xi',varargin{:}); for k=1:nz; UV=reshape(uv(:,:,k),[1 nx*ny]); VV=reshape(vv(:,:,k),[1 nx*ny]); u(:,:,k)=griddata(Y,X,UV,yi,xi',varargin{:}); v(:,:,k)=griddata(Y,X,VV,yi,xi',varargin{:}); % z(:,:,k)=griddata_fast(del,[C C(il) C(ig)],varargin{:}); end % k % Split vertical and time dimensions if size(NN,2)>2 u=reshape(u,[size(u,1) size(u,2) NN(3:end)]); v=reshape(v,[size(v,1) size(v,2) NN(3:end)]); end