Reputation: 111
I have 50 files that I want to run a script on one after the other, and to save the generated graph with a unique name each time. My script to create the graph is fine, but looping through the 50 files is not. I have left out many of the resources I'm using. My script is:
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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
do n=1961,2010
begin
fnam="/home/cohara/TempData/yearly_data/average/average_" + sprinti("0.4n",n) + ".nc"
x=addfile(fnam,"r")
data=x->var61(0,0,:,:)
xwks=gsn_open_wks("ps","Average_" + sprinti("0.4n",n)
resources=True
resources@tiMainString="Average Annual Temperature" + sprinti("0.4n",n)
plot=gsn_csm_contour_map(xwks,data,resources)
end
end do
Upvotes: 0
Views: 1844
Reputation: 1
The problem is in your calls to sprinti, you're doing:
sprinti("0.4n",n)
where it should be:
sprinti("%0.4i",n)
Where the 'i' stands for integer (the documentation at the NCL webpage uses 'i' for the variable name as well, which can lead to some confusion...)
This should work:
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"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
do n=1961,2010
begin
fnam="/home/cohara/TempData/yearly_data/average/average_" + sprinti("%0.4i",n) + ".nc"
x=addfile(fnam,"r")
data=x->var61(0,0,:,:)
xwks=gsn_open_wks("ps","Average_" + sprinti("%0.4i",n)
resources=True
resources@tiMainString="Average Annual Temperature" + sprinti("%0.4i",n)
plot=gsn_csm_contour_map(xwks,data,resources)
end
end do
Upvotes: 0