1

Here is my code:

!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

and the errors I get when I try to compile with gfortran are:

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
J Ney
  • 11
  • 1
  • 1
    What do you think `implicit none` is for? What would be without it? – PM 77-1 Dec 02 '16 at 00:18
  • Welcome, try to use descriptive question titles and avoid unnecessary stuff like greetings and thanks in advance. Use tag `fortran` for all Fortran questions and add another tag for a specific version if you need to distinguish. – Vladimir F Героям слава Dec 02 '16 at 08:36
  • You've an answer about the current errors. As I see the statement `integer :: 1t=0,gr=0,i` I'll anticipate your [next question](https://stackoverflow.com/q/3352741/). – francescalus Dec 02 '16 at 09:27

1 Answers1

1

The first error message is quite clear (well, clear to those who already know this stuff). In this line

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

the first variable declared has a name beginning with the digit 1. Fortran's rules require that all names begin with a letter or an underscore. I believe that this is common in other programming languages too. So the compiler barfs on 1t and the rest of the errors shown are probably direct consequences. Rename that variable and see what happens.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161