Project

FILE PARSING USING PYTHON

OBJECTIVE :

  • Your script should take column numbers as the input and plot the respective columns as separate images
  • Each file should be saved by the name of the column
  • The plot labels should be extracted from the file.
  • The code should exit gracefully if a non-compatible file is provided as an input.
  • Calculate the area under the P-V diagram.
  • Calculate the power output of this engine.
  • Calculate its specific fuel consumption.

WHAT IS FILE PARSING?

Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural language, computer languages or data structures.

In some machine translation and natural language processing systems, written texts in human languages are parsed by computer programs. Human sentences are not easily parsed by programs, as there is substantial ambiguity in the structure of human language, whose usage is to convey meaning (or semantics) amongst a potentially unlimited range of possibilities but only some of which are germane to the particular case

FILE PARSING allows us to read write text and get use that text in the form of values

in big data, we use file parsing to read lots of data

we can write secrete codes with this technique

\"\"\"
   Demonstrating file parsing in Python
\"\"\"
import matplotlib.pyplot as plt
import numpy as np
line_count =1
crank =[]
pressure=[]
max_pressure=[]
min_pressure =[]
mean_temperature =[]
max_temperature=[]
min_temperature=[]
volume =[]
mass =[]
density =[]
integrate_hr =[]
hr_rate =[]
c_p = []
c_v=[]
gamma =[]
kin_visc= []
dyn_visc =[]

try :

	open(\'engine_data.out\')

except:

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


#FILE PARISNG START 
for line in open(\'engine_data.out\'):
	if \'#\' not in line:
		crank.append(float(line.split()[0]))
		pressure.append(float(line.split()[1]))
		max_pressure.append(float(line.split()[2]))
		min_pressure.append(float(line.split()[3]))
		mean_temperature.append(float(line.split()[4]))
		max_temperature.append(float(line.split()[5]))
		min_temperature.append(float(line.split()[6]))
		volume.append(float(line.split()[7]))
		mass.append(float(line.split()[8]))
		density.append(float(line.split()[9]))
		integrate_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		



plt.plot(crank,pressure,linewidth=3)
plt.show()


plt.plot(crank,max_temperature,linewidth=3)
plt.show()



plt.plot(gamma,mass,linewidth=3)
plt.show()

plt.plot(volume,pressure,linewidth=3)
plt.show()

area = np.trapz(pressure,volume)
print(\'Area under PV = \',area)

rpm = 1500
rps = rpm/60
powerwatt= area*rps*1000
powerhp= powerwatt/0.746

print(\'power of engine = \',powerwatt, \'in KW,when rpm is 1500\')
print(\'power of engine = \',powerhp,\'in HP\')

specific_fuel_consumtion = (20*pow(10,-6)*3600)/(0.08*powerwatt)
print(\'specific_fuel_consumtion = \',specific_fuel_consumtion,\'g/kwh\')

FIG.1 SHOWS HOW TO OPEN AND READ THE FILE IN PYTHON

FIG.2 AREA UNDER CURVE, POWER OF ENGINE AND SPECIFIC FUEL CONSUMPTION VALUES

FIG.3 COMPATIBILITY CHECK SHOWN

FIG.4 PRESSURE VS VOLUME

CONCLUSION :

  • Successfully read the data from the file
  • Calculated the area under the P-V diagram.
  • Calculated the power output of this engine.
  • Calculated its specific fuel consumption.
  • Ploted PV diagram
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.