Tutorial by Examples

When Fortran was originally developed memory was at a premium. Variables and procedure names could have a maximum of 6 characters, and variables were often implicitly typed. This means that the first letter of the variable name determines its type. variables beginning with i, j, ..., n are intege...
Arithmetic if statement allows one to use three branches depending on the result of an arithmetic expression if (arith_expr) label1, label2, label3 This if statement transfers control flow to one of the labels in a code. If the result of arith_expr is negative label1 is involved, if the result i...
The non-block do construct looks like integer i do 100, i=1, 5 100 print *, i That is, where the labelled termination statement is not a continue statement. There are various restrictions on the statement that can be used as the termination statement and the whole thing is generally v...
Alternate return is a facility to control the flow of execution on return from a subroutine. It is often used as a form of error handling: real x call sub(x, 1, *100, *200) print*, "Success:", x stop 100 print*, "Negative input value" stop 200 print*, "Input va...
Fortran originally was designed for a fixed format form based on an 80 column punched card: Yes: This is a line of the author's own code These were created on a card punch machine, much like this: Images are original photography by the author The format, as shown on the illustrated sample ca...
In the early forms of Fortran the only mechanism for creating global variable store visible from subroutines and functions is to use the COMMON block mechanism. This permitted sequences of variables to be names and shared in common. In addition to named common blocks there may also be a blank (unna...
Assigned GOTO uses integer variable to which a statement label is assigned using the ASSIGN statement. 100 CONTINUE ... ASSIGN 100 TO ILABEL ... GOTO ILABEL Assigned GOTO is obsolescent in Fortran 90 and deleted in Fortran 95 and later. It can be avoided in modern code by using pro...
Computed GOTO allows branching of the program according to the value of an integer expression. GOTO (label_1, label_2,... label_n) scalar-integer-expression If scalar-integer-expression is equal to 1 the program continues at statement label label_1, if it is equal to 2 it goes to label_2 and so ...
Before Fortran 95 it was possible to use assigned formats for input or output. Consider integer i, fmt read *, i assign 100 to fmt if (i<100000) assign 200 to fmt print fmt, i 100 format ("This is a big number", I10) 200 format ("This is a small number", I6) e...
Consider the program implicit none integer f, i f(i)=i print *, f(1) end Here f is a statement function. It has integer result type, taking one integer dummy argument.1 Such a statement function exists within the scope in which it is defined. In particular, it has access to variables an...

Page 1 of 1