I am new to doing fortran programing. I would like to open multiple .txt files (CrossSec01 to CrossSec10) and read data an Allocatable arrays into a single file.
My code gives me "end of file error" in the "read". Can any novices out there help me, please?
Here's my code:
implicit none
real(8), allocatable :: dat(:,:,:) ! a 3D array, no defined size yet
integer :: i,j,k,m,n
integer :: x,y,z
open(unit=123,file="crossSec01.txt") ! opens 1st file reads & closes file
!read (100,20) ((dat(i,j,k)
read(123,*) y,x
z=30
close(123)
allocate (dat(i,j,k))
do k=1,z
write(str,'("crossSec",i2.2,".txt")')k
open(unit=345,file=str,status="old")
read(345,*)
read(345,*)
read(345,*)
do i = 1,y
read(345,*)(dat(i,j,k),j=1,x) ! This is where I get my fortran runtime error "end of file" error.
end do
close(345)
end do
i,j, andkknown/initialized at the time of the allocate statement? Are you reading in the correct number of elements from the file? I would start by addingstat/iostatto all I/O statements and toallocateto see whether each operations succeeds. - Alexander Vogt