Book examples

Below you will find a list of the examples in "Modern Fortran in Practice", published by Cambridge University Press.

Some of the source files are additional material, most represent complete programs described in the book. All examples are presented here as is.

Note: (30 september 2012) The set of examples should be complete. Please report missing files or mistakes. The examples are also contained in this zip-file.


Creative Commons License
The examples from the book "Modern Fortran in Practice" by Arjen Markus is licensed under a Creative Commons Attribution 3.0 Unported License.

1. Introduction to Modern Fortran

histogram_f77.fHistogram example, FORTRAN 77 style
histogram_f90.f90Histogram example, Fortran 90 style
histogram.dataInput data for the histogram examples

2. Array-valued functions

performance_arrays.f90Measure the performance of array-valued functions versus do-loops
nneighbours.f90Illustrate a number-theoretical problem concerning irrational numbers
qsort_reals.f90Compact implementation of the QuickSort algorithm

3. Mathematical abstractions

automdiff.f90Module for automatic differentiation
derivative_near_singular.f90Compute the derivative near a singular point
newton_automatic.f90TODO: Use automatic differentiation for root finding
integer_set.f90Manipulate sets of integers defined by a mathematical equation
integer_set_alloc.f90(TODO) Manipulate sets of integers defined by a mathematical equation (version with allocatables)
integer_programming.f90Solve an integer programming problem (optimisation)
integer_programming_alloc.f90(TODO) Solve an integer programming problem (version with allocatables)
enum_set.f90Enumerate the member of a set of integers (Pell's equation)
pde_types.f90(Extra) Solve a partial differential equation using user-defined operations
pde_types_implicit.f90(Extra) Solve an (ordinary) differential equation using a hidden implicit method

4. Memory management

readline.f90Read a file line by line
timealloc.f90Time the cost of allocation and deallocation
timearrays.f90Measure the performance of various types of arrays
timearrays_exp.f90Measure the performance of various types of arrays (expanded version)

5. An interface problem

integrate_plain.f90Straightforward implementation of an integration routine
integrate_openmp.f90Integration via OpenMP
integrate_reverse.f90Integration via reverse communication
integrate_class_v1.f90Integration via Fortran 2003 classes, version 1
integrate_class_v2.f90Integration via Fortran 2003 classes, version 2
integrate_class_v3.f90Integration via Fortran 2003 classes, version 3
integrate_class_v4.f90Integration via Fortran 2003 classes, version 4
integrate_class_v5.f90(TODO) Integration via Fortran 2003 classes, abstract interface
test_kinds.f90Show how to use interfaces and modules for generic kinds

6. Interfacing to C: SQLite as an example

csvtable.f90Using SQLite from Fortran
somedata.csvSample CSV data file for use with cvstable.f90
test_iso_c.f90Illustrate the use of the iso_c_binding module
sqlite3_iso_c.cDummy C routine for illustration of iso_c_binding module
mkisoc.batBatch file (Windows) to create iso_c_binding example

7. Graphics, GUIs and the Internet

plotgraph.f90Plot a simple graph, using PLplot
plotgui.tclPlot a simple graph, GUI in Tcl/Tk (uses runprogram.f90)
plotgui_ext.tclPlot a simple graph, GUI in Tcl/Tk (uses extension via Ftcl)
runprogram.f90Plot a simple graph, provide the graph data
compfunction.f90Compute the function (extension via Ftcl)
XGraph.zipExample using Xeffort for GUI (from www.xeffort.com)
cgi_example.f90Simple CGI example, providing a table
cgi_start.htmlSimple CGI example, HTML file to start the example
cgi_example.cfgConfiguration file, belonging to the simple CGI example
mkcgi.batBatch file (Windows) to make CGI example
cgiserver.tclBasic CGI server
runserver.batWindows batch file to run the basic CGI server
bibliography.xmlDescription of bibliography XML files
example_bib.xmlShort example of a bibliography XML file
example_bib.xmlShort example of a bibliography XML file
select_bib.f90Select entries from a bibliography XML file (SAX style)
print_bib.f90Print the entries in a bibliography XML file (DOM style)
mkbib.shShell script to build the XML examples
mkbib.batBatch file (Windows) to build the XML examples

8. Unit testing

test_tridiag.f90Example of the use of the ftnunit unit testing framework

9. Code reviews

No examples in this chapter

10. Robust implementation of several algorithms

interp.f90Straightforward implementation of interpolation
basic_stat.f90Straightforward implementation of basic statistics
newton.f90Straightforward implementation of Newton's method for finding roots
robust_interp.f90Robust implementation of interpolation
robust_stat.f90Robust implementation of basic statistics
robust_newton.f90Robust implementation of Newton's method for finding roots

11. Object-oriented programming

points2d3d.f90Module for points in two and three dimensions
random_walk.f90Random walk in two and three dimensions
particles.f90Simplified modelling of oil particles in a (uniform) flow field
abstract_point.f90Using an abstract type and concrete types derived from it
abstract_sort.f90Generic sortable and printable types
classes_geom.f90Simple hierarchy of geometrical types
prototypes_geom.f90Use a prototype approach to exploit specific properties of geometrical types
fishes.f90Age-dependent behaviour of fishes
changing_points2d3d.f90Change the behaviour of the point2d type
mkplugin.batBatch file (Windows) to create the plugin example
prng_class.f90Base type for random-number generators (plugin example)
prng_exponential_plugin.f90PRNG for exponentially distributed numbers (plugin example)
prng_uniform_plugin.f90PRNG for uniformly distributed numbers (plugin example)
prng_factory_plugin.f90Implementation of the PRNG factory (plugin example)
prng_use_plugin.f90Main program using the PRNG factory (plugin example)
dynlib.f90Generic code for dealing with dynamic libraries (plugin example)
win_gnu_dynlib.f90Gfortran-specific code for dynamic libraries (plugin example)
win_ifort_dynlib.f90Intel Fortran-specific code for dynamic libraries (plugin example)
linux_dynlib.f90Linux-specific code for dynamic libraries (plugin example)

12. Parallel programming

primes_plain.f90Straightforward implementation of finding 1000 primes
primes_chunks.f90Finding 1000 primes by searching in "chunks" of integers
primes_openmp.f90Finding 1000 primes with OpenMP
primes_mpi.f90Finding 1000 primes with MPI
primes_coarrays.f90Finding 1000 primes with coarrays
primes_coarrays_nolock.f90Finding 1000 primes with coarrays (no critical section or locks)
dd_openmp.f90Domain-decomposition with OpenMP
dd_mpi.f90Domain-decomposition with MPI
dd_coarrays.f90Domain-decomposition with coarrays

13. Appendix A

autotools.zipZip-file with autotools example (all files included)
autotools.tgzCompressed tar-file with autotools example (all files included)
cmake.zipZip-file with CMake example (all files included)
cmake.tgzCompressed tar-file with CMake example (all files included)
test_valgrind.f90Small demonstration of valgrind's capabilities
sort_doxygen.f90Source code documentation using Doxygen
sort_robodoc.f90Source code documentation using ROBODoc
doxyfile_srcConfiguration file for Doxygen (rename to "doxygen_src")
coverage_example.f90Example showing test coverage with gfortran and gcov
coverage_example_2.f90Variant on the first example
coverage_example_3.f90Static analysis with Intel Fortran

14. Appendix B

explicit_vs_assumed.f90Interface problem with explicit-shape
check_stack.f90Problems with ever increasing automatic arrays