Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes for python 3 #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ fig/
DatcomParser-*/
deb_dist/
*.egg-info/
.idea/
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 pydatcom.parser import DatcomParser
from pydatcom.exporter import DatcomExporter
from pydatcom.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()
26 changes: 13 additions & 13 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 @@ -271,7 +271,7 @@ def t_ANY_newline(self, t):
#print 'newline'

def t_ANY_error(self, t):
print("Illegal character '%s' at line" % t.value[0], t.lexer.lineno)
print(("Illegal character '%s' at line" % t.value[0], t.lexer.lineno))
t.lexer.skip(1)
sys.exit(1)

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 All @@ -493,8 +493,8 @@ def parse_table2d(self, rowWidth, colWidths, data):

def p_error(self, p):
if p:
print("Syntax error '%s' at line: %d, state: %s" \
% (p.value, self.lex.lineno, self.lex.lexstate))
print(("Syntax error '%s' at line: %d, state: %s" \
% (p.value, self.lex.lineno, self.lex.lexstate)))
else:
print("Syntax error at EOF")
sys.exit(1)
Expand Down Expand Up @@ -553,9 +553,9 @@ def p_term_terms(self, p):
def p_terms(self, p):
'terms : terms COMMA term'
p[0] = p[1]
for key in p[3].keys():
for key in list(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
52 changes: 26 additions & 26 deletions pydatcom/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,112 +21,112 @@ def __init__(self, parser_dict):
def common_plots(self):
## lift plots
self.plot2d(
title='{name}: Basic Lift Coefficient',
title='{name}-Basic Lift Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='CL_Basic', y_label='CL')
self.plot2d(
title='{name}: Flap effect on Lift Coefficient',
title='{name}-Flap effect on Lift Coefficient',
x_name='flap', x_label='Flap, deg',
y_name='dCL_Flap', y_label='dCL')
self.plot2d(
title='{name}: Elevator effect on Lift Coefficient',
title='{name}-Elevator effect on Lift Coefficient',
x_name='elev', x_label='Elevator, deg',
y_name='dCL_Elevator', y_label='dCL')
self.plot2d(
title='{name}: Pitch Rate effect on Lift Coefficient',
title='{name}-Pitch Rate effect on Lift Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCL_PitchRate', y_label='dCL')
self.plot2d(
title='{name}: Alpha Dot effect on Lift Coefficient',
title='{name}-Alpha Dot effect on Lift Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCL_AlphaDot', y_label='dCL')

## drag plots
self.plot2d(
title='{name}: Basic Drag Coefficient',
title='{name}-Basic Drag Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='CD_Basic', y_label='CD')
self.plot2d(
title='{name}: Drag Polar',
title='{name}-Drag Polar',
x_name='CL_Basic', x_label='CL',
y_name='CD_Basic', y_label='CD')
self.plot3d(
title='{name}: Flap effect on Drag Coefficient',
title='{name}-Flap effect on Drag Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='flap', y_label='Flap, deg',
z_name='dCD_Flap', z_label='dCD')
self.plot3d(
title='{name}: Elevator effect on Drag Coefficient',
title='{name}-Elevator effect on Drag Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='elev', y_label='Elevator, deg',
z_name='dCD_Elevator', z_label='dCD')

## side force plots
self.plot2d(
title='{name}: Basic Side Force Coefficient',
title='{name}-Basic Side Force Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCY_Beta', y_label='dCY')
self.plot2d(
title='{name}: Roll Rate effect on Side Force Coefficient',
title='{name}-Roll Rate effect on Side Force Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCY_RollRate', y_label='dCY')

## roll moment
self.plot2d(
title='{name}: Aileron effect on Roll Moment Coefficient',
title='{name}-Aileron effect on Roll Moment Coefficient',
x_name='alrn', x_label='Aileron, deg',
y_name='dCl_Aileron', y_label='dCl')
self.plot2d(
title='{name}: Side slip effect on Roll Moment Coefficient',
title='{name}-Side slip effect on Roll Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCl_Beta', y_label='dCl')
self.plot2d(
title='{name}: RollRate effect on Roll Moment Coefficient',
title='{name}-RollRate effect on Roll Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCl_RollRate', y_label='dCl')
self.plot2d(
title='{name}: YawRate effect on Roll Moment Coefficient',
title='{name}-YawRate effect on Roll Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCl_YawRate', y_label='dCl')

## pitch moment
self.plot2d(
title='{name}: Basic Pitch Moment Coefficient',
title='{name}-Basic Pitch Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='Cm_Basic', y_label='Cm')
self.plot2d(
title='{name}: Flap effect on Pitch Moment Coefficient',
title='{name}-Flap effect on Pitch Moment Coefficient',
x_name='flap', x_label='Flap, deg',
y_name='dCm_Flap', y_label='dCm')
self.plot2d(
title='{name}: Elevator effect on Pitch Moment Coefficient',
title='{name}-Elevator effect on Pitch Moment Coefficient',
x_name='elev', x_label='Elevator, deg',
y_name='dCm_Elevator', y_label='dCm')
self.plot2d(
title='{name}: Pitch Rate effect on Pitch Moment Coefficient',
title='{name}-Pitch Rate effect on Pitch Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCm_PitchRate', y_label='dCm')
self.plot2d(
title='{name}: Alpha Dot effect on Pitch Moment Coefficient',
title='{name}-Alpha Dot effect on Pitch Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCm_AlphaDot', y_label='dCm')

## yaw moment
self.plot3d(
title='{name}: Aileron effect on Yaw Moment Coefficient',
title='{name}-Aileron effect on Yaw Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='flap', y_label='Flap, deg',
z_name='dCn_Aileron', z_label='dCn')
self.plot2d(
title='{name}: Side Slip effect on Yaw Moment Coefficient',
title='{name}-Side Slip effect on Yaw Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCn_Beta', y_label='dCn')
self.plot2d(
title='{name}: Roll Rate effect on Yaw Moment Coefficient',
title='{name}-Roll Rate effect on Yaw Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCn_RollRate', y_label='dCn')
self.plot2d(
title='{name}: Yaw Rate effect on Yaw Moment Coefficient',
title='{name}-Yaw Rate effect on Yaw Moment Coefficient',
x_name='alpha', x_label='Alpha, deg',
y_name='dCn_YawRate', y_label='dCn')

Expand Down Expand Up @@ -171,13 +171,13 @@ def plot3d(self, title,
ax.grid()
plt.savefig(os.path.join(self.figpath,
os.path.join(self.figpath,
title.format(**self.d) + '.pdf')))
title.format(**self.d) + '.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
6 changes: 3 additions & 3 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def setUp(self):
pass

def test_parse(self):
parser = DatcomParser(os.path.join('test', 'data', 'Citation.out'))
parser = DatcomParser(os.path.join(os.path.curdir, 'data', 'Citation.out'))

def test_export(self):
parser = DatcomParser(os.path.join('test', 'data', 'Citation.out'))
parser = DatcomParser(os.path.join(os.path.curdir, 'data', 'Citation.out'))
exporter = DatcomExporter(parser.get_common(), 'modelica.mo')
result = exporter.get_export()

def test_plot(self):
parser = DatcomParser(os.path.join('test', 'data', 'Citation.out'))
parser = DatcomParser(os.path.join(os.path.curdir, 'data', 'Citation.out'))
plotter = DatcomPlotter(parser.get_common())
plotter.common_plots()