I am doing a chemistry research project and presently have a 378 x 378 matrix of zeros and ones in a file called Connectivity-M.txt
. I am trying to write a simple program to read down each column of the matrix and look for entries with a value of one. Since the matrix is of the format A(i,j)
I want to program to write the i
,j
location for each value of one that it finds to a new file, Wires.txt
. Here is my code so far:
program connectivity_matrixread
IMPLICIT none
integer :: i , j
INTEGER, DIMENSION(378,378) :: A
open(unit = 1 , file = "Connectivity-M.txt")
open(unit = 2 , file = "Wires.txt")
! Read values
do i = 1 , 378
do j = 1 , 378
Read(1,*) A(i,j)
if (A(i,j) .eq. 1) then
write(2,*) i , j
endif
enddo
enddo
end program connectivity_matrixread
The program manages to read the first column where there is only a single entry with a value of 1. It writes the i
,j
position of this entry but otherwise I get an error that reads:
At line 25 of file conn-read.f90 (unit = 1, file = 'Connectivity-M.txt')
Fortran runtime error: End of file
After moving the open file statement I am still getting the same error. The line the error refers to contains the read statement.
{}
. I, like many Fortran programmers, am too old and grumpy to assist people who don't make it as easy as possible. – High Performance Mark