Project

file parsing using python

import math
import matplotlib.pyplot as plot
import numpy as np

#Compatability check
filename=input(\"Enter the filename with extension(.out): \")
#stores the name of the file to variable \'filename\' with extension \'.out\'
try:
	data=open(filename,\'r\') #if the file exsists with extension \'.out\' then the filename is stored in the variable \'data\'
except FileNotFoundError:
	print(\"File not recognized. Please provide a valid CONVERGE output file\") #if not displays this message

line_count=1
#basic initialization that is preallocating the memory 
crank=[]
pressure=[]
temperature=[]      
Max_Pres=[]
Min_Pres =[]
Mean_Temp=[]
Max_Temp=[]
Min_Temp=[]
Volume=[]      
Mass=[]
Density=[]
Integrated_HR=[]          
HR_Rate=[]      
C_p=[]
C_v=[]
Gamma=[]
Kin_Visc=[] 
Dyn_Visc=[]

#file parsing starts
# individual line is read,split and the values are stored in the above preallocated cells according to their coloumn positions
for line in data:
	if \'#\' not in line:
		crank.append(float(line.split()[0]))
		pressure.append(float(line.split()[1]))   
		Max_Pres.append(float(line.split()[2]))
		Min_Pres.append(float(line.split()[3]))
		Mean_Temp.append(float(line.split()[4]))
		Max_Temp.append(float(line.split()[5]))
		Min_Temp.append(float(line.split()[6]))
		Volume.append(float(line.split()[7]))    
		Mass.append(float(line.split()[8]))
		Density.append(float(line.split()[9]))
		Integrated_HR.append(float(line.split()[10]))
		HR_Rate.append(float(line.split()[11]))
		C_p.append(float(line.split()[12]))
		C_v.append(float(line.split()[13]))
		Gamma.append(float(line.split()[14]))
		Kin_Visc.append(float(line.split()[15]))
		Dyn_Visc.append(float(line.split()[16]))
		line_count=line_count+1

parameter=np.array([[0],crank,pressure,Max_Pres,Min_Pres,Mean_Temp,Max_Temp,Min_Temp,Volume,Mass,Density,Integrated_HR,HR_Rate,C_p,C_v,Gamma,Kin_Visc,Dyn_Visc])
variable=[\'Crank(Degree)\',\'Pressure(MPA)\',\'Maximum Pressure(MPA)\',\'Minimum Pressure(MPA)\',\'Mean Temperature(K)\',\'Maximum Temperature(K)\',\'Minimum Temperature(K)\',\'Volume(m^3)\',\'Mass(kg)\',\'Density(kg/m^3)\',\'Integrated_HR(J)\',\'HR_Rate(J/time)\',\'C_p(J/kg-K)\',\'C_v(J/kg-K)\',\'Gamma\',\'Kinematic Viscosity(m^2/s)\',\'Dynamic Viscosity(Ns/m^2)\']

#below line gives the information about the parameters and their corresponding coloum number
print(\'crank=1npressure=2nMax_Pres=3nMin_Pres=4nMean_Temp=5nMax_Temp=6nMin_Temp=7nVolume=8nMass=9nDensity=10nIntegrated_HR=11nHR_Rate=12nC_p=13nC_v=14nGamma=15nKin_Visc=16nDyn_Visc=17\')

#the above numbers must be given as the inputs to obtain the plots
x=input(\"enter x-coordinate parametern \")
x=int(x)
y=input(\"enter y-coordinate parametern \")
y=int(y)
#plotting the results

plot.plot(parameter[x],parameter[y],linewidth=2)
plot.xlabel(variable[x-1])
plot.ylabel(variable[y-1])
plot.show()	

#work done 
Work_done = np.trapz(parameter[2],parameter[8]) #np.trapz integrates between the curve 
print(\'Work Done is  \',Work_done,\'J\' )

#power developed
#Assume that RPM is 1500
power=Work_done*1500/60
print(\'Power is \',power,\'W\')

#Specific Fuel Consumption

Fuel_consumed=20*pow(10,-6)*3600*100000 
sfc=(Fuel_consumed)/power
print(\'Specific Fuel Consumption is  \',sfc,\'gm/Whr\')

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.