我想写一个名称列表,其中包含多个项目(因此多行)到一个字符变量 . 使用gfortran编译时,以下代码运行良好,但在使用ifort编译时返回写入错误:
program test
implicit none
type testtype
real*8 :: x
character(len=32) :: str
logical :: tf
end type testtype
type(testtype) :: thetype
integer :: iostat
character(len=1000) :: mystr(10)
namelist /THENAMELIST/ thetype
integer :: i
thetype%x = 1.0d0
thetype%str="This is a string."
thetype%tf = .true.
mystr=""
write(*,nml=THENAMELIST,delim="QUOTE")
write(mystr,THENAMELIST,iostat=iostat,delim="QUOTE")
write(*,*)"Iostat:",iostat
do i = 1, size(mystr)
write(*,*)i,trim(mystr(i))
end do
end program test
输出如下:
> ifort -o test test.f90 ; ./test
&THENAMELIST
THETYPE%X = 1.00000000000000 ,
THETYPE%STR = "This is a string. ",
THETYPE%TF = T
/
Iostat: 66
1 &THENAMELIST THETYPE%X= 1.00000000000000 ,
2
3
4
5
6
7
8
9
10
英特尔的运行时错误消息列表告诉我:“严重(66):输出语句溢出记录” .
为了完整性,使用gfortran我当然得到了
> gfortran -o test test.f90 ; ./test
&THENAMELIST
THETYPE%X= 1.0000000000000000 ,
THETYPE%STR="This is a string. ",
THETYPE%TF=T,
/
Iostat: 0
1 &THENAMELIST
2 THETYPE%X= 1.0000000000000000 ,
3 THETYPE%STR="This is a string. ",
4 THETYPE%TF=T,
5 /
6
7
8
9
10
我在互联网上搜索过,并了解到内部文件不能是标量字符变量,但这和我发现的一样多 . GFortran接受一个标量变量,只是在该变量中写入换行符,但我认为这是非标准的fortran .
我使用的编译器是:
-
gfortran GNU Fortran(MacPorts gcc48 4.8-20130411_0)4.8.1 20130411(预发布)
-
ifort(IFORT)12.0.5 20110719(在Mac上)
-
ifort(IFORT)13.1.1 20130313(在GNU / Linux上)
我的问题是:我的语法中的错误是什么,或者我如何将名称列表写入内部文件,而不必通过写入实际的外部临时文件来修补问题并将其读入我的变量(这就是我的内容)现在做,但对于大名单来说哪个慢?)