Exemplo n.º 1
0
def read(nml_path, row_major=None, strict_logical=None):
    """Parse a Fortran 90 namelist file ``nml_file`` or file path ``nml_path``
    and return its contents as a ``Namelist``.

    File object usage:

    >>> with open(nml_path) as nml_file:
    >>>     nml = f90nml.read(nml_file)

    File path usage:

    >>> nml = f90nml.read(nml_path)

    This function is equivalent to the ``read`` function of the ``Parser``
    object.

    >>> parser = f90nml.Parser()
    >>> nml = parser.read(nml_file)

    Multidimensional array data contiguity is preserved by default, so that
    column-major Fortran data is represented as row-major Python list of
    lists.

    The ``row_major`` flag will reorder the data to preserve the index rules
    between Fortran to Python, but the data will be converted to row-major form
    (with respect to Fortran).

    The ``strict_logical`` flag will limit the parsing of non-delimited logical
    strings as logical values.  The default value is ``True``.

    When ``strict_logical`` is enabled, only ``.true.``, ``.t.``, ``true``, and
    ``t`` are interpreted as ``True``, and only ``.false.``, ``.f.``,
    ``false``, and ``.false.`` are interpreted as false.

    When ``strict_logical`` is disabled, any value starting with ``.t`` or
    ``t`` are interpreted as ``True``, while any string starting with ``.f`` or
    ``f`` is interpreted as ``False``."""

    parser = Parser()
    parser.row_major = row_major
    parser.strict_logical = strict_logical

    return parser.read(nml_path)
Exemplo n.º 2
0
def read(nml_path, row_major=None, strict_logical=None):
    """Parse a Fortran 90 namelist file ``nml_file`` or file path ``nml_path``
    and return its contents as a ``Namelist``.

    File object usage:

    >>> with open(nml_path) as nml_file:
    >>>     nml = f90nml.read(nml_file)

    File path usage:

    >>> nml = f90nml.read(nml_path)

    This function is equivalent to the ``read`` function of the ``Parser``
    object.

    >>> parser = f90nml.Parser()
    >>> nml = parser.read(nml_file)

    Multidimensional array data contiguity is preserved by default, so that
    column-major Fortran data is represented as row-major Python list of
    lists.

    The ``row_major`` flag will reorder the data to preserve the index rules
    between Fortran to Python, but the data will be converted to row-major form
    (with respect to Fortran).

    The ``strict_logical`` flag will limit the parsing of non-delimited logical
    strings as logical values.  The default value is ``True``.

    When ``strict_logical`` is enabled, only ``.true.``, ``.t.``, ``true``, and
    ``t`` are interpreted as ``True``, and only ``.false.``, ``.f.``,
    ``false``, and ``.false.`` are interpreted as false.

    When ``strict_logical`` is disabled, any value starting with ``.t`` or
    ``t`` are interpreted as ``True``, while any string starting with ``.f`` or
    ``f`` is interpreted as ``False``."""

    parser = Parser()
    parser.row_major = row_major
    parser.strict_logical = strict_logical

    return parser.read(nml_path)
Exemplo n.º 3
0
def patch(nml_path, nml_patch, out_path=None, row_major=None,
          strict_logical=None):
    """Create a new namelist based on an input namelist and reference dict.

    >>> f90nml.patch('data.nml', nml_patch, 'patched_data.nml')

    This function is equivalent to the ``read`` function of the ``Parser``
    object with the patch output arguments.

    >>> parser = f90nml.Parser()
    >>> nml = parser.read('data.nml', nml_patch, 'patched_data.nml')

    A patched namelist file will retain any formatting or comments from the
    original namelist file.  Any modified values will be formatted based on the
    settings of the ``Namelist`` object.
    """
    parser = Parser()
    parser.row_major = row_major
    parser.strict_logical = strict_logical

    return parser.read(nml_path, nml_patch, out_path)