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 float value 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, and skip_intzero. Consider the equally named arguments of the EndfParserPy constructor for an explanation of these options.

Returns:

String representation of the float number

Return type:

str

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 the e character omitted are supported.

Parameters:
  • valstr (str) – String that should be converted to float.

  • read_opts (Optional[dict]) – Dictionary with field/value pairs to influence conversion process. Supported options are accept_spaces and preserve_value_strings. Consider the equally named options of the EndfParserPy class for an explanation of their meaning.

Returns:

float that corresponds to string representation of number.

Return type:

float

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 width specifies the number of character-slots assigned to each float. For the other available options, see the help of fortstr2float().

Returns:

A list with the extracted float numbers

Return type:

list[float]

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:
  • vals (list[float]) –

  • 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:

str