[ncl-talk] Saving calculated WRF variable to netcdf file

Lyndz olagueralyndonmark429 at gmail.com
Sat Feb 29 02:16:54 MST 2020


Dear NCL-Experts,

*[Problem]*
I am calculating equivalent potential temperature (thetae) from a wrfout
file and save the variable to netcdf file.

I am calculating theta using the wrf_eth function instead of the
wrf_user_getvar.
I cant figure out how to save the calculated thetae with the correct lat
lon and pressure level.
Although there is no error in the script, I cant process the output file
(i.e., still non-cdf compliant).

Any suggestions on how I can fix this in NCL?

*[What I have so far]*
My script is as follows:

,**************************************************************************************
;This file calculates the equivalent potential temperature from a wrfout
file
;**************************************************************************************

begin
   nc_file = addfile("../WRF-4.0.3/test/em_real/G3D_Thompson_ACM2_120s/
wrfout_d01_2017-01-12_00_00_00.nc","r")
   T  = nc_file->T
   P  = nc_file->P
   PB = nc_file->PB
   qv = nc_file->QVAPOR

   T  = T + 300.        ; potential temperature in K.
   P  = P + PB          ; full pressure in Pa.
   tk = wrf_tk( P , T ) ; temperature in K.
   thetae = wrf_eth ( qv, tk, P )

;************************************************
;Get the lat lon and pressure level
;************************************************
   lat = wrf_user_getvar(nc_file, "XLAT",-1)
   lon = wrf_user_getvar(nc_file, "XLONG",-1)
   lev = wrf_user_getvar(nc_file, "pressure",-1)

;************************************************
;lev= bottom to top; lon = east to west; lat = south to north
'************************************************
   thetae!1 = "lev"
   thetae!2 = "lat"
   thetae!3 = "lon"

;***********************************************
; save to a netcdf file
;***********************************************
  diro = "./"
  filo = "Thetae_G3D_Thomp_ACM2.nc"
  ptho = diro+filo
  system("/bin/rm -f "+ptho)
  ncdf = addfile(ptho,"c")

  fAtt = True
  fAtt at title         = "Equivalent Potential Temperature"
  fAtt at source_file   = "WRF G3D_Thompson_ACM2"
  fAtt at Conventions   = "None"
  fAtt at creation_date = systemfunc("date")
  fileattdef(ncdf,fAtt)            ; copy file attributes
  filedimdef(ncdf,"time",-1,True)
  ncdf->thetae = thetae
  ncdf->lat = lat
  ncdf->lon = lon
  ncdf->lev = lev
end

Sincerely,
Lynds
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200229/b572463a/attachment.html>


More information about the ncl-talk mailing list