import math
import matplotlib.pyplot as plt
import numpy as np
file_name=input("Enter file name :")
try:
all_data=open(file_name,'r')
print('file open succesfully')
except:
print('file not found')
exit()
line_count=1
parameters=[]
for line in open(file_name):
if '#' in line:
parameters.append(line.split())
nc=len(parameters[1])
#no of columns=nc
#column number=cn
#column name=cv
#column units=cu
cn=[]
cv=[]
cu=[]
a=parameters[1].index('column')
for i in range(a,nc-1):
cn.append(i)
for j in parameters[2]:
if j is not '#':
cv.append(j)
for k in parameters[3]:
if k is not '#':
cu.append(k)
print('\nShowing data present in file \n')
print('COLUMN NO',' ','PARAMETER')
for i in range (0,len(cn)):
print('--')
# ploting
xaxis=int(input('\nEnter independant parameters(x-axis) column number:'))
yaxis=int(input('\nEnter independant parameters(y-axis) column number:'))
# to get the correct value of x and y axis reduced by 1
xaxis=xaxis-1
yaxis=yaxis-1
x=[]
y=[]
for line in open(file_name):
if '#' not in line:
x.append(float(line.split()[xaxis]))
y.append(float(line.split()[yaxis]))
# ploting
plt.plot(x,y,linewidth=3)
plt.xlabel(cv[xaxis]+cu[xaxis])
plt.ylabel(cv[yaxis]+cu[yaxis])
plt.show()
#calculation
pressure=[]
volume=[]
for line in open(file_name):
if '#' not in line:
pressure.append(float(line.split()[1]))
volume.append(float(line.split()[7]))
# calculating area |pressure conversion in pascal
p=1000000*np.array(pressure)
v=np.array(volume)
area=np.trapz(p,v)
print('\Area under P-V diagram (workdone)=',area,'joules')
# calculating power | calculating Specific Fuel Consumption
power=(area*(1500/60))/1000
print('power output of the engine =',power,'KW')
sfc=20*pow(10,-6)*3600/power
print('Specific fuel consumption =',sfc,'g/KW.h')
#### Output of program display in the command promt
Enter file name :engine_data.out
file open succesfully
Showing data present in file
COLUMN NO PARAMETER
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
Enter independant parameters(x-axis) column number:1
Enter independant parameters(y-axis) column number:2
\Area under P-V diagram (workdone)= 500.5866274680076 joules
power output of the engine = 12.514665686700189 KW
Specific fuel consumption = 0.005753249971073309 g/KW.h