Warning, /utils/matlab/cs_grid/uvcube2latlon.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
6a35563713 Davi*0001 function [U,V,ub,vb] = uvcube2latlon(xc,yc,u,v,xi,yi,cosalpha,sinalpha)
0002 % [ui,vi]=cube2latlon(xc,yc,u,v,xi,yi,cosalpha,sinalpha);
aea29c8517 Alis*0003 %
0004 % Re-grids model output on expanded spherical cube to lat-lon grid.
6a35563713 Davi*0005 % xc,yc are 2-D arrays of the cell-centered coordinates on cube-sphere
aea29c8517 Alis*0006 % u,v is a 2-D or 3-D horizontal components of model flow fields.
0007 % xi,yi are vectors of the new regular lat-lon grid to interpolate to.
6a35563713 Davi*0008 % cosalpha, sinalpha (optional) : cos and sin of rotation angle (or read TUV.mat)
0009 % ui,vi are the flow fields with dimensions of size(xi) x size(yi) x size(u,3).
aea29c8517 Alis*0010 %
0011 % e.g.
6a35563713 Davi*0012 % >> xc=rdmds('XC');
0013 % >> yc=rdmds('YC');
0014 % >> u =rdmds('uVeltave.0000513360');
0015 % >> v =rdmds('vVeltave.0000513360');
aea29c8517 Alis*0016 % >> xi=-179:2:180;yi=-89:2:90;
6a35563713 Davi*0017 % >> [ui,vi]=uvcube2latlon(xc,yc,u,v,xi,yi);
aea29c8517 Alis*0018 %
f8d374081f Jean*0019 % Written by adcroft@.mit.edu, 2001.
3476b7bd13 Alis*0020 NN=size(u);
aea29c8517 Alis*0021 [nnx ny nz]=size(u);
0022
0023 U=reshape(u,[ny 6 ny nz]);
0024 V=reshape(v,[ny 6 ny nz]);
0025
0026 uu=zeros(ny+1,6,ny,nz);
0027 vv=zeros(ny,6,ny+1,nz);
0028
0029 for k=1:6;
0030 uu(1:ny,k,:,:)=U(:,k,:,:);
0031 vv(:,k,1:ny,:)=V(:,k,:,:);
0032 end
0033
0034 for k=1:nz;
0035 uu(ny+1,1:2:6,:,k)=uu(1,2:2:6,:,k);
0036 uu(ny+1,2:2:6,:,k)=vv(ny:-1:1,[4:2:6 2:2:3],1,k)';
0037 vv(:,2:2:6,ny+1,k)=vv(:,[3:2:6 1],1,k);
0038 vv(:,1:2:6,ny+1,k)=squeeze(uu(1,[3:2:6 1],ny:-1:1,k))';
0039 end
0040
0041 ub=(uu(1:ny,:,:,:)+uu(2:ny+1,:,:,:))/2;
0042 vb=(vv(:,:,1:ny,:)+vv(:,:,2:ny+1,:))/2;
0043
ba1c792f5e Andr*0044 % Read cos and sin of rotation angle if not provided on input
0045 if nargin == 8
0046 cosalpha=reshape(cosalpha,[ny 6 ny]);
0047 sinalpha=reshape(sinalpha,[ny 6 ny]);
0048 clear U V
0049 for kk=1:nz;
0050 for k=1:6;
0051 U(:,k,:,kk)=squeeze(cosalpha(:,k,:)).*squeeze(ub(:,k,:,kk))-squeeze(sinalpha(:,k,:)).*squeeze(vb(:,k,:,kk));
0052 V(:,k,:,kk)=squeeze(sinalpha(:,k,:)).*squeeze(ub(:,k,:,kk))+squeeze(cosalpha(:,k,:)).*squeeze(vb(:,k,:,kk));
0053 end
0054 end
aea29c8517 Alis*0055
ba1c792f5e Andr*0056 else
0057
0058 load TUV
aea29c8517 Alis*0059 clear U V
ba1c792f5e Andr*0060
aea29c8517 Alis*0061 for kk=1:nz;
0062 for k=1:6;
0063 U(:,k,:,kk)=TUu(:,:,k).*squeeze(ub(:,k,:,kk))+TUv(:,:,k).*squeeze(vb(:,k,:,kk));
0064 V(:,k,:,kk)=TVu(:,:,k).*squeeze(ub(:,k,:,kk))+TVv(:,:,k).*squeeze(vb(:,k,:,kk));
0065 end
0066 end
0067
ba1c792f5e Andr*0068 end
0069
22586ff4d2 Alis*0070 ub=reshape(U,[nnx NN(2:end)]);
0071 vb=reshape(V,[nnx NN(2:end)]);
aea29c8517 Alis*0072
6a35563713 Davi*0073 %U=cube2latlon(xc,yc,U,xi,yi);
0074 %V=cube2latlon(xc,yc,V,xi,yi);
0075 del=cube2latlon_preprocess(xc,yc,xi,yi);
22586ff4d2 Alis*0076 U=cube2latlon_fast(del,ub);
0077 V=cube2latlon_fast(del,vb);