FIX: Remove undistributable CHEMKIN files
[freefoam.git] / bin / freefoam-para.py.in
blob92df0ed9d198fceccf198f9333ae166872c93a79
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
31 # Script
32 # freefoam-para
34 # Description
35 # Start ParaView with the OpenFOAM plugin
37 #------------------------------------------------------------------------------
39 """Usage: freefoam@PY_SCRIPT_SUFFIX@ para [-case <dir>] [-touch] [-h, -help]
41 Visualize the case <dir> with ParaView.
43 Options
44 -------
45 -case <dir> Specify alternative case or processor directory
46 -touch Only create the .foam file
48 """
50 import os
51 import os.path
52 import sys
53 import glob
54 import subprocess
55 # want to be future proof
56 sys.path.insert(0, '@FOAM_PYTHON_DIR@')
57 from FreeFOAM.compat import *
59 # parse options
60 case = '.'
61 touchOnly = False
62 args = sys.argv[1:]
63 while len(args) > 0:
64 a = args[0]
65 if a == '-case':
66 if len(args) < 2:
67 sys.stderr.write('Error: The -case option requires an argument\n')
68 sys.exit(1)
69 case = args[1]
70 del args[0:2]
71 elif a == '-touch':
72 touchOnly = True
73 del args[0]
74 else:
75 sys.stderr.write('Error: unknown option/argument "%s"\n'%a)
76 sys.stderr.write(__doc__+'\n')
77 sys.exit(1)
79 case = os.path.abspath(case)
81 # get a sensible caseName
82 caseName = os.path.basename(case)
83 caseFile = "%s.foam"%caseName
85 if touchOnly:
86 open(caseFile, 'at')
87 echo('created "%s"'%os.path.relpath(caseFile, os.getcwd()))
88 sys.exit(0)
90 # parent directory for normal or parallel results
91 parentDir = case
92 if caseName[:9] == 'processor':
93 parentDir = os.path.dirname(case)
95 # check existence of essential files
96 for check in 'controlDict fvSchemes fvSolution'.split():
97 f = os.path.join(parentDir, 'system', check)
98 if not os.path.isfile(f):
99 sys.stderr.write('Error: File does not exist "%s"\n'%f)
100 sys.exit(1)
102 try:
103 if os.path.exists(caseFile):
104 doDelete = False
105 else:
106 # only create/remove caseFile if it didn't already exist
107 doDelete = True
108 open(caseFile, 'at')
109 echo('created temporary "%s"'%caseFile)
111 # Try to find ParaView:
112 paraview = None
113 if 'FREEFOAM_PARAVIEW_APP' in os.environ:
114 # Using a environment variable the user can set...
115 paraview=os.environ['FREEFOAM_PARAVIEW_APP']
116 elif os.path.exists('@FOAM_PARAVIEW3_APP@'):
117 # Using the CMake configure value...
118 paraview="@FOAM_PARAVIEW3_APP@"
120 if not paraview and os.uname()[0] == 'Darwin':
121 # On Darwin it might also be an app-bundle
122 pv_dirs = []
123 if 'FREEFOAM_PARAVIEW_APP' in os.environ:
124 pv_dirs.append(os.environ['FREEFOAM_PARAVIEW_APP'])
125 pv_dirs.extend('/Applications ~/Applications'.split())
126 for d in pv_dirs:
127 d = os.path.expanduser(d)
128 for n in reversed(glob.glob(os.path.join(d, '[Pp]ara[Vv]iew*.app'))):
129 tmp = os.path.join(n, 'Contents', 'MacOS', 'paraview')
130 if os.path.isfile(tmp):
131 paraview = tmp
132 break
134 if not paraview:
135 # Otherwise notify the user
136 sys.stderr.write('Error: Could not find ParaView 3. Either compile it or point\n' +
137 'FREEFOAM_PARAVIEW_APP to the full path of the paraview application.\n')
138 sys.exit(1)
139 # We want to do nice exit when running paraview to give paraview opportunity
140 # to clean up
141 if 'FOAM_ABORT' in os.environ:
142 del os.environ['FOAM_ABORT']
143 sys.exit(subprocess.call([paraview, '--data=%s'%caseFile]))
144 finally:
145 if doDelete:
146 os.remove(caseFile)
148 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file