isawig2slha

Mon, 29 Apr 2013 15:04:31 +0200

author
Andy Buckley <andy@insectnation.org>
date
Mon, 29 Apr 2013 15:04:31 +0200
changeset 214
fa07ed634b18
parent 209
42fe24d30c22
permissions
-rwxr-xr-x

Better newline handling in final SLHA output formatting

andy@25 1 #! /usr/bin/env python
andy@25 2
andy@25 3 """\
andy@25 4 Usage: %prog IN.isa [OUT.spc]
andy@25 5
andy@25 6 Convert a HERWIG/ISAWIG model/decay spectrum file to an SLHA spectrum input
andy@25 7 file.
andy@25 8
andy@25 9 Conversion based on the HERWIG SUSY specification format, from
andy@25 10 http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/file.html
andy@209 11
andy@209 12 Author:
andy@209 13 Andy Buckley <andy.buckley@cern.ch>
andy@209 14 http://insectnation.org/projects/pyslha
andy@25 15 """
andy@25 16
andy@25 17 __author__ = "Andy Buckley <andy.buckley@cern.ch"
andy@25 18
andy@73 19
andy@73 20 import pyslha
andy@25 21 import sys, optparse
andy@73 22 parser = optparse.OptionParser(usage=__doc__, version=pyslha.__version__)
andy@25 23 opts, args = parser.parse_args()
andy@25 24 if len(args) < 1 or len(args) > 2:
andy@25 25 parser.print_help()
andy@25 26 sys.exit(1)
andy@25 27
andy@25 28 ## Choose output file
andy@25 29 import os
andy@25 30 o = os.path.basename(args[0])
andy@25 31 if "." in o:
andy@25 32 o = o[:o.rindex(".")]
andy@25 33 opts.OUTFILE = o + ".spc"
andy@25 34 if len(args) == 2:
andy@25 35 opts.OUTFILE = args[1]
andy@25 36
andy@25 37 ## Read spectrum file
andy@47 38 BLOCKS, DECAYS = pyslha.readISAWIGFile(args[0])
andy@25 39
andy@33 40 ## And write it out again!
andy@33 41 if opts.OUTFILE == "-":
andy@33 42 sys.stdout.write(pyslha.writeSLHA(opts.OUTFILE))
andy@33 43 else:
andy@47 44 pyslha.writeSLHAFile(opts.OUTFILE, BLOCKS, DECAYS)

mercurial