Project

FILE PARSING python

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



try:                #open file and read if not able to read file not found
       
      values = open(\'engine_data.out\',\'r\')

 
except FileNotFoundError:    
           print( \"File not recognized. Please provide a valid CONVERGE output file\") 


data=[]             # splitting the line and removing the line start with \'#\' and  converting into float data
for line in values:              #using in operator
       if \'#\' not in line:       #using not in operator   
         data.append(line.split()) #collect values in data array


data1=np.transpose(data)          #column array
data1=data1.astype(float)         #percision upto 15 digits 

# all parameters 
choose=[\'crank_angle\',\'pressure\',\'Max_Pres\',\'Min_Pres\',\'Mean_Temp\',\'Max_Tem p\',\'Min_Temp\',\'Volume\',\'Mass\',\'Density\',\'Integrated_HR\',\'HR_Rate\',\'C_p\',\'C_ v\',\'Gamma\',\'Kin_Visc\',\'Dyn_Visc\']
print(choose) 
print(\'These are the code number for the following number. please choose !!\') 


# parameters codes 
choose_num=[\'crank_angle=0\',\'pressure=1\',\'Max_Pres=2\',\'Min_Pres=3\',\'Mean_Temp= 4\',\'Max_Temp=5\',\'Min_Temp=6\',\'Volume=7\',\'Mass=8\',\'Density=9\',\'Integrated_HR=1 0\',\'HR_Rate=11\',\'C_p=12\',\'C_v=13\',\'Gamma=14\',\'Kin_Visc=15\',\'Dyn_Visc=16\'] 
print(choose_num) 

print(\"please press the code for first parameter and press enter: n\") 
x = int(input()) 
print(\"please press the code for second parameter and press enter: n\") 
y = int(input()) 


#calculating area under pV curve

volume = data1[7,:]                #get values in volume from data1 7 to last 
# converting into pascal 
pressure = data1[1,:]*pow(10,6)    #multiplying pressure values by 10^6

#plot from data 
plt.plot(data1[x,:],data1[y,:],linewidth=3,color=\'red\')  
plt.xlabel(choose[x]) 
plt.ylabel(choose[y]) 
plt.title(choose[y]+\'   VS   \'+choose[x]) 
plt.savefig(choose[y]+\'VS\'+choose[x]+\'.png\') 
plt.show()

#work is given by 
w= [] 
for i in range(0,8664): 
         w.append(volume[i+1]-volume[i]*(pressure[i+1]+pressure[i])*0.5) 

work =0 
for j in range (0,len(w)):
       work =work+w[j] 
print( \'work done is:\', work,\'joule\') 

#power calculation
speed =1500/60
#into rotation per second
power = work*speed 
print(\'power of engine is :\',power,\'watt\') 
#specific fuel consumption 
consumption = 20 
sfc = (consumption*3600)/power 
print(\'specific fuel consumption is:\',sfc ,\'gram/w*hr\') 

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.