"""
Usage: rotate_with_orbit orbit_file celestial_events_file
"""

import sys

import coords
from ascii_orbit import *
from source_utils import *

def read_input_data(forb_name, fcel_name):
    # Open the files
    forb = open(forb_name, 'r')
    fcel = open(fcel_name, 'r')
    # Read in the orbit
    o = AsciiOrbit()
    o.read(forb)
    forb.close()
    # Read in the events
    cel = EventSequence()
    cel.read(fcel, (), coords.CELESTIAL)
    fcel.close()
    return o,cel

def main(argv=None):
    # parse the command line
    if argv is None:
        argv = sys.argv
    argc = len(argv)-1
    if (argc == 0):
        print __doc__
        return 0
    elif (argc == 2):
        forb_name = argv[1]
        fcel_name = argv[2]
    else:
        print __doc__
        return 1
    # Read in the events and the orbit
    o,sc = read_input_data(forb_name, fcel_name)
    # Dump events to stdout in converted form
    sc.header += "Coordinates: local"
    sc.write(sys.stdout, o)
    return 0

if __name__=='__main__':
    sys.exit(main())
