-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathdump2vtk
86 lines (82 loc) · 2.04 KB
/
dump2vtk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
BEGIN {
L = 1
while (getline < ARGV[1] && $0 !~ /^Bonds/)
;
getline < ARGV[1]
i = 0
while (getline < ARGV[1]) {
b0[i] = $3 - 1
b1[i] = $4 - 1
i++
}
for (i = 2; i in ARGV; i++) {
while (getline < ARGV[i] && $0 !~ /^ITEM: ATOMS/) ;
j = 0
while (getline < ARGV[i]) {
x[j] = $3
y[j] = $4
z[j] = $5
j++
}
natoms = j
vtk = ARGV[i]
sub(/\.dump$/, ".vtk", vtk)
vtk = "a_" vtk
printf \
"# vtk DataFile Version 2.0\n" \
"created with dump2vtk\n" \
"ASCII\n" \
"DATASET POLYDATA\n" \
"POINTS %d float\n", \
natoms > vtk
for (j = 0; j in x; j++) {
print x[j], y[j], z[j] >> vtk
}
uf_ini(natoms)
for (j in b0)
if (small(b0[j], b1[j]))
uf_union(b0[j], b1[j])
delete nb
delete lb
for (cnt = j = 0; j < natoms; j++) {
k = uf_find(j)
if (lb[k] == 0)
lb[k] = ++cnt
l = nb[lb[k] - 1]++
ch[lb[k] - 1,l] = j
}
for (npoly = size = j = 0; j < cnt; j++)
if (nb[j] > 1) {
size += nb[j] + 1
npoly ++
}
printf "LINES %d %d\n", npoly, size >> vtk
for (j = 0; j < cnt; j++)
if (nb[j] > 1) {
printf "%d", nb[j] >> vtk
for (k = 0; k < nb[j]; k++)
printf " %d", ch[j, k] >> vtk
printf "\n" >> vtk
}
}
}
function small(i, j, d) {
d = (x[i] - x[j])**2 + (y[i] - y[j])**2 + (z[i] - z[j])**2
return d < (L/2)**2
}
function uf_ini(n, i) {
for (i = 0; i < n; i++)
root[i] = i
}
function uf_union(a, b) {
a = uf_find(a)
b = uf_find(b)
if (a != b)
root[b] = a
}
function uf_find(a, b) {
if (a == (b = root[a]))
return a
else
return root[a] = uf_find(b)
}