Fortran 90 Program Examples

These are the program examples discussed in the Fortran 90 lecture notes "Brief Introduction to the Fortran 90 Programming language". The programs are listed in the order they appear in the notes, together with a statement of the primary concepts they illustrate. A tar archive with all the files can also be downloaded.

Sec. 2) Variable types and declarations

[real.f90] Floating-point variable declarations and assignments
[integer.f90] Integer variable declarations and maximum integer value
[complex.f90] Complex variable declarations, functions for real an imaginary parts
[logical.f90] Logical variable declarations and boolean functions
[character.f90] Character and string declarations, assignments and functions
[arrays.f90] Array declarations and basic array operations
[carray.f90] Differences between character arrays and strings

Sec. 3) Program control constructs

[if.f90] The "if...end if" construct
[case.f90] The "select case" construct
[doloop1.f90] The "do...end do" loop construct
[doloop2.f90] The "infinite do loop" construct
[goto.f90] The "go to" construct

Sec. 4) Procedures and program structures

[writerev1.f90] Internal subroutine; direct access to main program's variables
[writerev2.f90] Internal subroutine; data passing using an argument list
[writerev3.f90] External subroutine; using a dummy string of variable size
[writerev.f90] [reverse.f90] Main program and external subroutine in different files
[polyfunc.f90] External function
[funcarg.f90] External functions as procedure arguments
[common1.f90] Global data using common block
[common2.f90] Common block in include-file
[pmodule.f90] [polyarray.f90] "Module" program unit for global data and procedures
[keyword.f90] Keyword and optional arguments

Sec. 5) Intrinsic procedures

[bitops.f90] Bit operations and binary representation of integers
[cputime.f90] Intrinsic routine cpu_time() for processor time

Sec. 6) External files and output formatting

[files.f90] External files; multiple numbered files
[read.f90] Reading to the end of a file of unknown size
[formats.f90] Formatting of output
[read2.f90] The "a" format for reading character strings

Sec. 7) Allocatable, assumed-shape, and automatic arrays

[advarray.f90] Advanced array features

Sec. 8) Optional arguments in procedures

[keyword.f90] Optional arguments

Sec. 9) Random number generators

[randomnumber.f90] Test program with Fortran90 intrinsic random number generator
[ran.f90] 64-bit congruential random number generator