1 """Conversion of Fortran values (as strings) to equivalent Python values. 3 The functions in this module are used to convert the string representation of 4 the values of basic Fortran data types into equivalent Python values. 6 :copyright: Copyright 2014 Marshall Ward, see AUTHORS for details. 7 :license: Apache License, Version 2.0, see LICENSE for details. 13 """Convert string repr of Fortran floating point to Python double.""" 16 return float(re.sub(
'(?<=[^eEdD])(?=[+-])',
'e',
17 v_str.lower().replace(
'd',
'e')))
21 """Convert string repr of Fortran complex to Python complex.""" 22 assert isinstance(v_str, str)
24 if v_str[0] ==
'(' and v_str[-1] ==
')' and len(v_str.split(
',')) == 2:
25 v_re, v_im = v_str[1:-1].split(
',', 1)
30 raise ValueError(
'{0} must be in complex number form (x, y).' 34 def pybool(v_str, strict_logical=True):
35 """Convert string repr of Fortran logical to Python logical.""" 36 assert isinstance(v_str, str)
37 assert isinstance(strict_logical, bool)
40 v_bool = v_str.lower()
43 if v_str.startswith(
'.'):
44 v_bool = v_str[1].lower()
46 v_bool = v_str[0].lower()
48 raise ValueError(
'{0} is not a valid logical constant.' 51 if v_bool
in (
'.true.',
'.t.',
'true',
't'):
53 elif v_bool
in (
'.false.',
'.f.',
'false',
'f'):
56 raise ValueError(
'{0} is not a valid logical constant.'.format(v_str))
60 """Convert string repr of Fortran string to Python string.""" 61 assert isinstance(v_str, str)
63 if v_str[0]
in (
"'",
'"')
and v_str[0] == v_str[-1]:
74 out = out.replace(2 * quote, quote)
def pybool(v_str, strict_logical=True)