File: make-optim-dumper

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (50 lines) | stat: -rwxr-xr-x 1,581 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python3


import os
import re

from collections import OrderedDict

# Get optimizations
opt_data = OrderedDict()
with open("config.optim", "r") as opt_file:
    opt_specs = [line for line in opt_file.read().split("\n") \
        if ( len(line) > 0)]
    for line in opt_specs:
        line_specs = line.split("=")
        key = line_specs[0]
        val = "=".join(line_specs[1:])[1:-1]
        if ( key == "optim_dumper_template" ):
            optim_dumper_template = val
        elif ( key == "optim_dumper_output" ):
            optim_dumper_output = val
        else:
            opt_data[key] = val

# Fix empty default flags
# (writing an empty string crashes the program when compiling with ifort
# or xlf)
if ( opt_data["fcflags_opt_default"] == "" ):
    opt_data["fcflags_opt_default"] = "--- None ---"

# Build source code
config_optim = ""
for srcdir in opt_data["fcflags_opt_dirlist"].split():
    key = "fcflags_opt_{}".format(srcdir)
    if ( key in opt_data ):
        config_optim += """

  write(my_unit,"(1x,a,a,3x,a,a,a)") "Optimizations for {srcdir}:",ch10, &
&   "{optim}",ch10,ch10""".format(srcdir=srcdir, optim=opt_data[key])

# Get template and substitute text
with open(optim_dumper_template, "r") as template_file:
    dump_source = template_file.read()
    dump_source = re.sub("@fcflags_opt_default@",
        opt_data["fcflags_opt_default"], dump_source)
    dump_source = re.sub("@config.optim@", config_optim, dump_source)

# Write down source file
with open(optim_dumper_output, "w") as dump_file:
    dump_file.write(dump_source)