-
Notifications
You must be signed in to change notification settings - Fork 0
Recipe IDL program to convert cubed sphere data to lat lon data
Matthew Thompson edited this page Sep 26, 2025
·
2 revisions
; cube_to_latlon.pro
pro cube_to_latlon
set_plot, 'Z'
LonBeg = -180
LonEnd = 180
LatBeg = -90
LatEnd = 90
lonCen = 0.5*(LonBeg+LonEnd)
LatCen = 0.0
undef = 1.e15
pngImgIdim=1440*4.0
pngImgJdim=pngImgIdim*0.5 + 1
boundaryImageObj = get_map_image_new(LatBeg, LatEnd, LonBeg, LonEnd, LonCen, LatCen, $
/NOBORDER, HORIZ_DIMS=[pngImgIdim, pngImgJdim])
elevfile='/discover/nobackup/projects/gmao/osse2/stage/c1440_NR/DATA/0.0625_deg/const/const_2d_asm_Nx/Y2005/M11/D01/c1440_NR.const_2d_asm_Nx.20051101.nc4'
read_and_interpolate, elevfile, 'lon', lons, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef
read_and_interpolate, elevfile, 'lat', lats, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef
myfile = "/discover/nobackup/projects/gmao/osse2/G5FCST/forecast-20121024_150000-C3072-4390102/G5FCST.inst1_2d_asm_Nx.20121026_1200z.nc4"
;myfile = "/discover/nobackup/projects/gmao/osse2/c5760_NR/scratch-3550451.out/c5760_NR.inst10mn_2d_met1_Nx.20120616_0840z.nc4"
;myfile = "/discover/nobackup/projects/gmao/osse2/H10UC90R72/scratch-3861154/H10UC90R72.inst30mn_2d_met1_Nx.20150215_0000z.nc4"
read_and_interpolate_cube, myfile, 'U250', u250, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef, /regridCubeToLatlon
read_and_interpolate_cube, myfile, 'V250', v250, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef, /regridCubeToLatlon
; write netcdf file
; Create a new NetCDF file with the filename inquire.nc:
id = NCDF_CREATE('c3072_NR_U250-V250.nc', /CLOBBER)
; Fill the file with default values:
NCDF_CONTROL, id, /FILL
xid = NCDF_DIMDEF(id, 'x', pngImgIdim)
yid = NCDF_DIMDEF(id, 'y', pngImgJdim)
tid = NCDF_DIMDEF(id, 't', 1)
; Define variables:
latid = NCDF_VARDEF(id, 'lat', [yid], /FLOAT)
lonid = NCDF_VARDEF(id, 'lon', [xid], /FLOAT)
timeid = NCDF_VARDEF(id, 'time', [tid], /FLOAT)
uid = NCDF_VARDEF(id, 'U250', [xid,yid], /FLOAT)
vid = NCDF_VARDEF(id, 'V250', [xid,yid], /FLOAT)
NCDF_CONTROL, id, /ENDEF
; Input data:
NCDF_VARPUT, id, timeid, 0
NCDF_VARPUT, id, lonid, lons
NCDF_VARPUT, id, latid, lats
NCDF_VARPUT, id, uid, u250
NCDF_VARPUT, id, vid, v250
NCDF_CLOSE, id ; Close the NetCDF file.
end