해결 방법은 문제에 필요한 기능을 갖춘 Fortran 90/95/2003/2008을 사용하는 것이지만 FORTRAN 77은 그렇지 않습니다. 파일을 한 번 읽으면 데이터 항목 수를 확인할 수 있습니다. 파일을 되감습니다. 필요한 길이의 배열을 할당하십시오. 파일을 다시 읽고 배열을 읽습니다.
은 2003/2008 포트란 (테스트하지)를 사용하여 :
use iso_fortran_env
real :: xtmp, ytmp
real, dimension (:), allocatable :: x, y
integer :: i, n
integer :: Read_Code
open (unit=75, file=...)
n = 0
LengthLoop: do
read (75, *, iostat=Read_Code) xtmp, ytmp
if (Read_Code /= 0) then
if (Read_Code == iostat_end) then
exit LengthLoop
else
write (*, '(/ "read error: ", I0)') Read_Code
stop
end if
end if
n = n + 1
end do LengthLoop
allocate (x(n))
allocate (y(n))
rewind (75)
do i=1, n
read (75, *) x(i), y(i)
end do
close (75)