#!/usr/bin/python3
# harversine - notices and documentation at the end of the file

#------------------------------------------------#-------------------------------------------#
def main () :
 check_input ()
 distance ()
 exit (0)

#------------------------------------------------#-------------------------------------------#
def check_input () :
 from sys import argv
 from os.path import basename , realpath
 prog = basename (realpath(argv[0]))             # argc[0]:/aa/bb/cc prog=cc

 if len ( argv ) != 5 :
  print ( 'usage: ' + prog + ' lat1 lon1 lat2 lon2' )
  print ( 'example:' , prog , '49.64662 6.10362 49.64689 6.10589' )
  exit  (1)
 
#------------------------------------------------#-------------------------------------------#
def distance () :
 from sys import argv
 from math import sqrt , radians , cos , sin , asin
 f = list(map(float , [argv[1],argv[2],argv[3],argv[4]] )) # string2float
 la1,lo1,la2,lo2 = map ( radians , f )                     # float2radians
 d = 2*asin(sqrt( sin((la2-la1)/2)**2 + sin((lo2-lo1)/2)**2 * cos (la1) * cos (la2))) * 6371000 # distance
 print ( "%5.2f" % d ) # earth radius: m=6371000 km=6371 miles=3956 nautical_miles=3440

#------------------------------------------------#-------------------------------------------#
main ()
print ( 'ERROR: sentinel after main' )

# Calculate distance in meters between two points on Earth using the Haversine formula
# https://en.wikipedia.org/wiki/Haversine_formula
# Usage: haversine lat1 lon1 lat2 lon2
## Creator: M.T. Carrasco Benitez | Rights: CC BY-SA - Creative Commons Attribution-ShareAlike
