Tim Edwards | c12c795 | 2021-08-26 11:23:42 -0400 | [diff] [blame] | 1 | #!/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 | |
| 10 | import os |
| 11 | import re |
| 12 | import sys |
| 13 | |
| 14 | plist = ["ldif", "hdif", "rd", "rs", "rsc", "rdc", "nqsmod"] |
| 15 | regexps = [] |
| 16 | for parm in plist: |
| 17 | regexps.append(re.compile('^\+[ \t]*' + parm + '[ \t]*=[ \t]*0.0', re.IGNORECASE)) |
| 18 | |
| 19 | if len(sys.argv) <= 1: |
| 20 | print('Usage: xyce_hack2.py <path_to_file>') |
| 21 | sys.exit(1) |
| 22 | |
| 23 | else: |
| 24 | infile_name = sys.argv[1] |
| 25 | |
| 26 | filepath = os.path.split(infile_name)[0] |
Tim Edwards | 477d9b7 | 2022-02-06 17:01:15 -0500 | [diff] [blame] | 27 | filename = os.path.split(infile_name)[1] |
| 28 | fileroot = os.path.splitext(filename)[0] |
Tim Edwards | 7325e44 | 2022-03-03 16:51:52 -0500 | [diff] [blame] | 29 | outfile_name = os.path.join(filepath, fileroot + '_temp') |
Tim Edwards | c12c795 | 2021-08-26 11:23:42 -0400 | [diff] [blame] | 30 | |
| 31 | infile = open(infile_name, 'r') |
Tim Edwards | 7325e44 | 2022-03-03 16:51:52 -0500 | [diff] [blame] | 32 | outfile = open(outfile_name, 'w') |
Tim Edwards | c12c795 | 2021-08-26 11:23:42 -0400 | [diff] [blame] | 33 | |
| 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 | |