Programming languages must be:
totally unambiguous (unlike natural languages, for example, English);
simple to use.
Fortran Evolution
Fortran stands for FORmula TRANslation. The first compiler appeared in 1957 and
the first official standard in 1972 which was given the name of `Fortran 66'. This was
updated in 1980 to Fortran 77, updated in 1991 to Fortran 90, updated in 1997 to
Fortran 95, and further updated in 2004 to Fortran 2003, and in 2010 to Fortran 2008.
Intrinsic Types
Fortran 95 has two broad classes of object type:
numeric;
non-numeric
Character Declarations
CHARACTER :: sex
CHARACTER(LEN=10) :: name
CHARACTER(LEN=10), DIMENSION(10,10) :: Harray
Constants (Parameters)
REAL, PARAMETER :: pi = 3.141592
REAL, PARAMETER :: radius = 3.5
REAL :: circum = 2.0 * pi * radius
CHARACTER(LEN=*),PARAMETER :: son = 'bart', dad = "Homer"
Parameters should be used:
Implicit Typing
Any undeclared variable has an implicit type:

Logical Operations and Control Constructs

Formatting input and output
Control Flow
conditional execution statements and constructs, (IF ... and IF ... THEN
...
ELSE ... END IF);
multi-way choice construct, (SELECT CASE);
loops, (DO ... END DO).
IF STATEMENT
For example:
IF (bool) a = 3
IF (x > y) Maxi = x
IF ... THEN ... ELSE Construct
IF (I > 17) THEN
Write(*,*) "I > 17"
END IF
IF ... THEN .... ELSEIF Construct
IF(< logical-expression >)THEN
< then-block >
[ ELSEIF(< logical-expression >)THEN
< elseif-block >
... ]
[ ELSE
< else-block > ]
END IF
Example:-
Consider the IF ...THEN ... ELSEIF construct:
IF (I > 17) THEN
Write(*,*) "I > 17"
ELSEIF (I == 17) THEN
Write(*,*) "I == 17"
ELSE
Write(*,*) "I < 17"
END IF
SELECT CASE Construct
A simple example of a select case construct is:
SELECT CASE (i)
CASE (2,3,5,7)
WRITE(*,”(A10)”) "i is prime"
CASE (10:)
WRITE(*,”(A10)”) "i is >= 10"
CASE DEFAULT
WRITE(*,”(A26)”) "i
is not prime and is < 10"
END SELECT
An IF .. ENDIF construct could have been used but a SELECT CASE is neater and
more efficient

Multiple spaces are indicated by preceding the X by an integer count value, so 2X means skip two positions in the input line or leave two spaces in the output line.
‘(I5,I5,F9.4,F9.4,F9.4)’ can be rewritten as ‘(2I5,3F9.4)’
Do Loops
INTEGER :: i
i = 0
DO
i = i + 1
IF (i > 100) EXIT
WRITE(*,”(A4,I4)”) "I is", i
END DO
! if I>100 control jumps here
WRITE(*,”(A27,I4)”) &
"Loop finished. I now equals", i
This will generate:
I is 1
I is 2
I is 3
....
I is 100
Loop finished. I now equals 101
The EXIT statement tells control to jump out of the current DO loop.
Arrayss
Arrays (or matrices) hold collections of different values of the same type. Individual
elements are accessed by subscripting the array.
REAL, DIMENSION(15) :: X
REAL, DIMENSION(1:5,1:3) :: Y, Z ! 5 rows, 3 columns

Input/Output
Write Statement
A simple form of the WRITE statement which allows you to output to the default
output device using a default format, is:
Write(*,*)<list>
A general form of the WRITE statement which allows you to output to any device
using a specified format, is of the form:
Write(unit=u,fmt=<format_specification>)<list>
The unit number allows you to write to any device such as a file or the screen (6
specifies the screen).
READ Statement
A simple form of the READ statement which allows you to input from the default
input device using a default format, is:
Read(*,*)<list>
A general form of the READ statement which allows you to input from any device
using a specified format is of the form:
Read(unit=u,fmt=<format_specification>)<list>
The unit number allows you to read from any device such as a file or the keyboard (5
specifies the keyboard),
Reading and writing to a file
To do
this use an OPEN statement such as:
Open (unit=u, file=<file_name>,iostat=ios)
totally unambiguous (unlike natural languages, for example, English);
simple to use.
Fortran Evolution
Fortran stands for FORmula TRANslation. The first compiler appeared in 1957 and
the first official standard in 1972 which was given the name of `Fortran 66'. This was
updated in 1980 to Fortran 77, updated in 1991 to Fortran 90, updated in 1997 to
Fortran 95, and further updated in 2004 to Fortran 2003, and in 2010 to Fortran 2008.
Intrinsic Types
Fortran 95 has two broad classes of object type:
numeric;
non-numeric
- INTEGER :: age ! whole number
- REAL :: height ! decimal number
- COMPLEX :: val ! x + iy
- CHARACTER :: sex ! single character
- CHARACTER(LEN=12) :: name ! string
- LOGICAL :: wed ! truth value
- REALs contain a decimal point, INTEGERs do not;
REALs can have an exponential form;
Character Declarations
CHARACTER :: sex
CHARACTER(LEN=10) :: name
CHARACTER(LEN=10), DIMENSION(10,10) :: Harray
Constants (Parameters)
REAL, PARAMETER :: pi = 3.141592
REAL, PARAMETER :: radius = 3.5
REAL :: circum = 2.0 * pi * radius
CHARACTER(LEN=*),PARAMETER :: son = 'bart', dad = "Homer"
Parameters should be used:
- if it is known that a variable will only take one value;
- for legibility where a value such as π occurs in a program;
- for maintainability when a constant value could feasibly be changed in the future.
Implicit Typing
Any undeclared variable has an implicit type:
- if the first letter of its name is I, J, K, L, M or N then the type is INTEGER;
- if it is any other letter then the type is REAL.
Logical Operations and Control Constructs
Formatting input and output
Control Flow
conditional execution statements and constructs, (IF ... and IF ... THEN
...
ELSE ... END IF);
multi-way choice construct, (SELECT CASE);
loops, (DO ... END DO).
IF STATEMENT
For example:
IF (bool) a = 3
IF (x > y) Maxi = x
IF ... THEN ... ELSE Construct
IF (I > 17) THEN
Write(*,*) "I > 17"
END IF
IF ... THEN .... ELSEIF Construct
IF(< logical-expression >)THEN
< then-block >
[ ELSEIF(< logical-expression >)THEN
< elseif-block >
... ]
[ ELSE
< else-block > ]
END IF
Example:-
Consider the IF ...THEN ... ELSEIF construct:
IF (I > 17) THEN
Write(*,*) "I > 17"
ELSEIF (I == 17) THEN
Write(*,*) "I == 17"
ELSE
Write(*,*) "I < 17"
END IF
SELECT CASE Construct
A simple example of a select case construct is:
SELECT CASE (i)
CASE (2,3,5,7)
WRITE(*,”(A10)”) "i is prime"
CASE (10:)
WRITE(*,”(A10)”) "i is >= 10"
CASE DEFAULT
WRITE(*,”(A26)”) "i
is not prime and is < 10"
END SELECT
An IF .. ENDIF construct could have been used but a SELECT CASE is neater and
more efficient
Multiple spaces are indicated by preceding the X by an integer count value, so 2X means skip two positions in the input line or leave two spaces in the output line.
‘(I5,I5,F9.4,F9.4,F9.4)’ can be rewritten as ‘(2I5,3F9.4)’
Do Loops
INTEGER :: i
i = 0
DO
i = i + 1
IF (i > 100) EXIT
WRITE(*,”(A4,I4)”) "I is", i
END DO
! if I>100 control jumps here
WRITE(*,”(A27,I4)”) &
"Loop finished. I now equals", i
This will generate:
I is 1
I is 2
I is 3
....
I is 100
Loop finished. I now equals 101
The EXIT statement tells control to jump out of the current DO loop.
Arrayss
Arrays (or matrices) hold collections of different values of the same type. Individual
elements are accessed by subscripting the array.
REAL, DIMENSION(15) :: X
REAL, DIMENSION(1:5,1:3) :: Y, Z ! 5 rows, 3 columns
Input/Output
Write Statement
A simple form of the WRITE statement which allows you to output to the default
output device using a default format, is:
Write(*,*)<list>
A general form of the WRITE statement which allows you to output to any device
using a specified format, is of the form:
Write(unit=u,fmt=<format_specification>)<list>
The unit number allows you to write to any device such as a file or the screen (6
specifies the screen).
READ Statement
A simple form of the READ statement which allows you to input from the default
input device using a default format, is:
Read(*,*)<list>
A general form of the READ statement which allows you to input from any device
using a specified format is of the form:
Read(unit=u,fmt=<format_specification>)<list>
The unit number allows you to read from any device such as a file or the keyboard (5
specifies the keyboard),
Reading and writing to a file
To do
this use an OPEN statement such as:
Open (unit=u, file=<file_name>,iostat=ios)
Comments
Post a Comment