Hi,
Thanks for your help. You can find the script as follows,
---
;-----------------------------------------------------------
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;-----------------------------------------------------------
;-----------------------------------------------------------
; Functions
;-----------------------------------------------------------
function labelbar(wks, plot)
local colors, levels, labels, nboxes
begin
;--- retrieve the contour levels and their associated colors ---
getvalues plot
"cnLevels" : levels
"cnFillColors" : colors
end getvalues
nboxes = dimsizes(colors)
labels = ""+levels ; labels for the labelbar
;--- set some labelbar resources ---
lbres = True
lbres@vpXF = 0.15 ; Position labelbar at
lbres@vpYF = 0.08 ; bottom center of frame.
lbres@vpWidthF = 0.70
lbres@vpHeightF = 0.10
lbres@lbPerimOn = False ; Turn off perimeter.
lbres@lbOrientation = "Horizontal" ; Default is vertical.
lbres@lbFillColors = colors
lbres@lbMonoFillPattern = True ; Fill them all solid.
lbres@lbLabelFontHeightF = 0.013 ; Label font height
lbres@lbLabelAlignment = "InteriorEdges"
lbid = gsn_create_labelbar(wks,nboxes,labels,lbres)
draw(lbid)
return(lbid)
end
;-----------------------------------------------------------
begin
;--- read input files ---
nc_obs = addfile("./input.nc", "r")
nc_lake = addfile("./cas_lake.nc", "r")
nc_nolake = addfile("./cas_nolake.nc", "r")
nc_ssc = addfile("./cas_ssc.nc", "r")
;--- read rcm grid ---
domain = addfile("./grid.nc", "r")
lsmask = domain->mask
xlat = domain->xlat
xlon = domain->xlon
;--- read data ---
lswt = short2flt(nc_obs->lswt)
lat = nc_obs->lat
lon = nc_obs->lon
tg_lake = nc_lake->tg
tg_lake!0 = "lat"
tg_lake!1 = "lon"
tg_lake@lat2d = xlat
tg_lake@lon2d = xlon
tg_nolake = nc_nolake->tg
tg_nolake!0 = "lat"
tg_nolake!1 = "lon"
tg_nolake@lat2d = xlat
tg_nolake@lon2d = xlon
tg_ssc = nc_ssc->tg
tg_ssc!0 = "lat"
tg_ssc!1 = "lon"
tg_ssc@lat2d = xlat
tg_ssc@lon2d = xlon
;--- create plot workspace ---
wks = gsn_open_wks ("pdf", "plot_vs")
gsn_define_colormap (wks, "amwg_blueyellowred")
i = NhlNewColor(wks, 0.8, 0.8, 0.8)
;--- define plor resource ---
res = True
res@gsnAddCyclic = False
res@gsnFrame = False
res@gsnLeftString = ""
;res@gsnMaximize = True
res@gsnRightString = ""
res@gsnSpreadColors = True
res@gsnSpreadColorEnd = -3
res@cnFillOn = True
res@cnFillMode = "RasterFill"
res@cnInfoLabelOn = False
res@cnLinesOn = False
res@cnLineLabelsOn = False
res@lbLabelBarOn = False
res@pmTickMarkDisplayMode = "Always"
res@tiXAxisFontHeightF = 0.008
res@tiYAxisFontHeightF = 0.008
res@tmXBLabelFontHeightF = 0.008
res@tmYLLabelFontHeightF = 0.008
res@vpWidthF = 0.2
res@vpHeightF = 0.2
res@cnLevelSelectionMode = "ManualLevels"
res@cnMinLevelValF = floor(min(lswt))-2
res@cnMaxLevelValF = ceil(max(lswt))+2
res@cnLevelSpacingF = 2
;--- mapping properties ---
res@mpDataBaseVersion = "HighRes"
res@mpProjection = "LambertConformal"
res@mpOutlineDrawOrder = "PostDraw"
res@mpGridAndLimbOn = False
res@mpLambertParallel1F = 30
res@mpLambertParallel2F = 60
res@mpLimitMode = "Corners"
res@mpLeftCornerLatF = min(lat)
res@mpLeftCornerLonF = min(lon)
res@mpRightCornerLatF = max(lat)
res@mpRightCornerLonF = max(lon)
res@mpLambertMeridianF = 51.0
;--- positions for plots ---
xpos = (/0.1,0.218,0.336,0.454/)
ypos = (/0.9,0.7,0.5,0.3/)
nplots = 16
months = (/ "DJF", "MAM", "JJA", "SON" /)
plot = new(nplots, graphic)
do i = 0, nplots-1
ii = i%4
if (ii .eq. 0) then
mm = months(i/4)
end if
print(i+" "+mm)
;--- top four plots ---
if(any(i.eq.(/0, 1, 2, 3/))) then
res@vpYF = ypos(0)
res@vpXF = xpos(i)
res@tmXTOn = False
res@tmXTLabelsOn = False
else
res@tmXTOn = False
res@tmXTLabelsOn = False
end if
;--- bottom four plots ---
if(any(i.eq.(/12, 13, 14, 15/))) then
res@vpYF = ypos(3)
res@vpXF = xpos(i-12)
res@tmXBOn = True
res@tmXBLabelsOn = True
res@tiXAxisString = "Longitude"
else
res@tmXBOn = False
res@tmXBLabelsOn = False
res@tmYLOn = False
res@tmYLLabelsOn = False
res@tiXAxisString = ""
end if
;--- rightmost four plots ---
if(any(i.eq.(/0, 4, 8, 12/))) then
res@vpYF = ypos(i/4)
res@vpXF = xpos(0)
res@tmYLOn = True
res@tmYLLabelsOn = True
res@tiYAxisString = "Latitude"
else
res@tmYLOn = False
res@tmYLLabelsOn = False
res@tiYAxisString = ""
end if
;--- leftmost four plots ---
if(any(i.eq.(/3, 7, 11, 15/))) then
res@vpYF = ypos(i/4)
res@vpXF = xpos(3)
res@tmYROn = False
res@tmYRLabelsOn = False
else
res@tmYROn = False
res@tmYRLabelsOn = False
end if
if(any(i.eq.(/5, 6, 9, 10/))) then
res@vpYF = ypos(i/4)
res@vpXF = xpos(i%4)
res@tmXBOn = False
res@tmXBLabelsOn = False
res@tmXTOn = False
res@tmXTLabelsOn = False
res@tmYROn = False
res@tmYRLabelsOn = False
res@tmYLOn = False
res@tmYLLabelsOn = False
end if
if (any(i.eq.(/0, 4, 8, 12/))) then
var_obs = month_to_season(lswt, mm)
plot(i) = gsn_csm_contour_map(wks, var_obs(0,:,:), res)
delete(var_obs)
end if
if (any(i.eq.(/1, 5, 9, 13/))) then
tmp = month_to_season(tg_lake, mm)
var_lake = tmp
var_lake = mask(tmp, lsmask, 0)
plot(i) = gsn_csm_contour_map(wks, var_lake(0,:,:), res)
delete(var_lake)
end if
if (any(i.eq.(/2, 6, 10, 14/))) then
tmp = month_to_season(tg_nolake, mm)
var_nolake = tmp
var_nolake = mask(tmp, lsmask, 0)
plot(i) = gsn_csm_contour_map(wks, var_nolake(0,:,:), res)
delete(var_nolake)
end if
if (any(i.eq.(/3, 7, 11, 15/))) then
tmp = month_to_season(tg_ssc, mm)
var_ssc = tmp
var_ssc = mask(tmp, lsmask, 0)
plot(i) = gsn_csm_contour_map(wks, var_ssc(0,:,:), res)
delete(var_ssc)
end if
end do
;--- add label bar ---
lb = labelbar(wks, plot(0))
;--- add title ---
txres = True
txres@gsnFrame = False
txres@txFontHeightF = 0.008
txres@txFont = "Helvetica-bold"
title = (/ "OBS", "LAKE", "NOLAKE", "SSC" /)
do i = 0, 3
txres@txPosXF = xpos(i)+0.1
txres@txPosYF = ypos(0)+0.01
txid = gsn_create_text(wks, title(i), txres)
draw(txid)
end do
txres@txAngleF = 90
do i = 0, 3
txres@txPosXF = xpos(3)+0.17
txres@txPosYF = ypos(i)-0.1
txid = gsn_create_text(wks, months(i), txres)
draw(txid)
end do
frame(wks)
;--- maximize plot ---
;psres = True
;maximize_output(wks, psres)
end
-----
> Hard to say offhand. Do you want to post your script?
>
>
> On Mar 29, 2011, at 9:39 AM, u.utku.turuncoglu@be.itu.edu.tr wrote:
>
>> Hi,
>>
>> I try to plot that is similar to following link,
>>
>> http://www.ncl.ucar.edu/Applications/Scripts/panel_23.ncl
>>
>> but in my case i am using gsn_csm_contour_map instead of
>> gsn_csm_contour.
>> The code gives following error in labelbar function.
>>
>> warning:cnFillColors is not a valid resource in map at this time
>> warning:NhlGetValues:Error retrieving cnFillColors
>> fatal:Execute: Error occurred at or near line 16 in file plot_vs.ncl
>>
>> fatal:Execute: Error occurred at or near line 239 in file plot_vs.ncl
>>
>> How can i solve it? I think that gsn_csm_contour_map causes this error
>> because when i change it to gsn_csm_contour, it works without error.
>>
>> Thanks,
>>
>> --ufuk
>>
>>
>> --
>> This message has been scanned for viruses and
>> dangerous content by MailScanner, and is
>> believed to be clean.
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Mar 30 02:58:24 2011
This archive was generated by hypermail 2.1.8 : Tue Apr 05 2011 - 09:01:21 MDT