In wrf out, dimension of u and v are different with mass.
Ref : WRF_Readme_Chapter3
To solve this, one can use wrf_user_getvar to get values of u and v on mass grid point. In fact, NCL just calculate the average of two adjacent points.
u=wrf_user_getvar(a,"ua",0)
v=wrf_user_getvar(a,"va",0)
slp=wrf_user_getvar(a,”slp”,0)
rh=wrf_user_getvar(a,"rh",0)
omg=wrf_user_getvar(a,"omg",0)
tc=wrf_user_getvar(a,"tc",0)
dewDep=wrf_user_getvar(a,"tc",0)-wrf_user_getvar(a,"td",0)
if one uses lat and lon to calculate divergence, please see uv2dv_cfd
div = uv2dv_cfd(u,v,lat2d(:,49),lon2d(49,:),0)
remark: uv2dv_cfd only applies one-dimensional lat lon array
mix_ratio=a->QVAPOR(0,:,:,:)
sh=mix_ratio/(1+mix_ratio)
the formula for moisture flux is (ref: website)
\[\displaystyle mf= V \cdot q = (q u,q v )\] \[\displaystyle mconv=-\nabla (V \cdot q) =- \left( \frac{d (q\cdot u)}{dx}+\frac{d(q\cdot v)}{dy} \right)\]Similar to divergence, one uses uv2dv_cfd to get convergence with known 1-dimensional lat lon.
mfc= -uv2dv_cfd(u*mix_ratio,v*mix_ratio,lat2d(:,49),lon2d(49,:),0)
(Recommend) However, one also uses center_finite_diff_n with known $ \displaystyle dx$ and $ \displaystyle dy$.
dmconvdy = -center_finite_diff_n (mix_ratio*v, dy, False, 0, 1)
dmconvdx = -center_finite_diff_n (mix_ratio*u, dx, False, 0, 2)
mfa=(dmconvdx+dmconvdy)
Using function center_finite_diff_n, one can calculate $ \displaystyle \frac{dq}{dx}$ and $ \displaystyle \frac{dq}{dy}$ with fixed $ \displaystyle dx$ and $ \displaystyle dy$.
dqdy = center_finite_diff_n (mix_ratio, dy, False, 0, 1)
dqdx = center_finite_diff_n (mix_ratio, dx, False, 0, 2)
mfa=(dqdx*u+dqdy*v)
Another method is using grad_latlon_cfd. However, its input variables lat lon are one-dimensional, it is not accurate if lat lon are 2-dimensional.
Also, NCL has many functions to calculate advection , such as advect_variable. However ,it requires globe grids which is, in other word, not suitable with local grids.
vor=wrf_user_getvar(a,"avo",0)