예제 #1
0
def reads(nml_string):
    """Parse a Fortran namelist string and return its contents.

    >>> nml_str = '&data_nml x=1 y=2 /'
    >>> nml = f90nml.reads(nml_str)

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

    >>> parser = f90nml.Parser()
    >>> nml = parser.reads(nml_str)
    """
    parser = Parser()
    return parser.reads(nml_string)
예제 #2
0
def reads(nml_string):
    """Parse a Fortran namelist string and return its contents.

    >>> nml_str = '&data_nml x=1 y=2 /'
    >>> nml = f90nml.reads(nml_str)

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

    >>> parser = f90nml.Parser()
    >>> nml = parser.reads(nml_str)
    """
    parser = Parser()
    return parser.reads(nml_string)
예제 #3
0
def patch(nml_path, nml_patch, out_path=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()

    return parser.read(nml_path, nml_patch, out_path)
예제 #4
0
def patch(nml_path, nml_patch, out_path=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()

    return parser.read(nml_path, nml_patch, out_path)
예제 #5
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)
예제 #6
0
파일: __init__.py 프로젝트: honnorat/f90nml
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)
예제 #7
0
def read(nml_path):
    """Parse a Fortran namelist file and return its contents.

    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)
    """
    parser = Parser()
    return parser.read(nml_path)
예제 #8
0
def read(nml_path):
    """Parse a Fortran namelist file and return its contents.

    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)
    """
    parser = Parser()
    return parser.read(nml_path)
예제 #9
0
def patch(nml_fname, nml_patch, out_fname=None):
    """Create a new namelist based on an input namelist and reference dict.

    >>> f90nml.patch('data.nml', nml_patch, 'patched_data.nml')"""
    return Parser().read(nml_fname, nml_patch, out_fname)
예제 #10
0
def read(nml_fname):
    """Parse a Fortran 90 namelist file (data.nml) and store its contents.

    >>> nml = f90nml.read('data.nml')"""
    return Parser().read(nml_fname)