~njansson/dolfin/hpc

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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python
#
# Copyright (C) 2006 Anders Logg
# Licensed under the GNU LGPL Version 2.1
#
# Modified by Garth N. Wells (gmsh function)
# Modified by Alexander H. Jarosch (gmsh fix)
# Modified by Angelo Simone (Gmsh and Medit fix)
# Modified by Andy R. Terrel (gmsh fix)
# Modified by Magnus Vikstrom (metis and scotch function)
# Modified by Bartosz Sawicki (diffpack function)
# Modified by Gideon Simpson (Exodus II function)
# Modified by Arve Knudsen (move logic into module meshconvert)
#
# Script for converting between various data formats

import getopt
import sys
import os
from commands import getoutput
import re
import warnings
import os.path

from dolfin import meshconvert

def main(argv):
    "Main function"

    # Get command-line arguments
    try:
        opts, args = getopt.getopt(argv, "hi:o:", ["help", "input=", "output="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
        
    # Get options
    iformat = None
    oformat = None
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-i", "--input"):
            iformat = arg
        elif opt in ("-o", "--output"):
            oformat = arg

    # Check that we got two filenames
    if not len(args) == 2:
        usage()
        sys.exit(2)
        
    # Get filenames
    ifilename = args[0]
    ofilename = args[1]

    if oformat and oformat != "xml":
        error("Unable to convert to format %s." % (oformat,))
    meshconvert.convert2xml(ifilename, ofilename, iformat=iformat)

def usage():
    "Display usage"
    print """\
Usage: dolfin-convert [OPTIONS] ... input.x output.y

Options:

  -h         display this help text and exit
  -i format  specify input format
  -o format  specify output format

Alternatively, the following long options may be used:

  --help     same as -h
  --input    same as -i
  --output   same as -o

Supported formats:

  xml      - DOLFIN XML mesh format (current)
  xml-old  - DOLFIN XML mesh format (DOLFIN 0.6.2 and earlier)
  mesh     - Medit, generated by tetgen with option -g
  gmsh     - Gmsh, version 2.0 file format
  metis    - Metis graph file format
  scotch   - Scotch graph file format
  diffpack - Diffpack tetrahedral grid format
  abaqus   - Abaqus tetrahedral grid format
  ExodusII - Sandia Format (requires ncdump utility from NetCDF)

If --input or --output are not specified, the format will
be deduced from the suffix:

  .xml  - xml
  .mesh - mesh
  .gmsh - gmsh
  .msh  - gmsh  
  .gra  - metis
  .grf  - scotch
  .grid - diffpack
  .inp  - abaqus
  .e	- Exodus II
  .exo  - Exodus II
  .ncdf - ncdump'ed Exodus II
"""
if __name__ == "__main__":
    main(sys.argv[1:])