Fortran library for Geodesics  2.0
Use as a standalone library

Download the source code from as a tarball from

or check out the source code from

Build the code with cmake

cmake -B BUILD -S .
cd BUILD
make
make test

possibly including some options via -D:

  • CONVERT_WARNINGS_TO_ERRORS warnings are fatal (default ON)
  • BUILD_DOCUMENTATION look for doxgen and build documentation (default ON)
  • BUILD_SHARED_LIBS make a shared (instead of static) library (default ON)

CMake code to install the library is not provided.

The library consists of the file geodesic.for

Licensed under the MIT/X11 License; see LICENSE.txt.

Also included are 3 small test programs:

  • geoddirect.for is a simple command line utility for solving the direct geodesic problem;
  • geodinverse.for is a simple command line utility for solving the inverse geodesic problem;
  • planimeter.for is a simple command line utility for computing the area of a geodesic polygon given its vertices.

Here, for example, is geodinverse.for

*> @file geodinverse.for
*! @brief A test program for invers()
*> A simple program to solve the inverse geodesic problem.
*!
*! This program reads in lines with lat1, lon1, lon2, lat2 and prints
*! out lines with azi1, azi2, s12 (for the WGS84 ellipsoid).
program geodinverse
implicit none
include 'geodesic.inc'
double precision a, f, lat1, lon1, azi1, lat2, lon2, azi2, s12,
+ dummy1, dummy2, dummy3, dummy4, dummy5
integer omask
* WGS84 values
a = 6378137d0
f = 1/298.257223563d0
omask = 0
10 continue
read(*, *, end=90, err=90) lat1, lon1, lat2, lon2
call invers(a, f, lat1, lon1, lat2, lon2,
+ s12, azi1, azi2, omask,
+ dummy1, dummy2, dummy3, dummy4, dummy5)
print 20, azi1, azi2, s12
20 format(1x, f20.15, 1x, f20.15, 1x, f19.10)
go to 10
90 continue
stop
end
program geodinverse
A simple program to solve the inverse geodesic problem.
Definition: geodinverse.for:9

Use geodinverse, for example, with

echo -30 0 29.5 179.5 | ./tools/geodinverse 

Finally, the two programs

  • ngsforward
  • ngsinverse

which are also built with cmake, provide drop-in replacements for replacements for the NGS tools FORWARD and INVERSE available from https://www.ngs.noaa.gov/TOOLS/Inv_Fwd/Inv_Fwd.html.

These cure two problems of the Vincenty algorithms used by NGS:

  • the accuracy is "only" 0.1 mm;
  • the inverse program sometimes goes into an infinite loop.

The corresponding source files

  • ngsforward.for
  • ngsinverse.for
  • ngscommon.for

are derived from the NGS source files

  • forward.for, version 2.0, dated 2002-08-21
  • inverse.for, version 3.0, dated 2012-11-04

and are therefore in the public domain.