| 1 | function [u,v] = cyl2cartuv(thetav,rhov,xi,yi,varargin) | 
| 2 | % [u,v]=cyl2cartuv(thetav,rhov,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 | %  theta=0 is at 12 o'clock. | 
| 9 | % | 
| 10 | % e.g. | 
| 11 | % >> t=rdmds('Ttave.0000513360'); | 
| 12 | % >> xi=-179:2:180;yi=-89:2:90; | 
| 13 | % >> ti=cyl2cart(x,y,t,xi,yi); | 
| 14 | % | 
| 15 | % $Header: /u/gcmpack/MITgcm_contrib/osse/utils/cyl2cartuv.m,v 1.2 2004/07/12 21:43:16 afe Exp $ | 
| 16 |  | 
| 17 | if ~isequal(size(thetav),size(rhov)) | 
| 18 | error('Theta and rho vector arrays must be same size'); | 
| 19 | end | 
| 20 |  | 
| 21 | %work out mappings of polar to cartesian | 
| 22 | NN=size(thetav); | 
| 23 | [ntheta nrho nz]=size(thetav); | 
| 24 | [RHO,THETA,NZ] = meshgrid(1:nrho,-pi+2*pi/ntheta:2*pi/ntheta:pi,1:nz); | 
| 25 | [x,y] = pol2cart(THETA(:,:,1),RHO(:,:,1)); | 
| 26 | nx=ntheta;ny=nrho; | 
| 27 |  | 
| 28 | % break out components | 
| 29 | uv=thetav.*cos(THETA)+rhov.*sin(THETA); | 
| 30 | vv=thetav.*-sin(THETA)+rhov.*cos(THETA); | 
| 31 |  | 
| 32 | X=reshape(x,[1 nx*ny]); | 
| 33 | Y=reshape(y,[1 nx*ny]); | 
| 34 | del=griddata_preprocess(Y,X,yi,xi',varargin{:}); | 
| 35 |  | 
| 36 | for k=1:nz; | 
| 37 | UV=reshape(uv(:,:,k),[1 nx*ny]); | 
| 38 | VV=reshape(vv(:,:,k),[1 nx*ny]); | 
| 39 | u(:,:,k)=griddata(Y,X,UV,yi,xi',varargin{:}); | 
| 40 | v(:,:,k)=griddata(Y,X,VV,yi,xi',varargin{:}); | 
| 41 | end % k | 
| 42 |  | 
| 43 | % Split vertical and time dimensions | 
| 44 | if size(NN,2)>2 | 
| 45 | u=reshape(u,[size(u,1) size(u,2) NN(3:end)]); | 
| 46 | v=reshape(v,[size(v,1) size(v,2) NN(3:end)]); | 
| 47 | end |