Compilation 使用Fortran90编译错误
好了,我已经和这些错误斗争了几个小时,下面是我的代码:Compilation 使用Fortran90编译错误,compilation,fortran90,gfortran,photran,Compilation,Fortran90,Gfortran,Photran,好了,我已经和这些错误斗争了几个小时,下面是我的代码: program hello implicit none integer :: k, n, iterator integer, dimension(18) :: objectArray call SetVariablesFromFile() do iterator = 1, 18 write(*,*) objectArray(iterator) end do contains subroutine SetVariablesFro
program hello
implicit none
integer :: k, n, iterator
integer, dimension(18) :: objectArray
call SetVariablesFromFile()
do iterator = 1, 18
write(*,*) objectArray(iterator)
end do
contains
subroutine SetVariablesFromFile()
IMPLICIT NONE
integer :: status, ierror, i, x
open(UNIT = 1, FILE = 'input.txt', &
ACTION = 'READ',STATUS = 'old', IOSTAT = ierror)
if(ierror /= 0) THEN
write(*, *) "Failed to open input.txt!"
stop
end if
do i = 1, 18
objectArray(i) = read(1, *, IOSTAT = status) x
if (status > 0) then
write(*,*) "Error reading input file"
exit
else if (status < 0) then
write(*,*) "EOF"
exit
end if
end do
close(1)
END subroutine SetVariablesFromFile
end program hello
程序你好
隐式无
整数::k,n,迭代器
整数,维度(18)::objectArray
调用SetVariablesFromFile()
do迭代器=1,18
写入(*,*)对象数组(迭代器)
结束
包含
子例程SetVariablesFromFile()
隐式无
整数::状态,ierror,i,x
打开(单位=1,文件=input.txt)&
操作='READ',状态='old',IOSTAT=ierror)
如果(ierror/=0),则
写入(*,*)“无法打开input.txt!”
停止
如果结束
i=1,18吗
objectArray(i)=读取(1,*,IOSTAT=status)x
如果(状态>0),则
写入(*,*)“读取输入文件时出错”
出口
否则,如果(状态<0),则
写入(*,*)“EOF”
出口
如果结束
结束
关闭(1)
结束子例程SetVariablesFromFile
结束节目你好
我遇到编译错误:
objectArray(i) = read(1, *, IOSTAT = status) x
是无效的Fortran。你需要把它写成
read(1,*,iostat=status) objectArray(i)
以这种正确的形式设置它,我在ifort 12.1和gfortran 4.4.3中都没有收到编译器错误,非常好,现在就编译!非常感谢。