diff --git a/interfaces/cython/cantera/ck2cti.py b/interfaces/cython/cantera/ck2cti.py index 4394c6f78..849cd7ce8 100644 --- a/interfaces/cython/cantera/ck2cti.py +++ b/interfaces/cython/cantera/ck2cti.py @@ -1385,6 +1385,11 @@ class Parser(object): 'next section on line {0}.'.format(self.line_number)) advance = False tokens.pop() + # Fix the case where there THERMO ALL or REAC UNITS + # ends the species section + if (tokens[-1].upper().startswith('THER') or + tokens[-1].upper().startswith('REAC')): + tokens.pop() break line, comment = readline() diff --git a/interfaces/cython/cantera/test/test_convert.py b/interfaces/cython/cantera/test/test_convert.py index 494742233..a62a5f3a7 100644 --- a/interfaces/cython/cantera/test/test_convert.py +++ b/interfaces/cython/cantera/test/test_convert.py @@ -159,6 +159,20 @@ class chemkinConverterTest(utilities.CanteraTest): self.assertEqual(gas.n_species, 3) self.assertEqual(gas.n_reactions, 2) + def test_unterminatedSections2(self): + self.assertRaises(ck2cti.InputParseError, + lambda: convertMech('../data/unterminated-sections2.inp', + outName='unterminated-sections2.cti', + quiet=True)) + + convertMech('../data/unterminated-sections2.inp', + outName='unterminated-sections2.cti', + quiet=True, permissive=True) + + gas = ct.Solution('unterminated-sections2.cti') + self.assertEqual(gas.n_species, 3) + self.assertEqual(gas.n_reactions, 2) + def test_nasa9(self): convertMech('../data/nasa9-test.inp', thermoFile='../data/nasa9-test-therm.dat', diff --git a/test/data/unterminated-sections2.inp b/test/data/unterminated-sections2.inp new file mode 100644 index 000000000..d952e7181 --- /dev/null +++ b/test/data/unterminated-sections2.inp @@ -0,0 +1,31 @@ +Elements +H C + +SPECIES +foo bar baz + + +thermo All + 300.000 1000.000 5000.000 +foo C 1H 4 G 200.000 3500.000 1000.000 1 + 7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2 +-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3 +-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4 +bar C 1H 4 G 200.000 3500.000 1000.000 1 + 7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2 +-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3 +-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4 +baz C 1H 4 G 200.000 3500.000 1000.000 1 + 7.48514950E-02 1.33909467E-02-5.73285809E-06 1.22292535E-09-1.01815230E-13 2 +-9.46834459E+03 1.84373180E+01 5.14987613E+00-1.36709788E-02 4.91800599E-05 3 +-4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4 + +reactions cal/mol +foo + bar = 2 baz 1.2345e12 1.0 200.0 +2foo + baz = 3bar 5.4321e10 1.0 500.0 + +transport +foo 2 357.000 5.180 0.000 0.000 1.000 +bar 2 266.800 4.982 0.000 0.000 1.000 +baz 2 266.800 4.982 0.000 0.000 1.000 +! some comment