A Modern Fortran Scientific Programming Ecosystem
Historically, large general-purpose libraries have formed the core of the Fortran scientific ecosystem (e.g., SLATEC, or the various PACKS). Unfortunately, as I have mentioned here before, these libraries were written in FORTRAN 77 (or earlier) and remained unmodified for decades. The amazing algorithms continued within them imprisoned in a terrible format that nobody wants to deal with anymore. At the time they were written, they were state of the art. Now they are relics of the past, a reminder of what might have been if they had continued to be maintained and Fortran had continued to remain the primary scientific and technical programming language.
Over the last few years, I've managed to build up a pretty good set of modern Fortran libraries for technical computing. Some are original, but a lot of them include modernized code from the libraries written decades ago. The codes still work great (polyroots-fortran contains a modernized version of a routine written 50 years ago), but they just needed a little bit of cleanup and polish to be presentable to modern programmers as something other than ancient legacy to be tolerated but not well maintained (which is how Fortran is treated in the SciPy ecosystem).
Here is the list:
Catagory | Library | Description | Release |
---|---|---|---|
Interpolation | bspline-fortran | 1D-6D B-Spline Interpolation | |
Interpolation | regridpack | 1D-4D linear and cubic interpolation | |
Interpolation | finterp | 1D-6D Linear Interpolation | |
Interpolation | PCHIP | Piecewise Cubic Hermite Interpolation Package | |
Plotting | pyplot-fortran | Make plots from Fortran using Matplotlib | |
File I/O | json-fortran | Read and write JSON files | |
File I/O | fortran-csv-module | Read and write CSV Files | |
Optimization | slsqp | SLSQP Optimizer | |
Optimization | fmin | Derivative free 1D function minimizer | |
Optimization | pikaia | Pikaia Genetic Algorithm | |
Optimization | simulated-annealing | Simulated Annealing Algorithm | |
One Dimensional Root-Finding | roots-fortran | Roots of continuous scalar functions of a single real variable, using derivative-free methods | |
Polynomial Roots | polyroots-fortran | Root finding for real and complex polynomial equations | |
Nonlinear equations | nlesolver-fortran | Nonlinear Equation Solver | |
Ordinary Differential Equations | dop853 | An explicit Runge-Kutta method of order 8(5,3) | |
Ordinary Differential Equations | ddeabm | DDEABM Adams-Bashforth algorithm | |
Numerical Differentiation | NumDiff | Numerical differentiation with finite differences | |
Numerical integration | quadpack | Modernized QUADPACK Library for 1D numerical quadrature | |
Numerical integration | quadrature-fortran | 1D-6D Adaptive Gaussian Quadrature | |
Random numbers | mersenne-twister-fortran | Mersenne Twister pseudorandom number generator | |
Astrodynamics | Fortran-Astrodynamics-Toolkit | Modern Fortran Library for Astrodynamics | |
Astrodynamics | astro-fortran | Standard models used in fundamental astronomy |
All of these libraries satisfy my requirements for being part of a modern Fortran scientific ecosystem:
- All are written in a modern Fortran style (free-form, modules, no obsolete constructs such as gotos or common blocks, etc.) All legacy code has been modernized.
- They are all usable with the Fortran Package Manager. A couple of previous posts here and here show how easy it is to do this with a one-line addition to your FPM manifest file.
- The real kind (single, double, or quad precision) is selectable via a preprocessor directive.
- All libraries are available in git repositories on GitHub and contributions are welcome. Every commit is unit tested using GitHub CI.
- All the sourcecode is documented online using FORD.
- All have permissive licenses (e.g., BSD-3) so you can use them however you want.
Fortran has many advantages for scientific computing. It's fast, standard, statically typed, compiled, stable, has a nice array syntax, and includes object oriented programming and native parallelism. It is great for technical and numerical codes that need to run fast and are intended to be used for decades. The libraries listed above will not stop working in a few years. An extremely complicated Fortran application can be recompiled with just a Fortran compiler. You cannot say the same for anything written in the Python scientific ecosystem, which is a Frankenstein hybrid of a scripting language hacked together with a pile of C/C++/Fortran libraries compiled by somebody else. Good luck trying to run Python you write now 20 years from now (or trying to run something written 20 years ago). Fortran is a simple and stable foundation upon which to build our scientific software, Python is not. Having readily available modern libraries along with recent improvements in the Fortran tooling and ecosystem should only serve to make Fortran more appealing in this area.
See also
- Complete list of of my repositories on GitHub
- SciFortran A library of fortran modules and routines for scientific calculations (in a way just like scipy for python) [LGPL License]
- Fortran90 Codes from John Burkhart [LGPL License]
- Alan Miller's Fortran Software All code written by Alan Miller is released into the public domain. Code written by other authors or from other sources (e.g., academic journals) may be subject to other restrictions.
- FPM registry package registry for the Fortran package manager
- Fortran-lang/stdlib A community driven standard library for (modern) Fortran
- GSL - GNU Scientific Library [GPL License]
- A plea for stability in the SciPy ecosystem Konrad Hinsen's Blog, Nov 16, 2017
- L. Kedward, et al, The State of Fortran, Computing in Science and Engineering 24(2):1-1, March 2022.