DISPATCH
f90nml Namespace Reference

Namespaces

 cli
 
 findex
 
 fpy
 
 namelist
 
 parser
 
 tokenizer
 

Functions

def read (nml_path)
 
def write (nml, nml_path, force=False, sort=False)
 
def patch (nml_path, nml_patch, out_path=None)
 

Detailed Description

A Fortran 90 namelist parser and generator.

:copyright: Copyright 2014 Marshall Ward, see AUTHORS for details.
:license: Apache License, Version 2.0, see LICENSE for details.

Function Documentation

◆ patch()

def f90nml.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.

Definition at line 70 of file __init__.py.

Referenced by f90nml.cli.parse().

◆ read()

def f90nml.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)

Definition at line 12 of file __init__.py.

Referenced by f90nml.cli.parse().

◆ write()

def f90nml.write (   nml,
  nml_path,
  force = False,
  sort = False 
)
Save a namelist to disk using either a file object or its file path.

File object usage:

>>> with open(nml_path, 'w') as nml_file:
>>>     f90nml.write(nml, nml_file)

File path usage:

>>> f90nml.write(nml, 'data.nml')

This function is equivalent to the ``write`` function of the ``Namelist``
object ``nml``.

>>> nml.write('data.nml')

By default, ``write`` will not overwrite an existing file.  To override
this, use the ``force`` flag.

>>> nml.write('data.nml', force=True)

To alphabetically sort the ``Namelist`` keys, use the ``sort`` flag.

>>> nml.write('data.nml', sort=True)

Definition at line 35 of file __init__.py.

Referenced by f90nml.cli.parse(), and f90nml.parser.Parser.read().