【发布时间】:2016-04-25 03:14:04
【问题描述】:
我有一个包含三列(ID 号、x、y)的文件
ifile.txt
1 32.2 21.4
4 33.2 43.5
5 21.3 45.6
12 22.3 32.5
32 21.5 56.3
43 33.4 23.4
44 23.3 22.3
55 22.5 32.4
我想在第 2 列和第 3 列上循环,这样读起来就像
for x=32.2 and y=21.4; do execute a fortran program
for x=33.2 and y=43.5; do execute the same program
and so on
虽然我的以下脚本正在运行,但我需要它以一种有效的方式。
s1=1 #serial number
s2=$(wc -l < ifile.txt) #total number to be loop
while [ $s1 -le $s2 ]
do
x=$(awk 'NR=='$s1' {print $2}' ifile.txt)
y=$(awk 'NR=='$s1' {print $3}' ifile.txt)
cat << EOF > myprog.f
...
take value of x and y
...
EOF
ifort myprog.f
./a.out
(( s1++ ))
done
请注意:myprog.f 是在 cat 程序中编写的。例如,
cat << EOF > myprog.f
....
....
take value of x and y
....
....
EOF
【问题讨论】:
-
xyz与shell变量$x和$y有什么关系,如果xy指的是这些shell变量,那么z指的是什么? -
很抱歉给您带来了困惑。不,这里 xy 没有引用这些变量。我已经改变了。谢谢。
-
所以您希望
$x和$y是myprog.f能够读取的环境 变量?$s1是否相关,还是仅用于驱动循环? -
是的,$s1 在这里并不重要。它仅用于驱动循环。
-
您的更新是否意味着您在循环的每次迭代中(重新)编写 Fortran 程序的源代码,使用
ifort编译它,然后执行它?你为什么不静态地编译一个带有arguments的程序?