From 3945472be7bf518d3d5fbedf881087b54d5e9f2a Mon Sep 17 00:00:00 2001 From: aeroaks Date: Mon, 14 Nov 2016 18:43:47 +0100 Subject: [PATCH 1/3] converted to python 3.5.1 --- pydatcom/__init__.py | 6 +++--- pydatcom/exporter.py | 8 ++++---- pydatcom/parser.py | 26 +++++++++++++------------- pydatcom/plotter.py | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pydatcom/__init__.py b/pydatcom/__init__.py index ec40397..48d4432 100644 --- a/pydatcom/__init__.py +++ b/pydatcom/__init__.py @@ -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 diff --git a/pydatcom/exporter.py b/pydatcom/exporter.py index 976cf43..994c4e8 100644 --- a/pydatcom/exporter.py +++ b/pydatcom/exporter.py @@ -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", @@ -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() diff --git a/pydatcom/parser.py b/pydatcom/parser.py index 51afda0..57640c2 100644 --- a/pydatcom/parser.py +++ b/pydatcom/parser.py @@ -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: @@ -166,7 +166,7 @@ class DatcomParser(Parser): 'BOOL', 'CASEID', 'NAMELIST'] \ - + reserved_INPUT.values() + + list(reserved_INPUT.values()) # Tokens @@ -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) @@ -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: @@ -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.*' @@ -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() @@ -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 == '': @@ -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) @@ -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] diff --git a/pydatcom/plotter.py b/pydatcom/plotter.py index ecb9cb6..7ecbbca 100644 --- a/pydatcom/plotter.py +++ b/pydatcom/plotter.py @@ -177,7 +177,7 @@ def plot3d(self, title, @staticmethod def command_line(): import argparse - from parser import DatcomParser + from .parser import DatcomParser argparser = argparse.ArgumentParser() argparser.add_argument("datcom_file", From 862c3618bea58a2cabdd6bf06b89b334fc4c4d09 Mon Sep 17 00:00:00 2001 From: aeroaks Date: Mon, 14 Nov 2016 18:52:46 +0100 Subject: [PATCH 2/3] file name correction for windows and python3 --- pydatcom/plotter.py | 50 ++++++++++++++++++++++----------------------- test/test.py | 6 +++--- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/pydatcom/plotter.py b/pydatcom/plotter.py index 7ecbbca..087bc71 100644 --- a/pydatcom/plotter.py +++ b/pydatcom/plotter.py @@ -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') @@ -171,7 +171,7 @@ 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 diff --git a/test/test.py b/test/test.py index 0bc3876..5198882 100644 --- a/test/test.py +++ b/test/test.py @@ -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() From 4da64f11dab61218c874ef92060dfb235938df71 Mon Sep 17 00:00:00 2001 From: aeroaks Date: Mon, 14 Nov 2016 18:58:49 +0100 Subject: [PATCH 3/3] added pycharm ide config folder to ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6085219..a204ddc 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ fig/ DatcomParser-*/ deb_dist/ *.egg-info/ +.idea/