简体   繁体   中英

What does this syntax mean in fortran?

I am working on a project and as I have not coded with Fortran before, I am struggling a lot. My professor gave me a code file which I need to fix but I don't understand the syntax.

So, in the file he has

         g = some formula,
     1        some formula
     2        * some formula
     3        / some formula.

What does 1, 2, 3, * and / do?

I asked my Professor, and he said that this is Fortran 77 code and 1, 2, 3 are used as indexing in column 6 and the g is in column 7 as that's how the Fortran code is written. But I was very confused why Fortran 77 only accepts code after column 7?

Thank you for all the replies.

What you are most likely looking at is Fixed source-form statement continuation which is part of the Fixed source form .

Fixed-form formatting is an old way of formatting code which still stems from the old punched-cards . Lines could only be 72 characters long, but sometimes you needed more. Hence, the statement-continuation character:

Except within commentary, character position 6 is used to indicate continuation. If character position 6 contains a blank or zero, the line is the initial line of a new statement, which begins in character position 7 . If character position 6 contains any character other than blank or zero, character positions 7–72 of the line constitute a continuation of the preceding non-comment line.

source: Fortran 2018 Standard, Section 6.3.3.3

Which character is used as statement-continuation marker, is up to the programmer and his style. Often you see a <ampersand>-character ( & ), or <dollar>-character ( $ ) or the <asterisk>-character ( * ) like so:

c23456789012345678901234567890123456789012345678901234567890123456789012
      g = something long
     &    + something_longer
     &    + something_even_longer

However, in the really old days, people often numbered their lines.

c23456789012345678901234567890123456789012345678901234567890123456789012
     0g = something long
     1    + something_longer
     2    + something_even_longer

and because space was limited, they removed all spaces, which sometimes becomes very confusing when you have numbers in your line:

c23456789012345678901234567890123456789012345678901234567890123456789012
     0g=1.2345+
     10.35697-
     22.5789

This does not add 10.35697 and subtract 22.5789, but adds 0.35697 and subtracts 2.5789

The usage of numbers as statement continuation markers is again inherited from the punched-cards. A single punched-card represented a single Fortran statement. And on the card, the row and column numbers were printed (Thanks to High Performance Mark for this information)

在此处输入图片说明


Note: the asterisk and slash in the OP are nothing more than the normal multiplication and division.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM