所有,我已经打了几个小时这些错误,这是我的代码:
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
我收到编译错误:
我在网上看到后一个错误可能是由于代码超过132个字符的长行代码,这似乎不是问题所在。我无法从第一个错误开始...任何帮助非常感谢!
答案 0 :(得分:1)
此,
objectArray(i) = read(1, *, IOSTAT = status) x
无效Fortran。你需要把它写成,
read(1,*,iostat=status) objectArray(i)
以正确的形式设置,我没有收到ifort 12.1的编译错误,也没有使用gfortran 4.4.3