Skip to content
Snippets Groups Projects
Commit e352efa8 authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

moved ibsimu2tw to scripts folder

added command line arguments
parent 94f1dcba
No related branches found
No related tags found
No related merge requests found
Pipeline #2805 passed
#!/usr/bin/env python
'''
- Convert an IBSimu's output (export_path_manager_data) to a TraceWin's binary.
......@@ -16,16 +17,46 @@
R. Miyamoto (2018.06.25)
'''
import argparse
import os
import subprocess
parser = argparse.ArgumentParser(description="Converts IBSimu output to TraceWin dst format")
parser.add_argument('-i', '--inp', dest='infile',
help="Input file", required=True)
parser.add_argument('-o', '--out', dest='outfile',
help="Output file", required=True)
parser.add_argument('--h2', dest='h2', action='store_const',
help="Include H2", const=True, default=False)
parser.add_argument('--h3', dest='h3', action='store_const',
help="Include H3", const=True, default=False)
parser.add_argument("-m", dest="mc2_H1", default=938.272,
type=float, help="H1 mass [MeV/c2]")
parser.add_argument("-f", dest="freq", default=352.21,
type=float, help="Frequency")
args = parser.parse_args()
#-- Constants and inputs
mc2_H1 = 938.272
freq = 352.21
mc2_H1 = args.mc2_H1
freq = args.freq
file_name_in = 'tracewin_path_format_2d_10M.txt'
file_name_out_H1 = 'ISRC.H1_ibsimu.2d_10M.83mA.dst'
file_name_out_H2 = 'ISRC.H2_ibsimu.2d_10M.83mA.dst' # Comment out if H2 file isn't needed
file_name_out_H3 = 'ISRC.H3_ibsimu.2d_10M.83mA.dst' # Comment out if H3 file isn't needed
file_name_in = args.infile
file_name_out_H1 = args.outfile
if args.h2:
if args.outfile[-4:]!='.dst':
raise ValueError('Do not accept file ending of output file')
file_name_out_H2 = args.outfile[:-4]+'_H2.dst'
if args.h3:
if args.outfile[-4:]!='.dst':
raise ValueError('Do not accept file ending of output file')
file_name_out_H3 = args.outfile[:-4]+'_H3.dst'
#W_cut = 0.01 # Filter for W [MeV]. Only for experts.
......@@ -50,14 +81,14 @@ def save_dst(file_name, x6, Ibeam, mc2=938.272, freq=352.21):
x6 = numpy.reshape(x6, (numpy.size(x6)))
with open(file_name, 'wb') as file:
out = struct.pack('b' , 125 )
out += struct.pack('b' , 100 )
out += struct.pack('i' , len(x6))
out += struct.pack('d' , Ibeam )
out += struct.pack('d' , freq )
out += struct.pack('b' , 125 ) # Typo in the manual !!!!
out += struct.pack('%s'%len(x6)+'d', *x6 )
out += struct.pack('d' , mc2 )
out = struct.pack('b' , 125 )
out += struct.pack('b' , 100 )
out += struct.pack('i' , len(x6) )
out += struct.pack('d' , Ibeam )
out += struct.pack('d' , freq )
out += struct.pack('b' , 125 ) # Typo in the manual !!!!
out += struct.pack('%s'%len(x6)+'d', *x6 )
out += struct.pack('d' , mc2 )
file.write(out)
#-- Parameters from the header
......
from distutils.core import setup
setup(name='ESS Python Tools',
version='1.7',
version='1.8',
description='ESS Related Tools',
url='https://gitlab01.esss.lu.se/ess-bp/ess-python-tools',
author='Yngve Inntjore Levinsen',
......@@ -29,6 +29,6 @@ setup(name='ESS Python Tools',
'Programming Language :: Python :: 3.6',
],
packages=['ess'],
scripts=['scripts/tracewin', 'scripts/tracewin_errorstudy'],
scripts=['scripts/tracewin', 'scripts/tracewin_errorstudy', 'scripts/ibsimu2tw'],
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment