Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pydatcom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from parser import DatcomParser
from exporter import DatcomExporter
from plotter import DatcomPlotter
from .parser import DatcomParser
from .exporter import DatcomExporter
from .plotter import DatcomPlotter
8 changes: 4 additions & 4 deletions pydatcom/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_export(self):
@staticmethod
def command_line():
import argparse
from parser import DatcomParser
from .parser import DatcomParser

argparser = argparse.ArgumentParser()
argparser.add_argument("datcom_file",
Expand All @@ -50,11 +50,11 @@ def command_line():
with open(args.out, 'w') as f:
f.write(result)
else:
print result
print(result)
else:
for case in parser.get_cases():
print 'case: %s\n%s\n' % \
(case['ID'], case.keys())
print('case: %s\n%s\n' %
(case['ID'], list(case.keys())))

if __name__ == "__main__":
DatcomExporter.command_line()
18 changes: 9 additions & 9 deletions pydatcom/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, file_name=None, debug=0,
if self.file_name == None:
while 1:
try:
s = raw_input('> ')
s = input('> ')
except EOFError:
break
if not s:
Expand Down Expand Up @@ -166,7 +166,7 @@ class DatcomParser(Parser):
'BOOL',
'CASEID',
'NAMELIST'] \
+ reserved_INPUT.values()
+ list(reserved_INPUT.values())

# Tokens

Expand Down Expand Up @@ -306,7 +306,7 @@ def t_CASE_INITIAL_JUNKALL(self, t):
def t_INPUT_FLOATVECTOR(self, t):
try:
vector = []
for num in string.split(t.value, ','):
for num in t.value.split(','):
vector.append(float(num))
t.value = vector
except ValueError:
Expand All @@ -327,7 +327,7 @@ def t_INPUT_FLOAT(self, t):

def t_INPUT_ERROR(self, t):
r'0.*ERROR.*\n(.+\n)'
print 'error: %s' % t.value
print('error: %s' % t.value)

def t_INPUT_ZEROLINE(self, t):
r'0.*'
Expand Down Expand Up @@ -386,10 +386,10 @@ def parse_table1d(self, cols, data):
table = {}
colLastOld = -1
lines = data.split('\n')
for i in xrange(len(cols)):
for i in range(len(cols)):
colLast = colLastOld + cols[i][1]
valList = []
for j in xrange(len(lines) - 1):
for j in range(len(lines) - 1):
# -1 to skip last newline
line = lines[j]
col = line[colLastOld + 1:colLast].strip()
Expand Down Expand Up @@ -467,13 +467,13 @@ def parse_table2d(self, rowWidth, colWidths, data):
rows = []
lines = data.split('\n')

for i in xrange(len(lines) - 1):
for i in range(len(lines) - 1):
# -1 to skip last newline
line = lines[i]
rows.append(float(line[0:rowWidth - 1]))
colLastOld = rowWidth
dataArray.append([])
for j in xrange(len(colWidths)):
for j in range(len(colWidths)):
colLast = colLastOld + colWidths[j]
col = line[colLastOld + 1:colLast].strip()
if col == '':
Expand Down Expand Up @@ -555,7 +555,7 @@ def p_terms(self, p):
p[0] = p[1]
for key in p[3].keys():
if key in p[0]:
print 'WARNING: duplicate key %s' % key
print('WARNING: duplicate key %s' % key)
else:
p[0][key] = p[3][key]

Expand Down
22 changes: 11 additions & 11 deletions pydatcom/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import numpy as np


def _safe_filename(name):
return re.sub(r'[<>:"/\\|?*]', '_', name)


class DatcomPlotter(object):

def __init__(self, parser_dict):
Expand Down Expand Up @@ -140,11 +144,11 @@ def plot2d(self, title,
ax.plot(x, y)
ax.set_xlabel(x_label.format(**self.d))
ax.set_ylabel(y_label.format(**self.d))
ax.set_title(title.format(**self.d))
rendered_title = title.format(**self.d)
ax.set_title(rendered_title)
ax.grid()
plt.savefig(os.path.join(self.figpath,
os.path.join(self.figpath,
title.format(**self.d) + '.pdf')))
_safe_filename(rendered_title) + '.png'))
plt.close(fig)

def plot3d(self, title,
Expand All @@ -159,25 +163,21 @@ def plot3d(self, title,
ax.set_xlabel(x_label.format(**self.d))
ax.set_ylabel(y_label.format(**self.d))
ax.set_zlabel(z_label.format(**self.d))
ax.set_title(title.format(**self.d))
#print 'len Z1:', len(Z)
#print 'len Z2:', len(Z[0])
#print 'len x:', len(x)
#print 'len y:', len(y)
rendered_title = title.format(**self.d)
ax.set_title(rendered_title)
X, Y = np.meshgrid(x, y)
surf = ax.plot_surface(X, Y, Z,
cmap=cm.jet, rstride=1, cstride=1)
fig.colorbar(surf, shrink=0.5, aspect=5)
ax.grid()
plt.savefig(os.path.join(self.figpath,
os.path.join(self.figpath,
title.format(**self.d) + '.pdf')))
_safe_filename(rendered_title) + '.png'))
plt.close(fig)

@staticmethod
def command_line():
import argparse
from parser import DatcomParser
from .parser import DatcomParser

argparser = argparse.ArgumentParser()
argparser.add_argument("datcom_file",
Expand Down