我有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发布于 2014-03-19 23:58:19
问题出在您对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 dohttps://stackoverflow.com/questions/22100791
复制相似问题