【发布时间】:2017-03-31 16:45:32
【问题描述】:
这里尝试将文件中的 10 个空格分隔的整数值读取到数组中:
subroutine ReadFileIntoArray (filename, int_array)
implicit none
character(len = *), intent (in) :: filename
integer, dimension(:), intent(in out) :: int_array
integer :: current_index
open (1, file = filename, status = 'old')
do current_index = 1, 10, 1
read(1, *) int_array(current_index)
end do
close (1)
end subroutine ReadFileIntoArray
! ---------------------------------------------------------------------- !
program ReadFileCalculateAverage
implicit none
integer, dimension(10) :: int_array
character (len = 9) :: filename = 'makrs.txt'
call ReadFileIntoArray(filename, int_array) ! <--- error line
end program ReadFileCalculateAverage
我遇到的错误 (在 Windows 10 上使用 Code::Blocks 16.01) 是:
Error: explicit interface required for 'ReadFileIntoArray' : assumed-shape argument
考虑到我对 Fortran 的了解有限,有什么方法可以更正上述代码?是否还有其他需要纠正的重大(仍未观察到的)错误?
【问题讨论】:
-
对所有 Fortran 问题使用标签 fortran 以获得更多关注。如果您的问题是特定的(这个不是),则为特定版本添加标签。
-
另外,如果您这样做或其他人重新标记了它,我可以轻松地结束这个问题。现在我不能... Se 也 stackoverflow.com/questions/42766530/… 完全是重复的。
-
@VladimirF 好的,我明白了。谢谢!