Arrays Fortran选择排序子程序,错误,数组无法读取

Arrays Fortran选择排序子程序,错误,数组无法读取,arrays,sorting,runtime,fortran,Arrays,Sorting,Runtime,Fortran,这是我的子程序。它从打印生成的随机数的print语句中接受输入数据。打印完成后,需要将输入读入数组,在第26行出现一次尝试,即: !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(*, 3

这是我的子程序。它从打印生成的随机数的print语句中接受输入数据。打印完成后,需要将输入读入数组,在第26行出现一次尝试,即:

!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

我得到一个错误,上面写着“fortran运行时错误:浮点读取期间的错误值”。我不明白这里出了什么问题,它以前分类过,结果好坏参半。我做了一些更改,例如将temp从整数移到实数,以保留第一百位数字,现在fubar,fubar无处不在。

正如M.S.B所说,可能是您的格式造成了问题,特别是浮点格式规范。错误消息表示您的一个数据项与指定的格式(1234.56格式的浮点)不匹配。尝试删除f6.2或使用列表定向读取(假定条目之间用空格分隔)


有关格式规范严格性的更多详细信息,请参阅。

这是一种不寻常的读取格式。尝试列表定向读取:读取(*,*)zIt可能不正常,并且可能对数据文件不正确,但它本身并没有错。该格式跳过两条记录,然后开始读取(尽管t1无效)。我们需要查看数据文件,以了解格式是否正确。
read(*, 300) z(1:121)