下面的脚本意外NAMELIST statement`创建派生类型然后试图输出其名称列表到文本文件:`错误:在GNUFortran
program test
implicit none
character(len=:), allocatable :: CurrentString
integer :: linelength, IO
type SubjectType
character(20) :: genre
character(20) :: maindude
end type SubjectType
type BookType
character(20) :: title
character(20) :: author
type(SubjectType) :: subject
integer, dimension(2,2):: array
integer :: BookID
end type Booktype
type(Booktype) :: Book
Book%title = "Harry Potter"
Book%author = "JK Rowling"
Book%subject%genre = "Fantasy"
Book%subject%maindude = "Ron Weasley"
Book%array = RESHAPE([1,2,3,4],[2,2])
Book%BookID = 105
open(10, file = 'namelist.txt')
namelist /mynamelist/ Book
write(10, nml = mynamelist)
close(10, status = 'keep')
end program test
然而,当编译它抛出一个错误:
||=== Build: Debug in Hello (compiler: GNU Fortran Compiler) ===|
D:\TEMP\Hello\main.f95|30|Error: Unexpected NAMELIST statement |
D:\TEMP\Hello\main.f95|31|Error: Symbol 'mynamelist' must be a
NAMELIST group name| ||=== Build failed: 2 error(s), 0 warning(s) (0
minute(s), 2 second(s)) ===|
A google search确实不是很有帮助。我发现的唯一论坛是为什么会发生这种情况,但不知道如何解决这个问题。我怎样才能让它在GFortran中运行?请注意,这在IFort中有效。