File size: 1,379 Bytes
7df9186 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import numpy as np
import sys
from matplotlib import pyplot as plt
def read():
A = np.loadtxt('rtsim.dat')
cav = abs(A[:, 0] + 1j*A[:, 1])
fwd = abs(A[:, 2] + 1j*A[:, 3])
rfl = abs(A[:, 4] + 1j*A[:, 5])
return cav, fwd, rfl
def show(data):
cav, fwd, rfl = data
plt.plot(cav, label='cav')
plt.plot(fwd, label='fwd')
plt.plot(rfl, label='rfl')
plt.legend()
plt.show()
def fail_pass(condition):
if not condition:
print('FAIL')
sys.exit(1)
else:
print('PASS')
def check_err(test_val, bound, err):
check = abs(test_val - bound) < err
print(test_val, bound, err, check)
return check
def make_check(data):
cav, fwd, rfl = data
err_bar = 10
fail_pass(check_err(cav[-1], 8739, err_bar) and
check_err(fwd[-1], 6714, err_bar) and
check_err(rfl[-1], 6022, err_bar))
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description='rtsim')
parser.add_argument('-c', '--check', action='store_true', default=True,
help='Purely run the check')
parser.add_argument('-s', '--show', action='store_true',
help='Show plots')
args = parser.parse_args()
data = read()
if args.show:
make_check(data)
show(data)
else:
make_check(data)
|