#VAW ETH Zurich
#20230307 / David Vetsch

import argparse

parser = argparse.ArgumentParser(description='Convert string definition from bmc to json file.')
parser.add_argument('filename', nargs='+', help='name of bmc format string definition file ')
args = parser.parse_args()


path = args.filename[0]
new_path = './cross_section_order.json'
title = '\nconvert cross section order from .bmc to model.json format\n'
tabsize = 2

print(title)

with open(path, 'r') as bmc_file, open(new_path, 'w') as cs_order_file:
    lines = [line for line in bmc_file]
    cs_order = lines[9].strip()
    cs_order = cs_order[23:-1]
    cs_order_array = cs_order.split()
    cs_order = ''
    for cs_name in cs_order_array:
        cs_order = cs_order + '\"{}\",'.format(cs_name)
    cs_order_file.write('\t\t\t\t\t\t\"cross_section_order\": ['.expandtabs(tabsize))
    cs_order_file.write(cs_order[:-1])
    cs_order_file.write('],')

print("done.\n")