forked from trondkr/model2roms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.py
121 lines (93 loc) · 4.25 KB
/
compile.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import subprocess
from datetime import datetime
import os
__author__ = 'Trond Kristiansen'
__email__ = 'me@trondkristiansen.com'
__created__ = datetime(2009, 11, 11)
__modified__ = datetime(2018, 4, 5)
__version__ = "1.0"
__status__ = "Development, 11.11.2009, 14.3.2012, 31.5.2012, 5.4.2018"
def help():
"""
@compile This is a simple script to call for automatic compiling of all
fortran files necessary to run the soda2roms package. This is turned on in
main.py with the compileAll=True
Call this from command line using python compile.py
NOTE!
To run this on Hecxagon do this first:
module swap PrgEnv-pgi PrgEnv-gnu
module unload notur
Then remove the -fcompiler=intelem command
NOTE: cleanarray.f90 is no longer used as fill.90 has better fill options
using Laplace equation.
"""
def compileallifort():
logfile = "compile.log"
if os.path.exists(logfile): os.remove(logfile)
log = open(logfile, 'a')
"""Start the processes"""
print("\n")
print("Compiling barotropic.f90 to create ==> barotropic.so")
proc = subprocess.Popen(
'f2py --verbose --fcompiler=intelem -c -m barotropic barotropic.f90 --f90flags="-no-heap-arrays"',
shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()
log.writelines(repr(stdout_value))
# obsolete: use fill.90 instead
# print "Compiling cleanArray.f90 to create ==> clean.so"
# proc = subprocess.Popen('f2py --verbose --fcompiler=intelem -c -m clean cleanArray.f90 --f90flags="-no-heap-arrays"',
# shell=True, stdout=subprocess.PIPE,)
# stdout_value = proc.communicate()[0]
# log.writelines(repr(stdout_value))
print("Compiling interpolation.f90 to create ==> interpolation.so")
proc = subprocess.Popen(
'f2py --verbose --fcompiler=intelem -c -m interpolation interpolation.f90 --f90flags="-no-heap-arrays"',
shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()[0]
log.writelines(repr(stdout_value))
print("Compiling fill.f90 to create ==> extrapolate.so")
proc = subprocess.Popen(
'f2py --verbose --fcompiler=intelem -c -m extrapolate fill.f90 --f90flags="-no-heap-arrays"',
shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()[0]
log.writelines(repr(stdout_value))
log.close()
print("Compilation finished and results written to file => %s" % (logfile))
print("\n===================================================================")
def compileallgfortran():
logfile = "compile.log"
if os.path.exists(logfile): os.remove(logfile)
log = open(logfile, 'a')
"""Start the processes"""
print("\n")
proc = subprocess.Popen('module swap PrgEnv-pgi PrgEnv-gnu', shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()
log.writelines(repr(stdout_value))
proc = subprocess.Popen('module unload notur', shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()
log.writelines(repr(stdout_value))
print("Compiling barotropic.f90 to create ==> barotropic.so")
proc = subprocess.Popen('f2py --verbose -c -m barotropic barotropic.f90',
shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()
log.writelines(repr(stdout_value))
print("Compiling interpolation.f90 to create ==> interpolation.so")
proc = subprocess.Popen('f2py --verbose -c -m interpolation interpolation.f90',
shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()[0]
log.writelines(repr(stdout_value))
print("Compiling fill.f90 to create ==> extrapolate.so")
proc = subprocess.Popen('f2py --verbose -c -m extrapolate fill.f90',
shell=True, stdout=subprocess.PIPE, )
stdout_value = proc.communicate()[0]
log.writelines(repr(stdout_value))
log.close()
print("Compilation finished and results written to file => %s" % logfile)
print("\n===================================================================")
def compilefortran(compiler):
if compiler == "gfortran":
compileallgfortran()
if compiler == "ifort":
compileallifort()
if __name__ == "__main__":
compilefortran("gfortran")