Skip to main content

A Python module and command line tool for parsing Fortran namelist files

https://ci.appveyor.com/api/projects/status/bcugyoqxiyyvemy8?svg=true https://coveralls.io/repos/marshallward/f90nml/badge.svg?branch=master https://zenodo.org/badge/DOI/10.5281/zenodo.3245482.svg

Documentation

The documentation for f90nml is available from Read The Docs.

http://f90nml.readthedocs.org/en/latest/

About f90nml

f90nml is a Python module and command line tool that provides a simple interface for the reading, writing, and modifying Fortran namelist files.

A namelist file is parsed and converted into a Namelist object, which behaves like a Python dict. Values are converted from Fortran data types to equivalent primitive Python types.

The command line tool f90nml can be used to modify individual values inside of a shell environment. It can also be used to convert the data between namelists and other configuration formats. JSON and YAML formats are currently supported.

Quick usage guide

To read a namelist file sample.nml which contains the following namelists:

&config_nml
   input = 'wind.nc'
   steps = 864
   layout = 8, 16
   visc = 1.0e-4
   use_biharmonic = .false.
/

we would use the following script:

import f90nml
nml = f90nml.read('sample.nml')

which would would point nml to the following dict:

nml = {
    'config_nml': {
        'input': 'wind.nc',
        'steps': 864,
        'layout': [8, 16],
        'visc': 0.0001,
        'use_biharmonic': False
    }
}

File objects can also be used as inputs:

with open('sample.nml') as nml_file:
    nml = f90nml.read(nml_file)

To modify one of the values, say steps, and save the output, manipulate the nml contents and write to disk using the write function:

nml['config_nml']['steps'] = 432
nml.write('new_sample.nml')

Namelists can also be saved to file objects:

with open('target.nml') as nml_file:
   nml.write(nml_file)

To modify a namelist but preserve its comments and formatting, create a namelist patch and apply it to a target file using the patch function:

patch_nml = {'config_nml': {'visc': 1e-6}}
f90nml.patch('sample.nml', patch_nml, 'new_sample.nml')

Command line interface

A command line tool is provided to manipulate namelist files within the shell:

$ f90nml config.nml -g config_nml -v steps=432
&config_nml
   input = 'wind.nc'
   steps = 432
   layout = 8, 16
   visc = 1.0e-4
   use_biharmonic = .false.
/

See the documentation for details.

Installation

f90nml is available on PyPI and can be installed via pip:

$ pip install f90nml

The latest version of f90nml can be installed from source:

$ git clone https://github.com/marshallward/f90nml.git
$ cd f90nml
$ pip install .

conda

There is a conda-forge feedstock (not maintained by the author):

$ conda install -c conda-forge f90nml

Information on supported versions and platforms, and detailed installation instructions using conda and conda-forge is available here:

https://github.com/conda-forge/f90nml-feedstock

Package distribution

f90nml is not distributed through any official packaging tools, but it is available on Arch Linux via the AUR:

$ git clone https://aur.archlinux.org/python-f90nml.git
$ cd python-f90nml
$ makepkg -sri

Volunteers are welcome to submit and maintain f90nml on other distributions.

Local install

Users without install privileges can append the --user flag to pip from the top f90nml directory:

$ pip install --user .

If pip is not available, then setup.py can still be used:

$ python setup.py install --user

When using setup.py locally, some users have reported that --prefix= may need to be appended to the command:

$ python setup.py install --user --prefix=

YAML support

The command line tool offers support for conversion between namelists and YAML formatted output. If PyYAML is already installed, then no other steps are required. To require YAML support, install the yaml extras package:

$ pip install f90nml[yaml]

To install as a user:

$ pip install --user .[yaml]

Contributing to f90nml

Users are welcome to submit bug reports, feature requests, and code contributions to this project through GitHub. More information is available in the Contributing guidelines.

Release files for f90nml 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for f90nml 1.5
File Size Uploaded
f90nml-1.5.tar.gz 71.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for f90nml 1.5
File Interpreter ABI Platform
f90nml-1.5.0-py2.py3-none-any.whl Python 3, Python 2 none any Details
f90nml-1.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 174.9 kB

Release files / f90nml-1.5.tar.gz

Download URL f90nml-1.5.tar.gz
Size 71.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d5585f0051234c742f7515c4b1f8484f8f628a71c4e31f2602357089dcc05fc1
BLAKE2b-256 checksum
How to use checksums
54395bef20ee2868924029b2d34523839798cc8e48183ca57d9704ae6ef92da6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / f90nml-1.5.0-py2.py3-none-any.whl

Download URL f90nml-1.5.0-py2.py3-none-any.whl
Size 52.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bdf616dbe7e83619feb86d54358fb8d97038133bfd8f9ba9a01eeca5dc4691a7
BLAKE2b-256 checksum
How to use checksums
21f24454eefc15cc326b46530d230c58cc0bb91a1e9797f2842b2a1720cbb233
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / f90nml-1.5-py2.py3-none-any.whl

Download URL f90nml-1.5-py2.py3-none-any.whl
Size 52.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
38bbbdfe81eb7ac62e924021c4df6bb5cf4846e2f8ad79bfecb0fd654250180a
BLAKE2b-256 checksum
How to use checksums
a9ee39fc4b67a7ae5ba91d6da18a1b66cbdf6b2f4f88e3a26ca36823f3482dd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.5 This release

3 release files

1.4.5

1 release file

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4

2 release files

1.3.1

1 release file

1.3

1 release file

1.2

1 release file

1.1.2

2 release files

1.1.1

1 release file

1.1

2 release files

1.0.2

2 release files

1.0.1

1 release file

1.0

1 release file

0.23

1 release file

0.22

1 release file

0.21

1 release file

0.20

1 release file

0.19

1 release file

0.18

1 release file

0.17

1 release file

0.16

1 release file

0.15

1 release file

0.14

1 release file

0.13

0.12

1 release file

0.11

1 release file

0.10.2

1 release file

0.10.1

1 release file

0.10

1 release file

0.9.1

1 release file

0.9

1 release file

0.8

1 release file

0.7

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page