3
!find smallest number
subroutine findsmall(z, i, j, small, count0, y)
implicit none
integer:: i, j, small, count0
real:: z(121), temp, y(121)

300 format(//, t1, 9(f6.2, 2x))

read(*, 300) z(1:121)

do i=1, 120, 1

 small = i

 do j=i+1, 121, 1

  if (z(small) > z(j)) then

  small = j

  end if

 end do

temp = z(i)
z(i) = z(small)
z(small) = temp

y(i) = z(i)

count0 = count0 + 1

end do

print 300, y(1:121)
print*, count0

end subroutine findsmall

This is my subroutine. It accepts input data from a print statement that prints generated random numbers. After the print occurs, the input needs to be read into the array, an attempt I've mead occurs on line 26 which is:

read(*, 300) z(1:121)

I get an error that says 'fortran runtime error: bad value during floating point read'. I don't understand what's wrong here, it sorted before with mixed results. I changed a couple things such as moving the temp from integer to real in order to keep the hundredths place digits, and now fubar, fubar everywhere.

  • 1
    That's an unusual format for a read. Try a list-directed read: read (*, *) z – M. S. B. Nov 21 '12 at 05:30
  • It may be unusual, and it may be incorrect for the data file, but it's not in itself wrong. The format skips two records and then starts reading (though the t1 has no effect.) we'd need to see the data file to know if the format is right or wrong. – Steve Lionel Aug 02 '13 at 15:08

1 Answers1

1

As M.S.B said, it's likely your format is causing the problem, specifically the floating point format specification. The error message implies that one of your data entries doesn't match the specified format (floating point in the form 1234.56). Try either removing f6.2 or using a list-directed read (assumes entries are separated by whitespace).

See FORTRAN READ() for more details on the strictness of the format specification.

Community
  • 1
  • 1
alex_d
  • 111
  • 5