import numpy as np
from scipy.optimize import *
import matplotlib.pyplot as plt
import matplotlib
col = []
title= []
c_1 = [];c_2 = []
c_3 = [];c_4 = [];c_5 = [];c_6 = [];c_7 = [];c_8 = [];c_9 = [];c_10 = [];c_11 = [];c_12 = [];c_13 = [];c_14 = [];c_15=[];c_16=[];c_17=[];
i = 1
f = open(\'engine_data.out.txt\',\'r\')
for line in f:
line = line.split()
if \'column\' in line:
for x in line:
if x != \'#\':
col.append(x)
if \'Crank\' in line:
for x in line:
title.append(x)
if \'#\' not in line:
if len(line) != 17:
print(error)
break
line = np.array(line, dtype = float)
c_1.append(line[0])
c_2.append(line[1])
c_3.append(line[2])
c_4.append(line[3])
c_5.append(line[4])
c_6.append(line[5])
c_7.append(line[6])
c_8.append(line[7])
c_9.append(line[8])
c_10.append(line[9])
c_11.append(line[10])
c_12.append(line[11])
c_13.append(line[12])
c_14.append(line[13])
c_15.append(line[14])
c_16.append(line[15])
c_17.append(line[16])
i = i +1 ;
if \'column\' in line:
line = f.readline()
line = line.split()
label = []
for x in line:
label.append(x)
c = np.array([[0],c_1,c_2,c_3,c_4,c_5,c_6,c_7,c_8,c_9,c_10,c_11,c_12,c_13,c_14,c_15,c_16,c_17])
for x in range(1,18):
plt.figure(x)
plt.plot(c[x])
plt.ylabel(label[x])
plt.savefig(label[x] + \'.png\')
plt.close()
print(\'Press y to see single column plot or n to see double column plot\')
z = input()
z = str(z)
if z == \'y\':
print(\'enter the col no. to plot{1-14}\')
j = input()
j = int(j)
plt.figure()
plt.plot(c[j])
plt.ylabel(label[j])
plt.show()
if z == \'n\':
print(\'enter x-axis column no.{1-14}\')
x = input()
x = int(x)
print(\'enter y-axis column no.{1-14}\')
y = input()
y = int(y)
plt.figure()
plt.plot(c[x],c[y])
plt.xlabel(label[x])
plt.ylabel(label[y])
plt.show()
#Area under the P-V graph
area = np.trapz(c[2],c[8])
print(\'The area under the P-v Graph is \',area*1000,\'Kj\' )
print(\'Power output is \',area*1000*1500*60,\'Kj/s\')
power = area*1000*1500/60
sfc = (20/1000000)/power
print(\'the specific fuel consumption is \',sfc,\'Kg/KWHs\')
print(\'enter any value to terminate\')
zz = input()