mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-04-01 03:00:13 -04:00
Disable high-level interface for MATLAB and tidy indentation
This commit is contained in:
@@ -7,22 +7,21 @@ header_template = """
|
||||
"""
|
||||
|
||||
# Each entry in the list is a chunk (probably a line) in the to-be-generated code
|
||||
body_template = """
|
||||
[
|
||||
high_level_interface = [
|
||||
"",
|
||||
{
|
||||
"type": "print",
|
||||
"arguments": [
|
||||
"'**************** INFORMATION ***************'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
"arguments": [
|
||||
"'This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -36,7 +35,7 @@ body_template = """
|
||||
]
|
||||
}
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -50,7 +49,7 @@ body_template = """
|
||||
]
|
||||
}
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -64,7 +63,7 @@ body_template = """
|
||||
]
|
||||
}
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
"",
|
||||
{
|
||||
@@ -72,7 +71,7 @@ body_template = """
|
||||
"arguments": [
|
||||
"'*********** HIGH LEVEL INTERFACE *****************'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -88,7 +87,7 @@ body_template = """
|
||||
},
|
||||
"'K'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -103,7 +102,7 @@ body_template = """
|
||||
},
|
||||
"'K'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -117,7 +116,7 @@ body_template = """
|
||||
]
|
||||
}
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -132,7 +131,7 @@ body_template = """
|
||||
},
|
||||
"'J/kg/K'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -147,13 +146,13 @@ body_template = """
|
||||
},
|
||||
"'J/kg/K'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
"",
|
||||
{
|
||||
"type": "print",
|
||||
"arguments": [ "'*********** HUMID AIR PROPERTIES *****************'" ],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -168,7 +167,7 @@ body_template = """
|
||||
},
|
||||
"'kg_w/kg_da'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -190,13 +189,13 @@ body_template = """
|
||||
},
|
||||
"'(fractional)'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
"",
|
||||
{
|
||||
"type": "print",
|
||||
"arguments": [ "'*********** INCOMPRESSIBLE FLUID AND BRINES *****************'" ],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -211,7 +210,7 @@ body_template = """
|
||||
},
|
||||
"'kg/m^3'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -226,13 +225,15 @@ body_template = """
|
||||
},
|
||||
"'Pa-s'"
|
||||
],
|
||||
"EOL":true
|
||||
},
|
||||
"EOL":True
|
||||
}
|
||||
]
|
||||
low_level_interface = [
|
||||
"",
|
||||
{
|
||||
"type": "print",
|
||||
"arguments": [ "'*********** LOW-LEVEL INTERFACE *****************'" ],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "custom_assignment",
|
||||
@@ -245,7 +246,7 @@ body_template = """
|
||||
"'HEOS'", "'Water&Ethanol'"
|
||||
]
|
||||
},
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "custom_assignment",
|
||||
@@ -258,7 +259,7 @@ body_template = """
|
||||
"0.5"
|
||||
]
|
||||
},
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "class_dereference",
|
||||
@@ -270,7 +271,7 @@ body_template = """
|
||||
"z"
|
||||
]
|
||||
},
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "class_dereference",
|
||||
@@ -287,7 +288,7 @@ body_template = """
|
||||
"101325", "1"
|
||||
]
|
||||
},
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
},
|
||||
{
|
||||
"type": "print",
|
||||
@@ -305,21 +306,21 @@ body_template = """
|
||||
},
|
||||
"'K'"
|
||||
],
|
||||
"EOL":true
|
||||
"EOL":True
|
||||
}
|
||||
|
||||
]
|
||||
"""
|
||||
|
||||
class BaseParser(object):
|
||||
|
||||
def __init__(self):
|
||||
self.pieces = high_level_interface + low_level_interface
|
||||
|
||||
def footer(self):
|
||||
return ''
|
||||
|
||||
def parse(self):
|
||||
j = json.loads(body_template)
|
||||
lines = []
|
||||
for line in j:
|
||||
for line in self.pieces:
|
||||
if isinstance(line, basestring):
|
||||
lines.append(line)
|
||||
elif isinstance(line, dict):
|
||||
@@ -401,7 +402,7 @@ class Octave(BaseParser):
|
||||
type_name_mapping = {'vector': None,
|
||||
'AbstractState': None}
|
||||
enum_name_mapping = {'input_pairs': "CoolProp"}
|
||||
indentation = ''
|
||||
indentation = ' '*0
|
||||
|
||||
def parse_arguments(self, arguments):
|
||||
out = []
|
||||
@@ -466,6 +467,9 @@ class MATLAB(BaseParser):
|
||||
type_name_mapping = {'vector': None,
|
||||
'AbstractState': None}
|
||||
indentation = ''
|
||||
|
||||
def __init__(self):
|
||||
self.pieces = high_level_interface
|
||||
|
||||
def parse_arguments(self, arguments):
|
||||
out = []
|
||||
@@ -516,7 +520,7 @@ class MATLAB(BaseParser):
|
||||
return l
|
||||
|
||||
def header(self):
|
||||
return '\n'
|
||||
return ''
|
||||
|
||||
class Java(BaseParser):
|
||||
|
||||
@@ -529,7 +533,7 @@ class Java(BaseParser):
|
||||
type_name_mapping = {'vector': 'DoubleVector',
|
||||
'AbstractState': 'AbstractState'}
|
||||
enum_name_mapping = {'input_pairs': "input_pairs"}
|
||||
indentation = ' '
|
||||
indentation = ' '*8
|
||||
|
||||
def parse_arguments(self, arguments):
|
||||
out = []
|
||||
@@ -544,9 +548,9 @@ class Java(BaseParser):
|
||||
|
||||
def dict2string(self, d):
|
||||
if d['type'] == 'comment':
|
||||
l = ' # ' + d['comment']
|
||||
l = '# ' + d['comment']
|
||||
elif d['type'] == 'print':
|
||||
l = ' System.out.println(' + ' + " " + '.join(self.parse_arguments(d['arguments'])) + ')'
|
||||
l = 'System.out.println(' + ' + " " + '.join(self.parse_arguments(d['arguments'])) + ')'
|
||||
elif d['type'] == 'function':
|
||||
l = self.map_function(d['function']) + '(' + ', '.join(self.parse_arguments(d['arguments'])) + ')'
|
||||
elif d['type'] == 'vector':
|
||||
@@ -578,10 +582,10 @@ class Java(BaseParser):
|
||||
return l
|
||||
|
||||
def header(self):
|
||||
return 'public class Example {\n static {\n System.loadLibrary("CoolProp");\n }\n\n public static void main(String argv[]){'
|
||||
return 'public class Example {\n static {\n System.loadLibrary("CoolProp");\n }\n\n public static void main(String argv[]){\n'
|
||||
|
||||
def footer(self):
|
||||
return ' }\n}'
|
||||
return '\n }\n}'
|
||||
|
||||
class Csharp(BaseParser):
|
||||
|
||||
@@ -594,7 +598,7 @@ class Csharp(BaseParser):
|
||||
type_name_mapping = {'vector': "DoubleVector",
|
||||
'AbstractState': 'AbstractState'}
|
||||
enum_name_mapping = {'input_pairs': "input_pairs"}
|
||||
indentation = ' '
|
||||
indentation = ' '*12
|
||||
|
||||
def parse_arguments(self, arguments):
|
||||
out = []
|
||||
@@ -636,7 +640,7 @@ class Csharp(BaseParser):
|
||||
return l
|
||||
|
||||
def header(self):
|
||||
return 'using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {'
|
||||
return 'using System;\nusing System.Collections.Generic;\nusing System.Text;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n'
|
||||
|
||||
def footer(self):
|
||||
return '\n }\n }\n}'
|
||||
|
||||
Reference in New Issue
Block a user