From a786135f13b540b3dcd873f02d555ff7ccade410 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Fri, 6 Dec 2013 23:15:18 +0000 Subject: [PATCH] [ck2cti] Add support for truncated section header names Accept truncated section names such as 'REAC' for 'REACTIONS' and 'ELEM' for 'ELEMENTS'. --- interfaces/python/ck2cti.py | 32 +++++++++++++++----------------- test/data/nasa9-test-therm.dat | 2 +- test/data/species-names.inp | 4 ++-- test/data/sri-falloff.inp | 6 ++---- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/interfaces/python/ck2cti.py b/interfaces/python/ck2cti.py index dffa00e51..5c0e396ef 100755 --- a/interfaces/python/ck2cti.py +++ b/interfaces/python/ck2cti.py @@ -1336,14 +1336,13 @@ class Parser(object): line, comment = readline() advance = True while line is not None: - tokens = line.split() + tokens = line.split() or [''] - if contains(line, 'ELEMENTS'): - index = get_index(tokens, 'ELEMENTS') - tokens = tokens[index+1:] + if tokens[0].upper().startswith('ELEM'): + tokens = tokens[1:] while line is not None and not contains(line, 'END'): # Grudging support for implicit end of section - if contains(line, 'SPECIES'): + if contains(line, 'SPEC'): self.warn('"ELEMENTS" section implicitly ended by start of ' 'next section on line {0}.'.format(self.line_number)) advance = False @@ -1358,14 +1357,13 @@ class Parser(object): break self.elements.append(token.capitalize()) - elif contains(line, 'SPECIES'): + elif tokens[0].upper().startswith('SPEC'): # List of species identifiers - index = get_index(tokens, 'SPECIES') - tokens = tokens[index+1:] + tokens = tokens[1:] while line is not None and not contains(line, 'END'): # Grudging support for implicit end of section - if (contains(line, 'REACTIONS') or contains(line, 'TRAN') or - contains(line, 'THERM')): + if (contains(line, 'REAC') or contains(line, 'TRAN') or + contains(line, 'THER')): self.warn('"SPECIES" section implicitly ended by start of ' 'next section on line {0}.'.format(self.line_number)) advance = False @@ -1385,13 +1383,13 @@ class Parser(object): self.speciesDict[token] = species self.speciesList.append(species) - elif contains(line, 'THERM') and contains(line, 'NASA9'): + elif tokens[0].upper().startswith('THER') and contains(line, 'NASA9'): entryPosition = 0 entryLength = None entry = [] while line is not None and not get_index(line, 'END') == 0: # Grudging support for implicit end of section - if (contains(line, 'REACTIONS') or contains(line, 'TRAN')): + if (contains(line, 'REAC') or contains(line, 'TRAN')): self.warn('"THERMO" section implicitly ended by start of ' 'next section on line {0}.'.format(self.line_number)) advance = False @@ -1440,7 +1438,7 @@ class Parser(object): entryPosition += 1 - elif contains(line, 'THERM'): + elif tokens[0].upper().startswith('THER'): # List of thermodynamics (hopefully one per species!) line, comment = readline() if line is not None and not contains(line, 'END'): @@ -1448,7 +1446,7 @@ class Parser(object): thermo = [] while line is not None and not contains(line, 'END'): # Grudging support for implicit end of section - if contains(line, 'REACTIONS') or contains(line, 'TRAN'): + if contains(line, 'REAC') or contains(line, 'TRAN'): self.warn('"THERMO" section implicitly ended by start of ' 'next section on line {0}.'.format(self.line_number)) advance = False @@ -1473,7 +1471,7 @@ class Parser(object): thermo = [] line, comment = readline() - elif contains(line, 'REACTIONS'): + elif tokens[0].upper().startswith('REAC'): # Reactions section for token in tokens[1:]: @@ -1568,11 +1566,11 @@ class Parser(object): revReaction.line_number = line_number self.reactions.append(revReaction) - elif contains(line, 'TRAN'): + elif tokens[0].upper().startswith('TRAN'): line, comment = readline() while line is not None and not contains(line, 'END'): # Grudging support for implicit end of section - if contains(line, 'REACTIONS'): + if contains(line, 'REAC'): self.warn('"TRANSPORT" section implicitly ended by start of ' 'next section on line {0}.'.format(self.line_number)) advance = False diff --git a/test/data/nasa9-test-therm.dat b/test/data/nasa9-test-therm.dat index b7c5af223..674bfdafc 100644 --- a/test/data/nasa9-test-therm.dat +++ b/test/data/nasa9-test-therm.dat @@ -1,4 +1,4 @@ -thermo NASA9 + therm NASA9 200.00 1000.00 6000.00 20000. 3/19/02 e- Ref-Species. Chase, 1998 3/82. 3 912/98 E 1.00 0.00 0.00 0.00 0.00 0.000548579903 0.000 diff --git a/test/data/species-names.inp b/test/data/species-names.inp index 5cc1932d4..e6796509c 100644 --- a/test/data/species-names.inp +++ b/test/data/species-names.inp @@ -1,7 +1,7 @@ Elements H C End -SPECIES +SPEC (Parens) @#$%^-2 [xy2]*{.} end @@ -21,7 +21,7 @@ thermo -4.84743026E-08 1.66693956E-11-1.02466476E+04-4.64130376E+00 4 end -reactions + reaction (Parens) + @#$%^-2 = 2 [xy2]*{.} 1.2345e12 1.0 200.0 2(Parens) + [xy2]*{.} = 3@#$%^-2 5.4321e10 1.0 500.0 end diff --git a/test/data/sri-falloff.inp b/test/data/sri-falloff.inp index bc21e5e46..5df775186 100644 --- a/test/data/sri-falloff.inp +++ b/test/data/sri-falloff.inp @@ -1,6 +1,4 @@ -ELEMENTS -H C AR -END + ELEM H C AR END SPECIES H @@ -22,4 +20,4 @@ H+R2(+M) = P2A+P2B(+M) 4.0E18 -0.5 100 LOW/7.0E26 -1.0 0/ SRI/1.1 700.0 1234.0 56 0.7/ R3/3/ P1/0.4/ R1A/0.0/ -END + END