So my problem right now is reading a .txt file and pulling out specific data. This data will then be written into an excel file where the rows will become columns now and vice versa. So far I have been able to read the file and create the excel sheet with columns but no data transfers. Below is the data that it reads and what is to be written into excel.
[' O/F=7.1800E+00 PERCENT FUEL= 12.2249 EQUIVALENCE RATIO=5.5559E-01 DENSITY=9.5028E-01']
[]
[' CHAMBER THROAT EXIT EXIT']
[' PC/P 1.0000 1.7346 1.0083 62.915']
[' P', ' PSIA 1500.0 864.8 1487.7 23.84']
[' T', ' DEG R 5886 5555 5880 3494']
[' H', ' BTU/LB -446.6 -674.1 -450.1 -1819.9']
[' S', ' BTU/(LB)(R) 2.3395 2.3395 2.3395 2.3395']
[' DEN (LBM/FT3) 6.50E-01 4.01E-01 6.45E-01 1.81E-02']
[' ']
[' M', ' MOL WT 27.357 27.616 27.361 28.499']
[' (DLV/DLP)T -1.01645 -1.01277 -1.01639 -1.00034']
[' (DLV/DLT)P 1.3300 1.2733 1.3292 1.0126']
[' CP', 'BTU/(LB)(R) 0.9274 0.8626 0.9265 0.4371']
[' CP GAS(SF) 0.4353 0.4326 0.4353 0.4041']
[' GAMMA GAS(SF) 1.2001 1.1993 1.2001 1.2084']
[' GAMMA (S) 1.1390 1.1395 1.1390 1.1949']
[' SON VEL', 'FT/SEC 3490.4 3375.7 3488.6 2698.9']
[' MU', 'LBF-S/FT2 2.01E-06 1.93E-06 2.01E-06 1.41E-06']
[' K', 'LBF/S-DEGR 3.16E-02 3.01E-02 3.16E-02 2.03E-02']
[' PRANDTL NO 0.69205 0.69371 0.69207 0.70189']
[' MACH NUMBER 0.0000 1.0000 0.1202 3.0726']
[' ']
[' AE/AT 1.0000 4.9993 9.0000']
[' CSTAR', ' FT/SEC 5139 5139 5139']
[' CF VAC 1.233 1.757']
[' CF 0.657 1.614']
[' IVAC', 'LBF-S/LBM 197.00 280.59']
[' I', ' LBF-SEC/LBM 104.92 257.74']
[' MOL WT(MIX) 27.357 27.616 27.361 28.499']
Below is the code I have so far
import csv
import sys
import xlsxwriter
import pandas as pd
import argparse
def parse_args():
parser = argparse.ArgumentParser(description='Read POST run outputs.')
parser.add_argument('infile',
type=argparse.FileType('r'),
help='POST file to be analyzed.')
parser.add_argument('outfile',
type=argparse.FileType('w'),
help='Output xlsx file.')
return parser.parse_args()
def read_post_file(LOX_CH4_GG_5zn.txt, LOX_CH4_GG_5zn.csv):
f = open(LOX_CH4_GG_5zn.txt,"r")
csv_f = csv.reader(f)
relevantData = False
firstDataSet = True
for row in csv_f:
string = str(row)
if 'O/F' in string and firstDataSet:
relevantData = True
elif 'MOLE FRACTIONS' in string:
relevantData = False
firstDataSet = False
if firstDataSet and relevantData:
print (string)
f.close()
if __name__ == "__main__":
args = parse_args()
read_post_file(args.infile.name, args.outfile.name)
workbook = xlsxwriter.Workbook('Com.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A', 20)
bold = workbook.add_format({'bold': True})
worksheet.write('A1', 'O/F', bold)
worksheet.write('B1', 'PC/P', bold)
worksheet.write('C1', 'P,PSIA', bold)
worksheet.write('D1', 'T,DEG(R)', bold)
worksheet.write('E1', 'H,BTU/LB', bold)
worksheet.write('F1', 'S,BTU/(LB)(R)', bold)
worksheet.write('G1', 'DEN,LBM/FT3', bold)
worksheet.write('H1', 'M,MOL WT', bold)
worksheet.write('I1', '(DLV/DLP)T', bold)
worksheet.write('J1', '(DLV/DLP)P', bold)
worksheet.write('I1', 'CP,BTU/(LB)(R)', bold)
worksheet.write('K1', 'CP GAS,SF', bold)
worksheet.write('L1', 'GAMMA GAS,SF', bold)
worksheet.write('K1', 'GAMMA,S', bold)
worksheet.write('K1', 'SON VEL,FT/SEC', bold)
worksheet.write('K1', 'MU,LBF-S/FT2', bold)
worksheet.write('K1', 'K,LBF/S-DEG(R)', bold)
worksheet.write('K1', 'PRANDTL NO', bold)
worksheet.write('K1', 'MACH NUMBER', bold)
worksheet.write('K1', 'AE/AT', bold)
worksheet.write('K1', 'CSTAR,FT/SEC', bold)
worksheet.write('K1', 'CF VAC', bold)
worksheet.write('K1', 'CF', bold)
worksheet.write('K1', 'IVAC, LBF-SEC/LBM', bold)
worksheet.write('K1', 'I,LBF-SEC/LBM', bold)
worksheet.write('K1', 'MOL WT(MIX)', bold)
workbook.close()
Any help is greatly appreciated one this.
input 1
The output is what was posted in the beginning of the question.