arrays - Fortran 运行时错误 : Index '645778864' of dimension 1 of array 'tstar' above upper bound of 24

标签 arrays runtime fortran90

我编写这个程序是为了测试另一个代码,它编译得很好,但在运行时我收到了这些类型的错误:

Fortran runtime error: Index '645778864' of dimension 1 of array 'tstar' above upper bound of 24

我的代码将数据文件(对应于一天中的不同时间的 6 列和 24 行)作为输入,读取它们并在子例程“profile”中使用它们来提取新参数(u 和 tp)。我调用了作为输入的 6 列对应的向量的元素数量 (24),但不明白为什么会出现这些错误。

program test
 implicit none

 character(len=12) filein,fileout
 integer :: row,ih,i
 real :: k = 0.4
 real :: z0 = 0.0012
 real, dimension(6) :: z=(/0.5,1.,2.,4.,8.,16./)
 real, dimension(6) :: u
 real, dimension(2) :: teta,tp
 real, dimension(2) :: dt
 real, dimension(24) :: L,tstar,Ho,ustar,tk
 real :: g = 9.81

 write(*,'(2x,''File di input .......''/)')
 read(*,'(a12)') filein
 write(*,'(2x,''File di output........''/)')
 read(*,'(a12)') fileout


 open(unit=60,File=filein)
 open(unit=80,File=fileout)

 write(80,*)

  do row = 1,24    
  read(60,*) ih,ustar,tk,(dt(i),i=1,2),Ho

  teta(1) = dt(1) + tk(row)
  teta(2) = (dt(2)-dt(1)) + teta(1)

  call profile(ustar,Ho,u,teta,tp)
  write(80,*) u,tp

 enddo

close(60)
close(80)


end program test

subroutine profile(ustar,Ho,u,teta,tp)
 implicit none
 integer :: i,j,row
 integer :: N = 6
 real, dimension(24), intent(in) :: ustar,Ho
 real, dimension(24) :: tstar,L,tk
 real, dimension(6),intent(out) :: u
 real, dimension(6) :: z=(/0.5,1.,2.,4.,8.,16./)
 real, dimension(2),intent(out) :: tp
 real, dimension(2) :: teta
 real :: k = 0.4
 real :: z0 = 0.0012
 real :: g = 9.81

 tstar = 0.
 L = 0.

 tstar(row) = -(Ho(row)/(1200.*ustar(row)))
 L(row) = (tk(row)*ustar(row))/(k*g*tstar(row))

 ! convective situation
 do i=1,6
  u(i) = (ustar(row)/k)*(alog(z(i)/z0) +1. - (1. - (16.*(z(i)/L(row))))**0.25)
  if(i.le.2) then
  tp(i) = teta(i) + (tstar(row)/k)*(alog(z(i+2)) - (2.*(alog(0.5 + (0.5*(sqrt(abs(1.-(16.*(z(i+2)/L(row)))))))))))
  endif

 enddo


end 

输入文件由 6 列组成,第一列是整数(一天中的小时数),另一列对应于从行中读取的实际数量:

read(60,*) ih,ustar,tk,(dt(i),i=1,2),Ho

代码是用Fortran90编写的,我使用gfortran来编译。我不是 Fortran 专家,所以我请您不要使用过于具体的术语。

好吧,我将“row”指定为子例程的参数,但现在它给了我错误:

At line 29 of file test.f90 (unit = 60, file = 'inputver.dat')
Fortran runtime error: End of file

为什么会出现这个错误?

最佳答案

您从未设置过row,因此它包含一些任意值,在您的情况下为645778864。从您的代码中我读到 tstar 的长度为 24,因此出现错误。

您应该指定,例如作为子程序的虚拟参数。

关于arrays - Fortran 运行时错误 : Index '645778864' of dimension 1 of array 'tstar' above upper bound of 24,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26971209/

相关文章:

io - 在fortran中将大数组写入文件的最佳方法?文本与其他

c - 如何通过 C 中的函数引用来传递数组?

objective-c - 将数组存储到 SQLite 数据库中

c# - 在运行时更改代码

matplotlib 摆脱 max_open_warning 输出

c++ - 如何使用 MPI 在不同的处理器上使用相同的数组

fortran - Fortran 90 中的中点规则

arrays - 搜索某个模块以比较数组

c++ - 有序合并问题

java - 字节好友可以在运行时创建字段和方法注解吗?