Skip to content

Repository files navigation

sml-tle

CI

A zero-dependency Standard ML library for parsing and working with Two-Line Element (TLE) sets. Validates checksums, parses orbital elements, and computes derived quantities such as mean anomaly propagation and semi-major axis.

API

Function/Value Description
exception TLE of string Raised on parse or validation errors
type elements Record of all parsed TLE fields (satnum, epochYear, epochDay, incl, raan, ecc, argp, meanAnom, meanMotion, bstar, revs)
checksum s Compute TLE checksum (mod-10 digit/dash sum) of first 68 chars of s
validLine s True if line is ≥69 chars and checksum matches stored last digit
getInt s Parse a trimmed integer field; raises TLE on non-numeric or out-of-32-bit-range input (never Overflow)
parse (l1, l2) Parse a TLE line pair; raises TLE on invalid checksum or format
meanAnomalyAt elem t Mean anomaly (degrees) at t minutes from epoch
semiMajorAxis elem Semi-major axis in km from Kepler's third law

TLE Field Positions (0-based)

Line 1: satnum 2-6, epochYear 18-19, epochDay 20-31, bstar 53-60.
Line 2: incl 8-15, raan 17-24, ecc 26-32 (implicit "0." prefix), argp 34-41, meanAnom 43-50, meanMotion 52-62, revs 63-67.

Worked Example

val line1 = "1 25544U 98067A   21094.52616280  .00003335  00000-0  69116-4 0  9997"
val line2 = "2 25544  51.6435 295.2994 0001972 330.2380 193.7088 15.48938500277852"
val elem  = Tle.parse (line1, line2)
val sma   = Tle.semiMajorAxis elem  (* ~6798.0 km *)
val ma30  = Tle.meanAnomalyAt elem 30.0  (* mean anomaly 30 min later *)

Cross-compiler notes

Integer fields are parsed with a bounded 32-bit check, so a large untrusted value can never raise Overflow. This keeps behaviour identical across MLton (32-bit int) and Poly/ML (63-bit int): an out-of-range integer field raises the documented TLE exception instead. Test output is byte-identical under both compilers.

Install / Build / Test

$ cd sml-tle
$ make all-tests

Example

make example builds and runs examples/demo.sml, which parses the same ISS (ZARYA) TLE used above and exercises checksum validation, field access, and the derived quantities (output is byte-identical under MLton and Poly/ML):

=== sml-tle demo ===

-- checksum + line validation --
  checksum line1  = 7
  validLine line1 = true
  validLine line2 = true
  validLine (corrupted checksum) = false

-- getInt --
  getInt "  42"  = 42
  getInt "bad" raises TLE = true

-- parse: ISS (ZARYA), NORAD 25544 --
  satnum      = 25544
  epochYear   = 21
  epochDay    = 94.52616280
  incl (deg)  = 51.6435
  raan (deg)  = 295.2994
  ecc         = 0.0001972
  argp (deg)  = 330.2380
  meanAnom    = 193.7088
  meanMotion  = 15.48938500
  bstar       = 0.00006912
  revs        = 27785

-- derived quantities --
  semiMajorAxis = 6797.967 km
  meanAnomalyAt 0 min = 193.7088 deg
  meanAnomalyAt 30 min = 309.8792 deg
  meanAnomalyAt 90 min = 182.2200 deg
  meanAnomalyAt 360 min = 147.7535 deg

About

Pure Standard ML NORAD TLE parser: checksum validation, mean-element decode, mean-motion propagation and semi-major axis (MLton + Poly/ML)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages