Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28896 Discussions

Compilation of Legacy fortran programs

sihaqqi
Novice
2,429 Views

Hello,

In order to run legacy Fortran programs (Fortran 4 or 77), how should the compiler be configured in VB2019. I have pasted the program below which I typed from a book to see if any result can be produced. I have attached a log file as well. Thank you

............................................................................

IN = 1
OUT = 1
MAX = 80
WRITE(0UT, 101)
10 CALL INPUT(X, LENGTH, MAX)
IF (LENGTH .LT. 2) GOTO 99
CALL MEANST(X, LENGTH, MEAN, STD)
CALL 0UTPUT(X, LENGTH, MEAN, STD)
GOTO 10
99 STOP
101 F0RMAT('1 Calculation of mean',* ' and standard deviation')
END
SUBROUTINE INPUT(X, N, MAX)

10 WRITE(0UT, 101)

READ (IN, 102) N
IF (N .GT. MAX) GOTO 10
IF (N .LT. 2) RETURN
DO 20 I = 1, N
WRITE(0UT, 103) I
READ(IN, 104) X (I )
20 CONTINUE
RETURN
101 F0RMAT(' How many points? ')
102 FORMAT (I2)
103 FORMAT('+', 13, ' : ')
104 F0RMAT(F10.0)
END

SUBROUTINE 0UTPUT(X, N, MEAN, STD)

WRITE(0UT, 101) N, MEAN, STD
RETURN
101 F0RMAT(' For', 13, ' points, mean =', F8.4,* ', sigma =', F8.4)
END

SUBROUTINE MEANST(X, LENGTH, MEAN, STD)

SUM = 0.0
SUMSQ = 0.0
DO 10 I = 1, LENGTH
SUM = SUM + X(I)
SUMSQ = SUMSQ + X(I )*X (I)
10 CONTINUE
MEAN = SUM / LENGTH
STD = SQRT((SUMSQ - SUM* SUM /LENGTH ) / (LENGTH - 1 ))
RETURN
END

0 Kudos
1 Solution
Arjen_Markus
Honored Contributor I
2,371 Views

Let me elaborate:

  • Fixed form uses the sixth column to tell the compiler that the line is a continuation of the previous line.
  • Free form uses an ampersand (&) at the end of the line to tell the compiler the NEXT line is a continuation.
  • This is one of the few differences between the two forms that you are likely to encounter, besides of course the use of fixed columns.

Andrew pointed out the mistake - zero instead of Oh.

The compiler options are available by right-clicking on a file name and selecting "Properties".

View solution in original post

0 Kudos
9 Replies
Arjen_Markus
Honored Contributor I
2,420 Views

You used a file extension ".f", which indicates fixed form (at least to most compilers as the language standard is silent about this sort of things). You should indent the code properly - the first six columns are reserved.

Alternatively, you can rename the file to ".f90" or set the appropriate compiler flag so that the compiler knows free form is meant. There do not seem to be any continuation lines and that means you probaby do not have to do anything beyond that.

For future reference: use the appropriate source form. Otherwise the compiler gets confused ;).

sihaqqi
Novice
2,397 Views

Thank you Arjen, I understand you are an expert but due to my ignorance, I cannot understand your advice fully. This program is written in Fortran 77. Usually .f is the extension for Fortran 90 and before. If I rename it as .f90. it gives me errors. Please refer Build Log2

I have followed the text at https://people.cs.vt.edu/~asandu/Courses/MTU/CS2911/fortran_notes/node4.html

To change from the fixed to free form, I think I shall have to adopt syntax style of Fortran 90 and upwards.

My code as per your advice is attached in the file console9.docs.  How do I set the compiler flag for fortran in VS2019. I do not understand what you mean by

"There do not seem to be any continuation lines and that means you probaby do not have to do anything beyond that."

The source form is what is available in VS2019 to avoid compi8ler confusion. Can you please be more specific so I can grasp what you mean. 

Again thank you for your guidance.

 

0 Kudos
Arjen_Markus
Honored Contributor I
2,372 Views

Let me elaborate:

  • Fixed form uses the sixth column to tell the compiler that the line is a continuation of the previous line.
  • Free form uses an ampersand (&) at the end of the line to tell the compiler the NEXT line is a continuation.
  • This is one of the few differences between the two forms that you are likely to encounter, besides of course the use of fixed columns.

Andrew pointed out the mistake - zero instead of Oh.

The compiler options are available by right-clicking on a file name and selecting "Properties".

0 Kudos
andrew_4619
Honored Contributor III
2,385 Views

Fortran is Fortran use .f for fixed form and .f90 for free form it makes no difference if you are using features that came after f77 or not.

Your code has errors for example subroutine output had a leading zero not letter O..... 

 

andrew_4619_0-1693910894179.png

 

sihaqqi
Novice
2,290 Views

Just one thing more. I have got these errors which I cannot understand after fixing the code. What do these mean. I have checked on google and these errors have popped for different reasons for mistakes in C++ but not the mistakes I may have in my Fortran program. Thanks for advice.

0 Kudos
andrew_4619
Honored Contributor III
2,264 Views

The 2 Format lines listed are invalid Fortran format statements. If you are trying to learn Fortran you should read a text book to get some insight. In that case it looks like bad scanning again. Your final problem is that X appears to be a real array but is not declared as such in both the main programs an in the subroutines. It surprises me that this code is in a book I can't imagine it ever worked on any compiler in the past.

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,355 Views

Also, when @Arjen_Markus says "...uses sixth column...", this means that "columns" are character positions, and not visual indentations as shown by a text editor when using TAB characters.

When posting code to this forum, click on the tool bar "..." to expose additional buttons, then click on the "</>", to specify you want to insert formatted text, then click on the "Markup" button, and select "Fortran", then Paste and/or edit your code in the text box. In this manner you preserve the formatting.

With Fixed Form Fortran (Fortran IV and 77), all the lines (except continuation lines), without line numbers, must have 6 spaces at the beginning of the line. Continuation lines have 5 spaces, then in 6th column, a non-blank character, typically a digit. Numbered lines, can place the number anywhere in the first 5 columns.

 

If your acquired source code was from a scanned document (as evidenced by the zero in place of O), then you have to process the resultant document for "lint": zero vs Oh, 1 vs l, comma vs period, c vs =, ??? vs ???

 

Jim Dempsey

jimdempseyatthecove
Honored Contributor III
2,235 Views

RE: 13':' and error message

 

This actually may be a bug in the compiler, but the usage is non-conformant.

 

The 13 represents a repeat count, however, what follows is not an edit descriptor, rather it is enquoted text, yet the compiler error message states that the colon (:) was an edit descriptor as opposed to text.

 

Jim Dempsey

0 Kudos
Reply