~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/tools/fapi_header_gen.py

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
 
3
 
'''Generate the fapi.c source from the ga-papi.h header.'''
4
 
 
5
 
import sys
6
 
 
7
 
def get_signatures(header):
8
 
    # first, gather all function signatures from ga-papi.h aka argv[1]
9
 
    accumulating = False
10
 
    signatures = []
11
 
    current_signature = ''
12
 
    EXTERN = 'extern'
13
 
    SEMICOLON = ';'
14
 
    for line in open(header):
15
 
        line = line.strip() # remove whitespace before and after line
16
 
        if not line:
17
 
            continue # skip blank lines
18
 
        if EXTERN in line and SEMICOLON in line:
19
 
            signatures.append(line)
20
 
        elif EXTERN in line:
21
 
            current_signature = line
22
 
            accumulating = True
23
 
        elif SEMICOLON in line and accumulating:
24
 
            current_signature += line
25
 
            signatures.append(current_signature)
26
 
            accumulating = False
27
 
        elif accumulating:
28
 
            current_signature += line
29
 
    return signatures
30
 
 
31
 
class FunctionArgument(object):
32
 
    def __init__(self, signature):
33
 
        self.pointer = signature.count('*')
34
 
        self.array = '[' in signature
35
 
        signature = signature.replace('*','').strip()
36
 
        signature = signature.replace('[','').strip()
37
 
        signature = signature.replace(']','').strip()
38
 
        self.type,self.name = signature.split()
39
 
 
40
 
    def __str__(self):
41
 
        ret = self.type[:]
42
 
        ret += ' '
43
 
        for p in range(self.pointer):
44
 
            ret += '*'
45
 
        ret += self.name
46
 
        if self.array:
47
 
            ret += '[]'
48
 
        return ret
49
 
 
50
 
class Function(object):
51
 
    def __init__(self, signature):
52
 
        signature = signature.replace('extern','').strip()
53
 
        self.return_type,signature = signature.split(None,1)
54
 
        self.return_type = self.return_type.strip()
55
 
        signature = signature.strip()
56
 
        self.name,signature = signature.split('(',1)
57
 
        self.name = self.name.strip()
58
 
        signature = signature.replace(')','').strip()
59
 
        signature = signature.replace(';','').strip()
60
 
        self.args = []
61
 
        if signature:
62
 
            for arg in signature.split(','):
63
 
                self.args.append(FunctionArgument(arg.strip()))
64
 
 
65
 
    def get_call(self, name=None):
66
 
        sig = ''
67
 
        if not name:
68
 
            sig += self.name
69
 
        else:
70
 
            sig += name
71
 
        sig += '('
72
 
        if self.args:
73
 
            for arg in self.args:
74
 
                sig += arg.name
75
 
                sig += ', '
76
 
            sig = sig[:-2] # remove last ', '
77
 
        sig += ')'
78
 
        return sig
79
 
 
80
 
    def get_signature(self, name=None):
81
 
        sig = self.return_type[:]
82
 
        sig += ' '
83
 
        if not name:
84
 
            sig += self.name
85
 
        else:
86
 
            sig += name
87
 
        sig += '('
88
 
        if self.args:
89
 
            for arg in self.args:
90
 
                sig += str(arg)
91
 
                sig += ', '
92
 
            sig = sig[:-2] # remove last ', '
93
 
        sig += ')'
94
 
        return sig
95
 
 
96
 
    def __str__(self):
97
 
        return self.get_signature()
98
 
 
99
 
if __name__ == '__main__':
100
 
    if len(sys.argv) != 2:
101
 
        print 'incorrect number of arguments'
102
 
        print 'usage: wapigen.py <ga-papi.h> > <fapi.c>'
103
 
        sys.exit(len(sys.argv))
104
 
 
105
 
    # print headers
106
 
    print '''
107
 
#if HAVE_CONFIG_H
108
 
#   include "config.h"
109
 
#endif
110
 
 
111
 
#include "ga-papi.h"
112
 
#include "typesf2c.h"
113
 
'''
114
 
 
115
 
    functions = {}
116
 
    # parse signatures into the Function class
117
 
    for sig in get_signatures(sys.argv[1]):
118
 
        function = Function(sig)
119
 
        functions[function.name] = function
120
 
 
121
 
    # now process the functions
122
 
    for name in sorted(functions):
123
 
        func = functions[name]
124
 
        maybe_return = ''
125
 
        if 'void' not in func.return_type:
126
 
            maybe_return = 'return '
127
 
        func = functions[name]
128
 
        wnga_name = name.replace('pnga_','wnga_')
129
 
        print '''
130
 
%s
131
 
{
132
 
    %s%s;
133
 
}
134
 
''' % (func.get_signature(wnga_name), maybe_return, func.get_call())