I read 3 arrays (X_halo
, Y_halo
, Z_halo
) from an input file. If I write the values loaded within the DO cycle I can print them correctly, but out of the loop no. And if I try to print the values of X_halo(i)
incorrect values are printed.
How can I do it?
program columns
IMPLICIT NONE
INTEGER,SAVE :: lun
INTEGER, PARAMETER :: ARRAYLEN=1044
CHARACTER(120) :: filename
DOUBLE PRECISION, DIMENSION (ARRAYLEN) :: X_halo, Y_halo, Z_halo
INTEGER :: i, istat
lun=1
filename = 'xyz.dat'
OPEN (UNIT=10, FILE=filename, STATUS='old', ACTION='read', IOSTAT=istat)
DO i=1,ARRAYLEN
READ (10, *, iostat=istat) X_halo(i), Y_halo(i), Z_halo(i)
! print*, 'id:', i, 'X= ', X_halo(i), 'Y= ', Y_halo(i), 'Z= ', Z_halo(i)
END DO
DO i=1,ARRAYLEN
print*, X_halo(i)
END DO
CLOSE (10)
end program columns
For example the first lines of the first column of the file xyz.dat are:
281.0788
189.8768
669.2193
720.7653
But the code returns:
6.9532597489392050E-310
2.2310395176993305E-314
6.9532121310250636E-310
6.9532238136146167E-310
Second problem: If you want to have ARRAYLEN as free variable to use the program for all the files in put, how can I do it?