Recipe: cube lat laon

From GEOS-5
Revision as of 12:33, 6 March 2017 by Weiyuan.jiang (talk | contribs) (Created page with "<syntaxhighlight lang="IDL"> pro cube_to_latlon, myfile, outfile, myvar, varname set_plot, 'Z' LonBeg = -180 LonEnd = 180 LatBeg = -90 LatEnd = 90 lonCen = 0.5*(LonBeg+L...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
pro cube_to_latlon, myfile, outfile, myvar, varname

set_plot, 'Z'

LonBeg = -180
LonEnd =  180
LatBeg =  -90
LatEnd =   90
lonCen = 0.5*(LonBeg+LonEnd)
LatCen = 0.0
undef = 1.e15
cResolution=90
pngImgIdim=cResolution*4.0
pngImgJdim=pngImgIdim*0.5 + 1

; Make Lats/Lons
dLAT = FLOAT(LatEnd-LatBeg)/FLOAT(pngImgJdim-1)
lats = LatBeg + FINDGEN(pngImgJdim)*dLAT
;lats = (LatBeg + FINDGEN(pngImgJdim)*dLAT)*!DPI/180.0
dLON = FLOAT(LonEnd-LonBeg)/FLOAT(pngImgIdim)
lons = LonBeg + FINDGEN(pngImgIdim)*dLON
;boundaryImageObj = get_map_image_new(LatBeg, LatEnd, LonBeg, LonEnd, LonCen, LatCen, $
;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/Ops6KM_R/replay2/Ops6KM_R.inst1_2d_asm_Mx.20160929_0000z.nc4"
;read_and_interpolate_cube, myfile, 'TBISCCP', IR, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef, /regridCubeToLatlon, /CONSERV, regridResolution=cResolution
;read_and_interpolate_cube, myfile, myvar, IR, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef, /regridCubeToLatlon, /CONSERV, regridResolution=cResolution
read_and_interpolate_cube, myfile, myvar, mydata, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef, /regridCubeToLatlon, /CONSERV, regridResolution=cResolution

; write netcdf file
; Create a new NetCDF file with the filename inquire.nc:
;id = NCDF_CREATE('c1440_IR.nc', /CLOBBER)
id = NCDF_CREATE(outfile, /CLOBBER)
; Fill the file with default values:
NCDF_CONTROL, id, /FILL
xid = NCDF_DIMDEF(id, 'lon', pngImgIdim)
yid = NCDF_DIMDEF(id, 'lat', pngImgJdim)
tid = NCDF_DIMDEF(id, 'time', 1)
; Define variables:
latid  = NCDF_VARDEF(id,  'lat', [yid], /FLOAT)
lonid  = NCDF_VARDEF(id,  'lon', [xid], /FLOAT)
timeid = NCDF_VARDEF(id,  'time', [tid], /FLOAT)
varid  = NCDF_VARDEF(id,  varname, [xid,yid], /FLOAT)
NCDF_ATTPUT, id,  lonid, 'long_name','longitude'
NCDF_ATTPUT, id,  lonid, 'units','degrees_east'
NCDF_ATTPUT, id,  latid, 'long_name','latitude'
NCDF_ATTPUT, id,  latid, 'units','degrees_north'
NCDF_CONTROL, id, /ENDEF
; Input data:
NCDF_VARPUT, id, timeid, 0
NCDF_VARPUT, id,  lonid, lons
NCDF_VARPUT, id,  latid, lats
NCDF_VARPUT, id,  varid, mydata
NCDF_CLOSE, id ; Close the NetCDF file.

end