File Parsing using Python

Objective :

   The aim of this project is do file parsing using python for different data provided in the file.

Explanation:

   File Parsing :

        Text parsing is a common programming task that splits the given sequence of characters or values (text) into smaller parts based on some rules. It has been used in a wide variety of applications ranging from simple file parsing to large scale natural language processing.

  • Import numpy module , matplotlib.pyplot  for plotting graph and also the math module for math operations.
  • Assign empty array for each data such crank angle, pressure, temperature and so on
  • now the basic operation to perform file parsing is to make the program to read the file. It can be executed by open command.
  • Thus skipping the lines in the data which contains' #' in it by creating a for a loop.
  • Then create a loop which helps to extract third only which contains the data wanted.
  • Now append all the values to the empty array accordingly
  • Now to perform the input method which helps the user to provide necessary data they wanted which is called a  script.
  • The program should provide the value that user define and the script has to be made accordingly.
  • In this program, the graph between the two data is generated according to the user-defined.
  • Also, the script has to provide value for Area, power, specific fuel consumption.

                  Area  = work done in the curve.

  • It can be calculated by integrating the cycle by using the command called Trapz.  

                 power = work done /  time

  • Specific fuel consumption = rate of fuel consumption/ power
  • Thus the output must be shown as such in the below image.

 

               

 

               

 

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

crank = []
pressure = []
max_pressure = []
min_pressure = []
mean_temp = []
max_temp = []
min_temp = []
volume =[]
mass = []
density =[]
intergrated_hr = []
hr_rate=[]
c_p = []
c_v =[]
gamma =[]
kinematic_viscosity=[]
dynamic_viscocity = []

 

#file parsing starts here

d = (input('enter file name'))


if d.endswith('out') is True:

	for line in open(d):
		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_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]))
			intergrated_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]))
			kinematic_viscosity.append(float(line.split()[15]))
			dynamic_viscocity.append(float(line.split()[16]))

	a = ([crank,pressure,max_pressure,min_pressure,mean_temp,max_temp,min_temp,volume,mass,density,intergrated_hr,hr_rate,c_p,c_v,gamma,kinematic_viscosity,dynamic_viscocity])
	

	x = int(input("give the first column number."))
	y = int(input("give the second column number."))
	plt.plot(a[x],a[y], color = 'blue', linewidth = '3')


	vt=[]
	line_count = 1

	for line in open(d,'r'):
		
		if "#" in line:
			if line_count is 3:


				l=(line.split()[1:18])
				vt.append(l)

				#print(vt)	

			


			line_count = line_count+1


	r =1
	h =[]
	for text in open(d,'r'):
		if '#' in text:
			if r is 4:
			
				
				k = (text.split()[1:18])
				h.append(k)


			r =r+1

else:
	print('file type is not recognized')


#in mega watt





plt.xlabel(vt[0][x]+h[0][x])

plt.ylabel(vt[0][y]+h[0][y])



plt.title(vt[0][x]+"Vs"+vt[0][y])

plt.show()

A =np.trapz(a[1],a[7]) 


print('area=',A)
rpm=1500
rps = rpm/60

p = A * rps *1000

P = p /0.746
print('horsepower is',P)
print('power in kw is',p)


BSFC = (20*pow(10,-6)*3600)/0.8*p
print('specific fuel consumption is',BSFC)

 

Conclusion:

  • Thus the above program indicates how the file parsing is done.
  • Also shown the example of the user interface.

Projects by Sachin M

SIDE CRASH OF CHRYSLER NEON The Chrysler Neon is a front-engine, front-wheel-drive compact car introduced in January 1994 for the model year 1995 by Chrysler\'s Dodge and Plymouth divisions in two and four-door body styles over two generations. BIW : BIW (Body in Whi Read more

FRONTAL CRASH OF CHRYSLER NEON The Chrysler Neon is a front-engine, front-wheel-drive compact car introduced in January 1994 for the model year 1995 by Chrysler\'s Dodge and Plymouth divisions in two and four-door body styles over two generations. BIW : BIW (Body in Read more

Objective :   To mesh the given bumper model using Hypermesh and simulate crash tube with different contact interface type using Radioss. Explanation : The given Bumper is meshed under given conditions.                 Read more

1.Objective :    To compare the simulation of different cases by assigning different laws and also observing the corresponding behaviour of the material for the given model. 2.Explanation: Regarding files such as 0000.rad and 0001.rad files are required t Read more

1.Objectives:      To compare the result of the base simulation and improve shell element properties. 2.Explanation :   2.1 Simulation 1 : First, 0000.rad file is imported to the Hypermesh. To get a minimum of 25 animation files, frequency is Read more

Objective:     The aim of this project is to do a geometry clean up for given models and perform 2D mesh using the midplane surface extract for the given parameters for the shell element. Procedure: Import the given model to Hypermesh --- Radioss. The Rad Read more

Objective :      The main aim of the task is to perform a curve fit for linear and cubic polynomials equation and to find which curve fits the best to the actual data curve. Explanation :            The main aim of the cur Read more

Objective:   The main objective the process is to mesh the given hood model using ansa and do the hemming process at last. Hemming:    The hemming process is used in many automation where it helps to join two different surfaces with different material Read more

`f(x) = 5-(x-2)^2 - 2(y-1)^2`        `5 - x^2-4+4x-2y^2-2+4y = 0`        `-x^2-2y^2+4x+4y-1=0`          g(x)=f(x)+λ `g(x) = -x^2-2y^2+4x+4y-1 + λ (x+4y-3)`   `(del g)/(d Read more


Loading...

The End