By Gisela Engeln-Müllges and Frank Uhlig (2013)
Springer
This comprehensive handbook gives an informal introduction to mathematical and computational principles governing numerical analysis, as well as practical guidelines for using over 130 elaborate numerical analysis routines. It develops detailed formulas for both standard and rarely found algorithms, including many variants for linear and non-linear equation solvers, one- and two-dimensional splines of various kinds, numerical quadrature and cubature formulas of all known stable orders, and stable IVP and BVP solvers, even for stiff systems of differential equations. The descriptions of the algorithms are very detailed and focus on their implementation, giving sensible decision criteria to choose among the algorithms and describing the merits and demerits of each one. “Numerical Algorithms with Fortran” is a depository of highly useful and effective algorithms and codes for the scientist and engineer who needs to have direct access to such algorithms. The programs have been widely field tested. The enclosed CD-ROM contains all computer codes, both for Fortran 77 and compatible with Fortran 90, a compiler, and a test bed of programs and data for most algorithms. Each program includes detailed comments and describes available options, all clearly marked, with a complete list of error codes, etc.
This page is for linking to available Fortran libraries and source code repositories. See Software repositories for collections of libraries and see Library distribution for methods for packaging and distributing Fortran libraries. Modern Fortran Libraries and Awesome Fortran are other lists of libraries.
Libraries linked here are classified as follows:
When available, the above tags should link to the license page for a particular library.
Fortran Standard Library - Utilities (containers, strings, files, OS/environment integration, unit testing & assertions, logging, …) Algorithms (searching and sorting, merging, …) Mathematics (linear algebra, sparse matrices, special functions, fast Fourier transform, random numbers, statistics, ordinary differential equations, numerical integration, optimization, …)(OS: MIT)
BeFoR64 - Base64 encoding/decoding library for FoRtran poor men, is a pure Fortran (KISS) library for base64 encoding/decoding for modern (2003+) Fortran projects. (OS: GPL)
coretran - easy-to-follow library to make Fortran easier in general with wrapped interfaces, sorting routines, kD-Trees, and other algorithms to handle scientific data and concepts.
erloff - make error-handling in Fortran a bit more flexible (OS: MIT)
fdict - native Fortran 90 dictionary with hash tables for retaining any data-type in a Python-like dictionary. (OS: MPL-2)
ferror - library to assist with error handling in Fortran projects.
ffhash generic and fast hash table similar to khash in C, by Jannis Teunissen.
FGSL - Fortran interface to the GNU Scientific Library. (OS: GPL)
FIAT - Fortran Implementation of Abstract Types
flib - standard library, function library, a tridiagonal matrix solver, and code for a doubly linked list, optimization, and interpolation. (OS: GPL-3.0 License)
FLIBS - collection of Fortran modules by Arjen Markus and Michael Baudin. (OS: BSD)
flink - Flexible Fortran Modules and Subroutines for Scientific Computing. (OS: GPL-3.0 License)
Focal - modern Fortran module library which wraps calls to the OpenCL runtime API with a higher abstraction level appropriate to the Fortran language. (OS: MIT)
forpy - use Python in Fortran and vice versa. (OS:LGPL)
FortranCL - Fortran interface for OpenCL, allows to execute code on GPUs and accelerators directly from Fortran. (OS: LGPL)
FortCUDA - Fortran interface to the CUDA GPU library. Contains a Python pre-processor to parse the CUDA C headers and creates ISO_C_BINDING interfaces for the method calls. Comes with a fairly complex example. (OS: GPL)
Fortran exceptions library - provides exception handling for Fortran 2003 and later, based on the methodology of Poppe et al. 2012 (OS: MIT)
fortranlib - Collection of personal scientific routines in Fortran. (OS: BSD-2-Clause License)
Fortran-Library - Code for geometry transformations, nonlinear optimization, Fourier transforms, clustering, statistics, mathematics, linear algebra, strings, and chemistry. (OS: GPL-3.0 License)
fortran_notes - containers and advanced data structures, hash functions, and design patterns (OS: MIT)
Fortran Template Library (FTL) - generic containers, versatile algorithms, easy string manipulation, and more. (OS: GPL-3)
Fortran Template Library (FTL) - Object oriented implementation of generic containers similar to the C++ STL (Standard Template Library) in native Fortran 2003. (OS: LGPL-3)
fortran-utils - Various utilities for Fortran programs, including types, constants, sorting, saving/loading 2D arrays, meshes, cubic splines, saving/loading PPM images, Lapack interface, HDF5 interface, special functions, and optimization, by Ondrej Certik et al.
ForUtils - Fortran 2008 utility functions and reusable classes
FTObjectLibrary - provides a collection of reference counted Fortran 2003 classes to facilitate writing generic object oriented Fortran programs (OS: MIT)
functional-fortran - library for functional programming in modern Fortran. (OS: BSD)
fycollections - generic collection templates for Fortran
IMSL - most comprehensive mathematics and statistics library available. (C)
JAMS - collection of general Fortran modules offering miscellaneous functions in the categories Computational, Date and Time, Input / Output, Math / Numerics, Screening, Sensitivity Analysis and Optimising / Fitting, and Miscellaneous. Written by Matthias Cuntz, Juliane Mai and Stephan Thober. (OS: MIT)
jsonff - Fortran library for dealing with JSON data (OS: MIT)
json-fortran - Fortran 2003/2008 JSON API. (OS: BSD)
kdtree2 - kd-tree implementation in C++ (and Fortran) by Matthew B. Kennel
libGPF - General Purpose Fortran Collection. Updated at GitHub.(OS: MIT)
NAG - world’s largest collection of robust, documented, tested and maintained numerical algorithms for users of the Fortran programming language. (C)
NEC Numeric Library Collection - collection of mathematical libraries that powerfully supports the development of numerical simulation programs in a wide range of fields. The libraries are available on Vector Engine. (C)
NPY-for-Fortran allows the developer to save Fortran arrays in Numpy’s .npy format. (OS:MIT)
parff - (almost) functional style parser combinator library for Fortran (OS: MIT)
PENF - Fortran (standard 2003) module useful to achieve portable codes. The module makes available portable kind-parameters and some useful procedures to deal with them. (OS: GPL)
petaca - collection of modern Fortran modules that provide broadly useful capabilities – things that the author has found himself using repeatedly across many projects. A unifying feature of the modules is their object-oriented interfaces and implementation. (OS:MIT)
qContainers - container library for Fortran language. It enables to store any internal Fortran data type and any derived data type to the container. It implements containers for key/value pairs: tree table and hash table, and containers for objects: list and vector. (OS: BSD)
Processor - F95 compliant general purpose library version 1.8.6 with HTML documentation. Covers string/array manipulations, stacks, hashes, noise, interpolation, smoothing, physical constants, and dates. Includes wrapper modules for several OS/compiler combinations for specific system access functions.(OS: LGPL)
S-EXPTRAN - Fortran library for reading and writing S-expressions. (OS: MIT)
VectorClass Fortran 2003 dynamic memory array that functions similarly (but not identically) to the C++ Vector class, by Tyler Chang. (OS: MIT)
Fortran Character String Utilities - library of string manipulation routines by George Benthien
fortran_pcre - Fortran wrapper around the C PCRE regular expression library. (OS:MIT)
regex-fortran is a Fortran-based basic RegEx package
M_matchis a Fortran-based basic RegEx package
fortran-unix contains a RE interface
M_regex builds on the Wiki example to call Posix RE procedures
GTKcontains a RE interface
regexp provides a RE interface
iso_varying_string - implementation of the ISO standard for varying strings (OS: MIT)
M_strings - modules for processing strings. Routines for parsing, tokenizing, changing case, substituting new strings for substrings, locating strings with simple wildcard expressions, removing tabs and line terminators and other string manipulations are included. (OS)
strff - library of convenient string functions (OS: MIT)
fortran-regex is a full regex module implemented in modern Fortran, with no external dependencies. (OS: MIT)
afnl - Fortran 90 numerical library with modules for numerical types, constants, error handling, integration, optimization, linear algebra, sorting and search, special functions, statistics, polynomials, root-finding, Fourier transforms, and dates and times, by Alberto Ramos (OS: GPL-2.0 License)
ARPREC - C++/Fortran 90 library for arbitrary precision math. Includes a complete interactive high-precision arithmetic computing interpreter (“toolkit”) written in Fortran, that will integrate symbolic expressions etc. (OS: BSD)
CERNLIB - collection of FORTRAN 77 libraries and modules maintained by CERN. (OS: GPL)
datapac - Fortran 77 statistical library written by James Filliben (at NIST) (PD)
DATAPLOT - powerful and flexible program for performing scientific, engineering, statistical, mathematical, and graphical analysis. At GitHub
Emmix Fits a mixture model of multivariate normal or t-distributions to a user supplied data set via the EM algorithm. With gfortran, must be compiled with -std=legacy option.
faiNumber-Fortran - A fast, flexible, and secure numerical library for Fortran with fast number parsing as one of its features. (OS: MIT)
FMLIB - David M. Smith’s libraries for multiple precision computation. The package performs multiple-precision real, complex, and integer arithmetic, providing the intrinsic Fortran numerical functions, as well as many special functions. An existing Fortran program can be checked by converting it from double precision to FM arithmetic. (NC)
forSISL - Modern Fortran interfaces to the SINTEF Spline Library (SISL)
fundamental_constants - Fortran modules with the CODATA fundamental physical constants, generated by a Python script.
FURY - Fortran Units (environment) for Reliable phYsical math, by Stefano Zaghi
GMP Fortran library - Fortran binding for GNU Multiple Precision Arithmetic library.
HSL Mathematical Software Library - free for academic use.
lookup_table_fortran A module for linear lookup tables. Supports multiple columns and various ways to read values from the table.
MP - Fortran multiple-precision arithmetic package by Richard Brent.
MPFUN2020 - thread-safe arbitrary precision package by David H. Bailey
MPFUN90 (broken link) - a pure Fortran 90 library for arbitrary precision math. Includes a complete interactive high-precision arithmetic computing interpreter (“toolkit”) written in Fortran, that will integrate symbolic expressions etc. (OS: BSD)
Muesli - A free numerical and graphical Fortran 95 library written by Edouard Canot at Univ of Rennes (?)
National Wind Technology Center Subroutine Library - A library of general-use Fortran 2003 routines used in many NWTC computer-aided engineering tools (OS: GPL)
NumDiff - A modern Fortran numerical differentiation library by Jacob Williams (OS: BSD).
NumericalHUB - Set of modern Fortran numerical libraries covering: zeroes of Systems of Equations, Lagrange Interpolation, Finite Differences, Cauchy Problems, Boundary Value Problems, and Initial Boundary Value Problems, associated with book How to learn Applied Mathematics through modern FORTRAN
Numerical methods in Fortran - solving linear, nonlinear equations, integral, ordinary differential equations, … using numerical methods in Fortran, by Carlos Planelles Alemany
Numerical methods in Fortran - numerical analysis and statistics algorithms, by Murat Koptur.
Numerical Methods for Scientists and Engineers, code in Fortran 77 and C from book by H. M. Antia (OS: GPL-2.0 License)
Numerical Methods of Statistics, Fortran 95 code from book by John Monahan.
SLATEC - Common Mathematical Library: a comprehensive software library containing over 1400 general purpose mathematical and statistical routines written in Fortran 77. (PD)
SLATEC - Fortran 90 version by John Burkardt. (?)
SLICOT - The Control and Systems Library (GPL)
starpac, Standards Time Series and Regressions Package in Fortran 77(PD), translated to Fortran 90 here.
stspac, A Fortran 77 statistical library written by Charlie Reeves (at NIST) (PD)
TOMS - code from the journal Transactions on Mathematical Software. Many programs were translated to Fortran 90 by Alan Miller and John Burkardt
physunits - Automated Computation and Consistency Checking of Physical Dimensions and Units in Scientific Programs, by Grant Petty
quaff - A library for making math with units a lot easier and more convenient (OS: MIT)
SciFortran - A library of fortran modules and routines for scientific calculations (in a way just like scipy for python). (OS: LGPL-3.0 License)
Simfit - package for simulation, statistical analysis, curve fitting and graph plotting, using models from a compiled library or from ASCII text files supplied by the user. Source code for over two hundred NAG library subroutines called by the Academic version of the Simfit package is available.
Tensor Toolbox for Modern Fortran (ttb)(OS: MIT License)
Freely Available Software for Linear Algebra (September 2018)
arpack-ng is a collection of Fortran77 subroutines designed to solve large scale eigenvalue problems.
BLAP95 (broken link) - a Fortran 95 interface to the Level 3 BLAS routines and key LAPACK computational and driver routines. (?)
BLAS: Basic Linear Algebra Subprograms that provide standard building blocks for performing basic vector and matrix operations (PD). Also OpenBLAS
DBCSR - Distributed Block Compressed Sparse Row matrix library (OS: GPL-2.0 License)
ELPA - Eigenvalue Solvers for Petaflop Applications (OS: LGPL-3.0)
LAPACK is the standard package for numerical linear algebra. (OS: BSD)
LIBXSMM - library for specialized dense and sparse matrix operations as well as for deep learning primitives such as small convolutions.
linalg - linear algebra library that provides a user-friendly interface to several BLAS and LAPACK routines. (OS:GPL-3.0 License)
Fortran_Davidson - Modern Fortran implementation of the Davidson diagonalization algorithms. (OS:Apache-2.0 License)
fortran_lsp - Fortran routines from “Solving Least Squares Problems” by C. Lawson and R. Hanson, with improved interfaces.
JADAMILU - computes eigenvectors of large sparse symmetric matrices. Provided as a precompiled library
MUMPS - parallel sparse direct solver
NTPoly - massively parallel library for computing the functions of sparse matrices.(OS: MIT License)
PROPACK - set of functions for computing the singular value decomposition of large and sparse or structured matrices. GitHub
PSBLAS3 - Parallel Sparse Basic Linear Algebra Subroutines (OS: BSD)
qrupdate - library for fast updates of QR and Cholesky decompositions.
qr_mumps - package for the solution of sparse, linear systems on multicore computers
Sparskit - basic tool-kit for sparse matrix computations (Version 2)
UMFPACK Fortran interface - mUMFPACK module provides a Fortran-2003 implementation of the full UMFPACK interface closely corresponding to that defined in the UMFPACK User Guide.
Alan Miller’s Fortran Software for subset selection in regression, random number generation, logistic regression, linear least squares, and other topics.
apstat, a collection of subroutines (AS1 - AS319) published in the journal Applied Statistics 1968-1994. Most are Fortran. Personal favourites include AS319 and AS164. Many have been translated to Fortran 90 by John Burkardt and Alan Miller
BMSL mathematical and statistical libraries, geared toward environmental / hydrological applications, by Ben Renard.
Climate time series analysis by Manfred Mudelsee.
CONFINT - sample size calculation for confidence intervals
datapac, A Fortran 77 statistical library written by James Filliben (at NIST) (PD)
Fast Statistical Methods, by Rybicki and Press.
Fortran Programs for Global Optimization, etc programs for econometric analysis such as Non-linear Least Squares, Robust Regression, Robust Two-Stage Least Squares, Ordinal Canonical Correlation, Ordinal Principal Component Analysis, Hybridization of canonical correlation and principal component analysis, fitting origin-displaced logarithmic spiral to data, solving the nearest correlation matrix problem, completing the correlation matrix, construction of composite indices by linear aggregation, etc. some of which are based on global optimization.
Least squares approximations in Fortran 90 by J-P Moreau. Also statistical programs in Fortran
MCMC f90 library - do Markov chain Monte Carlo simulation from a posterior distribution of unknown model parameters defined by a likelihood function and prior
MISCLIB, a library of statistical and support routines, written by Barry Brown (M.D.Anderson Cancer Institute) - open source
Modified Burg Algorithms in Multivariate Subset Autoregressive Modeling by A. Alexandre Trindade
MultiNest - Bayesian inference tool which calculates the evidence and explores the parameter space which may contain multiple posterior modes and pronounced (curving) degeneracies in moderately high dimensions, by Farhan Feroz and Mike Hobson
Multiple stream Mersenne Twister pseudorandom number generator (OS: BSD)
Multitaper Spectrum Estimation Library by Germán A. Prieto.
Multivariate Data Analysis Software in Fortran (and C) by Fionn Murtagh
Nonsmooth Clustering by Napsu Karmitsa. Also codes for regression and imputation
Oak Leaf - robust statistical estimates by Filip Hroch
ParaMonte - Plain Powerful Parallel Monte Carlo and MCMC Library for Python, MATLAB, Fortran, C++, C (OS: MIT License)
Random by Richard Brent. ranut is a uniform pseudo-random number generator which uses recurrences based on primitive trinomials, or in some cases trinomials which have large primitive factors (over the field GF(2)). rannw is a Fortran 77 pseudo-random number generator which uses a variant of Chris Wallace’s method to generate normally distributed (i.e. Gaussian) numbers.
RANDLIB - routines for nonuniform random number generation
rng_fortran, Fast pseudorandom number generator based on Xoroshiro128+. Supports OpenMP.
SLICE, efficient N-Dimensional Monte Carlo inversion algorithm.
STATPACK - Fortran 95/2003 library for solving the most commonly occurring mathematical and statistical problems in the processing of (huge) climate model outputs and datasets, and more generally in data analysis
stspac, A Fortran 77 statistical library written by Charlie Reeves (at NIST) (PD)
SEQBIN - Bayesian/Frequentist Designs for Sequential/Group-Sequential Trials of a Single Binomial Parameter
STPLAN - performs power, sample size, and related calculations needed to plan frequentist studies
TIMSAC package for analysis, prediction and control of time series
Applied Statistics algorithm 298 Hybrid minimization routine using simulated annealing and a user-supplied local minimizer.
Applied Statistics algorithm 319 Variable metric unconstrained function minimization without derivatives.
cobyla.f90 Mike Powell’s routine for minimization of non-linear functions with smooth non-linear constraints, using local linear approximations to the constraints.
conmin.zip The classic CONMIN package for constrained minimization updated to Fortran 90.
CUTEst - Constrained and Unconstrained Testing Environment with safe threads for optimization software
DualSimplex Fortran 90 module for solving linear programs of the form max c^T x s.t. A x <= b where, c is a cost vector and A x <= b is a system of linear inequality constraints, by Tyler Chang.
FilterSD - Fortran 77 subroutines for solving nonlinear programming problems and linearly constrained problems in continuous optimization
GALAHAD is a library of modern Fortran modules for nonlinear optimization. (OS: lgpl-3.0)
global.f90 At Arnold Neumaier’s site, this is recommended as the most successful of the global optimization packages.
libga - genetic algorithm optimisation library by Alberto Ramos
lm.zip Levenberg-Marquardt algorithm for non-linear least squares (unconstrained). This is a translation of the MINPACK routines, LMDER & LMDIF.
minim.f90 The Nelder-Mead simplex algorithm for unconstrained minimization. It does NOT require or use derivatives.
MINPACK contains routines for solving nonlinear equations and nonlinear least squares problems. (OS: BSD)
minuit - Fortran 77 library for function minimization and error Analysis by F. James (OS: GPL-2.0)
NLopt - NLopt is a free/open-source library for nonlinear optimization, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms. By Steven G. Johnson (OS: GNU LGPL)
NonSmooth Optimization (NSO) Software by Napsu Karmitsa and coworkers
Optimization codes by Andrei Neculai THREECG: A simple three-term conjugate gradient algorithm which satisfies both the descent and the conjugacy conditions. DESCON: Conjugate Gradient Algorithm with guaranteed descent and conjugacy conditions for large-scale Unconstrained Optimization. ASCALCG: Accelerated Scaled Conjugate Gradient Algorithms for Unconstrained Optimization. AHYBRIDM: Accelerated Hybrid Conjugate Gradient Algorithm with Modified Secant Condition for Unconstrained Optimization. CONMIN: Shanno Conjugate Gradient with Beale restart memoryless variable metric algorithm for Unconstrained Optimization. ASA: Anticipative Scalar Approximation of Hessian for Unconstrained Optimization. RELAXED: Relaxed Gradient Descent Method with Backtracking for Unconstrained Optimization. UNO Fortran subroutines library for unconstrained optimization using searching methods.SPENBAR Sparse PENalty BARrier package for solving general nonlinear programming problems with equality and inequality constraints and simple bounds on variables. All the constrained are penalized. Minimization of the penalty function is given by TN package of S. Nash. FIBO Fibonacci method for function minimization. MAXFUN Powell direct search method for function maximization. ZERO Simple algorithms for computing zeros of a nonlinear function of a variable in a given interval.
PCx - interior-point predictor-corrector linear programming package
pikaia - Modern Fortran Edition of the Pikaia Genetic Algorithm by Jacob Williams
Software by M. J. D. Powell and Powell’s Derivative-Free Optimization solvers (PDFO) by Zaikun Zhang
PowellOpt is a collection of derivative-free optimization algorithms by M.J.D. Powell.
qnstop suite of serial and parallel Fortran 95/2003 codes for deterministic global optimization and stochastic optimization by Layne Watson.
RALFit - non-linear least squares solver that is primarily developed by the Numerical Analysis group at STFC Rutherford Appleton Laboratory.
Roots of a real function in Fortran 90 by J-P Moreau
simulated-annealing - Simulated Annealing with Modern Fortran by Jacob Williams
tapenade - tool for automatic differentiation (forward/reverse) of Fortran and C programs
TENSOLVE contains both TOMS 739 (UNCMIN) for unconstrained minimization, and TOMS 768 (TENSOLVE) for the solution of sets of non-linear equations.
TOMS algorithm 778 solves bound-constrained optimization problems by using the compact formula of the limited memory BFGS updates.
TOMS algorithm 813 is for local minimization, with or without convex constraints. It requires the user to supply first derivatives. This version is in standard Fortran. It uses the so-called spectral projected gradient (SPG) method.
tn.zip Stephen Nash’s truncated-Newton code for the minimization of continuous functions. It can use differences instead of derivatives, and bounds may be imposed on the parameters.
tron.zip Newton’s method for large bound-constrained optimization problems by Chih-Jen Lin & Jorge More’, a MINPACK-2 project.
uobyqa.f90 Mike Powell’s package for unconstrained minimization when derivatives are not available.
VTDIRECT95: Fortran 95 implementation of D. R. Jones’ deterministic global optimization algorithm called DIRECT, which is widely used in many multidisciplinary design optimization problems
autofit is a Fortran code for fitting permutationally invariant polynomials (PIPs). (OS: Apache-2.0 License)
FortLearner - linear regression, logistic regression, stochastic gradient descent, decision trees, ensemble trees, boosting trees, and dimension reduction.
gpf - small Fortran library for Gaussian process regression. It currently implements value predictions with dense Gaussian processes, and projected-process approximate Gaussian processes. (OS: Apache-2.0 License)
neural-fortran is a parallel neural net microframework. (OS: MIT)
NN_MOD - Fortran 2008 Module/Class for training neural network regressors
accis - Fortran plotting and graphics library
cairo-fortran: Fortran bindings for libcairo. (GPL v3)
DISLIN - high-level scientific data plotting library. (NC)
EGGX/ProCALL - X11 graphics library for C and FORTRAN created to achieve extreme simplicity. Uses only (OS: GPL)
gtk-fortran - cross-platform library to build Graphical User Interfaces (GUI). It is a GTK / Fortran 2003 binding based on the ISO_C_BINDING module. (OS: GPL)
GNUFOR2 - Fortran 90 interface to Gnuplot which helps to plot graphs, surfaces, histograms and images. (?)
GnuplotFortran - Fortran Interface to Gnuplot. (OS: LGPL)
F03GL - Fortran 2003 bindings for OpenGL, GLU and GLUT (?)
F90GL - Fortran 90 bindings for OpenGL and the GL Utility Toolkit (GLUT) (PD)
ForColormap - A colormap fpm library independent of any graphical toolkit.
fortran-sdl2 - Fortran interface to Simple DirectMedia Layer 2.0 (SDL 2.0). It uses the ISO_C_BINDING module. (OS: ISC)
fortran-xlib - interface to (a subset) of Xlib. (OS: ISC)
g2 - easy to use, portable and powerful 2D graphics library. Currently supported devices: PostScript, X11, PNG and JPEG (using gd) and Win32 (xfig in development). g2 is written in C (ANSI) and has a Fortran interface. (OS: LGPL)
g95gl - alternate Fortran 95 (interop) bindings for OpenGL and the GL Utility Toolkit (GLUT)
giza - scientific plotting library for C/Fortran, meant as a replacement for pgplot, by Daniel Price
Graph2D - cross-platform scientific plotting library, backward compatible with the Tektronix “Plot 10” and “Advanced Graphing II” API. Usable in interactive and/or batch mode. (OS: LGPL V3.0)
grapheps - port of a very compact Postscript library
GrWin - Windows graphics library for FORTRAN and C.
libvogle - basic vector-based graphics library in C, but Fortran-callable
Lib_VTK_IO - pure Fortran library to write and read data conforming the VTK standard. This library is not a porting or a wrapper of the VTK code, but it is only an exporter/importer of VTK data format written in pure Fortran language (standard Fortran 2003). (OS: GPL)
MathGL - library for making high-quality scientific graphics under Linux and Windows via Qt, FLTK or OpenGL. (OS: GPL)
ogpf - object-based Fortran 2003/2008 code for 2D, 3D plotting and animation, implements an interface to gnuplot. On GitHub: ogpf (PD)
plotterf90 - graphics subroutine library producing Postscript written by Masao Kodama. (?)
pltFor - Fortran-Python interface library to plot figures directly in Fortran, by DamienMinenna
Pyplot-Fortran - simple module for generating plots from Fortran using Python’s matplotlib.pyplot.
text_viz - Text-mode 2D-Graphics for Fortran. (?)
Fortran and Matlab Codes for differential equations - from Ernst Hairer
FOODIE - Fortran Object-Oriented Differential-equations Integration Environment.
ODEPACK is a systematized collection of ODE solvers. (PD)
PETSc The Portable, Extensible Toolkit for Scientific Computation (PETSc, pronounced PET-see; the S is silent), is a suite of data structures and routines developed by Argonne National Laboratory for the scalable (parallel) solution of scientific applications modeled by partial differential equations.
PoisFFT - Free parallel fast Poisson solver.
numerical-anal boundary value problems and heat transfer.
Differential equations in Fortran by J-P Moreau
dop853 - Modern Fortran Edition of Hairer’s DOP853 ODE Solver, by Jacob Williams
ddeabm - Modern Fortran implementation of the DDEABM Adams-Bashforth algorithm, by Jacob Williams
INTEGRAL - routines for the integration of functions of various types and for integration of systems of ordinary differential equations (ODEs)
Quadrule - sets up a variety of quadrature rules, used to approximate the integral of a function over various domains in 1D, by John Burkardt. He has many other quadrature codes linked there
quadrature-fortran - Adaptive Gaussian Quadrature with Modern Fortran, by Jacob Williams
stroud - routines from the book Gaussian quadrature formulas by Stroud & Secrest (1966), translated to modern Fortran by Ivan Pribec
Fortran-parallel-sort Fortran library to perform parallel sorts using OpenMP, by Corentin Cadiou (OS: CC0-1.0 License)
hs-sort sorting routines in Fortran 77 by Houlsby & Sloan, with a modern Fortran wrappers by Ivan Pribec
ORDERPACK - library with routines for unconditional, unique, and partial ranking, sorting, and permutation. (?)
DelaunaySparse serial and parallel codes, written in FORTRAN 2003 with OpenMP 4.5, for performing interpolation in medium to high dimensions via a sparse subset of the Delaunay triangulation.
bspline-fortran - multidimensional B-spline interpolation of data on a regular grid, by Jacob Williams.
finterp - multidimensional linear interpolation with modern Fortran, by Jacob Williams.
WenOOF - WENO interpolation Object Oriented Fortran library
NIST Digital Library of Mathematical Functions has a software index for special functions
Special functions in Fortran 90 and Bessel programs in Fortran 90 by J-P Moreau
Special_Functions translated code from book “Computation of Special Functions” by Shanjie Zhang and Jian-Ming Jin to Fortran 90 by John Burkardt. Links to other codes for special functions are provided.
FFTPack provide an easily usable package of functions using FFTPack library (Fortran 77).
fftpack51 computes the Fast Fourier Transform, using double precision arithmetic, translated to Fortran 90 by John Burkardt
fortran-csv-module - read and write CSV Files using Modern Fortran.
csvio-f90, the CSVIO F90 module, is a Fortran 90 module for easily reading and writing CSV files. (OS: BSD)
WKML is based on FoX, and writes KML (Keyhole Markup Language). (OS: BSD)
xml (?)
xml-fortran (OS: BSD)
fortranposix - An implementation of some POSIX functions in Fortran 90/95. (OS: LGPL)
fortyxima/filesys - Modern Fortran wrappers around the file system interface of libc as part of the Fortyxima library: rename and remove files, recursively create and remove directories, obtain filenames in a directory, check whether a given file exists and if a directory or a symbolic link, obtain the current working directory and change to a directory, create hard links and symbolic links, resolve the target of symbolic links, canonize path names. Fortyxima/filesys replaces the old modfilesys library. (OS: BSD)
Posix90 - The Fortran 90 Posix interface project. (OS: GPLv2+)
This page is for selected links to source code for or descriptions of applications written in Fortran. These might be examples of contemporary “real-world” programs, or educational older codes. There are thousands of currently active examples across the sciences.
See Software repositories for collections of libraries and see Library distribution for methods for packaging and distributing Fortran libraries.
http://www.dmoz.org/Computers/Programming/Languages/Fortran/Source_Code/
http://gcc.gnu.org/wiki/GfortranApps Code that works with gfortran
http://g95.org/g95_status.shtml Code that works with g95
http://www.easterbrook.ca/steve/?p=1558 discusses why a lot of climate models are written in Fortran.
This is 830k LOC
http://www.metoffice.gov.uk/science/creating/daysahead/nwp/um.html
http://www.nemo-ocean.eu NEMO (Nucleus for European Modelling of the Ocean)
http://www.nemo-ocean.eu/content/download/250/1629/file/coding_rules_OPA9.pdf Their Fortran 95 Coding Rules.
http://www.giss.nasa.gov/tools/modelE/ The most recent GISS model.
http://ftp.giss.nasa.gov/pub/modelE/modelE1.tar.gz Source code.
http://igcmg.ipsl.jussieu.fr/Doc/IPSLCM4 IPSL Climate model documentation.
http://tddft.org/programs/octopus The Octopus code.
http://www.cfs.dl.ac.uk/gamess-uk/index.shtml GAMESS UK home page.
http://www.msg.chem.iastate.edu/gamess/ GAMESS US home page.
https://www.cp2k.org/ CP2K is a Fortran2003 program to perform simulations of solid state, liquid, molecular and biological systems.
OFF an Open source Finite volumes Fluid dynamics code.
GENEUS is an open-source Fortran 2008 program for simulating superconductor/ferromagnet nanostructures. It is based on the Usadel quantum diffusion equation, and supports nonequilibrium calculations, self-consistent calculations, and uses convergence acceleration algorithms to remain fast for tricky problems.
http://aa.usno.navy.mil/software/novas/novas_f/novasf_intro.phpNaval Observatory Vector Astrometry Software. Used to prepare the U.S. parts of The Astronomical Almanac.
http://www.rickadams.org/adventure/e_downloads.html Adventure.
Several versions of Zork were ported to Fortran:
http://mirror.ifarchive.org/if-archive/games/source/dungeon-2.5.6.tar.gz
And of course, Star Trek:
http://startrek-f95.sourceforge.net/
ForSudoku - A Fortran sudoku generator and solver.
PL/M Compiler. Fortran IV code that does compile using gfortran. PL/M is the language that CP/M was written in (see http://www.cpm.z80.de/source.html for more details).
“The VCU nuclear reactor simulator, Richmond Pile 3, is a classroom and research tool that emulates a large commercial pressurized water reactor (PWR).” It uses gtk-fortran.
Alam, Shahid (2014). Is Fortran Still Relevant? Comparing Fortran with Java and C++ International Journal of Software Engineering & Applications (IJSEA), Vol.5, No.3, May 2014.
Chin, L. S., D. J. Worth and C. Greenough (2006). Thoughts on using the Features of Fortran 95. Software Engineering Group Notes no. SEG-N-003.
Cohen, M. (1999). Object orientation and Fortran 2002: part II. ACM SIGPLAN Fortran Forum 18, 14–21.
Decyk, V. K., C. D. Norton, and B. K. Szymanski. (1997). Expressing Object-Oriented Concepts in Fortran 90. ACM SIGPLAN Fortran Forum 16, 13–18.
Diaz, Javier, Marco Pinna, Andrei V. Zvelindovsky, and Ignacio Pagonabarraga (2021). Parallel Hybrid Simulations of Block Copolymer Nanocomposites using Coarray Fortran. Macromolecular Theory and Simulations.
Erwig, Martin, et al. Parametric Fortran (3 papers)
Gray, M. G. and R. M. Roberts (1997). Object-based programming in Fortran 90. Computers in Physics 11, 355–361.
Haveraaen, M., et al. (2015) High-Performance Design Patterns for Modern Fortran Scientific Programming
Johnson, Seth R., Andrey Prokopenko, and Katherine J. Evans (2020). Automated Fortran–C++ Bindings for Large-Scale Scientific Applications Computing in Science & Engineering Sept.-Oct. 2020, pp. 84-94, vol. 22.
Kedward, L. et al. (2022) The State of Fortran Computing in Science & Engineering, doi: 10.1109/MCSE.2022.3159862.
Magnin, V., Alves, J., Arnoud, A., Markus, A., and Esposito Marzino, M., “Fortran… et puis quoi encore ?”, Bulletin 1024, no. 22, pp.143–161, November 2023, DOI:10.48556/SIF.1024.22.143, licence CC BY-NC-ND 4.0, also available in English: “Fortran… ok, and what’s next?” (hal-04448657 and arXiv:2402.07520).
Markus, A. (2001). Generic programming in Fortran 90. ACM SIGPLAN Fortran Forum 20(3), 20-23.
Markus, A. (2006). Design patterns and Fortran 90/95. ACM SIGPLAN Fortran Forum, 25(1), 13-29.
McCalpin, J. D. (1996). A Case Study of Some Issues in the Optimization of Fortran 90 Array Notation Scientific Programming.
McCormack, D. (2005). Generic programming in Fortran with Forpedo. ACM SIGPLAN Fortran Forum 24(2), 18-29.
McGavin, P. and R. Young (2001). A generic list implementation. ACM SIGPLAN Fortran Forum 20(1), 16-20.
Morris, K. (2015) Emulating Multiple Inheritance in Fortran 2003/2008 Scientific Programming.
Nanthaamornphong, A., and A. Leatongkam (2019) Extended ForUML for Automatic Generation of UML Sequence Diagrams from Object-Oriented Fortran Scientific Programming.
Ott, Jordan, et al. (2020). A Fortran-Keras Deep Learning Bridge for Scientific Computing Scientific Programming.
Padua, D. (2000). The Fortran I Compiler Computing in Science $ Engineering.
Poppe, K., R. Cools, and B. Vandewoestyne (2012). Error handling in Fortran 2003. Fortran Forum 31(2), 7-19. Updated article here
Pietzer, A., et al. (2008). Exposing Fortran Derived Types to C and Other Languages IEEE Explore.
Reid, J. (2003). The future of Fortran. Computing in Science & Engineering 5, 59–67.
Schonfelder, J.L. (2003) Variable Precision Arithmetic: A Fortran 95 Module Scientific Programming.
Singleterry, Robert C. (2018) Single Thread to Fortran Coarray Transition Process for the Control Algorithm in the Space Radiation Code HZETRN NASA-TP-2018-219811.
Sharma, A., and I. Moulitsas (2017) MPI to Coarray Fortran: Experiences with a CFD Solver for Unstructured Meshes Scientific Programming.
Shterenlikht, A. and L. Cebamanos (2018). Cellular automata beyond 100k cores: MPI vs Fortran coarrays Proceedings of the 25th European MPI Users’ Group Meeting.
Vanderbauwhede, Wim (2022). Making legacy Fortran code type safe through automated program transformation. The Journal of Supercomputing volume 78, pages 2988–3028.
Worth, D. J. (2008). State of the art in object oriented programming with fortran. Technical Report RAL-TR-2008-002.
Yue, S., and J. Gray (2014). SPOT: A DSL for Extending Fortran Programs with Metaprogramming Scientific Programming.
Dauptain, Antoine (2021). Screening the coding style of Large Fortran HPC Codes
Ehlert, Sebastian (2022). Using objects across language boundaries: Exploring the limits of language interoperability and consistent API design
Stulajter, Miko M., Ronald M. Caplan, and Jon A. Linker (2021). Can Fortran’s ‘do concurrent’ replace directives for accelerated computing?
Discovering and Enjoying Fortran(2023) by Simon Rowe
Why You Should Consider Using Fortran As A Data Scientist: An exploration of the benefits that Fortran can bring to Data Science and Machine Learning(2023) by Egor Howell
Why Fortran is a scientific powerhouse(2023), The Myths of Fortran(2022), and Why Fortran is Easy to Learn(2022) by Michael Wirth
Is Fortran “a dead language”? Some C++ folk seem to think so…(2022) by Jim Cownie
I enjoyed modern Fortran(2022) by Radek Gruchalski
Fast, Cheap, and Turbulent—Global Ocean Modeling With GPU Acceleration in Python(2021) by Dion Häfner, Roman Nuterman, and Markus Jochum. Discussed here
Computer Language Benchmarks Game - Which programming language is fastest?
On the Performance of GPU accelerated q-LSKUM based meshfree solvers in Fortran, C++, Python, and Julia(2021) by Nischay Ram Mamidi et al.
raytracer(2021) - raytracer benchmark in dozens of languages, by edin
Assessment of Programming Languages for Computational Numerical Dynamics(2021) by Arturo Burgos. Compares Fortran, Julia, Matlab, and Python
What Julia can and can’t replace about Fortran(2021), by Joshua Laughner
Testing Julia: Fast as Fortran, Beautiful as Python(2021) by Martin D. Maas. Code here. Also Why is Fortran still used?, Will Julia replace Fortran for high-performance computing?
What is the superiority of Fortran over alternative languages like Chapel or Julia?(2021) - discussion at Fortran Discourse
NetworkDynamics.jl – Composing and simulating complex networks in Julia(2021) by Michael Lindner et al. Discussed here. Network Dynamics Benchmarks comparing Fortran, Julia and Python here
This old programming language is suddenly getting more popular again(2021) by Liam Tung, ZDNet
Resurrecting Fortran(2021) by Ondrej Certik
Performance comparison R, Julia, Fortran for Bayesian binary probit(2021) by Dries Benoit
The Quest for Speed - An Indicative Survey in Improving Performance(2021) by Bryn Noel Ubald
A Comparative Study on the Efficiency of Compiled Languages and MATLAB/Simulink for Simulation of Highly Nonlinear Automotive Systems(2020) by Amir Hossein Pasdar, Shahram Azadi, and Reza Kazemi, Journal of Applied and Computational Mechanics. Discussed here
First year of Fortran-lang(2020) by Milan Curcic
Basic Comparison of Various Computing Languages: Python, Julia, Matlab, IDL, R, Java, Scala, C, Fortran(2020) by Jules Kouatchou and Alexander Medema
What does Fortran need in 2020 to survive?(2020) by zmiimz
The Linear Algebra Mapping Problem(2019) by Christos Psarras, et al
Programming languages and particle physics(2019) by Jim Pivarski
Why I chose C for backtesting: Lessons from a journey to build an intraday backtesting engine(2019) by M. Emmanuel
Is Julia the best language for quantitative finance?(2019) by M. Emmanuel
Why to Use Fortran For New Projects(2019) by John Pask and Ondřej Čertík
A Comparison of Programming Languages in Economics: An Update(2018) by S. Boragan Aruoba and Jesus Fernandez-Villaverde. original paper code at GitHub
The Need for Speed Part 2: C++ vs. Fortran vs. C(2018) by Avi. Part 1
Energy efficiency across programming languages: how do energy, time, and memory relate?(2017) by Rui Pereira et al.
Comparison of performance: Python NumPy and Numba, MATLAB, and Fortran(2017) by Charles Jekel
A Comparative Study of Programming Languages for Next-Generation Astrodynamics System(2016) by Helge Joachim Eichhorn, Frazer McLean, and Juan Luis Cano Rodríguez
Fortran is alive!(2016) from VORtech
Why physicists still use Fortran(2015) by Daniel C. Elton
Formula translation in Blitz++, NumPy and modern Fortran: A case study of the language choice tradeoffs(2014) by Sylwester Arabas, Dorota Jarecka, Anna Jaruga, and Maciej Fijałkowski, Scientific Programming 22 (2014) 201–222
Scientific computing’s future: Can any coding language top a 1950s behemoth? (2014) by Lee Phillips
Why (and Why Not) to Use Fortran Instead of C++, Matlab, Python etc.(2012) by Nick Maclaren
The Rise and Fall of High Performance Fortran(2011) by Ken Kennedy, Charles Koelbel, and Hans Zima, Communications of the ACM
Debunking the Myths About Fortran(2011) by Craig T. Dedo
C++ vs Fortran(2011) by lmf
C vs Fortran for scientific computing by Jannis Teunissen
The Joy of Fortran (2010) by Sam Urmy
Should Fortran be taught to Undergraduates? (2009) by Mike Croucher of NAG
Why Fortran? (2007) by Viktor K. Decyk, Charles D. Norton, and Henry J. Gardner, Computing in Science and Engineering
Scientific Programming in Fortran(2007) by W. Van Snyder, Scientific Programming 15 pp3–8
Fortran: A Modern Standard Programming Language For Parallel Scalable High Performance Technical Computing(2006) by David B. Loveman
Programming languages in economics: a comparison among Fortran77, C++, and Java(2005) by Vieira, Wilson da Cruz and Levi H. Santana de Lelis
The Importance Of Fortran In The 21st Century (2003) by Walt Brainerd, Journal of Modern Applied Statistical Methods.
Cloudy’s Journey from FORTRAN to C, Why and How(2000) - by G. J. Fernald, published in Astronomical Data Analysis Software and Systems IX, ASP Conference Proceedings, Vol. 216, edited by Nadine Manset, Christian Veillet, and Dennis Crabtree. Astronomical Society of the Pacific, ISBN 1-58381-047-1, 2000., p.32
On the Numerical Efficiency of C++ in Scientic Computing(1999) by Erlend Arge et al.
Fortran 90 subsets offer simplified environment for first-time users(1998) by Donald L. Shirer, Computers in Physics 12, 166; doi: 10.1063/1.168632
Using the F Programming Language in the Classroom(1997) by Bob Hancock
Portability and Power with the F Programming Language(1997) by Walt Brainerd, David Epstein, and Richard Hendrickson, Linux Journal.
Fortran 90 for Science Students(1995) by John Prentice
Should C Replace FORTRAN as the Language of Scientific Programming?(1995) by Linda Wharton
Retire Fortran?: a debate rekindled (1992) by David Cann. Communications of the ACM
Computing in Science: Fortran outlasts them all - While hardware technology proceeds apace, scientists still battle away with Fortran programming(1989) by Don Monro, New Scientist.
Has FORTRAN a Future?(1985) by Michael Metcalf, Computer Physics Communications Volume 38, Issue 2, October–November 1985, Pages 199-210
Why C++ will replace FORTRAN (or, at least, why it should)(1984) by Thomas Keffer, ACCU
A debate: Retire FORTRAN?: Yes. New applicative languages, based on mathematical functions rather than FORTRAN‐like statements, will enhance our ability to decompose problems for concurrent processing.(1984) by James R. McGraw, Physics Today 37, 5, 66
A debate: Retire FORTRAN?: No. Supercomputers simply need supercompilers that automatically restructure programs for concurrent processing.(1984) David J. Kuck and Michael Wolfe, Physics Today 37, 5, 67
The gtk-fortran library is a set of Fortran modules that allow the GTK libraries to be called using the C interoperability features of modern Fortran. Gtk-fortran is cross-platform: Linux, MSYS2 in Windows, FreeBSD, macOS, Raspberry Pi… The wiki documentation is user centered and offers tutorials, how-to, references and explanations.
gtk-fortran uses CMake for building but is also available in conda-forge (Linux and macOS only). You can also use it as a simple fpm (Fortran Package Manager) dependency.
In addition to the standard GTK routines (along with GLib, GDK and Cairo) there is a high-level interface which uses Fortran’s optional argument system to create a programming interface to the most common widgets that should be more comfortable to IDL (Interactive Data Language) programmers. There is also an interface with the PLplot scientific plotting library, and additional tools.
Although the gtk-fortran project is licensed under GNU GPL v3 (with the additional permissions described in the GCC Runtime Library Exception version 3.1), there is a gtk-fortran-extra repository with examples under MIT license, that you can use to start your own GTK scientific application without worrying about license problems. These examples also demonstrates how you can obtain an application that can be built with or without its GUI.
The forGE project is “a framework designed to simplify construction of modern Fortran programs using the GTK GUI functions” from gtk-fortran.
This two day practical hands-on workshop is aimed at Fortran programmers who want to write modern code, or to modernize existing codes, to make it more maintainable by encouraging good software engineering practices. Tools, scientific libraries and techniques for Fortran are covered to help you develop sustainable software for your academic research in a collaborative environment, with an emphasis on writing performance portable Fortran. There will be an section on parallel computing and the latest Fortran 2018 standard. Click here for further information
Fortran is the primordial HPC language. Its handling of multidimensional arrays have ensured that compilers can produce highly efficient code, and inclusion of coarrays in the 2008 standard made it the first major programming language with builtin support for parallelism. The 2008 inclusion of object-oriented modernised the language, bringing it on par with many of its contenders. In 2019 the Fortran standards committee started work on generics (templates). Templates are planned for the 202y release of Fortran, the one after the upcoming 2023 release.
Unlike C++ templates, Fortran templates are type-safe (strong concepts) and does not support meta-programming. This enables some very powerful programming techniques not matched by other high performance languages.
In this workshop we will give a hands-on preview of such techniques. This includes defining your own Fortran integrated domain specific programming languages (IDSLs) while benefitting from Fortran’s efficient code generation. We also look at the dichotomy between well-structured code and efficient code, and show some systematic transformations between these. Lastly, we suggest just-in-time compilation and interpreters for user defined Fortran IDSLs, achieving much of the same flexibility as the current integration of Fortran and Python.
Targeted at scientists who wish to extend their knowledge of Fortran to cover advanced features of the language.
Three day course is targeted at scientists with little or no knowledge of the Fortran programming language, but need it for participation in projects using a Fortran code base, for development of their own codes, and for getting acquainted with additional tools like debugger and syntax checker as well as handling of compilers and libraries. The language is for the most part treated at the level of the Fortran 95 standard; features from later Fortran standard editions are limited to improvements on the elementary level.
“This intermediate course concentrates on some of the more recent features which are central to Modern Fortran. Attendees should be familiar with the basics of Fortran programming which might be covered in an introductory course [].
So, attendees should be comfortable writing structured Fortran programs based on modules and procedures, and have a sound grounding in variables, logic, flow-of-control, and so on. Some knowledge of Fortran I/O is assumed.
There are two main topics in this intermediate course: the facilities in Fortran for abstraction and polymorphism provided by classes and interfaces, and the facilities for formal interoperability with ANSI C. The course will cover type extension (“classes” and “inheritance”), type-bound procedures (“methods”), generic procedures (“polymorphism”), and so on. The standard iso_c_binding module provides facilities for interoperability with C; this allow the communication of Fortran entities with direct analogues C, and also Fortran objects (particularly arrays) which have no direct analogue in C.
Further language features concerning arrays, pointers, and facilities for structured programming using submodules will also be covered along the way.“
“This course provides an introduction to the basics of writing Fortran. It will cover basic syntax, variables, expressions and assignments, flow of control, and introductions to i/o and user-defined types. Common Fortran idioms are introduced and contrasted with those available in C-like languages; the course will try to focus on real usage rather than formal descriptions.
At the end of the course you should be able to understand many Fortran programs and be confident to start to write well-structured and portable Fortran. Fortran is a rather “large” language, so it is not possible to cover all its features in a two day course. Further elements of Fortran are discussed in the “Intermediate Modern Fortran” course.“
“[A]n introduction to OpenMP in Fortran …. It is designed with lecture-style material along with hands on exercises. The material covers the OpenMP 4.5 specification, with a little of 5.x.
Topics Covered: * OpenMP overview: shared memory and parallel do * Data sharing clauses and reductions * Vectorisation and code optimisation * NUMA and Hybrid MPI+OpenMP * OpenMP for GPUs * Tasks and Tools“
Fortran is a course introduced by Prof. Paul Tackley in earth science teaches modern Fortran 95 and review briefly Fortran 2003/2008 at ETH.
Description From the web page
FORTRAN 95 is a modern programming language that is specifically designed for scientific and engineering applications. This course gives an introduction to programming in this language, and is suitable for students who have only minimal programming experience, for example with MATLAB scripts. The focus will be on Fortran 95, but Fortran 77 will also be covered for those working with already-existing codes. A hands-on approach will be emphasized rather than abstract concepts, using example scientific problems relevant to Earth science.
Scientific Computing II by Antti Kuronen
Scientific Programing and Numerical Computation taught by Wu-ting Tsai
Object Oriented Programming with Fortran by Chris Geroux
Object-oriented Programming with Fortran
Fortran by David Apsley. Originally based on an undergraduate course. Subsequently extended to more advanced Fortran.
1.Modern Programming Languages: Fortran90/95/2003/2008
This course provides an introduction to some of the most widely used methods of computational physics, including numerical solutions of differential equations (initial and boundary value prob- lems) in classical and quantum mechanics, Monte Carlo simulations, and numerical diagonalization of quantum many-body Hamiltonians. In addition to giving the students a basic working knowledge of these particular techniques, the goal is to make them comfortable with scientific computing in general, so that they will be prepared to tackle also other computational problem that they may encounter in the future. The Fortran 90 programming language will be used.
Many Fortran programs written in the early years are of continuing value, but old source code does not always work unaltered with modern compilers. Where the compiler produces error messages, these notes may help in finding ways to fix the offending statements.
In theory there should be few problems because the designers of Fortran have always taken trouble to retain compatibility with older forms of the language. Each successive Fortran Standard has incorporated the preceding Standard as a subset, with only a few exceptions. In the few cases where a feature has been dropped it is because there is a superior replacement and the original was seriously problematic. Some dropped features were completely unportable, for example Hollerith constants and the storage of character strings in numerical variables was dropped when the CHARACTER data type was introduced in Fortran 77. Others were dropped because they were wholly incompatible with the principles of structured programming, for example the ASSIGN statement and assigned GO TO.
Changes are sometimes appropriate because old code written in Fortran 77 or Fortran 66 does not actually conform to either official standard. Unfortunately many of the recent changes come from coders who are less experienced, so are not aware that they are adding unnecessary compilations. Compiler-specific extensions were often used, for a variety of reasons:
Many programmers were scientists or engineers who were more concerned with code that worked on limited computers than language niceties.
Limitations in earlier forms of Fortran meant that some desirable features, such as dynamic storage allocation, could not be used without resorting to extensions.
Some code was written for a specific platform, so standard-conformance was of less importance.
Note: reference to DEC Fortran in what follows are to the series of compilers produced by the Digital Equipment Company for its PDP-8, PDP-11, and VAX series of computers. The company was subsequently taken over by HP, but the Fortran division was absorbed into Intel Fortran, whose compilers are most likely to contain appropriate compatibility features.
Reads from standard input. Example:
ACCEPT *, X, Y, Z
Status: in DEC Fortran, always non-standard.
Action: read from standard input using * as the I/O unit, e.g.
read *, x, y, z
This provides a way, when returning from a CALL statement, to jump to some other labelled point in the calling routine, typically in the event of some error condition. Example:
CALL MYSUB(args, *123, *456)
C ... code here for normal return
123 CONTINUE
C ... code here for to handle abnormal exit
456 CONTINUE
C ... ditto for some other condition
SUBROUTINE MYSUB(args, *2, *3)
C *N corresponds to a RETURN statement with given integer value
IF(ENDFIL) RETURN 2
IF(ERROR) RETURN 3
Status: Declared obsolescent in Fortran 90, but still standard.
Action: still standard-conforming so can be left unchanged at present. A better solution is to change the code to return an integer argument and test the value in the calling routine after the subroutine call e.g. using an if-block or select case structure.
A three-way branch to labelled statements depending on the value of a real or integer expression: less than zero, equal to zero, greater than zero. Two of the labels may be the same for a two-way branch. Example:
IF(X-Y) 10, 20, 30
10 CALL YBIG
GO TO 100
20 CALL EQUAL
GO TO 100
30 CALL XBIG
Status: Declared obsolescent in Fortran 90, but still standard.
Action: may be left unchanged. Better to use a SELECT CASE block with integer expressions, or a IF/ELSEIF/ELSE/ENDIF block for real expressions to avoid the clutter of statement labels.
This allows the value of a statement label to be assigned to an integer variable, which can be used in a subsequent GO TO statement to procure a jump to one of a preset number of labelled statements. This seems to have been a feature of the very earliest Fortran in order to allow internal subroutines and functions, where one needs a return to a statement just after the calling point. The GOSUB statement in the Basic language is a more elegant way of doing the same thing. Example:
ASSIGN 1234 TO MYPOS
GO TO 1000
1234 CONTINUE
C ------ INTERNAL FUNCTION: HAVERSINE -----
1000 Y = 2.0 * (SIN(X/2))**2
GO TO MYPOS
Status: In Fortran 90 declared obsolescent, deleted in Fortran 95 (but still supported by some current compilers as an extension).
Action: rarely encountered in the wild, but needs careful handling. If used as demonstrated above it can be replaced by an internal subroutine or function, but some programmers may have played more elaborate tricks with ASSIGN which need careful analysis.
Allows one of a number of format statements to be selected in advance to be used with a given read/write statement. Example:
ASSIGN 900 TO MYFMT1
WRITE(6,MYFMT1) RESULT
ASSIGN 901 TO MYFMT2
WRITE(6,MYFMT1) RESULT
C...
900 FORMAT(F10.0)
901 FORMAT(E10.1)
Status: In Fortran 90 declared obsolescent, deleted in Fortran 95 (but still supported by some current compilers as an extension).
Action: usually simplest to store the complete format string in a character variable; if this is given the same name as the integer used originally, then the read and write statements do not need to be changed.
character(len=10) :: myfmt1
myfmt1 = '(f10.0)'
write(*,myfmt1) result
myfmt1 = '(e10.1)'
write(*,myfmt1) result
The actual length of the function is that declared for the name in the calling routine. Example:
CHARACTER UPCASE*10, STRING*20
C...
STRING = UPCASE('test')
C...
CHARACTER*(*) UPCASE(ARG)
This does not do what it appears: the function always returns a string of 10 characters when called from this routine because of the declaration (but references to the function from other program units may return different lengths).
Status: declared obsolescent in Fortran 95, because it is misleading, and the functionality that it does not quite provide can be done properly other ways, such as a subroutine with passed-length arguments, or a function with a return argument with a length which does depend upon its arguments.
Action: if it really works best to leave it alone, but note it as generally the mark of a programmer being too clever by half.
Example:
SUBROUTINE SUB(IMAGE)
REAL IMAGE(512,*)
Status: declared obsolescent in Fortran 95^{1}, because it can only be used for the last dimension of a multi-dimensional array, and provides no information on the actual upper-bound to the called procedure.
Action: If the procedure has an explicit interface, for example it is (or can be) in a module, then use an assumed-shape array (colon replaces the asterisk).
It should be noted that there are some tricks that you can do with assumed-size arrays that you can’t do as easily with assumed-shape arrays. One example, that is relatively common in linear algebra routines, is to pass sub-matrices by passing the top left hand element, i.e. with
SUBROUTINE SUB(A, LDA)
REAL A(LDA, *)
then
CALL SUB(A,LDA)
passes the full matrix and
CALL SUB(A(3,2), LDA)
passes a sub-matrix. Whilst it is possible to do this with assumed-shape arrays, by slicing, this often results in the compiler creating internal copies of the data.
A feature hardly ever used in practice as it has no value, but something the earlier standards forgot to prohibit.
Status: Declared obsolescent in Fortran 90, deleted from Fortran 95.
Action: Can easily be replaced by a jump to e.g. a labelled CONTINUE statement after the END IF.
Optional arguments were only standardized in Fortran 90, but many earlier compilers implemented them and allowed pairs of commas in CALL statements or function references to denote omitted arguments. For example:
CALL MYSUB(x,,z)
Status: Never standardized, common extension in DEC Fortran and others.
Action: Reorder the arguments so that the optional ones are at the end of the list; check that the formal arguments are declared optional within the procedure.
Example:
CHARACTER*10 STRING
Status: Declared obsolescent in Fortran 95.
Action: Can be replaced with the new syntax such as CHARACTER(LEN=10) which is clearer and more consistent with other forms of data type declaration.
For many years output to a device called a “printer” was treated specially in Fortran to provide a primitive way of controlling page layout. The first character of each line was removed and used to control the line and page spacing:
character | Effect |
---|---|
space | Output on next line |
0 | Skip one line |
1 | Skip to next page |
+ | Output continues on same line |
It should be noted that the effect of “+” as first character was especially device-dependent: on some devices it would continue the same line, on others would overwrite starting at the left margin again, on others it would appear to have no effect. Although this technically applied only to output destined for a “printer”, many compilers especially on Unix-like operating systems, could not tell whether output would go to a printer or not, so applied it to all output text files, which could be very annoying. The practice appears to have died out in recent years, but lives on in the specification for list-directed output, which requires a leading space at the start of every output line. Its influence in old code can be recognised by the presence of something like “1X” or even “1H ” at the start of each output format.
Status: Deleted from Fortran 2008 (without any period of being “obsolescent”, but not before time, many think).
Action: None needed in general. Blank lines can easily be produced by using slashes in output formats. There is no general way of getting a page throw on modern printers, except by using a specific printer control language. Those writing new code should note that they no longer need to worry about the first character on each line.
Branches to one of a number of labelled statements according to the value, 1 to N, of an integer variable. Example:
GO TO (101, 102, 103), MYVAL
101 X = X + Y
GO TO 200
102 X = X - Y
GO TO 200
103 X = X * Y
200 CONTINUE
Status: Declared obsolescent in Fortran 95.
Action: May be replaced by the SELECT CASE structure, which is more powerful and does not involve the risk of failing to include a GO TO statement in each clause to branch to the end. It also allows a case default
section as a long-stop. For example:
select case(myval)
case(1)
x = x + y
case(2)
x = x - y
case(3)
x = x * y
case default
print *,'Invalid value of myval'
end select
Early forms of Fortran allowed the DATA statement, uniquely among non-executable statements, to be intermixed with executable statements. There seems little point in doing this.
Status: Declared obsolescent in Fortran 95.
Action: Simply move the offending DATA statements to a position above all the executable statements in that program unit. In some cases the initialisation of a variable can be done more clearly in the corresponding type declaration statement.
An early form of what later became the internal file READ, reading a string of characters under format control to extract (usually) numerical values. Example:
DECODE(20, 105, string) areal, breal
105 FORMAT(F10.2, F10.4)
The first item in the list is a character count, no longer needed in an internal file read. Optionally the items in parentheses could include IOSTAT=intvar and ERR=label.
Status: Never standardized, but in DEC Fortran and many others.
Action: Convert to an internal file read, e.g.
read(string, '(f10.2, f10.4)') areal, breal
Originally an IBM Fortran statement to specify the properties of a direct-access file. Example:
DEFINE FILE unit(nrecs, lenrec, U, ivar)
This defines a file consisting of exactly nrecs records each of length lenrec - but the units of this were system-dependent, 16-bit records on early systems, 32-bit records (perhaps) on later ones. The U argument was required to denote an unformatted file, the final integer variable was the associated variable which was updated with (bizarrely) the number of the record after the record just read/written. DEFINE FILE did not actually open the file: this was done by the first READ or WRITE accessing that unit.
Status: Never standardized.
Action: Replace by an OPEN statement using ACCESS=“DIRECT” and a suitable RECLEN value (note units are still system-dependent, but an option of the INQUIRE statement allows you to find the appropriate length). Any programs which actually make use of the associated variable need careful examination as there is no simple equivalent in standard Fortran.
An early attempt to provide array arguments of unspecified length. Example:
SUBROUTINE APROC(ARRAY)
DIMENSION ARRAY(1)
Status: commonly used in Fortran 66 at a time when compilers did not check array-bounds against the declared length, so the array size of the actual argument could be flexible. The feature was deleted in Fortran 77, but may still work with current compilers if array-bound checking is not enabled.
Action: the simplest replacement is to replace the 1 by an asterisk, to make it an assumed size array, but this was declared obsolescent in Fortran 95. A better solution is to use a colon, turning it into an assumed shape array, but this requires an explicit interface.
This was theoretically permitted in Fortran 66 but little used, fortunately.
Status: Removed in Fortran 77.
Action: If this is encountered in the wild, the logic of the program needs to be examined carefully to see why the jump out and back in is done, and then the program flow refactored appropriately.
Example:
REAL X
DO 15, X = 0.5, 5.0, 0.5
Status: Declared obsolescent in Fortran 90, deleted from Fortran 95, because the repeated addition of the increment combined with the approximations inherent in floating point arithmetic made the actual number of loops somewhat processor-dependent. Many compilers continue to permit this, as an extension, for compatibility with old code.
Action: Should be replaced by a DO loop with an integer loop variable, and then an assignment to a real variable, providing you can work out how many loops the original programmer intended. For example:
do ix = 1,10
x = 0.5 * ix
Example:
DO 100 J = 1,NJ
DO 100 I = 1,NI
X = X + ARRAY(I,J)
100 CONTINUE
Status: Declared obsolescent in Fortran 90. Deleted in Fortran 2018.
Action: Better to replace the labelled form of DO with DO - END DO throughout, and indent the contents, which solves the problem much more neatly.
Example:
DO 100 J = 1,NJ
DO 100 I = 1,NI
100 X = X + ARRAY(I,J)
Status: Declared obsolescent in Fortran 90. Deleted in Fortran 2018.
Action: Better to replace the labelled form of DO with DO - END DO throughout, and indent the contents, which solves the problem much more neatly.
Status: The complex data type only had one precision (single) in Fortran 77, but this was a fairly common extension.
Action: Replace by a COMPLEX statement using a suitable kind parameter. For example:
integer, parameter :: dp = selected_real_kind(15,50)
complex(dp) :: variable, list
Status: In Fortran 77, double precision was one of the six intrinsic data types, but since Fortran 90 it has been relegated to being an alias for the higher precision kind of the real type.
Action: None required, but ideally new code should make use of the SELECTED_REAL_KIND function to select the kind of a floating point variable according to the range and precision required, as this is more portable. The DOUBLE COMPLEX statement is sometimes encountered: in modern Fortran both real and complex data types have a higher precision kind, so this does require modification to be standard-conforming. Note that double precision constants using the “d” suffix are also obsolescent, as appending an underscore and the appropriate kind value is more portable.
An early form of what later became the internal file WRITE, converting usually a numerical variable to the corresponding string of characters under format control. Example:
ENCODE(20, 105, string) xreal
105 FORMAT(F10.2)
The first item in the list is a character count, no longer needed in an internal file write. Optionally the items in parentheses could include IOSTAT=intvar and ERR=label.
Status: Never standardized, but in DEC Fortran and many others.
Action: Convert to an internal file write, e.g.
write(string, '(f10.2)') xreal
The ENTRY allowed a function or subroutine to have two or more entry points, which could have different sets of formal arguments. This is incompatible with the best principles of structured programming, and leads to programs which are hard to understand.
Status: Declared obsolescent in Fortran 2008.
Action: Simplest to leave this alone. In principle a better structure can generally be obtained using either a single entry point with optional arguments, or else several thin shells with individual argument lists, all of which call the same lower-level routine. In either case a lot of refactoring is required.
The EQUIVALENCE statement is still part of modern Fortran but when found in old code it often turns out to be used in ways which are non-standard, for example to associate numerical variables with ones of character type, or to transfer bit-patterns from one data type to another. The TRANSFER intrinsic function should be used to do this. One form of EQUIVALENCE which conformed to Fortran 66 but not later standards was to have a reference to a multi-dimensional array with just one subscript.
Status: The nH descriptor was declared obsolescent in Fortran 90 and removed from Fortran 95. In early Fortran nH was also permitted for input but this was removed in Fortran 77.
Action: In output formats it can easily be replaced by a character string descriptor e.g. 4Hthis becomes “this” or ‘this’. If encountered in used with READ the code needs careful inspection, since it had the effect of altering the FORMAT string e.g. to update a column header, for subsequent output. Reading into a character variable might be a suitable replacement.
Status: The Q descriptor has never been standard, but was used in DEC Fortran and others with READ statements to transfer the length (or remaining length) of an input text line to be transferred to an integer variable.
Action: Modern Fortran has no exact equivalent, but a non-advancing READ can use the size
keyword to get similar functionality.
Status: Never standard, but $ was used in DEC Fortran and many others to suppress the end-of-line sequence (such as CR and LF) at the end of a line of text. “\” was used in a few other compilers for the same purpose.
Action: Replace with a non-advancing write statement.
Status: Declared obsolescent in Fortran 95, but still part of Fortran 2008.
Action: No need to change, but the modern free-format layout has many advantages, and there are some free converters to this form, including Michael Metcalfe’s convert.f90 and Alan Miller’s to_f90.f90.
Status: Hollerith constants in expressions (as opposed to within Format specifications) were removed in Fortran 77 when the character data type was introduced. A few compilers continued to allow them as an extension.
Action: Replace with a character string enclosed in quotes or apostrophes.
Some early IBM computers with Fortran compilers pre-connected certain input/output units to devices, typically:
Unit | Device |
---|---|
5 | Input from card reader |
6 | Output to line printer |
7 | Output to card punch |
Other Fortran compilers tended to follow suit, and 5 is still pre-connected for input from the user’s keyboard, and 6 for output to the user’s screen, even on modern systems.
Status: Never defined in any Standard.
Action: Best to replace the unit number with an asterisk, which is a standard notation for reading from the standard input unit or writing to standard output unit. Card punches seem to have vanished from the scene.
Note: I/O unit 0 is sometimes seen in Fortran designed for use on Unix systems and similar: on many compilers it was pre-connected to the standard error output stream and was meant to separate error messages from regular text output. In Fortran 2008 the intrinsic module ISO_FORTRAN_ENV has an item ERROR_UNIT which has the same purpose.
Example:
REAL X / 3.14159 /, ANSWER / 42.0 /
Status: Never standardized, but a common extension in early Fortrans.
Action: Replace with modern syntax, e.g.
real :: x = 3.14159, answer = 42.0
Note that the double colon is needed to allow initial values to be specified.
In DEC Fortran OPEN statements many non-standard keywords may appear; a few which have simple translations into modern Fortran are shown in this table.
DEC Fortran keyword | Modern Equivalent |
---|---|
ACCESS = ‘APPEND’ | position = ‘append’ |
NAME = ‘filename’ | file = ‘filename’ |
READONLY | action = ‘read’ |
RECORDSIZE = n | recl = n |
TYPE = ‘OLD’ | status = ‘old’ (etc.) |
The DEC Fortran CLOSE statement might also use “DISPOSE=” which can be replaced by “STATUS=”.
Example:
PARAMETER name = 12345.6
Status: This simple form was in DEC Fortran and perhaps others, but never standardized.
Action: Simplest just to put parentheses around the name=value pairs, but better to absorb the statement into a type statement with a parameter attribute, e.g.
real, parameter :: name = 12345.6
This caused execution to pause, after which it could be resumed by some action by the computer operator, e.g. after a tape had been mounted.
Status: Declared obsolescent in Fortran 90, deleted from Fortran 95.
Action: Best to replace by a write statement sending the message (if any) to the standard output unit, followed by a read from the standard input unit.
Before the OPEN statement was introduced in Fortran 77, there was no standard way of associating I/O unit numbers with external files: this was left to job control. Typically the first time a program executed a WRITE statement on a given unit (provided the number was not 5, 6, or perhaps 7) the run-time system would create a file with a suitable name. For example if you write to unit 13 then the file might be called “FOR013.DAT” or perhaps “fort.13” but systems varied a lot in the names they used. Some systems would allow automatic connection of input files provided they already existed with a name of the required form.
Status: A feature not covered by any Fortran Standard.
Action: Use an OPEN statement to connect each I/O unit with a named file.
Examples:
REAL*8 dblex, bigone
INTEGER*2 shorty
status: The notation mirrors that of the CHARACTER statement, but for other data types has never been permitted by any Fortran Standard. Despite this, many compilers support it. The notation is designed to specify the number of bytes used to store the variables: thus REAL*8
specifies 8 bytes, often corresponding to double precision type. Although the notation is simple and has a fairly obvious meaning, Fortran has never been restricted to byte-oriented hardware. The designers of Fortran 90 designed what they thought was a superior replacement involving variables of different kinds, where the kind can be chosen for the required values of precision and exponent range.
Action: REAL*8
and INTEGER*2
can be replaced by something like this:
integer, parameter :: dp = selected_real_kind(15, 50)
real(dp) :: dblex, bigone
integer, parameter :: short = selected_int_kind(3)
integer(short) :: shorty
Note that there is no guarantee that this integer specification will result in 2-byte (16-bit) wordlength, only that it will be enough to store numbers of 3 decimal digits. If the hardware has no suitable number representation of this size, then variables with a longer wordlength will result.
Status: These originated in DEC Fortran as a way of declaring data structures. The derived-type definition in Fortran 90 replaced the STRUCTURE and RECORD statements but is different in many details. There is no standard equivalent of MAP and UNION statements which were designed to allow aliases for elements of data structures.
Action: STRUCTURE and RECORD can be converted to modern standard forms in a straightforward fashion by using derived types, but some work is likely to be involved. Replace the “STRUCTURE /structure-name/” statements with “TYPE structure-name” statements, and replace “RECORD /structure-name/” statements with “TYPE(structure-name)” statements.
type person_t ! was: structure /person_t/
character(64) :: name
integer :: age
end type ! was: end structure
type(person_t) :: people_array(100) ! was: record /person_t/ people_array(100)
Access to derived type components is with the percent character (“%”), rather than the period (“.”):
do, i=1, size (people_array)
print *, i, trim (people_array(i)%name), ', ', people_array(i)%age
end do
If UNION or MAP statements were used, the difficulties are much larger. Use of Fortran 2003 type extension (EXTENDS) and polymorphism (CLASS) may be of value. For example, using type extension different specializations could be defined:
type, extends(person_t) :: student_t ! was a map of a union
integer :: student_id
real :: gpa
end type
type, extends(person_t) :: employee_t ! was a map of a union
integer :: employee_id
character(:), allocatable :: title
real :: salary
end type
By using CLASS and SELECT TYPE, procedures may be written which generically support type person_t and any of its specializations:
subroutine person_print (this)
class(person_t), intent(in) :: this
print *, 'name, age: ', this%name, ', ', this%age
select type (this)
type is (student_t)
print *, 'student ID and GPA: ', this%student_id, this%gpa
type is (employee_t)
print *, 'title: ', this%title
print *, 'employee ID and salary: ', this%employee_id, ', $', this%salary
end select
end subroutine
Status: These are single statements each of which defines a function for use within the same program unit. They were declared obsolescent in Fortran 95.
Action: Still standard Fortran so can be left alone, but a better replacement is to define internal functions (or subroutines) where the body is not limited to what can be achieved in a single expression.
Example:
TYPE "The value of X is", X
Status: Never standard, only in early DEC Fortran.
Action: replace with a PRINT statement, or WRITE statement using the standard output unit.
Status: Standard Fortran has never accepted tab characters in source-code, but many compilers permitted them, but treated them in different ways. Since their presence is normally invisible they are best avoided.
Action: use a text editor or some other utility to translate them to a suitable number of spaces. In modern Fortran using free-format layout translating them to a single space might suffice.
Status: A DEC Fortran notation for writing direct-access records.
Action: Change to WRITE(unit, rec=record)
.
Status: these are completely non-standard functions used in passing actual arguments by different mechanisms to the usual, typically to obtain dynamic storage in the age of Fortran 77, or to interface with procedures written in C or other languages.
Action: there is no standard alternative, but most of the features that these functions supported have simpler equivalents in modern Fortran, for example: dynamic memory, and (from Fortran 2003 on) a standard way of interfacing with C-language code.
The recent version of this article contained many quite arrogant and incorrect statements, many of which have been removed. The reality is that code such as Lapack and many other scientific codes were written to work on limited computers, and “niceties” of standards was less of an issue. Sadly many recent changes are pedantic rather than pragmatic, making writing Fortran harder not simpler. So it goes; two steps forward, one step back – or perhaps three steps back.
Assumed size arrays still appear to be “current” in F95 and subsequent revisions of the standard, based on the font used to describe them and their omission from the list of obsolescent features in Annex B of each standard. ↩
Discussion of Fortran and Lua in Programming in Modern Fortran tutorial
IREP - tool for filling C/C++ or Fortran data structures from Lua input tables
fortran-lua53 - collection of ISO C binding interfaces to Lua 5.3 for Fortran 2003 and to call Lua from Fortran and vice versa, by interkosmos and zoziha
Aotus: Advanced Options and Tables in Universal Scripting - Fortran wrapper around the C-API of Lua, for usage as configuration
FortLua - simple set of Lua bindings for use in Fortran, tested to be compatible with Lua 5.2.3+, by Drew Dolgert
cafut A single-file object-oriented unit testing utility for Coarray Fortran.
Fortran Unit Test Framework (FRUIT)
Fortuno User friendly, flexible and extensible object-oriented Fortran unit testing framework for testing serial, MPI-parallelized and coarray-parallelized applications.
Fytest Note Fytest is deprecated, you should consider to use the Fortuno unit testing framework instead.
test-drive A simple and lightweight testing framework developed by the Fortran-lang community, entirely written in modern Fortran.
M_framework - is an aggregate of Fortran modules useful for creating terminal messages, comparing expected values to results, writing logfiles and playback journals and performing unit tests for Fortran.
toast - Testing Or ASsertion Toolkit - Fortran unit testing library
FortUTF - Unit Test framework written purely in Fortran to be compatible with as many projects as possible
XFunit - Native Fortran 2003 Unit Testing Framework
CMake and CTest - Minimalistic cmake/ctest environment for fortran unit tests, with cmake dependency management and CI examples.
The Fortran 2023 standard is sold at the ISO web site for CHF 216. The standards committee uses its Interpretation Document as a reference. The main new features are resumed in its introduction, pages xiii-xiv.
John Reid wrote The new features of Fortran 2023 and co-authored Modern Fortran Explained: Incorporating Fortran 2023, 6th ed.(2023), Oxford University Press
Jacob Williams listed some of the new features and his opinions of them in a post The New Features of Fortran 202x
Keywords are specifically NOT reserved words as per the Fortran specifications (F03 section 2.52, F90 section 2.52, and F77 section 2.2).
The following keywords were defined in FORTRAN 77: assign, backspace, block data, call, close, common, continue, data, dimension, do, else, else if, end, endfile, endif, entry, equivalence, external, format, function, goto, if, implicit, inquire, intrinsic, open, parameter, pause, print, program, read, return, rewind, rewrite, save, stop, subroutine, then, write.
The following keywords were added in Fortran 90: allocatable, allocate, case, contains, cycle, deallocate, elsewhere, exit?, include, interface, intent, module, namelist, nullify, only, operator, optional, pointer, private, procedure, public, recursive, result, select, sequence, target, use, while, where.
The following keywords were added in Fortran 95: elemental, forall, pure.
The following features were added in Fortran 2003: abstract, associate, asynchronous, bind, class, deferred, enum, enumerator, extends, final, flush, generic, import (in interfaces), non_overridable, nopass, pass, protected, value, volatile, wait.
The following keywords were added in Fortran 2008: block, codimension, do concurrent, contiguous, critical, error stop, submodule, sync all, sync images, sync memory, lock, unlock, impure.
The following keywords were added in Fortran 2018: select rank, non_recursive, import (in block and contained procedures).
GFortran, the GNU Fortran compiler, is part of the GNU Compiler Collection (GCC) since 2005 (it was forked from G95 in January 2003), which is licensed under GPLv3+ with GCC Runtime Library Exception. In 2023, GFortran nearly implements all of the Fortran 2008 standard and partially Fortran 2018.
Since 2015 and GCC 5.1, a major version is published every year: the first stable 2022 version was therefore GFortran 12.1. Four subsequent minor versions are then published during the four next years (for example 11.2, 10.3, 9.4 and 8.5). It can be interesting to install several versions, the latest for bleeding edge features and older ones for their robustness. For example, it is not rare to see up to 10% variations in the CPU speed of your program depending on the GCC version, and the latest version is not always the fastest.
You will find here the basic information needed to install GFortran on Linux, macOS, FreeBSD and Windows systems. More details can be found at fortran-lang.
Just install with your package manager the GFortran package, named gfortran
in Debian-based distributions (Ubuntu, Mint…) or gcc-fortran
in RPM-based distributions (Fedora, Red Hat, CentOS, openSUSE…) and Arch-based (Arch Linux, Manjaro, EndeavourOS…) distributions.
If you have installed Homebrew, install its GCC package:
% brew install gcc
If you have conda, a gfortran package is available for macOS and Linux:
% conda install -c conda-forge gfortran
Just install the GCC package, for example for the latest GCC 12 release:
# pkg install gcc12
There are several ways to install GFortran on Windows. An easy way is to use the Quickstart Fortran application.
If you use MSYS2, GFortran packages are available for the latest release. For example, for the UCRT64 environment, type:
$ pacman -S mingw-w64-ucrt-x86_64-gcc-fortran
The basic usage of GFortran is
gfortran [options] file...
For example, if your project has a module and the main program, just type:
$ gfortran my_module.f90 my_main.f90
The default executable is named a.out
under Unix-like systems and a.exe
under Windows systems.
You can use both GCC options and the GFortran specific options. For example, the default name of the executable can be changed by adding the -o
GCC option:
$ gfortran my_module.f90 my_main.f90 -o my_exec
In this section, we present only a selection of useful options, as there are hundreds of them!
You can use the GCC debugging options:
-g
produces debugging information in the operating system’s native format.-p
and -pg
generate extra code to write profile information suitable for the analysis program prof (-p
) or gprof (-pg
).You can use also the Fortran specific options:
-fcheck=all
to enable all run-time test (array bounds, memory allocation, pointers…).-std
specifies the standard to which the program is expected to conform, which may be one of f95
, f2003
, f2008
, f2018
, gnu
(default), or legacy
. For example: -std=f2008
for the Fortran 2008 standard.-pedantic
issues warnings for uses of extensions to the language.-Wall
enables commonly used warning options.-Wextra
enables some warning options for usages of language features which may be problematic.GCC provides the link options -static-libgfortran
and -static-libquadmath
to force the use of the static versions.
You can use the GCC optimization options:
-O0
(default) reduces compilation time and make debugging produce the expected results.-O1
to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.-O2
to optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff.-O3
to optimize yet more.-Ofast
enables all -O3
optimizations but also optimizations that are not valid for all standard-compliant programs.-Og
to optimize debugging experience. It should be the optimization level of choice for the standard edit-compile-debug cycle.-Os
to optimize for size. It enables all -O2
optimizations except those that often increase code size.-Oz
to optimize aggressively for size rather than speed.GCC offers also machine-specific options starting with -m
, especially:
-march=cpu-type
generates instructions for the machine type cpu-type. -march=native
enables all instruction subsets supported by the local machine. Further details in the GCC doc.-mtune=native
produces code optimized for the local machine.Parallel computation is achieved by exploiting different aspects of modern architectures: from vectorization instructions, multi-threading, message passing and offloading to GPU devices. The followings enable handling one or more of these aspects:
The first level of parallelism with vectorization can be achieved by the combination of -O3
and -march=native
which enables the compiler to exploit the local machine vector instructions (SSE, AVX, AVX2, AVX512, etc):
$ gfortran -O3 -march=native
Programmer-instructed vectorization can be achieved with OpenSIMD (part of OpenMP), for details see this OpenMP API Specification page.
Use the option -fopenmp
. You can specify the number of threads using the environment variable OMP_NUM_THREADS
, for example in a UNIX-like system type that command before running the executable:
$ export OMP_NUM_THREADS=4
You can also spawn threads dynamically at run time in two different ways:
within the directives
use omp_lib
!$omp paralel do num_threads(num_threads)
... parallel code
!$omp end parallel do
As a routine call
use omp_lib
call omp_set_num_threads(num_threads)
!$omp parallel do
... parallel code
!$omp end parallel do
OpenACC support was introduced in GCC 5. Depending on the target GPU architecture (Intel, Nvidia, AMD) different offloading backends are available, read here. For Nvidia PTX offloading, you need to install the following backend:
$ sudo apt install gcc-offload-nvptx
Now, you can compile your code with the flag -fopenacc
and test
!$acc parallel loop
do i = 1,n
... parallel code offloaded to GPU
end do
GFortran does not natively support coarrays (Fortran 2008) and the parallel programming features introduced by the 2018 standard. You need to install the OpenCoarrays software.
For example, in an Ubuntu Linux distribution type:
$ sudo apt install libcoarrays-dev libcoarrays-mpich-dev
$ git clone https://github.com/sourceryinstitute/OpenCoarrays.git
$ cd OpenCoarrays
$ ./install.sh
and accept the installation of the MPICH library (although OpenCoarrays can also work with Open MPI).
You need to define the environment variables in your terminal (you can add it in your ~/.bash_profile
):
$ source /home/my_login/OpenCoarrays/prerequisites/installations/opencoarrays/2.9.2/setup.sh
here for the 2.9.2 version.
Use the command caf
instead of gfortran
to compile your program, and cafrun -n
to run it with the number of images you want:
$ caf main.f90
$ cafrun -n 4 ./a.out
If you want to build OpenMPI locally follow these instructions.
You can also install a pre-built package (linux or WSL):
$ sudo apt-get update
$ sudo apt-get install openmpi-bin
Then include the header file in your Fortran program/modules:
include 'mpif.h' ! To be included in files calling MPI functions
call MPI_INIT(err) ! should be invoked just once at the beginning of your main program
... code ! N instances of your program with specific communication steps
call MPI_FINALIZE(err) ! should be invoked just once at the end of your main program
Compile and run the code:
$ mpif90 main.f90 -o main.exe
$ mpirun -np 4 main.exe
This is a useful link with a concise Hello world for starters.
GFortran is free software developed by volunteer users and any help is welcome.
You can report bugs in the GCC Bugzilla system: first, update your major GFortran version to its latest release, then search if the bug was already reported, then file the bug. You can also use the GFortran mailing list fortran@gcc.gnu.org if you are uncertain on how to handle Bugzilla.
Anyone interested in joining the GFortran developers team should send an email to gfortran@gcc.gnu.org or jvdelisle@gcc.gnu.org to receive an invitation to join the GFortran Mattermost workspace (now hosted by the Oregon State University Open Source Lab), which was created in December 2022 to facilitate chat, patch discussions, mentoring new folks, etc. See also that January 2023 message by Paul Richard Thomas to comp.lang.fortran. And that 2008 message by Tobias Burnus to comp.lang.fortran contains advice that are still pertinent.
See the Quickstart Guide to Hacking Gfortran. The GNU Fortran Compiler Internals documents the internals of GFortran.
You can also contribute to GFortran at the Google Summer of Code: https://gcc.gnu.org/wiki/SummerOfCode.
You can read the GCC sources by cloning that read-only git repository:
$ git clone git://gcc.gnu.org/git/gcc.git
or if you have firewall problems:
$ git clone https://gcc.gnu.org/git/gcc.git
Concerning Fortran, the sub-directories are gcc/fortran
, libgfortran
, gcc/testsuite/gfortran.dg
and gcc/testsuite/gfortran.fortran-torture
.
To build GCC, you also need to install the libraries GMP, MPFR and MPC.
Unofficial GFortran 32-bit and 64-bit binary packages based on the current development source code can be found on http://gcc.gnu.org/wiki/GFortranBinaries. For example, to install the latest 64-bit nightly binary in a Linux system, download and install the latest GCC trunk build:
$ cd /tmp
$ wget https://gfortran.meteodat.ch/download/x86_64/nightlies/gcc-trunk.tar.xz
$ cd /opt
$ sudo tar -xJf /tmp/gcc-trunk.tar.xz
$ /opt/gcc-trunk/bin/gfortran --version
GNU Fortran (GCC) 13.0.1 20230227 (experimental) [master r13-6353-g529e03b988]
Then set LD_LIBRARY_PATH
and PATH
: see that GFortran wiki page for details on bash and csh/tcsh. For zsh, this will work for both the x86_64 and i386 versions:
# Determine platform
ARCH=`uname -m`
# GFortran
export PATH=/opt/gcc-trunk/bin:${PATH}
if [[ ${ARCH} == "x86_64" ]]; then
LIB64="64"
fi
if [ -z "$LD_LIBRARY_PATH" ]; then
LD_LIBRARY_PATH="/opt/gcc-trunk/lib${LIB64}"
else
LD_LIBRARY_PATH="/opt/gcc-trunk/lib${LIB64}:$LD_LIBRARY_PATH"
fi
export LD_LIBRARY_PATH