blob: 9308dad878549702c2ced6ee39d4b051bb30980d [file] [log] [blame]
Tim Edwardsc12c7952021-08-26 11:23:42 -04001#!/usr/bin/env python3
2#
3#--------------------------------------------------------------------
4# Workaround for the problem that xyce does not ignore ACM model
5# parameters passed to bsim3 models, and throws an error. These
6# parameters have no known effect on simulation and therefore
7# should be removed.
8#--------------------------------------------------------------------
9
10import os
11import re
12import sys
13
14plist = ["ldif", "hdif", "rd", "rs", "rsc", "rdc", "nqsmod"]
15regexps = []
16for parm in plist:
17 regexps.append(re.compile('^\+[ \t]*' + parm + '[ \t]*=[ \t]*0.0', re.IGNORECASE))
18
19if len(sys.argv) <= 1:
20 print('Usage: xyce_hack2.py <path_to_file>')
21 sys.exit(1)
22
23else:
24 infile_name = sys.argv[1]
25
26 filepath = os.path.split(infile_name)[0]
Tim Edwards477d9b72022-02-06 17:01:15 -050027 filename = os.path.split(infile_name)[1]
28 fileroot = os.path.splitext(filename)[0]
Tim Edwards7325e442022-03-03 16:51:52 -050029 outfile_name = os.path.join(filepath, fileroot + '_temp')
Tim Edwardsc12c7952021-08-26 11:23:42 -040030
31 infile = open(infile_name, 'r')
Tim Edwards7325e442022-03-03 16:51:52 -050032 outfile = open(outfile_name, 'w')
Tim Edwardsc12c7952021-08-26 11:23:42 -040033
34 line_number = 0
35 replaced_something = False
36 for line in infile:
37 line_number += 1
38
39 for rex in regexps:
40 rmatch = rex.match(line)
41 if rmatch:
42 # If a match is found, comment out the line.
43 replaced_something = True
44 break
45
46 if rmatch:
47 newline = re.sub('^\+', '* +', line)
48 else:
49 newline = line
50
51 outfile.write(newline)
52
53 infile.close()
54 outfile.close()
55 if replaced_something:
56 print("Something was replaced in '{}'".format(infile_name))
57 os.rename(outfile_name, infile_name)
58 else:
59 print("Nothing was replaced in '{}'.".format(infile_name))
60 os.remove(outfile_name)
61