Skip to main content

Documentation 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.

Because IRBEM is itself written in Fortran 77, calling any of its subroutines from your own Fortran code requires nothing more than a standard 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 a Makefile 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:
make all      # compile everything
make install  # copy headers and libraries to the install prefix
make test     # run the built-in regression tests
Run make help from the repository root to see every available target and its description.

Linking against IRBEM

Link against the static archive liboneradesp.a. Add the path to the library with -L and request the library by name with -loneradesp:
gfortran my_program.f90 -L/path/to/irbem -loneradesp -o my_program
The static archive bundles every IRBEM object file into a single .a file; no shared-object file needs to be present at runtime.
If you compiled IRBEM with g77, add the flag -fno-second-underscore to your own compilation command. Without it g77 emits double-underscore symbol names that do not match the single-underscore symbols in the library, causing unresolved-symbol link errors.
g77 my_program.f -fno-second-underscore -L/path/to/irbem -loneradesp -o my_program

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 typeC equivalentWidth
INTEGERint32_t32-bit signed integer
DOUBLE PRECISIONdouble64-bit IEEE 754 float
Arrays are stored in column-major (Fortran) order. When you pass a 2-D array such as 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.
PROGRAM test_irbem
  IMPLICIT NONE

  ! --- Inputs ---
  INTEGER          ntime, kext, sysaxes
  INTEGER          options(5)
  INTEGER          iyear(1), idoy(1)
  DOUBLE PRECISION ut(1)
  DOUBLE PRECISION x1(1), x2(1), x3(1)
  DOUBLE PRECISION maginput(25,1)

  ! --- Outputs ---
  DOUBLE PRECISION lm(1), lstar(1), blocal(1), bmin(1), xj(1), mlt(1)

  ! --- Configuration ---
  ntime   = 1
  kext    = 5             ! Olson-Pfitzer Quiet external field model
  options = (/1,0,0,0,0/) ! options(1)=1: compute L*
  sysaxes = 0             ! GDZ coordinates: altitude, latitude, East longitude

  ! --- Spacecraft position: Tromsø, 651 km altitude ---
  iyear(1) = 2015
  idoy(1)  = 33           ! day 33 = 2 February
  ut(1)    = 22363.0d0    ! seconds elapsed since midnight
  x1(1)   = 651.0d0       ! altitude, km
  x2(1)   = 63.0d0        ! geodetic latitude, deg
  x3(1)   = 20.0d0        ! East longitude, deg

  ! --- Magnetic field driving parameters ---
  maginput       = 0.0d0
  maginput(1,1)  = 40.0d0  ! Kp × 10  (Kp = 4.0)

  ! --- Call IRBEM ---
  CALL make_lstar1(ntime, kext, options, sysaxes,       &
                   iyear, idoy, ut, x1, x2, x3,         &
                   maginput,                             &
                   lm, lstar, blocal, bmin, xj, mlt)

  ! --- Print results ---
  WRITE(*,'(A,F10.4)') 'Lstar  = ', lstar(1)
  WRITE(*,'(A,F10.4)') 'Lm     = ', lm(1)
  WRITE(*,'(A,F10.4)') 'MLT    = ', mlt(1)
  WRITE(*,'(A,F10.4)') 'blocal = ', blocal(1)
  WRITE(*,'(A,F10.4)') 'bmin   = ', bmin(1)
  WRITE(*,'(A,F10.4)') 'xj     = ', xj(1)

END PROGRAM test_irbem
Compile and run:
gfortran test_irbem.f90 -L/path/to/irbem -loneradesp -o test_irbem
./test_irbem
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 subroutine make_lstar1 appears as make_lstar1_ in the object file.
#include "irbem.h"   /* provided in the IRBEM distribution */
#include <stdint.h>

int main(void) {
    int32_t  ntime = 1, kext = 5, sysaxes = 0;
    int32_t  options[5] = {1, 0, 0, 0, 0};
    int32_t  iyear[1] = {2015}, idoy[1] = {33};
    double   ut[1]    = {22363.0};
    double   x1[1]    = {651.0}, x2[1] = {63.0}, x3[1] = {20.0};
    double   maginput[25] = {40.0}; /* index 0 = Kp*10; rest zero */
    double   lm[1], lstar[1], blocal[1], bmin[1], xj[1], mlt[1];

    make_lstar1_(&ntime, &kext, options, &sysaxes,
                 iyear, idoy, ut, x1, x2, x3,
                 maginput, lm, lstar, blocal, bmin, xj, mlt);

    printf("Lstar = %f\n", lstar[0]);
    return 0;
}
Link the C program the same way as Fortran:
gcc test_irbem.c -L/path/to/irbem -loneradesp -lgfortran -o test_irbem
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.

Build docs developers (and LLMs) love