#! /usr/bin/env python
# This file is part of the Astrometry.net suite.
# Licensed under a 3-clause BSD style license - see LICENSE
from __future__ import print_function
import sys

# Assume this script is in $(INSTALL_DIR)/bin/ and the
# python base directory is in $(INSTALL_DIR)/lib/python/ .
try:
    # If the PYTHONPATH is already set up, don't mess with it.
    import astrometry.util.fits
except:
    import os
    sys.path.insert(1, os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'lib', 'python')))

from astrometry.util.fits import fits_table

import optparse
parser = optparse.OptionParser(prog='[input files] [output file]')
opt,args = parser.parse_args()
if len(args) < 2:
    parser.print_usage()
    sys.exit(-1)
infns = args[:-1]
outfn = args[-1]
print('Writing to output file', outfn)
T = None
for fn in infns:
    print('Reading input', fn)
    Ti = fits_table(fn)
    if T is None:
        T = Ti
    else:
        T.add_columns_from(Ti)
T.writeto(outfn)
    

    
    
