0
votes

I am a fortran beginner and writing a very simple program, compiler GNU fortran.

program t1
implicit none
real :: a, b
a=35.4
CHARACTER (LEN=*) :: str = 'This is a test program'
REAL, PARAMETER :: pi = 3.14
WRITE (*,*) a
WRITE (*,*) str
WRITE (*,*) pi
end program

I got error Error: Unexpected data declaration statement at line 3

Error: Symbol 'a' has no IMPLICIT type line 4 and similar for line 8. I am not getting what is going wrong here. Can someone comment?

1

1 Answers

1
votes

Fortran has a strict order. First you declare your data, variables, types, interfaces and then you have your executable code, you cannot mix it. Use the order:

program t1

  implicit none

  real :: a, b
  CHARACTER (LEN=*), parameter :: str = 'This is a test program'
  REAL, PARAMETER :: pi = 3.14

  a=35.4

  WRITE (*,*) a
  WRITE (*,*) str
  WRITE (*,*) pi
end program