This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Strange problem with gfortran version 4.0.2


Hello,

I admit that I am using an old version of the gfortran compiler,
so the problem I am reporting may well have been solved already.

I ran into a strange result with the program. The output is:

1.0a             -999.0000              11
1.0000e000000     1.010000               0
1.0                  1.000000               0
1.0.             -999.0000              11

I expected the value in the second column to be 1.0 or -999.0 not 1.01!

Here is the program:
! chkread.f90 --
!     Small test program to see how a compiler
!     treats malformed numbers.
!
program chkread

   implicit none
   real :: x
   integer :: i, ierr

   character(len=15), dimension(5) :: string = &
   (/ '1.0a           ', &
      '1.0000e000000  ', &
      '1.0                ', &
      '1.0.           ', &
      '1a             ' /)

   do i = 1,4
       x = -999.0
       read( string(i), *, iostat = ierr ) x
       write(*,*) string(i), x, ierr
   enddo
end program chkread

I compile with default options: gfortran -o chkread chkread.f90
The system is: Red Hat Linux.

Kind regards,

Arjen Markus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]