DISPATCH
f90nml.namelist.Namelist Class Reference
Inheritance diagram for f90nml.namelist.Namelist:
Collaboration diagram for f90nml.namelist.Namelist:

Public Member Functions

def __init__ (self, args, kwds)
 
def __contains__ (self, key)
 
def __delitem__ (self, key)
 
def __getitem__ (self, key)
 
def __setitem__ (self, key, value)
 
def __str__ (self)
 
def column_width (self)
 
def column_width (self, width)
 
def indent (self)
 
def indent (self, value)
 
def end_comma (self)
 
def end_comma (self, value)
 
def uppercase (self)
 
def uppercase (self, value)
 
def float_format (self)
 
def float_format (self, value)
 
def logical_repr (self)
 
def logical_repr (self, value)
 
def true_repr (self)
 
def true_repr (self, value)
 
def false_repr (self)
 
def false_repr (self, value)
 
def start_index (self)
 
def start_index (self, value)
 
def default_start_index (self)
 
def default_start_index (self, value)
 
def write (self, nml_path, force=False, sort=False)
 
def patch (self, nml_patch)
 
def todict (self, complex_tuple=False)
 

Public Attributes

 start_index
 
 false_repr
 
 true_repr
 

Detailed Description

Representation of Fortran namelist in a Python environment.

Namelists can be initialised as empty or with a pre-defined `dict` of
`items`.  If an explicit default start index is required for `items`, then
it can be initialised with the `default_start_index` input argument.

In addition to the standard methods supported by `dict`, several additional
methods and properties are provided for working with Fortran namelists.

Definition at line 28 of file namelist.py.

Constructor & Destructor Documentation

◆ __init__()

Member Function Documentation

◆ __contains__()

def f90nml.namelist.Namelist.__contains__ (   self,
  key 
)
Case-insensitive interface to OrderedDict.

Definition at line 87 of file namelist.py.

◆ __delitem__()

def f90nml.namelist.Namelist.__delitem__ (   self,
  key 
)
Case-insensitive interface to OrderedDict.

Definition at line 91 of file namelist.py.

◆ __getitem__()

def f90nml.namelist.Namelist.__getitem__ (   self,
  key 
)
Case-insensitive interface to OrderedDict.

Definition at line 95 of file namelist.py.

◆ __setitem__()

def f90nml.namelist.Namelist.__setitem__ (   self,
  key,
  value 
)
Case-insensitive interface to OrderedDict.

Python dict inputs to the Namelist, such as derived types, are also
converted into Namelists.

Definition at line 99 of file namelist.py.

References f90nml.namelist.Namelist.default_start_index(), and f90nml.namelist.is_nullable_list().

◆ __str__()

def f90nml.namelist.Namelist.__str__ (   self)
Print the Fortran representation of the namelist.

Currently this can only be applied to the full contents of the namelist
file.  Indiviual namelist groups or values may not render correctly.

Definition at line 121 of file namelist.py.

References f90nml.namelist.Namelist._writestream().

◆ column_width() [1/2]

def f90nml.namelist.Namelist.column_width (   self)
Set the maximum number of characters per line of the namelist file.

Tokens longer than ``column_width`` are allowed to extend past this
limit.  (Default: 72)

Definition at line 140 of file namelist.py.

References f90nml.namelist.Namelist._column_width.

Referenced by f90nml.namelist.Namelist.column_width(), and f90nml.namelist.Namelist.patch().

◆ column_width() [2/2]

def f90nml.namelist.Namelist.column_width (   self,
  width 
)
Validate and set the column width.

Definition at line 149 of file namelist.py.

References f90nml.namelist.Namelist._column_width, and f90nml.namelist.Namelist.column_width().

◆ default_start_index()

def f90nml.namelist.Namelist.default_start_index (   self)
Set the default start index for vectors with no explicit index.

When the `default_start_index` is set, all vectors without an explicit
start index are assumed to begin with `default_start_index`.  This
index is shown when printing the namelist output.
(Default: None)

If set to `None`, then no start index is assumed and is left as
implicit for any vectors undefined in `start_index`.

Definition at line 351 of file namelist.py.

References f90nml.namelist.Namelist._default_start_index.

