The following simple code:
program small_test
double precision :: a, b, c, d
open(5,file='infile.dat',status='old')
READ (5,*) a, b, c, d
print *, a, b, c, d
end program
works just fine when I compile with gfortran, no trap flags:
$> gfortran small_test.f90
The input data is
0.087266463 0.087266463 3. 100.
and the output is
8.7266463000000002E-002 8.7266463000000002E-002 3.0000000000000000 100.00000000000000
as expected.
But when I compile to trap floating point errors,
gfortran -ffpe-trap=invalid,zero,overflow,underflow,precision,denormal -fdump-core small_test.f90
the code fails with error
Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
How could this simple code possibly produce an error?
(What's really going on is that I am debugging a much larger code and I need the traps to find some problem somewhere else in the code. But I need to get past this trivial input statement, where they are tripping me up somehow.)