Degenerate Conic

Algorithms • Modern Fortran Programming • Orbital Mechanics

Oct 12, 2022

A Modern Fortran Scientific Programming Ecosystem

Scientific Programming Ecosystem

Image created with the assistance of NightCafe Creator.

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 GitHub release
Interpolation regridpack 1D-4D linear and cubic interpolation GitHub release
Interpolation finterp 1D-6D Linear Interpolation GitHub release
Interpolation PCHIP Piecewise Cubic Hermite Interpolation Package GitHub release
Plotting pyplot-fortran Make plots from Fortran using Matplotlib GitHub release
File I/O json-fortran Read and write JSON files GitHub release
File I/O fortran-csv-module Read and write CSV Files GitHub release
Optimization slsqp SLSQP Optimizer GitHub release
Optimization fmin Derivative free 1D function minimizer GitHub release
Optimization pikaia Pikaia Genetic Algorithm GitHub release
Optimization simulated-annealing Simulated Annealing Algorithm GitHub release
One Dimensional Root-Finding roots-fortran Roots of continuous scalar functions of a single real variable, using derivative-free methods GitHub release
Polynomial Roots polyroots-fortran Root finding for real and complex polynomial equations GitHub release
Nonlinear equations nlesolver-fortran Nonlinear Equation Solver GitHub release
Ordinary Differential Equations dop853 An explicit Runge-Kutta method of order 8(5,3) GitHub release
Ordinary Differential Equations ddeabm DDEABM Adams-Bashforth algorithm GitHub release
Numerical Differentiation NumDiff Numerical differentiation with finite differences GitHub release
Numerical integration quadpack Modernized QUADPACK Library for 1D numerical quadrature GitHub release
Numerical integration quadrature-fortran 1D-6D Adaptive Gaussian Quadrature GitHub release
Random numbers mersenne-twister-fortran Mersenne Twister pseudorandom number generator GitHub release
Astrodynamics Fortran-Astrodynamics-Toolkit Modern Fortran Library for Astrodynamics GitHub release
Astrodynamics astro-fortran Standard models used in fundamental astronomy GitHub release

dependencies

Example of module dependencies in a Fortran application. This is for the Halo solver.

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