[ncl-talk] fatal:Variable (plot) is undefined
grace
313695096 at qq.com
Mon Nov 2 19:24:59 MST 2015
Hi all:
I am trying to plot precipitation with wrfout data and try to add .shp on the plot.it says fatal:Variable (plot) is undefined .My NCL version is 6.2.0.
How can I slove those problem?
This is my script:
; Example script to produce plots for a WRF real-data run,
; with the ARW coordinate dynamics option.
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
;
; The WRF ARW input file.
; This needs to have a ".nc" appended, so just do it.
a = addfile("/public/home/huanglei/wrfdata/5km/wrfout_d03_2015-08-02_12:00:00.nc","r")
; We generate plots, but what kind do we prefer?
; type = "x11"
type = "pdf"
; type = "ps"
; type = "ncgm"
wks = gsn_open_wks(type,"plt_Precip_5km0802")
; Set some basic resources
res = True
res at MainTitle = "REAL-TIME WRF"
mpres = True ; Map resources
mpres at mpOutlineOn = False ; Turn off map outlines
mpres at mpFillOn = False ; Turn off map fill
mpres at mpGridAndLimbOn = True
;res at mpProjection = "Lambert"
pltres = True ; Plot resources
pltres at PanelPlot = True ; Tells wrf_map_overlays not to remove overlays
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; What times and how many time steps are in the data set?
FirstTime = True
times = wrf_user_getvar(a,"times",-1) ; get all times in the file
ntimes = dimsizes(times) ; number of times in the file
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
do it = 0,24,3 ; TIME LOOP
print("Working on time: " + times(it) )
if (FirstTime) then ; Save some times for tracking tendencies
times_sav = times(it)
end if
res at TimeLabel = times(it) ; Set Valid time to use on plots
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; First get the variables we will need
; Get non-convective, convective and total precipitation of 5km
rain_exp = wrf_user_getvar(a,"RAINNC",it)
rain_con = wrf_user_getvar(a,"RAINC",it)
rain_tot = rain_exp + rain_con
rain_tot at description = "Total Precipitation"
;calculate the precipitation
if( FirstTime ) then
if ( it .eq. 0 ) then
rain_exp_save = rain_exp
rain_con_save = rain_con
rain_tot_save = rain_tot
else
rain_exp_save = wrf_user_getvar(a,"RAINNC",it-1)
rain_con_save = wrf_user_getvar(a,"RAINC",it-1)
rain_tot_save = rain_exp_save + rain_con_save
FirstTime = False
times_sav = times(it-1)
end if
end if
rain_tot_tend = rain_tot - rain_tot_save
rain_tot_tend at description = "Precipitation of 5km"
; Bookkeeping, just to allow the tendency at the next time step
rain_exp_save = rain_exp
rain_con_save = rain_con
rain_tot_save = rain_tot
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if( .not. FirstTime ) then ; We will skip the first time
; Plotting options for Precipitation
opts_r = res
opts_r at UnitLabel = "mm"
opts_r at cnLevelSelectionMode = "ExplicitLevels"
opts_r at cnLevels = (/ .1, .2, .4, .8, 1.6, 3.2, 6.4, \
12.8, 25.6, 51.2, 102.4/)
opts_r at cnFillColors = (/"White","White","DarkOliveGreen1", \
"DarkOliveGreen3","Chartreuse", \
"Chartreuse3","Green","ForestGreen", \
"Yellow","Orange","Red","Violet"/)
opts_r at cnInfoLabelOn = False
opts_r at cnConstFLabelOn = False
opts_r at cnFillOn = True
opts_r at gsnDraw = False
opts_r at gsnFrame = False
; Precipitation Tendencies
opts_r at SubFieldTitle = "from " + times_sav + " to " + times(it)
contour_tend = wrf_contour(a,wks, rain_tot_tend,opts_r) ; total (color)
delete(opts_r)
; MAKE PLOTS
plot = wrf_map_overlays(a,wks,contour_tend,pltres,mpres)
end if ; END IF FOR SKIPPING FIRST TIME
;>============================================================<
; add China map
;>------------------------------------------------------------<
shp_name1 = "/public/home/huanglei/map/diquJie_polyline.shp"
lnres = True
lnres at gsLineColor = "gray25"
lnres at gsLineThicknessF = 0.5
id = gsn_add_shapefile_polylines(wks,plot,shp_name1,lnres)
; shp_name2 = "/home/huanglei/map/China/cnmap/cnhimap.shp"
; prres=True
; prres at gsLineThicknessF = 2.0
; prres at gsLineColor = "black"
; plotcn3 = gsn_add_shapefile_polylines(wks,plot,shp_name2,prres)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
times_sav = times(it)
FirstTime = False
draw(plot) ; This will draw the map and the shapefile outlines.
frame(wks)
end do ; END OF TIME LOOP
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151103/9dc264b4/attachment.html
More information about the ncl-talk
mailing list