Fortan to

Keywords: fortan to
Description: NOTE: Before FORTRAN 90, most FORTRAN compilers enforced fixed-format source code . a carryover from IBM punch cards comments must begin with a * or C or ! in column 1 statement

NOTE: Before FORTRAN 90, most FORTRAN compilers enforced fixed-format source code. a carryover from IBM punch cards

  • comments must begin with a * or C or ! in column 1
  • statement labels must occur in columns 1-5
  • continuation lines must have a non-blank character in column 6
  • statements must start in column 7
  • the line-length may be limited to 72 characters (derived from the 80-byte width of a punch-card, with last 8 characters reserved for (optional) sequence numbers)

If errors are produced when you compile your FORTRAN code, first check the column alignment. Some compilers also offer free form source by using a compiler flag

If one of the input values is zero, then the program will end with an error code of "1" in the job control card listing following the execution of the program. Normal output will be one line printed with A, B, C, and AREA. No specific units are stated.

This program has two input checks: one for a blank card to indicate end-of-data, and the other for a zero value within the input data. Either condition causes a message to be printed.

In keeping with computing tradition, the first example presented is a simple program to display the words "Hello, world" on the screen (or printer).

This program prints "HELLO, WORLD" to Fortran unit number 6, which on most machines was the line printer or terminal. (The card reader or keyboard was usually connected as unit 5). The number 7 in the WRITE statement refers to the statement number of the corresponding FORMAT statement. FORMAT statements may be placed anywhere in the same program or function/subroutine block as the WRITE statements which reference them. Typically a FORMAT statement is placed immediately following the WRITE statement which invokes it; alternatively, FORMAT statements are grouped together at the end of the program or subprogram block. If execution flows into a FORMAT statement, it is a no-op ; thus, the example above has only two executable statements, WRITE and STOP .

The initial 13H in the FORMAT statement in the above example defines a Hollerith constant. here meaning that the 13 characters immediately following are to be taken as a character constant (note that the Hollerith constant is not surrounded by delimiters). (Some compilers also supported character literals enclosed in single quotes. a practice that came to be standard with FORTRAN 77.)

The space immediately following the 13H is a carriage control character, telling the I/O system to advance to a new line on the output. A zero in this position advances two lines (double space), a 1 advances to the top of a new page and + character will not advance to a new line, allowing overprinting.

As of FORTRAN 77, single quotes are used to delimit character literals, and inline character strings may be used instead of references to FORMAT statements. Comment lines may be indicated with either a C or an asterisk ( * ) in column 1.

As of Fortran 90, double quotes are allowed in addition to single quotes. An updated version of the Hello, world example (which here makes use of list-directed I/O. supported as of FORTRAN 77) could be written in Fortran 90 as follows:

The following introductory example in FORTRAN 77 finds the greatest common divisor for two numbers and using a verbatim implementation of Euclid's algorithm .

  • The PRINT and READ statements in the above use ' * ' as a format, specifying list-directed formatting. List-directed formatting instructs the compiler to make an educated guess about the required input or output format based on the following arguments.
  • As the earliest machines running Fortran had restricted character sets, FORTRAN 77 uses abbreviations such as .EQ. NE. LT. GT. LE. and .GE. to represent the relational operators =, ≠, <, >, ≤, and ≥, respectively.
  • This example relies on the implicit typing mechanism to specify the INTEGER types of NA. NB. IA. IB. and ITEMP .
  • In the function NGCD(NA, NB). the values of the function arguments NA and NB are copied into the local variables IA and IB respectively. This is necessary as the values of IA and IB are altered within the function. Because argument passing in Fortran functions and subroutines utilize call by reference by default (rather than call by value. as is the default in languages such as C ), modifying NA and NB from within the function would effectively have modified the corresponding actual arguments in the main PROGRAM unit which called the function.
  • The IMPLICIT statement can be used to specify the implicit type of variables based on their initial letter if different from the default implicit typing scheme described above. In this example, this statement specifies that the implicit type of variables beginning with the letter X shall be COMPLEX .
  • The PARAMETER statement may be used to specify constants. The second constant in this example ( XJ ) is given the complex-valued value , where is the imaginary unit .
  • The first number in the DO statement specifies the number of the last statement considered to be within the body of the DO loop. In this example, as neither the END IF nor the FORMAT is a single executable statement, the CONTINUE statement (which does nothing) is used simply in order for there to be some statement to denote as the final statement of the loop.
  • EXP() corresponds to the exponential function . In FORTRAN 77, this is a generic function. meaning that it accepts arguments of multiple types (such as REAL and, in this example, COMPLEX ). In FORTRAN 66, a specific function would have to be called by name depending on the type of the function arguments (for this example, CEXP() for a COMPLEX -valued argument).
  • When applied to a COMPLEX -valued argument, REAL() and AIMAG() return the values of the argument's real and imaginary components, respectively.

Incidentally, the output of the above program is as follows (see the article on Euler's formula for the geometric interpretation of these values as eight points spaced evenly about a unit circle in the complex plane ).

Error can be seen occurring in the last decimal place in some of the numbers above, a result of the COMPLEX data type representing its real and imaginary components in single precision. Incidentally, Fortran 90 also made standard a double-precision complex-number data type (although several compilers provided such a type even earlier).

In this example of Fortran 90 code, the programmer has written the bulk of the code inside of a DO loop. Upon execution, instructions are printed to the screen and a SUM variable is initialized to zero outside the loop. Once the loop begins, it asks the user to input any number. This number is added to the variable SUM every time the loop repeats. If the user inputs 0, the EXIT statement terminates the loop, and the value of SUM is displayed on screen.

Also apparent in this program is a data file. Before the loop begins, the program creates (or opens, if it has already been run before) a text file called "SumData.DAT". During the loop, the WRITE statement stores any user-inputted number in this file, and upon termination of the loop, also saves the answer.

Photogallery Fortan to:

Fortan Dental Care: Dog Tooth Care Products | Free P&P on orders 29+

DeviantArt: More Artists Like Into the rich by porkcow

History of FORTRAN and FORTRAN II  Software Preservation Group

Wheel Whores  View topic - Fortan wheels, any information out there?

Presentation "Chapter 2 Basic Elements of Fortan Dr. Ali Can ...


Simply Fortran from Approximatrix

My '81 Scorpion [Archive] - Japanese Nostalgic Car

DeviantArt: More Artists Like Popeye VS Fortran by NinSeMarvel

Presentation "Chapter 2 Basic Elements of Fortan Dr. Ali Can ...


Zemax - Zemax

SAPEC Agro Espaa | LinkedIn

Wheel Whores  View topic - Fortan wheels, any information out there?

Zemax - Zemax

Mercedes-AMG GT S: first ride |

He played through the entire maths class, the teacher was none the ...


Presentation "10-1. Systems Analysis & Programming 10.1 Systems ...

Approximatrix Simply Fortran Download - Softpedia

Download Approximatrix Simply Fortran 2.7 Build 1491: Complete ...