Referenced by f90nml.namelist.Namelist.__setitem__(), f90nml.namelist.Namelist.patch(), and f90nml.parser.Parser.read().

◆ end_comma() [1/2]

def f90nml.namelist.Namelist.end_comma (   self)
Append commas to the end of namelist variable entries.

Fortran will generally disregard any commas separating variable
assignments, and the default behaviour is to omit these commas from the
output.  Enabling this flag will append commas at the end of the line
for each variable assignment.

Definition at line 192 of file namelist.py.

References f90nml.namelist.Namelist._end_comma.

Referenced by f90nml.namelist.Namelist.end_comma(), and f90nml.namelist.Namelist.patch().

◆ end_comma() [2/2]

def f90nml.namelist.Namelist.end_comma (   self,
  value 
)
Validate and set the comma termination flag.

Definition at line 203 of file namelist.py.

References f90nml.namelist.Namelist._end_comma, and f90nml.namelist.Namelist.end_comma().

◆ false_repr() [1/2]

def f90nml.namelist.Namelist.false_repr (   self)
Set the string representation of logical false values.

This is equivalent to the first element of ``logical_repr``.

Definition at line 290 of file namelist.py.

References f90nml.namelist.Namelist._logical_repr.

◆ false_repr() [2/2]

def f90nml.namelist.Namelist.false_repr (   self,
  value 
)
Validate and set the logical false representation.

Definition at line 298 of file namelist.py.

References f90nml.namelist.Namelist._logical_repr.

◆ float_format() [1/2]

def f90nml.namelist.Namelist.float_format (   self)
Set the namelist floating point format.

The property sets the format string for floating point numbers,
following the format expected by the Python ``format()`` function.

Definition at line 222 of file namelist.py.

References f90nml.namelist.Namelist._float_format.

Referenced by f90nml.namelist.Namelist.float_format(), and f90nml.namelist.Namelist.todict().

◆ float_format() [2/2]

def f90nml.namelist.Namelist.float_format (   self,
  value 
)
Validate and set the upper case flag.

Definition at line 231 of file namelist.py.

References f90nml.namelist.Namelist._float_format, and f90nml.namelist.Namelist.float_format().

◆ indent() [1/2]

def f90nml.namelist.Namelist.indent (   self)
Set the whitespace indentation of namelist entries.

This can be set to an integer, denoting the number of spaces, or to an
explicit whitespace character, such as a tab (``\t``).
(Default: 4)

Definition at line 160 of file namelist.py.

References f90nml.namelist.Namelist._indent.

Referenced by f90nml.namelist.Namelist.indent(), and f90nml.namelist.Namelist.patch().

◆ indent() [2/2]

def f90nml.namelist.Namelist.indent (   self,
  value 
)
Validate and set the indent width.

Definition at line 170 of file namelist.py.

References f90nml.namelist.Namelist._indent, and f90nml.namelist.Namelist.indent().

◆ logical_repr() [1/2]

def f90nml.namelist.Namelist.logical_repr (   self)
Set the string representation of logical values.

There are multiple valid representations of True and False values in
Fortran.  This property sets the preferred representation in the
namelist output.

The properties ``true_repr`` and ``false_repr`` are also provided as
interfaces to the ``logical_repr`` tuple.
(Default: ``.false., .true.``)

Definition at line 243 of file namelist.py.

References f90nml.namelist.Namelist._logical_repr.

Referenced by f90nml.namelist.Namelist.logical_repr(), and f90nml.namelist.Namelist.todict().

◆ logical_repr() [2/2]

def f90nml.namelist.Namelist.logical_repr (   self,
  value 
)
Set the string representation of logical values.

Definition at line 257 of file namelist.py.

References f90nml.namelist.Namelist.false_repr, f90nml.namelist.Namelist.logical_repr(), and f90nml.namelist.Namelist.true_repr.

◆ patch()

def f90nml.namelist.Namelist.patch (   self,
  nml_patch 
)
Update the namelist from another partial or full namelist.

This is different from the intrinsic `update()` method, which replaces
a namelist section.  Rather, it updates the values within a section.

Definition at line 387 of file namelist.py.

