我有50个文件要一个接一个地运行脚本,并且每次都使用唯一的名称保存生成的图形。我创建图表的脚本很好,但循环访问50个文件却没有。我遗漏了许多我正在使用的资源。我的剧本是:
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
答案 0 :(得分:0)
问题在于你打电话给sprinti,你正在做:
sprinti("0.4n",n)
应该是:
sprinti("%0.4i",n)
' i'代表整数(the NCL webpage处的文档也使用' i'作为变量名称,这可能导致一些混淆......)
这应该有效:
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