!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
这是我的子程序。它接受来自打印生成的随机数的打印语句的输入数据。打印发生后,需要将输入读入数组,我在第 26 行进行了一次尝试,即:
read(*, 300) z(1:121)
我收到一条错误消息,提示“fortran 运行时错误:浮点读取期间的错误值”。我不明白这里出了什么问题,它以前排序过,结果好坏参半。我更改了一些内容,例如将温度从整数移动到实数以保留百分之一的数字,现在 fubar,fubar 无处不在。
最佳答案
正如 M.S.B 所说,很可能是您的格式导致了问题,特别是浮点格式规范。错误消息暗示您的数据条目之一与指定格式不匹配(1234.56 形式的 float )。尝试删除 f6.2 或使用列表定向读取(假设条目由空格分隔)。
参见 FORTRAN READ()有关格式规范严格性的更多详细信息。
关于arrays - Fortran 选择排序子例程、错误、数组无法读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13485233/