I want to convert a Tecplot file into an array but I don't know how to do it. Here is an extract of the file:
TITLE = "Test"
VARIABLES = "x" "y"
ZONE I=18, F=BLOCK
0.1294538E-01 0.1299554E-01 0.1303974E-01 0.1311453E-01 0.1313446E-01 0.1319080E-01
0.1322709E-01 0.1323904E-01 0.1331753E-01 0.1335821E-01 0.1340850E-01 0.1347061E-01
0.1350522E-01 0.1358302E-01 0.1359585E-01 0.1363086E-01 0.1368307E-01 0.1370017E-01
0.1377368E-01 0.1381353E-01 0.1386420E-01 0.1391916E-01 0.1395847E-01 0.1400548E-01
0.1405659E-01 0.1410006E-01 0.1417611E-01 0.1419149E-01 0.1420015E-01 0.1428019E-01
0.1434745E-01 0.1436735E-01 0.1439856E-01 0.1445430E-01 0.1448778E-01 0.1454278E-01
I want to retrieve x
and y
as array. So x
should contain:
0.1294538E-01 0.1299554E-01 0.1303974E-01 0.1311453E-01 0.1313446E-01 0.1319080E-01
0.1322709E-01 0.1323904E-01 0.1331753E-01 0.1335821E-01 0.1340850E-01 0.1347061E-01
0.1350522E-01 0.1358302E-01 0.1359585E-01 0.1363086E-01 0.1368307E-01 0.1370017E-01
And y
should contain:
0.1377368E-01 0.1381353E-01 0.1386420E-01 0.1391916E-01 0.1395847E-01 0.1400548E-01
0.1405659E-01 0.1410006E-01 0.1417611E-01 0.1419149E-01 0.1420015E-01 0.1428019E-01
0.1434745E-01 0.1436735E-01 0.1439856E-01 0.1445430E-01 0.1448778E-01 0.1454278E-01
I have seen np.loadtxt('./file.dat', skiprows=3)
but I can't find the right options to say read all numbers and separate every 18 figures.
Also, I started something like this with no luck:
with open(file, 'r') as a:
for line in a.readlines():
A = re.match(r'TITLE = (.*$)', line, re.M | re.I)
B = re.match(r'VARIABLES = (.*$)', line, re.M | re.I)
C = re.match(r'ZONE (.*$)', line, re.M | re.I)
if A or B or C:
continue
else:
D = re.match(r'(.*$)', line, re.M | re.I)
value = "{:.16}".format(D.group(1))
y.append(float(value))
j = j+1
if j == 18:
j = 0
Thank you for your help!