【问题标题】:For loop crashes in gnuplotgnuplot中的for循环崩溃
【发布时间】:2017-08-22 20:37:12
【问题描述】:

我在使用繁重的 gnuplot 脚本时遇到了不稳定的行为。

脚本打算绘制边界线。使用填充曲线和线条样式。还通过

显示单参数曲线族
plot for [i=1:4] f(x,i) title sprintf("f(x,i) i=%d",i) w l  dt 2

我在这里发了一个例子https://pbs.twimg.com/media/DHbeEgXXkAAV6aS.jpg:large

在这个情节之后,我继续介绍阿根廷。在新的代码行之后,蓝色的虚线开始出现异常。其中两个就这样消失了。

我开始调试代码并最终使用 set table 实用程序将整个绘图输出到单个文件中。

我发现 for 循环的行为异常。标题行显示循环变量 i 从开始值到结束值正确运行。然而,函数 f(x,i) 没有正确地输入正确的 i 值。

在第一次迭代中,循环运行良好,脚本绘制了 f(x,1)。在第二次迭代中,函数被正确输入并显示 f(x,2)。但此后,尽管标题字符串正确显示了 i 的变化,但该函数始终输入 i=2

结果图是

非常感谢能帮助我找到错误的提示。


我现在将添加几行代码。绘图命令

plot for [i=1:words(europa_cet)] countries u ($1+($2<36?1:0)*15):(mercator($2)) index (word(europa_cet,i)+0) w filledcurve lc rgb colorFondoCET,\
       for [i=1:words(paises_wet)] countries u ($1+15+dst*word(dst_wet,i)*15):(mercator($2)) index (word(paises_wet,i)+0) w filledcurve lc rgb colorFondoWET,\
       for [i=1:words(southAm)] countries u ($1+(4+dst*word(dstSouthAm,i))*15):(mercator(abs($2))) index int(word(southAm,i)) w filledcurve lc rgb colorFondoGET,\
       "magallanes.dat" u (new!=2?$1+dst*15:1/0):(mercator($2)) w filledcurve lc rgb colorFondoEET,\
   "no_magallanes.dat" u (new!=2?$1:1/0):(mercator($2)) w filledcurve lc rgb colorFondoEET,\
 for [k=1:5:1] mercator(orto(x,real(b1)+real(k)*real(15.0))) tit  sprintf("orto a %02d signo %d",k,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+1*15)) tit  sprintf("no loop orto a %02d signo %d",1,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+2*15)) tit  sprintf("no loop orto a %02d signo %d",2,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+3*15)) tit  sprintf("no loop orto a %02d signo %d",3,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+4*15)) tit  sprintf("no loop orto a %02d signo %d",4,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+5*15)) tit  sprintf("no loop orto a %02d signo %d",5,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+0*15)) tit  sprintf("no loop orto a %02d signo %d",0,Signo) w l lc rgb 'blue' dt 2 lw 3,\

for-loop(第 6 行)不起作用。逐行调用(第 7-12 行)确实有效。

以及从set table获得的输出,每次迭代的第一行

# Curve 43 of 104, 100 points FIRST iteration
# Curve title: "orto a 01 signo 1"
# x y type
-22.5 0.874361°  i
-21.9697 0.887919°  i
-21.4394 0.901287°  i
-20.9091 0.914467°  i

# Curve 44 of 104, 100 points SECOND iter
# Curve title: "orto a 02 signo 1"
# x y type
-22.5 0.407722°  i 
-21.9697 0.426936°  i
-21.4394 0.445968°  i 
-20.9091 0.464814°  i

# Curve 45 of 104, 100 points THIRD iter (REPEATS 2nd)
# Curve title: "orto a 03 signo 1" 
# x y type
-22.5 0.407722°  i
-21.9697 0.426936°  i
-21.4394 0.445968°  i
-20.9091 0.464814°  i

# Curve 46 of 104, 100 points FOURTH iter (repeats 2nd)
# Curve title: "orto a 04 signo 1"
# x y type
-22.5 0.407722°  i
-21.9697 0.426936°  i
-21.4394 0.445968°  i
-20.9091 0.464814°  i

# Curve 47 of 104, 100 points FIFTH iter (repeats 2nd)
# Curve title: "orto a 05 signo 1"
# x y type
-22.5 0.407722°  i
-21.9697 0.426936°  i
-21.4394 0.445968°  i
-20.9091 0.464814°  i

【问题讨论】:

  • 可能与 i 是一个整数这一事实有关,因此如果函数 f 执行任何算术运算,例如除法等,结果可能不是预期的 - 可能您尝试使用f(x, real(i)) 来将i 显式转换为浮动?
  • 不错。我希望它会奏效。但它失败了。我什至把 f 内的所有整数都变成了实数。它也没有工作。
  • 您能否发布相关功能和/或更完整的示例?否则很难说可能出了什么问题……
  • 当然。首先是墨卡托proj 公式mercator(lat)=log(tan(180/4.0+lat/2.0))(角度单位)和终结线公式terminator(x,y)=(x-y)&lt;0?atan(cos(x-y)/tan(23.5)):1/0 然后函数是f(x,i)=mercator(terminator(x,b0+i*15)),其中b0 是一个实常数。我试过real(i)15.0real(15),没有成功。
  • b0的值是多少,你的x坐标的范围是多少?更好的是:你能提供一个minimal, complete, and verifiable example 吗?我假设对于 xib0 的某些值,您的函数未定义。

标签: for-loop gnuplot


【解决方案1】:

现在我已经隔离了问题。

