Skip to content

Instantly share code, notes, and snippets.

@aubreyrjones
Created March 9, 2021 06:26
Show Gist options
  • Save aubreyrjones/93a2f41c813407bccfa376330854300a to your computer and use it in GitHub Desktop.
Save aubreyrjones/93a2f41c813407bccfa376330854300a to your computer and use it in GitHub Desktop.
A script that y-mirrors the output from CLO3D.
#!/usr/bin/env python
import argparse
def parse_list(body):
return map(float, body.split(','))
def list_max(lst, curMax):
return reduce(max, lst, curMax)
arg_parser = argparse.ArgumentParser(description="flip a plt")
arg_parser.add_argument('file', type=str, nargs=1)
args = arg_parser.parse_args()
lines = []
with open(args.file[0]) as f:
lines = f.readlines()
setupLineNumbers = {}
maxX = 0.0
maxY = 0.0
for lineNumber, command in enumerate(lines):
prefix = command[:2]
if prefix in ('IP', 'SC'):
setupLineNumbers[prefix] = lineNumber
if prefix in ('PU', 'PD', 'PA'):
body = command[2:-2]
if body:
coords = parse_list(body)
maxX = list_max(coords[::2], maxX)
maxY = list_max(coords[1::2], maxY)
lines[setupLineNumbers['IP']] = 'IP0,%s,%s,0\n' % (maxY, maxX)
lines[setupLineNumbers['SC']] = 'SC0,1,0,-1,2;\n'
print "".join(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment