~chaffra/fiat/main

« back to all changes in this revision

Viewing changes to asci2vtk2d.py

  • Committer: Garth N. Wells
  • Date: 2010-02-03 12:55:55 UTC
  • Revision ID: gnw20@cam.ac.uk-20100203125555-0cnifkf232cm94a8
Remove some duplicate files. Others remain.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/sw/bin/python
2
 
 
3
 
# 2d mode: x y z, z = f(x,y)
4
 
import sys
5
 
 
6
 
if len(sys.argv) > 1:
7
 
    filename = sys.argv[1]
8
 
    print filename
9
 
    base = filename.split(".")[0]
10
 
    output = "%s.vtk" % (base,)
11
 
    print "output to %s" % (output,)
12
 
else:
13
 
    print "python asci2vtk.py foo"
14
 
    sys.exit(0)
15
 
 
16
 
 
17
 
fin = open( filename , "r" )
18
 
 
19
 
coords = [ ]
20
 
 
21
 
for line in fin.xreadlines():
22
 
    coords.append( line.split() )
23
 
 
24
 
fin.close()
25
 
 
26
 
n = len( coords )
27
 
 
28
 
print "%s points" % (str(n),)
29
 
 
30
 
 
31
 
fout = open( output , "w" )
32
 
print >>fout, """# vtk DataFile Version 2.0
33
 
points
34
 
ASCII
35
 
DATASET UNSTRUCTURED_GRID
36
 
POINTS %s float""" % (str(n),)
37
 
 
38
 
for c in coords:
39
 
    print >>fout, "%s %s %s" % (c[0],c[1],0)
40
 
 
41
 
print >>fout, "CELLS %s %s" % (n,2*n)
42
 
for i in range( n ):
43
 
    print >>fout, "1 %s" % (i,)
44
 
 
45
 
print >>fout, "CELL_TYPES %s" % (n,)
46
 
for i in range( n ):
47
 
    print >>fout, "1"
48
 
 
49
 
print >>fout, "POINT_DATA %s" % (n,)
50
 
print >>fout, """SCALARS Z float 1
51
 
LOOKUP_TABLE default"""
52
 
 
53
 
for i in range( n ):
54
 
    print >>fout, coords[i][2]
55
 
 
56
 
fout.close()