Skip to content

Instantly share code, notes, and snippets.

@Tyaedalis
Last active August 6, 2017 01:15
Show Gist options
  • Save Tyaedalis/9106e78414b7d9ecc038cfba53e5d417 to your computer and use it in GitHub Desktop.
Save Tyaedalis/9106e78414b7d9ecc038cfba53e5d417 to your computer and use it in GitHub Desktop.
from os import walk
files = []
for (dirpath, dirnames, filenames) in walk('./data/'):
files.extend(filenames)
break
data = []
OFratio = None
for file in files:
t = []
with open('./data/' + file) as f:
for i, line in enumerate(f):
if i in [15, 24, 25, 31, 34, 39]:
t.append(line.split())
OFratio = t[0][2]
Pc = t[1][1]
Tc = t[2][1]
Te = t[2][4]
Pe = t[1][4]
MW = t[4][4]
gamma = t[3][4]
Mach = t[5][5]
data.append([Pc, Tc, Te, Pe, MW, gamma, Mach])
if len(data) < 15:
print('[WRN] Less than 15 keys!')
block = ''.join(['MixtureRatioData\n{\n OFratio =', OFratio,
'\n PressureData\n {\n',
''.join([' key = {}, {}, {}, {}, {}, {}, {}\n'.format(*line) for line in data]),
' }\n}'])
with open('results.txt', 'a') as f:
f.write(block)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment