Reputation: 31
!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.
Upvotes: 3
Views: 1055
Reputation: 111
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.
Upvotes: 1