Can someone please explain how Fortran reads in data, particularly from text files. I thought I understood the behavior and the formatting options of I/O but the below example has me puzzled.
I am attempting to read in three values from the text file Domain.txt which contains three lines shown below
221 
500.0200 
500.0000
This file is then read by my program below
program main
implicit none
integer :: N
real    :: xmax,xmin
open(unit=1,file='Domain.txt')
read(1,*) N      ! Read first  line
read(1,*) xmax   ! Read second line
read(1,*) xmin   ! Read third  line
print*, N
print*, xmax
print*, xmin
end program
The result of this program is
      221
500.019989
500.000000
So my confusion arises with the second output for the xmax variable. Why would it read in the second line as 500.019989 and not 500.0200?
I have tried using fortran formatting format(fm.d) in the read statement to say only read in the first two digits after the decimal place, but I was never able to resolve the issue.
I am using gfortran 4.8.5. Any help would be appreciated. I also know this is somewhat a duplicate of the question asked here (Reading REAL's from file in FORTRAN 77 - odd results) but I do not have enough reputation to comment and ask a question about the solution.
 
     
    