#!python

import argparse
from soxs import Spectrum, PhotonList, FillFOVModel

parser = argparse.ArgumentParser(description='Create a SIMPUT photon list of a uniformly filled '+
                                             'field of view source from a spectrum supplied in a file.')
parser.add_argument("simput_prefix", type=str, 
                    help='The prefix of the SIMPUT file to be used as the root of the '+
                         'catalog. If it does not exist, it will be created.')
parser.add_argument("phlist_prefix", type=str, 
                    help='The prefix of the photon list file to be written.')
parser.add_argument("ra0", help="The right ascension of the source center in degrees.")
parser.add_argument("dec0", help="The declination of the source center in degrees.")
parser.add_argument("fov", help="The field of view on a side in arcminutes.")
parser.add_argument("specfile", type=str, help="The file containing the spectrum to be used.")
parser.add_argument("exp_time", help='The exposure time to use, in seconds.')
parser.add_argument("--area", default=30000.0, 
                    help='The collecting area to use, in cm^2. Default: 30000.0')
parser.add_argument("--append", action='store_true',
                    help='If set, append a new source an existing SIMPUT catalog. ')
parser.add_argument("--overwrite", action='store_true',
                    help='Overwrite an existing file with the same name.')
parser.add_argument("--random_seed", type=int,
                    help="A constant integer random seed to produce a consistent set of random numbers.")

args = parser.parse_args()

spec = Spectrum.from_file(args.specfile)
fov_src = FillFOVModel(args.ra0, args.dec0, args.fov)
phlist = PhotonList.from_models(args.phlist_prefix, spec, fov_src, args.exp_time,
                                args.area, prng=args.random_seed)
phlist.write_photon_list(args.simput_prefix, append=args.append, overwrite=args.overwrite)
