正如@d_1999所指出的那样,编译器应该是
gfortran
不
g++
.
READ
指定,此处为
READ (1, *, iostat=istat) X_halo(i), Y_halo(i), Z_halo(i)
program columns
! Add implicit none to catch that `istat` is not declared
IMPLICIT NONE
INTEGER,SAVE :: lun
INTEGER, PARAMETER :: ARRAYLEN=1440
! Make `filename` bigger than a single character
CHARACTER(120) :: filename
! can add `ARRAYLEN` here
DOUBLE PRECISION, DIMENSION (ARRAYLEN) :: X_halo, Y_halo, Z_halo
! Have added `istat` here
INTEGER :: i, istat
lun=1
filename = 'xyz.dat'
! Have replaced `xyz.dat` with `filename` and using a higher `UNIT` number
OPEN (UNIT=10, FILE=filename, STATUS='old', ACTION='read', IOSTAT=istat)
! Using `ARRAYLEN` for the loop.
! I've also capitalised the keywords (matter of preference)
DO i=1,ARRAYLEN
! And the important format specifier
READ (10, *, iostat=istat) X_halo(i), Y_halo(i), Z_halo(i)
END DO
CLOSE (10)
end program columns
其中一些问题(例如。
filename
没有足够大)会被用
-Wall
gfortran -Wall columns.f90 -o columns.exe