namelist
请教大家,我建了一个文档,里面设置了参数,a和b,希望输出,a+b的结果,但是运行出错,问题出在哪里了呢?program hello
implicit none
integer(kind=4) :: a,b
namelist /legend/ a,b
a=0
b=0
open(10,file="test01.txt",status="replace")
read(10,nml=legend)
write(*,*) a+b
end program
文档的内容如下
&legend
a=1
b=2
在Open语句中,Status="replace"会导致”test01.txt"文件被删除,然后产生一个同名的空白文件。
改"replace"为"unknown"或"old" 风平老涡 发表于 2020-9-19 21:35
在Open语句中,Status="replace"会导致”test01.txt"文件被删除,然后产生一个同名的空白文件。
改"replace ...
At line 9 of file D:\wendang\fortran\test\20200919\main.f90 (unit = 10, file = 'test01.txt')
Fortran runtime error: End of file
Error termination. Backtrace:
Could not print backtrace: libbacktrace could not find executable to open
#00x657724a3
#10x6570bf8e
#20x65669e92
#30x6570d7af
#40x6576a12e
#50x6578727a
#60x6577695e
#70x656f9d7f
#80x4015aa
#90x401652
#100x401232
Process returned 2 (0x2) execution time : 0.027 s
Press any key to continue. 胆怯滴大侠 发表于 2020-9-19 21:41
At line 9 of file D:\wendang\fortran\test\20200919\main.f90 (unit = 10, file = 'test01.txt')
Fortr ...
感谢您的回答,可是还是不行,是不是我哪里还有问题啊? 胆怯滴大侠 发表于 2020-9-19 21:41
感谢您的回答,可是还是不行,是不是我哪里还有问题啊?
文件"test01.txt"改为
&legend a=1, b=2 /
每一行结束必须有"/" 风平老涡 发表于 2020-9-19 22:21
文件"test01.txt"改为
&legend a=1, b=2 /
program hello
implicit none
integer:: a,b
namelist /pa /a,b
open(101,file="test01.txt",status="old")
read(101,nml=pa)
write(*,*) a+b
end program
风平老涡 发表于 2020-9-19 22:21
文件"test01.txt"改为
&legend a=1, b=2 /
你好,这是改过的txt
&pa/
a=1 /
b=2 /
&end / 胆怯滴大侠 发表于 2020-9-20 20:03
你好,这是改过的txt
&pa/
a=1 /
现在得到的结果是错误的,很大,1+2不等于17606072啊 本帖最后由 风平老涡 于 2020-9-20 21:29 编辑
胆怯滴大侠 发表于 2020-9-20 20:04
现在得到的结果是错误的,很大,1+2不等于17606072啊
namelist的变量名不能有空格,namelist /pa /a,b 可改为namelist /pa/a,b。 "test01.txt"文件可改为:
&pa a=1,b=2 /
或者
&pa
a=1, b=2 /
或者
&pa a=1,
b2 /
风平老涡 发表于 2020-9-20 21:15
namelist的变量名不能有空格,namelist /pa /a,b 可改为namelist /pa/a,b。 "test01.txt"文件可改为:
&pa ...
:'(还是不行啊
页:
[1]
2