Recipe: winds

From GEOS-5
Jump to navigation Jump to search
pro winds_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=720
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

read_and_interpolate_cube, myfile, 'U10M', u10m, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef, /regridCubeToLatlon, /CONSERV, regridResolution=cResolution
read_and_interpolate_cube, myfile, 'V10M', v10m, pngImgIdim, pngImgJdim, LonBeg, LonEnd, LatBeg, LatEnd, undef, /regridCubeToLatlon, /CONSERV, regridResolution=cResolution
mag = sqrt(u10m*u10m + v10m*v10m)

; 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)
; this attribute is critical for GrADS
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

; Output data:
NCDF_VARPUT, id, timeid, 0
NCDF_VARPUT, id,  lonid, lons
NCDF_VARPUT, id,  latid, lats
NCDF_VARPUT, id,  varid, mag
NCDF_CLOSE, id ; Close the NetCDF file.

end