References f90nml.namelist.Namelist._f90repr(), f90nml.namelist.Namelist._newline, f90nml.namelist.Namelist._var_strings(), f90nml.namelist.Namelist._write_nmlgrp(), f90nml.namelist.Namelist.column_width(), f90nml.namelist.Namelist.default_start_index(), f90nml.namelist.Namelist.end_comma(), f90nml.namelist.Namelist.indent(), f90nml.namelist.is_nullable_list(), and f90nml.namelist.Namelist.uppercase().

◆ start_index() [1/2]

def f90nml.namelist.Namelist.start_index (   self)
Set the starting index for each vector in the namelist.

``start_index`` is stored as a dict which contains the starting index
for each vector saved in the namelist.  For the namelist ``vec.nml``
shown below,

.. code-block:: fortran

   &vec_nml
       a = 1, 2, 3
       b(0:2) = 0, 1, 2
       c(3:5) = 3, 4, 5
       d(:,:) = 1, 2, 3, 4
   /

the ``start_index`` contents are

.. code:: python

   >>> import f90nml
   >>> nml = f90nml.read('vec.nml')
   >>> nml['vec_nml'].start_index
   {'b': [0], 'c': [3], 'd': [None, None]}

The starting index of ``a`` is absent from ``start_index``, since its
starting index is unknown and its values cannot be assigned without
referring to the corresponding Fortran source.

Definition at line 311 of file namelist.py.

References f90nml.namelist.Namelist._start_index.

◆ start_index() [2/2]

def f90nml.namelist.Namelist.start_index (   self,
  value 
)
Validate and set the vector start index.

Definition at line 343 of file namelist.py.

References f90nml.namelist.Namelist._start_index.

◆ todict()

def f90nml.namelist.Namelist.todict (   self,
  complex_tuple = False 
)
Return a dict equivalent to the namelist.

Since Fortran variables and names cannot start with the ``_``
character, any keys starting with this token denote metadata, such as
starting index.

The ``complex_tuple`` flag is used to convert complex data into an
equivalent 2-tuple, with metadata stored to flag the variable as
complex.  This is primarily used to facilitate the storage of the
namelist into an equivalent format which does not support complex
numbers, such as JSON or YAML.

Definition at line 590 of file namelist.py.

References f90nml.namelist.Namelist._f90bool(), f90nml.namelist.Namelist._f90complex(), f90nml.namelist.Namelist._f90float(), f90nml.namelist.Namelist._f90int(), f90nml.namelist.Namelist._f90str(), f90nml.namelist.Namelist.float_format(), f90nml.namelist.Namelist.logical_repr(), and f90nml.namelist.Namelist.start_index.

◆ true_repr() [1/2]

def f90nml.namelist.Namelist.true_repr (   self)
Set the string representation of logical true values.

This is equivalent to the second element of ``logical_repr``.

Definition at line 269 of file namelist.py.

References f90nml.namelist.Namelist._logical_repr.

◆ true_repr() [2/2]

def f90nml.namelist.Namelist.true_repr (   self,
  value 
)
Validate and set the logical true representation.

Definition at line 277 of file namelist.py.

References f90nml.namelist.Namelist._logical_repr.

◆ uppercase() [1/2]

def f90nml.namelist.Namelist.uppercase (   self)
Print group and variable names in uppercase.

Definition at line 210 of file namelist.py.

References f90nml.namelist.Namelist._uppercase.

Referenced by f90nml.namelist.Namelist.patch(), and f90nml.namelist.Namelist.uppercase().

◆ uppercase() [2/2]

def f90nml.namelist.Namelist.uppercase (   self,
  value 
)
Validate and set the uppercase flag.

Definition at line 215 of file namelist.py.

References f90nml.namelist.Namelist._uppercase, and f90nml.namelist.Namelist.uppercase().

◆ write()

def f90nml.namelist.Namelist.write (   self,
  nml_path,
  force = False,
  sort = False 
)
Write Namelist to a Fortran 90 namelist file.

>>> nml = f90nml.read('input.nml')
>>> nml.write('out.nml')

Definition at line 370 of file namelist.py.

References f90nml.namelist.Namelist._writestream().

Referenced by fortranfile.FortranFile.__init__(), fortranfile.FortranFile.writeInts(), fortranfile.FortranFile.writeReals(), and fortranfile.FortranFile.writeRecord().


The documentation for this class was generated from the following file: