Skip to content

Commit

Permalink
fix tcl2py encoding=utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
yexiang1992 committed Mar 3, 2023
1 parent 999b5f3 commit 9c7c31b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Binary file modified src/opstool/preprocessing/__pycache__/tcl2py.cpython-39.pyc
Binary file not shown.
15 changes: 11 additions & 4 deletions src/opstool/preprocessing/tcl2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def tcl2py(input_file: str,
import_txt = "from openseespy.opensees import *\n\n"
prefix = ''

with open(input_file, 'r') as f:
with open(input_file, 'r', encoding="utf-8") as f:
tcl_src = f.read()
tcl_src = tcl_src.replace("{", " { ")
tcl_src = tcl_src.replace("}", " } ")
interp, contents = _TclInterp(prefix)
interp.eval(tcl_src)

with open(output_file, mode='w') as fw:
with open(output_file, mode='w', encoding="utf-8") as fw:
fw.write(import_txt)
for line in contents:
fw.write(line + "\n")
Expand Down Expand Up @@ -208,7 +208,7 @@ def _timeSeries(*args):
args = _remove_commit(args)
args = [_type_convert(i) for i in args]
if args[0] == 'Path':
if '-time' in args or '-values' in args:
if ('-time' in args) or ('-values' in args):
time, values = None, None
if '-time' in args:
idx = args.index('-time')
Expand Down Expand Up @@ -241,7 +241,14 @@ def _timeSeries(*args):
def _pattern(*args):
args = _remove_commit(args)
args = tuple([_type_convert(i) for i in args])
contents.append(f"{prefix}pattern{args[:-1]}")
if args[0].lower() == "plain" and isinstance(args[2], str):
contents.append(f"{prefix}timeSeries('{args[2]}', {args[1]})")
args = list(args)
args[2] = args[1]
args = tuple(args)
contents.append(f"{prefix}pattern{args[:-1]}")
else:
contents.append(f"{prefix}pattern{args[:-1]}")
txt = args[-1]
txt.replace("\\n", '')
interp.eval(txt)
Expand Down

0 comments on commit 9c7c31b

Please sign in to comment.