Fortran library for Geodesics 1.52
Loading...
Searching...
No Matches
Geodesic routines implemented in Fortran
Author
Charles F. F. Karney (charl.nosp@m.es@k.nosp@m.arney.nosp@m..com)
Version
1.52

The documentation for other versions is available at https://geographiclib.sourceforge.io/m.nn/Fortran for versions numbers m.nn ≥ 1.28.

Abstract

This is a Fortran implementation of the geodesic algorithms from GeographicLib. This is a self-contained library which makes it easy to do geodesic computations for an ellipsoid of revolution in a Fortran program. It is written in Fortran 77 (avoiding features which are now deprecated) and should compile correctly with just about any Fortran compiler.

Downloading the source

The Fortran library is part of GeographicLib which available for download at

as either a compressed tar file (tar.gz) or a zip file. After unpacking the source, the Fortran library can be found in the directory legacy/Fortran. The library consists of the file geodesic.for. The Fortran-90 interface is defined in geodesic.inc.

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

Library documentation

Here is the application programming interface for the library (this is just the documentation for the source file, geodesic.for).

Sample programs

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

To compile, link, and run this, you would typically use

f95 -o geodinverse geodinverse.for geodesic.for
echo 30 0 29.5 179.5 | ./geodinverse 

These sample programs can also be built with the supplied cmake file, CMakeLists.txt, as follows

mkdir BUILD
cd BUILD
cmake ..
make
make test
echo 30 0 29.5 179.5 | ./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.

Using the library

  • Optionally put
    include "geodesic.inc"
    in declaration section of your subroutines.
  • make calls to the geodesic routines from your code. The interface to the library is documented in geodesic.for.
  • Compile and link as described above.

External links

Change log

  • Version 1.52 (released 2021-06-22)
    • Be more aggressive in preventing negative s12 and m12 for short lines.
  • Version 1.50 (released 2019-09-24)
    • Allow arbitrarily complex polygons in area. In the case of self-intersecting polygons the area is accumulated "algebraically", e.g., the areas of the 2 loops in a figure-8 polygon will partially cancel.
  • Version 1.49 (released 2017-10-05)
    • Fix code formatting and add two tests.
  • Version 1.48 (released 2017-04-09)
    • Change default range for longitude and azimuth to (−180°, 180°] (instead of [−180°, 180°)).
  • Version 1.47 (released 2017-02-15)
    • Improve accuracy of area calculation (fixing a flaw introduced in version 1.46).
  • Version 1.46 (released 2016-02-15)
    • More accurate inverse solution when longitude difference is close to 180°.
  • Version 1.45 (released 2015-09-30)
    • The solution of the inverse problem now correctly returns NaNs if one of the latitudes is a NaN.
    • Include a test suite that can be run with "make test" after configuring with cmake.
    • The library now treats latitudes outside the range [−90°, 90°] as NaNs; so the sample programs no longer check for legal values of latitude.
  • Version 1.44 (released 2015-08-14)
    • Improve accuracy of calculations by evaluating trigonometric functions more carefully and replacing the series for the reduced length with one with a smaller truncation error.
    • The allowed ranges for longitudes and azimuths is now unlimited; it used to be [−540°, 540°).
    • The sample programs, geoddirect and geodinverse, enforce the restriction of latitude to [−90°, 90°].
    • The inverse calculation sets s12 to zero for coincident points at pole (instead of returning a tiny quantity).