user758077
user758077

Reputation:

Compile error for a simple Fortran 77 program

I copied and pasted in Sublime Text the following program from a Fortran 77 tutorial:

program circle
      real r, area

c This program reads a real number r and prints
c the area of a circle with radius r.

      write (*,*) 'Give radius r:'
      read  (*,*) r
      area = 3.14159*r*r
      write (*,*) 'Area = ', area

      stop
      end

I saved it as circle.f and compiled from the Terminal (macOS Sierra):

gfortran circle.f

It returned the error message:

circle.f:1:1:

 program circle
 1
Error: Non-numeric character in statement label at (1)
circle.f:1:1:

 program circle
 1
Error: Unclassifiable statement at (1)

How can I fix it? (The answer for another similar question does not solve the problem.)

Upvotes: 0

Views: 961

Answers (1)

chw21
chw21

Reputation: 8140

Fortran 77 has fixed form source. Only characters between the 7th and the 73rd column can be used for statements. (The first 6 characters are used to declare the whole line a comment, as numeric labels, or to denote this line to be a continuation of the previous.) The 74th and later characters are simply ignored.

Inside this range, spaces are ignored. So the following lines would be identical:

column   1    1    2    2    3    3    4    4
1   5    0    5    0    5    0    5    0    5
-----------------------------------------------
      if (i .le. 10) call my_sub(i)
      if(i.le.10)callmy_sub(i)
          i   f ( i. le .10) cal lmy_ sub(i)

I leave it up to you to decide which one is easiest to read.

But if you start at the first character, even with the starting "program" statement, the compiler will complain. It expected a c, C, ! (to declare the whole line a comment) or a digit as the beginning of a numeric label.

Upvotes: 2

Related Questions