blob: 480e3ae1784f1d30ac93cf61dc42a490fb6b8ab0 [file] [log] [blame]
Tim Edwards1c74f852021-06-09 16:46:50 -04001#!/usr/bin/env python3
2#
3#--------------------------------------------------------------------
4# Workaround for the problem that xyce does not like having "vt"
5# as a subcircuit parameter name, because it is a xyce reserved
6# name. Change the parameter name in the one file that uses it.
7# This script is not robust, and depends on the fact that the
8# one file that declares "vt" does not have any corner model files,
9# and the characters "vt" do not appear in any other context.
10#--------------------------------------------------------------------
11
12import os
13import re
14import sys
15
16if len(sys.argv) <= 1:
17 print('Usage: xyce_hack.py <path_to_file>')
18 sys.exit(1)
19
20else:
21 infile_name = sys.argv[1]
22
23 filepath = os.path.split(infile_name)[0]
24 outfile_name = os.path.join(filepath, 'temp')
25
26 infile = open(infile_name, 'r')
27 outfile = open(outfile_name, 'w')
28
29 line_number = 0
30 replaced_something = False
31 for line in infile:
32 line_number += 1
33
34 if 'vt' in line:
35 newline = re.sub('vt', 'local_vt', line)
36 replaced_something = True
37 else:
38 newline = line
39
40 outfile.write(newline)
41
42 infile.close()
43 outfile.close()
44 if replaced_something:
45 print("Something was replaced in '{}'".format(infile_name))
46 os.rename(outfile_name, infile_name)
47 else:
48 print("Nothing was replaced in '{}'.".format(infile_name))
49 os.remove(outfile_name)
50