#! /usr/bin/env python

"""\
Usage: %prog IN.slha [OUT.isa]

Convert an SLHA model/decay spectrum file to a HERWIG/ISAWIG SUSY spectrum input
file, in the format written by ISAWIG. The intention of this script is to allow
HERWIG to be used with spectra generated by codes other than ISAWIG,
e.g. SoftSUSY, SPheno, etc. And fundamentally because the author was fed up with
having to make ISASUSY compile with gfortran on platforms where CERNLIB wasn't
available!

Conversion based on the HERWIG SUSY specification format, from
http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/file.html
"""

__author__ = "Andy Buckley <andy.buckley@cern.ch"


import sys, optparse
parser = optparse.OptionParser(usage=__doc__)
opts, args = parser.parse_args()
if len(args) < 1 or len(args) > 2:
    parser.print_help()
    sys.exit(1)

## Choose output file
import os
o = os.path.basename(args[0])
if "." in o:
    o = o[:o.rindex(".")]
opts.OUTFILE = o + ".isa"
if len(args) == 2:
    opts.OUTFILE = args[1]

## Read spectrum file
import pyslha
BLOCKS, DECAYS = pyslha.readSLHAFile(args[0])

## And write it out again!
if opts.OUTFILE == "-":
    sys.stdout.write(pyslha.writeISAWIG(opts.OUTFILE))
else:
    pyslha.writeISAWIGFile(opts.OUTFILE, BLOCKS, DECAYS)
