fortran_utils
The endf_parserpy.interpreter.fortran_utils module implements
several functions for converting strings with
Fortran-formatted numbers to Python float and int
variables. It also provides functions for converting these Python
variables to string representations.
- endf_parserpy.interpreter.fortran_utils.float2fortstr(val, write_opts=None)[source]
Convert a float value to string.
This function converts a
floatvalue to a string representation. Various options are supported to influence the conversion process.- Parameters:
val (float) – The float variable/number whose string representation is desired.
write_opts (dict) – Python dictionary with field/value pairs to influence conversion process. Supported field names are
prefer_noexp,width,abuse_signpos,keep_E, andskip_intzero. Consider the equally named arguments of theEndfParserPyconstructor for an explanation of these options.
- Returns:
String representation of the
floatnumber- Return type:
- endf_parserpy.interpreter.fortran_utils.fortstr2float(valstr, read_opts=None)[source]
Convert a Fortran number string to float.
Convert a number string to a
float. Fortran number strings with theecharacter omitted are supported.- Parameters:
read_opts (Optional[dict]) – Dictionary with field/value pairs to influence conversion process. Supported options are
accept_spacesandpreserve_value_strings. Consider the equally named options of theEndfParserPyclass for an explanation of their meaning.
- Returns:
floatthat corresponds to string representation of number.- Return type:
- endf_parserpy.interpreter.fortran_utils.read_fort_floats(line, n=6, read_opts=None)[source]
Read several floats from a string.
The string representations of each number are assumed to be stored one-after-another in text fields of a fixed size.
- Parameters:
line (str) – String containing numbers to read
n (int) – Number of float numbers to read
read_opts (Optional[dict]) – The field
widthspecifies the number of character-slots assigned to each float. For the other available options, see the help offortstr2float().
- Returns:
A list with the extracted
floatnumbers- Return type:
- endf_parserpy.interpreter.fortran_utils.write_fort_floats(vals, write_opts=None)[source]
Write several floats to a string.
Floats are written as text fields of fixed width one-after-another.
- Parameters:
write_opts (Optional[dict]) – Dictionary with options to influence number formatting, see help of
float2fortstr()for available options.
- Returns:
String with numbers written one-after-another in text fields of fixed width.
- Return type: