Because IRBEM is itself written in Fortran 77, calling any of its subroutines from your own Fortran code requires nothing more than a standardDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/PRBEM/IRBEM/llms.txt
Use this file to discover all available pages before exploring further.
CALL statement and the correct linker flags. No wrapper layer is needed. C code can reach the same subroutines through the trailing-underscore symbol names that Fortran compilers emit (or through the C header provided with the library).
Building the library
The repository ships with aMakefile that produces both a static archive (liboneradesp.a) and a shared library (libirbem.so / libirbem.dll). Run the standard Make targets from the IRBEM root:
Linking against IRBEM
- Static library
Link against the static archive The static archive bundles every IRBEM object file into a single
liboneradesp.a. Add the path to the library with -L and request the library by name with -loneradesp:.a file; no shared-object file needs to be present at runtime.Data type requirements
IRBEM subroutines follow strict Fortran 77 type conventions. Passing variables of the wrong width causes silent data corruption or a crash with no diagnostic message.| Fortran type | C equivalent | Width |
|---|---|---|
INTEGER | int32_t | 32-bit signed integer |
DOUBLE PRECISION | double | 64-bit IEEE 754 float |
maginput(25, NTIME_MAX) from C, the first index (the 25-element parameter vector) varies fastest in memory. Most newer IRBEM routines use variable-length first dimensions; check the specific subroutine signature in the API reference before allocating.
Fortran example — make_lstar1
The following self-contained program calls make_lstar1 to compute magnetic coordinates for a single spacecraft position over Tromsø, Norway on 2 February 2015.
The
maginput array has dimensions (25, NTIME_MAX). Only the elements relevant to the chosen external field model need to be set; all others should remain zero or the IRBEM error sentinel (-1×10³¹ in Fortran). Element index 1 is Kp×10 (required by OPQ77), and the full mapping of the 25 elements to physical quantities is documented in the API Reference.C calling convention
IRBEM provides a C-compatible header file that declares every subroutine with its C prototype. On most platforms, Fortran compilers append a single trailing underscore to symbol names, so the Fortran subroutinemake_lstar1 appears as make_lstar1_ in the object file.
The
-lgfortran flag is required when linking a C program against a Fortran library because IRBEM relies on Fortran runtime support routines (I/O, math). If you linked against the shared library instead of the static archive, you may also need -lm.Variable-length array dimensions
Older IRBEM routines fix the first dimension of output arrays at compile time (e.g.NTIME_MAX = 100000). Newer routines accept the actual number of time steps as the first argument (ntime) and size their internal allocations dynamically. Always match your array declarations to the subroutine signature documented in the API Reference for the specific function you are calling.