繁体   English   中英

Fortran错误含义

[英]Fortran Error Meanings

我一直在跟踪有关使用FORTRAN编写的书籍和PDF,以编写集成程序。 我使用gfortran编译代码,并获得以下错误的多个副本。

1)Unexpected data declaration statement at (1)
2)Unterminated character constant beginning at (1)
3)Unclassifiable statement at (1)
4)Unexpected STATEMENT FUNCTION statement at (1)
5)Expecting END PROGRAM statement at (1)
6)Syntax error in data declaration at (1)
7)Statement function at (1) is recursive
8)Unexpected IMPLICIT NONE statement at (1)

我不知道它们的真正含义或如何解决,Google搜索证明为null,并且我们在本网站上的其他主题涉及其他错误。 对于错误5)我像在C ++中一样放入Program main和end program main,但仍然得到相同的结果。 错误7)毫无意义,我正在尝试在程序中进行递归。 错误8)我读到隐含的无内容是为了防止不必要的减速。

糟糕的代码本身,但我对编译错误更感兴趣,因为我仍然需要微调数组数据处理,但是直到我能正常工作时,我才能这样做。

         Program main
  implicit none      
  real, dimension(:,:), allocatable :: m, oldm
  real a
  integer io, nn
  character(30) :: filename
  real, dimension(:,:), allocatable :: alt, temp, nue, oxy
  integer locationa, locationt, locationn, locationo, i
  integer nend
  real dz, z, integral
  real alti, tempi, nuei, oxyi
  integer y, j

  allocate( m(0, 0) ) ! size zero to start with?

  nn = 0
  j = 0

   write(*,*) 'Enter input file name: '

   read(*,*) filename

   open( 1, file = filename )



  do !reading in data file

   read(1, *, iostat = io) a

   if (io < 0 ) exit

   nn = nn + 1

   allocate( oldm( size(m), size(m) ) )

   oldm = m 

   deallocate( m )

   allocate( m(nn, nn) )

   m = oldm

   m(nn, nn) = a ! The nnth value of m

   deallocate( oldm )

  enddo



  ! Decompose matrix array m into column arrays [1,n]

  write(*,*) 'Enter Column Number for Altitude'
  read(*,*) locationa
  write(*,*) 'Enter Column Number for Temperature'
  read(*,*) locationt
  write(*,*) 'Enter Column Number for Nuetral Density'
  read(*,*) locationn 
  write(*,*) 'Enter Column Number for Oxygen density'
  read(*,*) locationo

  nend = size(m, locationa) !length of column #locationa

  do i = 1, nend

   alt(i, 1) = m(i, locationa)

   temp(i, 1) = log(m(i, locationt))

   nue(i, 1) = log(m(i, locationn))

   oxy(i, 1) = log(m(i, locationo))

  enddo



  ! Interpolate Column arrays, Constant X value will be array ALT with the 3 other arrays

  !real dz = size(alt)/100, z, integral = 0
  !real alti, tempi, nuei, oxyi
  !integer y, j = 0
  dz = size(alt)/100


  do z = 1, 100, dz
  y = z !with chopped rounding alt(y) will always be lowest integer for smooth transition.
  alti = alt(y, 1) + j*dz ! the addition of j*dz's allow for all values not in the array between two points of the array. 

   tempi = exp(linear_interpolation(alt, temp, size(alt), alti))

   nuei = exp(linear_interpolation(alt, nue, size(alt), alti))

   oxyi = exp(linear_interpolation(alt, oxy, size(alt), alti))
   j = j + 1



   !Integration

   integral = integral + tempi*nuei*oxyi*dz 

  enddo


  end program main


  !Functions

  real function linear_interpolation(x, y, n, x0)

   implicit none

   integer :: n, i, k

   real :: x(n), y(n), x0, y0

   k = 0


  do i = 1, n-1

   if ((x0 >= x(i)) .and. (x0 <= x(i+1))) then  

    k = i ! k is the index where: x(k) <= x <= x(k+1)
    exit ! exit loop

   end if

  enddo


  if (k > 0) then  ! compute the interpolated value for a point not in the array

   y0 = y(k) + (y(k+1)-y(k))/(x(k+1)-x(k))*(x0-x(k))

  else

   write(*,*)'Error computing the interpolation !!!'

   write(*,*) 'x0 =',x0, ' is out of range <', x(1),',',x(n),'>'

  end if

  ! return value

     linear_interpolation = y0

  end function linear_interpolation

我可以提供确切错误的更详细描述,我希望错误名称就足够了,因为每种类型我都有一些。

我想我可以在您的代码示例中发现一些严重的错误。 语法错误是exp(...语句中的括号不平衡。它们应该像这样:

tempi = exp(linear_interpolation(alt, temp, size(alt), alti) ) ! <- extra ")"
nuei = exp(linear_interpolation(alt, nue, size(alt), alti) )
oxyi = exp(linear_interpolation(alt, oxy, size(alt), alti) )

正是这样的事情可能会产生一长串令人困惑的错误,就像您得到的一样。 因此,戴夫(Dave)和乔纳森(Jonathan)给出的建议不能经常重复。

另一个错误(“无法分类的语句”)适用于您的循环:

do(i=1, nend)
! ...
do(z=1, 100, dz)
! ...

这些应写成无括号。

“数据声明错误”源于您尝试声明和初始化多个变量,例如

real dz = size(alt)/100, z, integral = 0

除了在代码中的位置不正确(如前所述)外,这只能通过双冒号分隔符完成:

real :: dz = size(alt)/100, z, integral = 0

我个人建议始终编写这样的声明。 但是,必须注意的是,像这样的初始化变量具有隐式赋予它们save属性的副作用。 这在主程序中没有影响,但重要的是要知道; 您可以通过将初始化放在单独的行中来避免这种情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM