#!/usr/bin/env python

# Made by Min-Su Shin (Department of Astrophysical Sciences, Princeton University)
# It will be useful for preparing observation or checking possible observable targets.
# Since PyEphem module is used, you need to install PyEphem before running realtime_obs_help.py.

import ephem, string, math, sys, commands

if (len(sys.argv) != 4 ) :
	print "[usage] realtime_obs_help.py 2005/10/30 00:20 ID_ra_dec.list"
	print "Note: time is UTC!!! ID_ra_dec.list has three columns: ID, ra(deg), dec(deg)"
	sys.exit()

obs_date1 = sys.argv[1]
obs_date2 = sys.argv[2]
obs_date = obs_date1 + " " + obs_date2
# Setting the location of the observatory
# Apache Point Observatory's location (longitude, latitude, and height)
# If you want to change the location of the observatory, change the variables: obs_lon, obs_lat
# gatech.elev. The detail explanation is given in PyEphem manual.
obs_lon = '-105.820278'
obs_lat = '32.780278'
gatech = ephem.Observer()
gatech.elev = 2788
gatech.long, gatech.lat = obs_lon, obs_lat
gatech.date = obs_date

# Sidereal Time
mst = gatech.sidereal_time()

input_file = open(sys.argv[3],'r')
print "Input date : "+obs_date+" (UTC)"
print "ID \t RA \t DEC \t AZ \t ALT (Air mass) \t RISE \t TRANSIT (Zenith Dist.) \t SET"
count = 1
while 1:
	line = input_file.readline()
	if not line : break
	lines = string.split(line)
	objid = lines[0]
	ra = lines[1] 
	ra = ephem.degrees(ra) # radian
	ra = ephem.hours(ra)
	dec = lines[2]
	obj_pointer = ephem.FixedBody()
	obj_pointer._ra = ra
	obj_pointer._dec = dec
	obj_pointer.compute(gatech)
	zenith_dist = 0.5*math.pi - obj_pointer.alt
	print objid, ra, ephem.degrees(dec), obj_pointer.az, obj_pointer.alt, "(", 1.0/math.cos(zenith_dist), ")", obj_pointer.rise_time, obj_pointer.transit_time, "(", zenith_dist*180.0/math.pi, ")", obj_pointer.set_time
print "It was generated by realtime_obs_help.py."
