【发布时间】:2021-09-14 21:56:08
【问题描述】:
下面是当前程序,一切都检查给我,除了当我执行程序本身时,它给了我这个错误。
Fortran runtime error: Bad integer for item 1 in list input.
第一个数字是 60000。
implicit none
!declaring the single precision for real numbers, array, and variables.
integer :: i, firstnumber
real*4 :: average, sum_, standarddeviation
real*4, allocatable :: arrayone(:)!making sure that the array is single precision real
open(unit=1,file="C:\cygwin64\data sets for labs and assignments\Numbers.txt")!opening file
do
read(1,*)firstnumber!reading the first number
end do
allocate(arrayone(firstnumber))!allocating the array with the first number variable obtained from previous statement
close(1)
do i = 2, firstnumber
open(i,file="C:\cygwin64\data sets for labs and assignments\Numbers.txt")
read(i,*)
sum_ = Sum(arrayone) !sums all of the numbers from arrayone
average = Sum_/firstnumber
standarddeviation = sqrt(sum_ - average) * (sum_ - average)!calculates the standard deviation of the data set
close(i)
end do
print*,"Average = "
print*,"Standard Deviation = "
deallocate(arrayone)!Deallocating arrayone
print*,"Done!"
end program Assignmentthree
【问题讨论】:
-
看来您是作为 Fortran 初学者学习的。请注意,
real*4不是标准的 Fortran 语法,而是常见的非标准扩展。您还应该为调试付出一些自己的努力。尝试始终打印您刚刚阅读的内容并诊断从中发生的情况。 -
您尝试多次阅读
firstnumber,而不是一次,因为它处于无限循环中。这不可能是你的意思?之后使用read(i,*),您不会读取任何变量。最后,以不同的单位打开同一个文件,和读取后续行是不一样的。 -
60000不是一个坏整数,但您没有在循环中第二次读取60000:删除第一个do。你仍然不会让这个程序工作(还有很多其他问题),但第一个不必要的循环是你看到的第一个问题的(可能)原因。 -
real*4不标准与您的问题有何关系?它没有。对于初学者来说,语法是非标准的,这是一个友好的不请自来的建议。如果你的导师需要它,你无论如何都必须使用它。 -
您的老师没有教您如何调试?您必须自己或在我们的帮助下学习一些最基本的技术。就像我写的那样:在你的代码中插入一些
print语句,这样你就知道程序在做什么。让程序告诉你它每次读到了什么。
标签: arrays fortran integer gfortran