我再次粘贴情节(多)线。在multiplot 环境中,情节线运行两次,一次用于左侧(日出)子情节,第二次用于右侧(日落)子情节。它们在函数orto 的定义和b1 的值方面有所不同。

plot "usa.dat" u (usaBool?($1+6*15):1/0):(mercator($2)) w filledcurve lc rgb colorFondoFET,\
 for [i=1:words(europa_cet)] countries u ($1+($2<36?1:0)*15):(mercator($2)) index (word(europa_cet,i)+0) w filledcurve lc rgb colorFondoCET,\
       for [i=1:words(paises_wet)] countries u ($1+15+dst*word(dst_wet,i)*15):(mercator($2)) index (word(paises_wet,i)+0) w filledcurve lc rgb colorFondoWET,\
       for [i=1:words(southAm)] countries u ($1+(4+dst*word(dstSouthAm,i))*15):(mercator(abs($2))) index int(word(southAm,i)) w filledcurve lc rgb colorFondoGET,\
       "magallanes.dat" u (new!=2?$1+dst*15:1/0):(mercator($2)) w filledcurve lc rgb colorFondoEET,\
   "no_magallanes.dat" u (new!=2?$1:1/0):(mercator($2)) w filledcurve lc rgb colorFondoEET,\
 mercator(orto(x,b1+1*15)) tit  sprintf("no loop orto a %02d signo %d",1,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+2*15)) tit  sprintf("no loop orto a %02d signo %d",2,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+3*15)) tit  sprintf("no loop orto a %02d signo %d",3,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+4*15)) tit  sprintf("no loop orto a %02d signo %d",4,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+5*15)) tit  sprintf("no loop orto a %02d signo %d",5,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 mercator(orto(x,b1+0*15)) tit  sprintf("no loop orto a %02d signo %d",0,Signo) w l lc rgb 'blue' dt 2 lw 3,\
 for [i=1:words(europa_cet)] countries u ($1+($2<36?1:0)*15):(mercator($2)) index (word(europa_cet,i)+0) w l lt 1 lc rgb colorLinea,\
       for [i=1:words(paises_wet)] countries u ($1+15*(1+dst*word(dst_wet,i))):(mercator($2)) index (word(paises_wet,i)+0) w l lt 1 lc rgb colorLinea,\
       for [i=1:words(southAm)] countries u ($1+(4+dst*word(dstSouthAm,i))*15):(mercator(abs($2))) index int(word(southAm,i)) w l lt 1 lc rgb colorLinea,\
       "magallanes.dat" u (new!=2?$1+dst*15:1/0):(mercator($2)) w l lt 1 lc rgb colorLinea,\
   "no_magallanes.dat" u (new!=2?$1:1/0):(mercator($2)) w l lt 1 lc rgb colorLinea,\
   "usa.dat" u (usaBool?($1+6*15):1/0):(mercator($2)) w l lt 1 lc rgb 'gray50',\
   for [i=0:2] "ciudadesChile.dat" u ($2-($6-1+((new==0&i==2)?-1:((new==2&i==1)?1:0))-dst*word(dstSouthAm,i+1))*15):(mercator(abs($1))) index i w p pt 7 lc 1 ps 1.5,\
   "ciudadesUsa.dat" u (usaBool?($2+6*15):1/0):(mercator(abs($1))) w p pt 7 lc rgb 'blue' ps 1.5,\
 for [k=1:5:1] mercator(orto(x,real(b1)+real(k)*real(15.0))) tit  sprintf("orto a %02d signo %d",k,Signo) w l lc rgb 'green' dt 2 lw 10,\
 for [i=0:2] "ciudadesChile.dat" u ($2-($6-1+((new==0&i==2)?-1:((new==2&i==1)?1:0))-dst*real(word(dstSouthAm,i+1)+0))*15-$4*.5):(mercator(abs($1+$5*1.1))):(stringcolumn($3)) index i w labels font "Arial-Bold,10" tc rgb word(corporativa,1),\
   "ciudadesUsa.dat" u (usaBool?($2+6*15-$4*.5):1/0):(mercator(abs($1+$5*1.1))):3 w labels font "Arial-Bold,10" tc rgb 'blue',\
 for [i=1:words(Coastlines)] coastline u 1:(mercator($2)) index (word(Coastlines,i)+0) w  l lt 1 lc rgb 'gray50',\

问题出在倒数第三行,以for [i=0:2]开头的那一行。

如果这一行被删除;循环for [k=1:5:1] 运行正常。

如果for [k=1:5:1]放在倒数第三行之后,脚本运行正常。

如果for [k=1:5:1] 放在倒数第三行之前,则循环无法正常运行。

for [i=0:2] 打印智利和阿根廷城市的名称。 $1 列是纬度,$2 是经度。他们从中心转移到$4$5。变量iindex 控制国家:Argentina=0Chile=1RegionMagallanes (Chile)=2。变量new 控制智利的时区new=0 早于2015 年; new=1 是当前状态,new=2 指的是 2015 年。列 $6指的是参考时区(-3 阿根廷和麦哲伦,-4 智利)。

该脚本还控制冬季 (dst=0) 或夏季 (dst=1) 条件。

我已经尝试一一删除for [i=0:2] 行的部分(单项式)。没有成功。即使我编辑了ciudadesChile.dat 文件并将分隔$1$2 的选项卡更改为空格。没有成功。

【讨论】:

  • 这听起来很奇怪。您使用的是哪个版本的 gnuplot?您可能想通过gnuplot mailing lists 之一联系专家。
  • 是的,很奇怪。这就是我发帖的原因。我会尝试一个邮件列表。不过我不习惯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-03
相关资源
最近更新 更多