lpasmanoranjan
New member
I am extracting qvapor at 200m, 250m, 500m above ground level from the WRF outputs and would like to save it in NetCDF format. My following script is running, but the generated NetCDF file seems is not correct. I am new to NCL. So can't understand the mistakes.
Code:
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
begin
filename = "wrfout_d01_2022-03-01_00:00:00"
rlevs = (/200., 250., 500./) ;Required levels
ilon_shift = -1
nlevs = dimsizes(rlevs)
fname_split = str_split(filename, "_")
filedate = fname_split(2)
filetime = fname_split(3)
ftime_split = str_split(filetime, ":")
filedate_hr = filedate + "_" + ftime_split(0)
a = addfile(filename, "r")
system("rm -f outfile.nc")
fout = addfile("outfile.nc","c")
times = wrf_user_getvar(a,"times",-1) ; get times in the file
ntimes = dimsizes(times) ; number of times in the file
xlat = wrf_user_getvar(a, "XLAT",0)
xlon = wrf_user_getvar(a, "XLONG",0)
xtim = wrf_user_getvar(a, "XTIME",-1)
terrian = wrf_user_getvar(a, "HGT",0)
opt = True
do it = 0, ntimes-1, 1
z = wrf_user_getvar(a, "z", it) ; model height
qvapor = wrf_user_getvar(a, "qvapor", it)
alevs = z ; setting above ground level
ds_z = dimsizes(z)
do k=0,ds_z(0)-1
alevs(k,:,:) = z(k,:,:) - terrain
nc_out = wrf_user_interp_level(qvapor(:,:,:),alevs,rlevs,opt)
fout->nc_out = nc_out
fout->xtime = xtim
fout->xlat = xlat
fout->xlong = xlon
end do
end do
end