- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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".
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ;).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I wrote about source forms in Doctor Fortran in "Source Form Just Wants to be Free" - Doctor Fortran (stevelionel.com)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page