-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_fortran_checks.py
executable file
·97 lines (83 loc) · 2.79 KB
/
run_fortran_checks.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
#! /usr/bin/python3
import os
import sys
import argparse
import re
import subprocess
class myFormatter(argparse.ArgumentDefaultsHelpFormatter,
argparse.RawTextHelpFormatter):
pass
parser = argparse.ArgumentParser(
formatter_class=myFormatter,
description=
'Run validatation programs against IERS2010 Fortran library',
epilog=('''National Technical University of Athens,
Dionysos Satellite Observatory\n
Send bug reports to:
Xanthos Papanikolaou, [email protected]
July, 2023'''))
parser.add_argument(
'--cpp-dir',
metavar='CPP_DIR',
dest='cpp_dir',
default=os.path.abspath(os.getcwd()),
required=False,
help='Directory with C++ test executables')
parser.add_argument(
'--for-dir',
metavar='FOR_DIR',
dest='for_dir',
default=os.path.abspath(os.getcwd()),
required=False,
help='Directory with FORTRAN subroutines')
parser.add_argument(
'--data-dir',
metavar='DATA_DIR',
dest='data_dir',
default=os.path.abspath(os.getcwd()),
required=False,
help='Directory with test data')
parser.add_argument(
'--markdown',
action='store_true',
dest='markdown',
help='Print results in Markdown format (matrix)')
parser.add_argument(
'--verbose',
action='store_true',
dest='verbose',
help='Verbose mode on')
# Fortran subroutines
for_sr = ['FCNNUT.F']
def for_sr2fc(for_sr): return 'py'+os.path.splitext(for_sr.lower())[0]
def for_sr2py(for_sr): return os.path.splitext(for_sr.lower())[0] + '.py'
# C++ test progs
cpp_sr = ['test-fcnnut.out']
if __name__ == '__main__':
## parse cmd
args = parser.parse_args()
verboseprint = print if args.verbose else lambda *a, **k: None
for s in zip(for_sr, cpp_sr):
# Compile Fortran subroutine
sr = s[0]
fsrc = os.path.join(args.for_dir, sr)
if not os.path.isfile(fsrc):
printf("ERROR. Failed to locate file {:}".format(fsrc))
sys.exit(1)
cfsrc = for_sr2fc(sr)
exe = 'f2py3 -c {:} -m {:}'.format(fsrc, cfsrc).split()
verboseprint('Running command: [{:}]'.format(exe))
result = subprocess.run(exe, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT, check=False)
## run the C++ test program; STDOUT to '.tmp'
sr = s[1]
cprog = os.path.join(args.cpp_dir, sr)
exe = '{:}'.format(cprog).split()
verboseprint('Running command: [{:}]'.format(exe))
with open('.tmp', 'w') as fout:
result = subprocess.run(exe, stdout=fout, stderr=subprocess.STDOUT, check=False)
## run the python script
sr = s[0]
pprog = os.path.join(args.for_dir, for_sr2py(sr))
exe = '{:} {:}'.format(pprog, '.tmp').split()
verboseprint('Running command: [{:}]'.format(exe))
subprocess.run(exe, check=False)