{ } Raw JSON

bundles / numpy 2.4.4 / numpy / f2py / crackfortran / param_parse

function

numpy.f2py.crackfortran:param_parse

source: /numpy/f2py/crackfortran.py:3026

Signature

def param_parse(d, params)

Summary

Recursively parse array dimensions.

Extended Summary

Parses the declaration of an array variable or parameter dimension keyword, and is called recursively if the dimension for this array is a previously defined parameter (found in params).

Parameters

d : str

Fortran expression describing the dimension of an array.

params : dict

Previously parsed parameters declared in the Fortran source file.

Returns

out : str

Parsed dimension expression.

Examples

* If the line being analyzed is `integer, parameter, dimension(2) :: pa = (/ 3, 5 /)` then `d = 2` and we return immediately, with
d = '2'
✓
param_parse(d, params)
⚠
Traceback (most recent call last):
  File "<doctest numpy.f2py.crackfortran:param_parse[0]>", line 1, in <module>
    param_parse(d, params)
                   ^^^^^^
NameError: name 'params' is not defined
* If the line being analyzed is `integer, parameter, dimension(pa) :: pb = (/1, 2, 3/)` then `d = 'pa'`; since `pa` is a previously parsed parameter, and `pa = 3`, we call `param_parse` recursively, to obtain
d = 'pa'
params = {'pa': 3}
✓
param_parse(d, params)
✗
'3'
* If the line being analyzed is `integer, parameter, dimension(pa(1)) :: pb = (/1, 2, 3/)` then `d = 'pa(1)'`; since `pa` is a previously parsed parameter, and `pa(1) = 3`, we call `param_parse` recursively, to obtain
d = 'pa(1)'
params = dict(pa={1: 3, 2: 5})
✓
param_parse(d, params)
✗
'3'

Aliases

  • numpy.f2py.crackfortran.param_parse