Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/f2py/common_rules.py @ 87:2a2c65a20a8b
Add Python libs and headers
author | Chris Cannam |
---|---|
date | Wed, 25 Feb 2015 14:05:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
86:413a9d26189e | 87:2a2c65a20a8b |
---|---|
1 #!/usr/bin/env python | |
2 """ | |
3 | |
4 Build common block mechanism for f2py2e. | |
5 | |
6 Copyright 2000 Pearu Peterson all rights reserved, | |
7 Pearu Peterson <pearu@ioc.ee> | |
8 Permission to use, modify, and distribute this software is given under the | |
9 terms of the NumPy License | |
10 | |
11 NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
12 $Date: 2005/05/06 10:57:33 $ | |
13 Pearu Peterson | |
14 | |
15 """ | |
16 from __future__ import division, absolute_import, print_function | |
17 | |
18 __version__ = "$Revision: 1.19 $"[10:-1] | |
19 | |
20 from . import __version__ | |
21 f2py_version = __version__.version | |
22 | |
23 import pprint | |
24 import sys | |
25 errmess=sys.stderr.write | |
26 outmess=sys.stdout.write | |
27 show=pprint.pprint | |
28 | |
29 from .auxfuncs import * | |
30 from . import capi_maps | |
31 from . import func2subr | |
32 from .crackfortran import rmbadname | |
33 ############## | |
34 | |
35 def findcommonblocks(block,top=1): | |
36 ret = [] | |
37 if hascommon(block): | |
38 for n in block['common'].keys(): | |
39 vars={} | |
40 for v in block['common'][n]: | |
41 vars[v]=block['vars'][v] | |
42 ret.append((n, block['common'][n], vars)) | |
43 elif hasbody(block): | |
44 for b in block['body']: | |
45 ret=ret+findcommonblocks(b, 0) | |
46 if top: | |
47 tret=[] | |
48 names=[] | |
49 for t in ret: | |
50 if t[0] not in names: | |
51 names.append(t[0]) | |
52 tret.append(t) | |
53 return tret | |
54 return ret | |
55 | |
56 def buildhooks(m): | |
57 ret = {'commonhooks':[],'initcommonhooks':[],'docs':['"COMMON blocks:\\n"']} | |
58 fwrap = [''] | |
59 def fadd(line,s=fwrap): s[0] = '%s\n %s'%(s[0], line) | |
60 chooks = [''] | |
61 def cadd(line,s=chooks): s[0] = '%s\n%s'%(s[0], line) | |
62 ihooks = [''] | |
63 def iadd(line,s=ihooks): s[0] = '%s\n%s'%(s[0], line) | |
64 doc = [''] | |
65 def dadd(line,s=doc): s[0] = '%s\n%s'%(s[0], line) | |
66 for (name, vnames, vars) in findcommonblocks(m): | |
67 lower_name = name.lower() | |
68 hnames, inames = [], [] | |
69 for n in vnames: | |
70 if isintent_hide(vars[n]): hnames.append(n) | |
71 else: inames.append(n) | |
72 if hnames: | |
73 outmess('\t\tConstructing COMMON block support for "%s"...\n\t\t %s\n\t\t Hidden: %s\n'%(name, ','.join(inames), ','.join(hnames))) | |
74 else: | |
75 outmess('\t\tConstructing COMMON block support for "%s"...\n\t\t %s\n'%(name, ','.join(inames))) | |
76 fadd('subroutine f2pyinit%s(setupfunc)'%name) | |
77 fadd('external setupfunc') | |
78 for n in vnames: | |
79 fadd(func2subr.var2fixfortran(vars, n)) | |
80 if name=='_BLNK_': | |
81 fadd('common %s'%(','.join(vnames))) | |
82 else: | |
83 fadd('common /%s/ %s'%(name, ','.join(vnames))) | |
84 fadd('call setupfunc(%s)'%(','.join(inames))) | |
85 fadd('end\n') | |
86 cadd('static FortranDataDef f2py_%s_def[] = {'%(name)) | |
87 idims=[] | |
88 for n in inames: | |
89 ct = capi_maps.getctype(vars[n]) | |
90 at = capi_maps.c2capi_map[ct] | |
91 dm = capi_maps.getarrdims(n, vars[n]) | |
92 if dm['dims']: idims.append('(%s)'%(dm['dims'])) | |
93 else: idims.append('') | |
94 dms=dm['dims'].strip() | |
95 if not dms: dms='-1' | |
96 cadd('\t{\"%s\",%s,{{%s}},%s},'%(n, dm['rank'], dms, at)) | |
97 cadd('\t{NULL}\n};') | |
98 inames1 = rmbadname(inames) | |
99 inames1_tps = ','.join(['char *'+s for s in inames1]) | |
100 cadd('static void f2py_setup_%s(%s) {'%(name, inames1_tps)) | |
101 cadd('\tint i_f2py=0;') | |
102 for n in inames1: | |
103 cadd('\tf2py_%s_def[i_f2py++].data = %s;'%(name, n)) | |
104 cadd('}') | |
105 if '_' in lower_name: | |
106 F_FUNC='F_FUNC_US' | |
107 else: | |
108 F_FUNC='F_FUNC' | |
109 cadd('extern void %s(f2pyinit%s,F2PYINIT%s)(void(*)(%s));'\ | |
110 %(F_FUNC, lower_name, name.upper(), | |
111 ','.join(['char*']*len(inames1)))) | |
112 cadd('static void f2py_init_%s(void) {'%name) | |
113 cadd('\t%s(f2pyinit%s,F2PYINIT%s)(f2py_setup_%s);'\ | |
114 %(F_FUNC, lower_name, name.upper(), name)) | |
115 cadd('}\n') | |
116 iadd('\tF2PyDict_SetItemString(d, \"%s\", PyFortranObject_New(f2py_%s_def,f2py_init_%s));'%(name, name, name)) | |
117 tname = name.replace('_', '\\_') | |
118 dadd('\\subsection{Common block \\texttt{%s}}\n'%(tname)) | |
119 dadd('\\begin{description}') | |
120 for n in inames: | |
121 dadd('\\item[]{{}\\verb@%s@{}}'%(capi_maps.getarrdocsign(n, vars[n]))) | |
122 if hasnote(vars[n]): | |
123 note = vars[n]['note'] | |
124 if isinstance(note, list): note='\n'.join(note) | |
125 dadd('--- %s'%(note)) | |
126 dadd('\\end{description}') | |
127 ret['docs'].append('"\t/%s/ %s\\n"'%(name, ','.join(map(lambda v, d:v+d, inames, idims)))) | |
128 ret['commonhooks']=chooks | |
129 ret['initcommonhooks']=ihooks | |
130 ret['latexdoc']=doc[0] | |
131 if len(ret['docs'])<=1: ret['docs']='' | |
132 return ret, fwrap[0] |