source: anuga_core/source/anuga/shallow_water/tsh2sww.py @ 7317

Last change on this file since 7317 was 7317, checked in by rwilson, 15 years ago

Replaced 'print' statements with log.critical() calls.

File size: 2.1 KB
Line 
1"""Given a .tsh, print an sww
2"""
3
4######################
5# Module imports
6#
7
8import sys
9from os import sep, path
10sys.path.append('..'+sep+'pyvolution')
11
12from shallow_water import Domain
13from anuga.pyvolution.pmesh2domain import pmesh_to_domain_instance
14import time, os 
15from anuga.pyvolution.data_manager import get_dataobject   
16from anuga.utilities.numerical_tools import mean
17import anuga.utilities.log as log
18
19
20def tsh2sww(infilename, sww_file_name = None, verbose = False):
21    """
22    This converts a mesh file (.tsh/.msh) to an .sww file.
23    This is usefull to visualise the mesh.
24   
25    Note: This currently just writes the output file in the input file dir.
26    """
27    if verbose == True: log.critical('Creating domain from %s' % infilename)
28    domain = pmesh_to_domain_instance(infilename, Domain)
29    if verbose == True: log.critical("Number of triangles = %d" % len(domain))
30
31    domain.smooth = True
32    domain.format = 'sww'   #Native netcdf visualisation format
33       
34    file_path, filename = path.split(infilename)
35    filename, ext = path.splitext(filename)
36   
37    if not (sww_file_name == None):
38        file_path, filename = path.split(sww_file_name)
39        filename, ext = path.splitext(filename)
40    domain.set_name(filename)
41       
42    domain.reduction = mean
43    if verbose == True: log.critical("file_path %s" % file_path)
44    if file_path == "":file_path = "."
45    domain.set_datadir(file_path)
46
47    if verbose == True:
48        log.critical("Output written to %s%s%s.%s"
49                     % (domain.get_datadir(), sep, domain.get_name(),
50                        domain.format)
51    sww = get_dataobject(domain)
52    sww.store_connectivity()
53    sww.store_timestep('stage')
54
55if __name__ == "__main__":
56    usage = "usage:python %s pmesh_file_name [verbose|non_verbose]" %         path.basename(sys.argv[0])
57    if len(sys.argv) < 2:
58        print usage
59    else:
60        filename = sys.argv[1]
61        verbose = False
62    if len(sys.argv) > 2:
63        if sys.argv[2][0] == "v" or sys.argv[2][0] == "V":
64            verbose = True
65        tsh2sww(filename, verbose = verbose)
66   
Note: See TracBrowser for help on using the repository browser.