Scientific Computing

Fortran test frameworks

Unit test frameworks should be lightweight to setup and maintain. End users should be able to easily run the unit and integration tests themselves as part of a typical end-user install.

The simplest approach is to write several small test programs and execute them using CMake or Meson. This method can also be an appropriate choice where the program uses complex library interactions that may not mix well with a generic test framework.

The Veggies Fortran test framework is an example of a Fortran unit testing framework. Check the Fortran-lang group for a contemporary discussion on Fortran test frameworks.

Git autocorrect commands

Git commands can be lengthy, but Git autocorrect can help with command typos.

git config --global help.autocorrect prompt

This prompts with a suggestion for a mistyped Git command.

Matlab filesystem matlab.io.filesystem

Matlab cross-platform capabilities involve cross-platform factors dealing with filesystem and system calls. The standard library for Matlab matlab-stdlib provides several features on top of factory Matlab. Filesystem functions including canonicalized paths, finding executable programs, and retrieving filesystem type are among key capabilities of Matlab-stdlib.

Matlab R2025a makes public the internal functionality introduced in Matlab R2024b. The filePermissions function returns an object like matlab.io.UnixPermissions according to the operating platform.

As this functionality and classes are officially released, Matlab-stdlib is planned to incorporate them for new-enough Matlab releases, while continuing to work for older Matlab releases–currently back to R2019b.

When is sudo needed?

Needless use of administrator “sudo” privileges during install of a library or program is generally undesirable. Admin / superuser privileges are typically invoked for a single command by sudo, including on Windows. Casual use of “sudo” can goof up the operating system itself, create cybersecurity risks, and mess up the desired program installation. The install might do undesirable things like put itself under “/root” directory or make paths non-readable by the non-privileged user.

In general we write procedures without invoking sudo, to avoid careless sudo invocation. We assume the user knows when it’s appropriate to invoke sudo. sudo is commonly used with commands installing from repositories like “apt install”.

Python “pip install” defaults to PEP 370 --user if needed. In general, don’t install with sudo pip or sudo conda to avoid wrecking the system configuration.

Dropbox shared link

Dropbox shared link URLs can be readily used in scripts and programs including cURL, Wget, Matlab, Python, CMake, …. Dropbox treats non-web browser user agents distinctively. It may be necessary to set the URL options manually. Dropbox share URLs commonly end in “dl=0”, which will result in a webpage download instead of the intended file. We suggest changing the link to end in “dl=1”.

Get HDF5 library version

Computing platforms may have multiple version of the HDF5 library installed. The HDF5 library version currently being used can be determined by the program as in the following examples by language. The HDF5 library can write backward-compatible HDF5 files by HDF5 version bounds. At the time of writing, there is no way to introspect the HDF5 library version required to read a specific HDF5 file.

Matlab

Matlab release vs. HDF5 library version:

Matlab HDF5
R2024b (Update 3) 1.14.4.3
R2024a 1.10.11
R2023b 1.10.10
R2022a 1.10.8
R2021b 1.10.7
R2015a 1.8.12

Check Matlab HDF5 library version:

[major, minor, rel] = H5.get_libversion()

Python

Check Python h5py HDF5 library version:

import h5py

print(h5py.h5.get_libversion())

C, C++, Fortran

In C, C++, Fortran, check HDF5 library version with H5get_libversion().


Related: get NetCDF library version

Static linked executable

Static linking of the executable compiler / libc / system libraries can help mitigate missing library issues. Dynamically / shared linked executables on Windows require the DLL path to be in the environment variable PATH or the executable directory. On Linux / BSD, the shared library path must be in the environment variable LD_LIBRARY_PATH. On macOS, the shared library path must be in the environment variable LIBRARY_PATH. If the developer switches compiler environments, or the end user is missing compiler libraries, the executable may fail to run due unresolved dynamic library path.

Relatively few Windows users have compilers installed. Missing DLLs and DLL Hell are part of distributing Windows programs, where batch scripts can be used to set environment variables and Path for the program. A typical error code for missing DLL is -1073741515 → 0xc0000135 STATUS_DLL_NOT_FOUND.

Simply specifying static compiler linking flags does not guarantee portable executables, which are a more general problem. Even using a slim libc like musl doesn’t generally work for graphical programs using X11 / Wayland. The Cosmopolitan project creates a single binary executable from C/C++ code that works across operating systems.

Compiler flags

GCC / Gfortran can statically link compiler libraries including libgfortran into the final executable using flags -static and -static-libgfortran This increases the size of the executable, which may be negligible compared to the nuisances avoided.

gfortran -static -static-libgfortran myprog.f90 mylib.f90 -o myprog.exe

Other compilers have similar static compiler library link options:

For special cases where the system libc and libc++ aren’t used, the compilers typically have additional flags like -static-libgcc and -static-libstdc++.

Caveats

Some libraries may only be available as dynamic, and the options above typically will use the dynamic version if static isn’t available. macOS static linked executable may only work on your specific computer; macOS prefers dynamic linking. In general, we use the default build system linking (dynamic or static) unless there is a reason to specify static linking.