| #!/usr/bin/env python3 |
| |
| import os |
| import sys |
| |
| |
| def main(args): |
| assert len(args) == 2, args |
| |
| infile = args.pop(0) |
| assert os.path.isfile(infile), infile |
| outdir = args.pop(0) |
| assert os.path.isdir(outdir), outdir |
| assert not args, args |
| |
| basename = os.path.basename(infile) |
| fname, ext = basename.split('.', 1) |
| |
| part_a = [] |
| part_b = [] |
| |
| direction = None |
| for line in open(infile): |
| if line.startswith('.subckt'): |
| bits = line.split() |
| assert len(bits) > 1, (bits, line) |
| if bits[1].endswith('_b'): |
| direction = 'b' |
| else: |
| direction = 'a' |
| |
| if direction is None: |
| part_a.append(line) |
| part_b.append(line) |
| elif direction == 'a': |
| part_a.append(line) |
| elif direction == 'b': |
| part_b.append(line) |
| |
| fname_a = os.path.join(outdir, f'{basename}') |
| assert not os.path.exists(fname_a), fname_a |
| fname_b = os.path.join(outdir, f'{fname}_b.new.{ext}') |
| assert not os.path.exists(fname_b), fname_b |
| |
| print("split_nlowvt_rf.py: Wrote", fname_a, "with", len(part_a), "lines") |
| with open(fname_a, 'w') as f: |
| f.write(''.join(part_a)) |
| print("split_nlowvt_rf.py: Wrote", fname_b, "with", len(part_b), "lines") |
| with open(fname_b, 'w') as f: |
| f.write(''.join(part_b)) |
| |
| |
| if __name__ == "__main__": |
| sys.exit(main(sys.argv[1:])) |