S
Satish Chimakurthi
Hi all,
This is in continuation of my email today regarding reading data files. I am stuck with one more problem now.
Here are my two data files:
a. fluid_grid.dat
1.00000000000000 0.00000000000000D+000
0.959753969508636 0.280842158538236
0.842255363975169 0.539078752924891
0.656961888321583 0.753923787456623
0.418788196289889 0.908083942512068
0.146905379223583 0.989150549489397
b. fluid_pressure.dat
1.2
2
4
5
3.22
There are six values in each of the two columns in file "fluid_grid.dat" and 6 values in one column in "fluid_pressure.dat".
I read the contents of the first file in two arrays "x" and "y", x contains the values in the first column and y contains the second column values respectively.
I also read the contents of the second file in array "pres"
I wrote the following code for some calculations.
from math import sqrt
ifile4=open('fluid_grid.dat','r')
lines=ifile4.readlines()
x=[]
y=[]
FX=[]
FY=[]
for line in lines:
xi,yi=[float(item) for item in line.replace('D','E').split()]
x.append(xi)
y.append(yi)
pres=[]
pressure_data=open('fluid_pressure.dat','r')
for i in range(1,6):
a=eval(pressure_data.readline())
pres.append(a)
for i in range(1,6):
NXA=y[i-1]-y
NXD=sqrt(((y-y[i-1])**2)+((x-x[i-1]**2))
NYA=x-x[i-1]
NYD=sqrt(((y-y[i-1])**2)+((x-x[i-1]**2))
NX=NXA/NXD
NY=NYA/NYD
FX.append(pres*NX)
FY.append(pres*NY)
I ran this code only to get the following error:
File "<string>", line 24
NYA=x-x[i-1]
^
SyntaxError: invalid syntax
I remember Mr.Skip Montanaro quoting in his email earlier that at the point I make the assignment neither x has no
i'th elements. I am sure this is what is happening now.
Can someone advise any possible work around to this problem ??
Thanks in advance
Best Regards,
Satish Kumar Chimakurthi
SATISH KUMAR CHIMAKURTHI
Graduate Research Assistant
CFD GROUP
Mechanical Engineering
UNIVERSITY OF KENTUCKY
Lexington
KENTUCKY - 40508
U.S.A
Email: (e-mail address removed)
Mobile:859-420-9890
Office: 859-257-6336 X 80691
This is in continuation of my email today regarding reading data files. I am stuck with one more problem now.
Here are my two data files:
a. fluid_grid.dat
1.00000000000000 0.00000000000000D+000
0.959753969508636 0.280842158538236
0.842255363975169 0.539078752924891
0.656961888321583 0.753923787456623
0.418788196289889 0.908083942512068
0.146905379223583 0.989150549489397
b. fluid_pressure.dat
1.2
2
4
5
3.22
There are six values in each of the two columns in file "fluid_grid.dat" and 6 values in one column in "fluid_pressure.dat".
I read the contents of the first file in two arrays "x" and "y", x contains the values in the first column and y contains the second column values respectively.
I also read the contents of the second file in array "pres"
I wrote the following code for some calculations.
from math import sqrt
ifile4=open('fluid_grid.dat','r')
lines=ifile4.readlines()
x=[]
y=[]
FX=[]
FY=[]
for line in lines:
xi,yi=[float(item) for item in line.replace('D','E').split()]
x.append(xi)
y.append(yi)
pres=[]
pressure_data=open('fluid_pressure.dat','r')
for i in range(1,6):
a=eval(pressure_data.readline())
pres.append(a)
for i in range(1,6):
NXA=y[i-1]-y
NXD=sqrt(((y-y[i-1])**2)+((x-x[i-1]**2))
NYA=x-x[i-1]
NYD=sqrt(((y-y[i-1])**2)+((x-x[i-1]**2))
NX=NXA/NXD
NY=NYA/NYD
FX.append(pres*NX)
FY.append(pres*NY)
I ran this code only to get the following error:
File "<string>", line 24
NYA=x-x[i-1]
^
SyntaxError: invalid syntax
I remember Mr.Skip Montanaro quoting in his email earlier that at the point I make the assignment neither x has no
i'th elements. I am sure this is what is happening now.
Can someone advise any possible work around to this problem ??
Thanks in advance
Best Regards,
Satish Kumar Chimakurthi
SATISH KUMAR CHIMAKURTHI
Graduate Research Assistant
CFD GROUP
Mechanical Engineering
UNIVERSITY OF KENTUCKY
Lexington
KENTUCKY - 40508
U.S.A
Email: (e-mail address removed)
Mobile:859-420-9890
Office: 859-257-6336 X 80691