# - - - c h e c k A r g s
def checkArgs():
"""Process all command line arguments.
[ if sys.argv[1:] is a valid set of command line arguments ->
return (raDec, latLon, dt) where raDec is a set of
celestial coordinates as a sidereal.RADec instance,
latLon is position as a sidereal.LatLon instance, and
dt is a datetime.datetime instance
else ->
sys.stderr +:= error message
stop execution ]
"""
There should be exactly four arguments:
The combined right ascension and declination,
separated by the mandatory “+” or “-”.
The latitude, as an angle followed by “n” or “s” (case-insensitive).
The longitude, as an angle followed by “e” or “w” (case-insensitive).
The timestamp, as a combined date-time string.
#-- 1 --
# [ if sys.argv[1:] has exactly four elements ->
# rawRADec, rawLat, rawLon, rawDT := those elements
# else ->
# sys.stderr +:= error message
# stop execution ]
argList = sys.argv[1:]
if len(argList) != 4:
usage ("Incorrect command line argument count." )
else:
rawRADec, rawLat, rawLon, rawDT = argList
The work of checking the first argument is delegated to
subsidiary routines: Section 4.7, “checkRADec: Check equatorial
coordinates”.
For the rest, standard parsing functions exist:
Section 9.18, “parseLat(): Convert an external
latitude”, Section 9.19, “parseLon(): Convert an external
longitude”, and Section 9.6, “parseDatetime(): Convert an external
date-time string”.
#-- 2 --
# [ if rawRADec is a valid set of equatorial coordinates ->
# raDec := those coordinates as a sidereal.RADec instance
# else ->
# sys.stderr +:= error message
# stop execution ]
raDec = checkRADec ( rawRADec )
#-- 3 --
# [ if rawLat is a valid latitude ->
# lat := that latitude in radians
# else ->
# sys.stderr +:= error message
# stop execution ]
try:
lat = sidereal.parseLat ( rawLat )
except SyntaxError, detail:
usage ( "Invalid latitude: %s" % detail )
#-- 4 --
# [ if rawLon is a valid longitude ->
# lon := that longitude in radians
# else ->
# sys.stderr +:= error message
# stop execution ]
try:
lon = sidereal.parseLon ( rawLon )
except SyntaxError, detail:
usage ( "Invalid longitude: %s" % detail )
#-- 5 --
# [ if rawDT is a valid date-time string ->
# dt := that date-time as a datetime.datetime instance
# else ->
# sys.stderr +:= error message
# stop execution ]
try:
dt = sidereal.parseDatetime ( rawDT )
except SyntaxError, detail:
usage ( "Invalid timestamp: %s" % detail )
#-- 6 --
latLon = sidereal.LatLon ( lat, lon )
return (raDec, latLon, dt)