名称“1t”中的字符无效

时间:2016-12-02 00:14:06

标签: fortran

这是我的代码:

!lab 4(a) solution by James Ney
program lab4_a
implicit none
integer :: n
real :: L,R
interface
    function testFun (x)
                real :: testFun
                real, intent (in) :: x
        end function testFun
end interface

print *, "lab 4(a) solution by James Ney"
print *, "Enter left and right ends of interval and number of subintervals"

read *, L,R,n

call MeshCalcs(testFun,L,R,n)

contains

subroutine MeshCalcs(F,a,b,n)
        implicit none
        integer, intent(in) :: n
        real, intent(in) :: a,b
        real :: del,fVal,xVal
        integer :: 1t=0,gr=0,i
        real ::F,sum=0,average
        del=(b-a)/real(n)
        do i=0,n
         xVal=a+(i*del)
         fVal=F(xVal)
         sum=sum+fVal
        end do
    Average=sum/(n+1.0)
        print "('Average is: ',f10.2)",average
        do i=0,n
                xVal=a+(i*del)
                fVal=F(xVal)
                if (fVal>average) then
                 gr=gr+1
                else if(fVal<average) then
                 1t=1t+1
                end if
        end do
print "('number of function values greater than average =',i4)",gr
print "('number of function values less than average =',i4)",1t

end subroutine MeshCalcs

end Program Lab4_a

real function testFun(x)
real, intent (in) :: x
testFun=-(x-4.0)**2+9.0
end function testFun

我尝试使用gfortran编译时得到的错误是:

lab4_2a.f90:27.20:

        integer :: 1t=0,gr=0,i
                    1
Error: Invalid character in name at (1)
lab4_2a.f90:43.5:

   1t=1t+1
     1
Error: Non-numeric character in statement label at (1)
lab4_2a.f90:43.6:

   1t=1t+1
      1
Error: Invalid character in name at (1)
lab4_2a.f90:47.62:

print "('number of function values less than average =',i4)",1t
                                                              1
Error: Syntax error in PRINT statement at (1)
lab4_2a.f90:41.5:

   gr=gr+1
     1
Error: Symbol 'gr' at (1) has no IMPLICIT type
lab4_2a.f90:30.12:

        do i=0,n
            1
Error: Symbol 'i' at (1) has no IMPLICIT type

1 个答案:

答案 0 :(得分:1)

第一条错误信息非常清楚(对于那些已经知道这些东西的人来说很清楚)。在这一行

integer :: 1t=0,gr=0,i

声明的第一个变量的名称以数字1开头。 Fortran的规则要求所有名称都以字母或下划线开头。我相信这在其他编程语言中也很常见。因此1t上的编译器barfs和显示的其余错误可能是直接后果。重命名该变量,看看会发生什么。