PHYS 580 COMPUTATIONAL PHYSICS SPRING 2005
Sample Fortran programs
Clink on the links below; you can save these files to disk and compile them.
Note: very important! To view properly, you must view as page source (open the file, and then ctrl+u) You can also right-click on the link and choose "Save Target As..."
Basic Fortran: formatting, simple input and output
Simple example of numerical differentiation of sine function
Data types, declaring variables, and intrinsic functions
Example 6 (intrinsic functions)
Do loops
Declaring and dimensioning arrays
Example 10 (how to give multiple arrays the same dimension--use of parameter statement)
Simple example of integration using trapezoidal rule
Control statements (IF...THEN) and "logical" data type
Example 13 (logical data type)
Revised example of trapezoidal rule with error traps
Subroutines and functions
Example 14 (subroutines)
Example 15 (functions)
Example 16 (advanced used of functions and subroutines)
Do...while...end do loop
Character data type
Writing to files and formatting
Example 20 (simple formatting)
Example 21 (more formatting)
Opening and closing files
Example 23 (advanced opening and closing with error traps)
Example of Gauss-Legendre quadrature: calling program and Gauss-Legendre subroutine (compile both together)
More on dimensioning arrays
Example 24 (useful example for project #2!)
Benchmark programs for testing optimization
Matrix multiplication (for tests of speed and optimization) requires library ranlib.f
Eigenvalues (requires library eiglib.f)
Package of C++ programs for benchmarking against above programs (thanks to Edgar Teran); you must do
gunzip speed.tar.gz
tar -xvf speed.tar
make -f speedeigen.mk
make -f speedmult.mk
Matlab script for benchmarking against above (thanks to Hai Ah Nam)
BLAS benchmark program for matrix multiplication (requires ranlib.f) (speedup is compiler dependent; small speedup on GNU f77 compiler, large speedup for Intel compiler)
Last modified May 3, 2005