I/O error: PGFIO-F-215

Hi,

I have coded a program to perform some operations on a sparse system of equations. The first step of the program is to read the matrix and the right hand side vector from a text file.
The data in the file include the dimension of the matrix (n) and the number of nonzero elements(nnz) in the first line separated by space, the entries of the matrix in the next line, each line contains the row number, the colum number and the value of the element separated by space, and finally the RHS vector, each entry in a separate line.
(for example for a 3*3 system:
3 5
1 1 10
1 2 5
2 2 4
3 1 -5
3 3 7
18
20
-15
)

The piece of code I am using to read these, which works fine in Intel Visual Fortran, is:

Open(unit=10, file=“input.txt”, status=“old”)

read(10,) n, nonzero
allocate(mat(nonzero), row(nonzero), col(nonzero), b(n))
do i= 1, nonzero
read(10,
) row(i),col(i), mat(i)
end do
do i= 1, m
read(10,*) b(i)
end do
close(10)

The “input.txt” file is located in the project folder and also added to the project resources.

The error I get reads:
"
PGFIO-F-215/list-directed read/unit=10/formatted/attempt to read past end of file. File name = input.txt formatted, sequential access record = 1
"
As the record number shows, and I checked by putting pause after each reading line, the program opens the file with no problem, but can not perform the very first read line ( read(10,*) n, nonzero ) .


Can anyone help me with this issue?

Many thanks,

Omid

Using IMPLICIT NONE would have pointed out the bug on the following line, where you should have n instead of m.

do i= 1, m

Secondly, it is usually a losing game to comment on a post where only snippets of code are shown.

Check that you did not corrupt your data file by making it part of your project as a “resource”.

Check that you are opening the input file in the correct directory. If the file was opened in a directory where it did not exist, an empty file would get created, and the first READ would cause EOF.

Using IMPLICIT NONE would have pointed out the bug on the following line, where you should have n instead of m

Definitely a problem, but not the cause of the above error.

post where only snippets of code are shown.

Having a reproducing example is very helpful. Not always necessary, but helpful.

Check that you are opening the input file in the correct directory. If the file was opened in a directory where it did not exist, an empty file would get created, and the first READ would cause EOF.

Since he has “old” for the status, the open would fail if it couldn’t find the file.

but can not perform the very first read line ( read(10,*) n, nonzero ) .

How was the “input.txt” file created? The error suggest to me that the end line isn’t a newline (\n) or carriage-return/newline (\r\n).

Here’s an reproducing example:

PGI$ cat test_read.f90

program foo

integer, allocatable :: row(:), col(:), mat(:), b(:)
integer :: n, nonzero

Open(unit=10, file="input.txt", status="old")
read(10,*) n, nonzero
allocate(mat(nonzero), row(nonzero), col(nonzero), b(n))
do i= 1, nonzero
read(10,*) row(i),col(i), mat(i)
end do
do i= 1, n
read(10,*) b(i)
end do
close(10)

do i=1,nonzero
  print *, row(i), col(i), mat(i)
enddo
do i = 1,n
  print *, b(i)
enddo

end program foo

PGI$ pgfortran test_read.f90
PGI$ test_read.exe
PGFIO-F-209/OPEN/unit=10/'OLD' specified for file which does not exist.
 File name = input.txt
 In source file test_read.f90, at line number 7
PGI$ mv i.txt input.txt
PGI$ cat input.txt
3 5
1 1 10
1 2 5
2 2 4
3 1 -5
3 3 7
18
20
-15

PGI$ test_read.exe
            1            1           10
            1            2            5
            2            2            4
            3            1           -5
            3            3            7
           18
           20
          -15
  • Mat