~ubuntu-branches/ubuntu/maverick/dolfin/maverick

« back to all changes in this revision

Viewing changes to misc/utils/order/dolfin-order

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2008-09-16 08:41:20 UTC
  • Revision ID: james.westby@ubuntu.com-20080916084120-i8k3u6lhx3mw3py3
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# Copyright (C) 2008 Anders Logg
 
4
# Licensed under the GNU LGPL Version 2.1
 
5
#
 
6
# Script for ordering a DOLFIN mesh according to the UFC ordering scheme
 
7
 
 
8
import sys, os, shutil
 
9
 
 
10
from dolfin import Mesh, File
 
11
 
 
12
def main(args):
 
13
    "Main function"
 
14
 
 
15
    # Check that we got at least
 
16
    if not len(args) > 0:
 
17
        usage()
 
18
        sys.exit(2)
 
19
        
 
20
    # Convert each mesh
 
21
    for filename in args:
 
22
        print "Ordering %s..." % filename
 
23
 
 
24
        # Read and order mesh
 
25
        mesh = Mesh(filename)
 
26
        mesh.order()
 
27
 
 
28
        # Make backup copy
 
29
        shutil.move(filename, filename + ".bak")
 
30
 
 
31
        # Write file and gzip if necessary
 
32
        gzip = False
 
33
        if len(filename) >= 3 and filename[-3:] == ".gz":
 
34
            filename = filename[:-3]
 
35
            gzip = True
 
36
        file = File(filename)
 
37
        file << mesh
 
38
        if gzip:
 
39
            os.system("gzip " + filename)
 
40
 
 
41
def usage():
 
42
    "Print usage instructions"
 
43
    print "Usage: dolfin-order mesh0.xml[.gz] [mesh1.xml[.gz] mesh2.xml[.gz] ...]"
 
44
 
 
45
if __name__ == "__main__":
 
46
    main(sys.argv[1:])