# Problem writing title while looping

From: Almami Johnson <almamij_at_nyahnyahspammersnyahnyah>
Date: Fri Dec 13 2013 - 05:21:20 MST

Dear all

I come across a problem which I don't know how to work it out. I have
made this script (see below) that displays 12 subplots in a panel;
each subplot represents a month (January, February ... December). I
have done a do loop to do the calculation and at the same time
attached each month with a long_name being respectively January,
February ... December. The problem is for all 12 subplots, the title
comes out as "December". Could you please me on this? i.e. to have for
each subplot the actual month: January .... December?

Thanks !

****************The script
"\$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

begin

;*****************************************************************************************
; Creating Function to Read at once Precip and Convert Calendar to
;*****************************************************************************************

undef("getPrecip")
function getPrecip(fname[1]:string, vname[1]:string)
local x

begin
x = f->\$vname\$(0,{-10:35},{-30:40}) ; read specified time period
return(x)
end

;*****************************************************************************************
; Creating a new variable corresponding to all the 12 months and getting each
;*****************************************************************************************

x = getPrecip("ensmean_pre_events_above_75P_01_mean_Correct.nc","moderate_wet_days_wrt_75th_percentile_of_reference_period")

dim = dimsizes(x(:,:))
nlat = dim(0)
nlon = dim(1)

pre = new((/12,nlat,nlon/), "float")
f45 = new((/12,nlat,nlon/), "float")
diff= new((/12,nlat,nlon/), "float")

month = (/"January","February","March","April","May","June","July","August","September","October","November","December"/)
moncount = (/"01","02","03","04","05","06","07","08","09","10","11","12"/)
nplots = dimsizes(month)

do i = 0,nplots-1
print("Getting data and preparing for " +month(i)+ " corresponding
to " +moncount(i)+ " for both present-day and future")

pre(i,:,:) =
getPrecip("ensmean_pre_events_above_75P_"+moncount(i)+"_mean_Correct.nc","moderate_wet_days_wrt_75th_percentile_of_reference_period")
printVarSummary(pre(i,:,:))

f45(i,:,:) =
getPrecip("ensmean_f85_events_above_75P_"+moncount(i)+"_mean_Correct.nc","moderate_wet_days_wrt_75th_percentile_of_reference_period")
printVarSummary(f45(i,:,:))

print("Now taking the difference between future and present for
"+month(i)+ " corresponding to " +moncount(i))

diff(i,:,:) = f45(i,:,:) - pre(i,:,:)
diff@long_name = " "+month(i)
diff@units = " "
copy_VarCoords(pre(i,:,:),diff(i,:,:))
printVarSummary (diff(i,:,:)) ; print a summary of the variable

end do

;************************************************************************************************************
; Create graphic array for panel plot and Open a Work Station
;************************************************************************************************************

plots = new(nplots,graphic) ; Open a
variale plots to store 4 Figures
wks = gsn_open_wks("ps","Events_Above_75P") ; open a workstation

;*************************************************************************************************************
; Create Colors
;*************************************************************************************************************

; colors = (/ (/255,255,255/), (/0,0,0/), (/255,255,255/),
(/220,255,220/),(/200,235,200/), \
; (/160,215,160/), (/120,195,120/), (/80,175,80/),
(/40,155,40/), (/10,120,10/), \
; (/0,100,0/), (/0,70,0/), (/0,40,0/), (/0,10,0/) /) * 1.0
; we multiply by 1 to make colors float

; colors = colors/255.
; normalize (required by NCL)

; colors = RGBtoCmap("green.txt")
gsn_define_colormap(wks, "precip_diff_12lev")
; generate new color map

;*************************************************************************************************************
; Create plots options
;*************************************************************************************************************

res = True ; plot options desired
res@gsnSpreadColors = True ; span full colormap
res@gsnDraw = False ; don't draw
res@gsnFrame = False ; don't advance frame
res@cnFillOn = True ; turn on color fill

res@cnLevelSelectionMode = "ExplicitLevels"
; set explicit contour levels
res@cnLevels =
(/-50.,-40.,-30.,-25.,-20.,-16.,-12.,-8.,-5.,-2.,-1.,1.,
2.,5.,8.,12.,16.,20.,25.,30.,40.,50./)

res@cnLinesOn = False ; turn off contour lines
res@cnLineLabelsOn = False ; turn off the values
that would be on the contours
res@mpFillOn = False ; turn off gray continents
res@gsnMaximize = True ; Use the full page
res@gsnPaperOrientation = "landscape" ; Change orientation
res@mpProjection = "Mercator"
res@mpLimitMode = "LatLon"
res@gsnAddCyclic = False ; Regional data
; res@mpMaxLatF = max(latitude) ; Taking the whole domain
; res@mpMinLatF = min(latitude)
; res@mpMaxLonF = max(longitude)
; res@mpMinLonF = min(longitude)

res@mpMaxLatF = 25.0
res@mpMinLatF = -5.0
res@mpMaxLonF = 30.0
res@mpMinLonF = -30.0

res@mpOutlineBoundarySets = "National" ; Display the
conutries borders
res@mpOutlineOn = True ; Turn on the outline
of the map
res@mpGeophysicalLineThicknessF = 3.0 ; Increase the
thickness of map border
res@pmTickMarkDisplayMode = "Always" ; Turn on map
tickmarks, i.e. writing lons and lats along the axes
res@lbLabelBarOn = False ; turn off
individual colorbars
;*********************************************************************************************************************
; Changing the font seize
;*********************************************************************************************************************
res@tmXBLabelFontHeightF = 0.02 ; resize tick
labels for X axis
res@tmYLLabelFontHeightF = 0.02 ; resize tick
labels for Y axis
; change label
spacing to avoid overlap
;res@lbLabelStride = 2 ; and write every
other label
res@lbLabelFontHeightF = 0.018 ; change the size
of the label bar
;res@tiMainString = "1st Plot Test" ; Provide a main Tile

res@gsnStringFontHeightF = 0.018 ; Increase the
title font size (long_name)

;*******************************************************************************************************
; Displaying the Panel Plot
;*******************************************************************************************************

do i = 0, nplots-1

plots(i) = gsn_csm_contour_map(wks,diff(i,:,:),res)

end do

pnlres = True ; Add panel options
pnlres@gsnFrame = False ; Don't frame yet
pnlres@txString = "RCP4.5 minus Historical" ; add main title for the panel
pnlres@gsnPanelLabelBar = True ; Setting
a common colorbar
pnlres@lbLabelFontHeightF = 0.02 ;
Increase font size of the numbers in the label bar
pnlres@pmLabelBarWidthF = 0.9 ; label bar width
pnlres@pmLabelBarHeightF = 0.08 ; label bar height
pnlres@pmLabelBarOrthogonalPosF = 0.002 ; move
the labelbar up and down
pnlres@pmLabelBarParallelPosF = 0.03 ;move the
labelbar left or right
pnlres@lbLabelAutoStride = True ; Optimal
labels, i.e. avoid overlap
pnlres@gsnPanelDebug = True ; To get
information from panel
pnlres@gsnPanelFigureStrings=
(/"a)","b)","c)","d)","e)","f)","g)","h)","i)","j)","k)","l)"/) ;
pnlres@gsnPanelFigureStringsFontHeightF = 0.018 ;
Increase the size of these strings
pnlres@gsnPanelFigureStringsPerimOn = False ;
Remove the box around these strings
pnlres@amJust = "TopLeft" ; Where
to put these strings
the white space to the panel plot