Dear all,
I have a ncl code, in which I have roughly 50*5 plots which I want to
plot alltogether in a pdf with gsn_panel.
I am plotting 5 plots on one page, resulting in 50 pages. For this, I am
looping over gsn_panel.
The code works fine for a small amount of pages, but it takes VERY long
for this high number of pages.
Is there any chance to reduce the running time of the code?
As the code is rather long and also refers to other functions defined in different codes, I only send the relevant code snippet, where I loop over the panel plots.
Secondly, I attach a simplified code, which is ready to run. However, here the looping works quite fast. Therefore, I guess the slowing down has something to do with all the indexing within the loop in the original code.
Here is the code snippet from my original code to illustrate the problem:
----------------------------------------------------------------------------------
; calculate page number
n_pages = n_total
;---set panel resources
panel_res = True ; specify desired panel mods
panel_res@gsnFrame = False ; Don't advance frame. because add labelbar
panel_res@gsnMaximize = True
panel_res@gsnPaperOrientation = "portrait"
panel_res@gsnPanelCenter = False ; don't center the plots
tx3Res = True
tx3Res@txJust = "CenterLeft"
gsRes = True ; set polyline resources
gsRes@gsLineThicknessF = 3.0 ; Extra thick lines
if (nd .eq. 4) ; 4 plots on one page --> change legend position
xleg = (/ (/0.90,0.92/), (/0.90,0.92/), (/0.90,0.92/), (/0.90,0.92/) /)
yleg = (/ (/0.47,0.47/), (/0.44,0.44/), (/0.41,0.41/), (/0.38,0.38/) /)
tx3Res@txFontHeightF = 0.013 ; Font Height for legend labels
else
xleg = (/ (/0.68,0.70/), (/0.68,0.70/), (/0.68,0.70/), (/0.68,0.70/) /)
yleg = (/ (/0.11,0.11/), (/0.08,0.08/), (/0.05,0.05/), (/0.02,0.02/) /)
tx3Res@txFontHeightF = 0.013 ; Font Height for legend labels
end if
xtxt = (/ xleg(0,1)+0.01, xleg(0,1)+0.01, xleg(0,1)+0.01, xleg(0,1)+0.01 /)
ytxt = (/ yleg(0,0), yleg(1,0), yleg(2,0), yleg(3,0) /)
;---panel plot, how many plots on one page in x and y direction?
if (nd .ge. 5)
panel_ny = 3
else
panel_ny = 2
end if
panel_mx = 2
do i = 0, n_pages-1
print(round(int2flt(i)/n_pages*100,2) + " % of panel created")
panel_res@txString = "Wind roses " + position_name(ind_total(i)) + \
" (" + height_dir_model_korrel( ind_total(i) ) + " m)" + "~C~" +\ ;~C~ forces a line break: ~I~ writes the letters in indexal size
"~I~" + time_strings_post_selection(0) + " - " +time_strings_post_selection(dim_selection-1) ; + model_name + case_number
gsn_panel(wks, plot(:,ind_total(i)), (/ panel_ny, panel_mx /), panel_res)
do j = 0, nd-2 ; legend for circles
gsRes@gsLineColor = colors(j)
gsn_polyline_ndc(wks,xleg(j,:),yleg(j,:),gsRes)
end do
gsn_text_ndc(wks,plot_name(:nd-2),xtxt(:nd-2),ytxt(:nd-2),tx3Res)
gsn_labelbar_ndc(wks,nbar,labels,0.1,0.98,lbres) ; add labelbar
frame(wks)
delete(panel_res@txString)
end do
----------------------------------------------------------------------------------------
And here is the simplified code, which is ready to run:
----------------------------------------------------------------------------------------
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
outpath = ; to be defined
x = ispan(0,10,1)
y = ispan(0,10,1)
plot = new( (/5,50/), graphic )
fn = outpath + "panel_loops_test"
wks = gsn_open_wks("pdf", fn)
res = True
res@gsnDraw = False
res@gsnFrame = False ; do not advance the frame
do i = 0,49
do j = 0,4
plot(j,i) = gsn_csm_xy(wks,x,y,res)
end do
end do
; draw panels
n_pages = 50
panel_res = True ; specify desired panel mods
panel_res@gsnFrame = False ; Don't advance frame. because add labelbar
panel_res@gsnMaximize = True
panel_res@gsnPaperOrientation = "portrait"
panel_res@gsnPanelCenter = False ; don't center the plots
do i = 0,n_pages-1
gsn_panel(wks, plot(:,i), (/ 3, 2 /), panel_res)
frame(wks)
end do
end
---------------------------------------------------------------------------------------------------
Any help is appreciated very much! Thank you!
Best regards,
Julia
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jan 28 08:22:01 2014
This archive was generated by hypermail 2.1.8 : Fri Feb 07 2014 - 16:39:11 MST