Command line interface

f90nml includes a command line tool which can be used to modify namelist variables inside of a shell environment. It can also be used to convert data between namelists and the JSON and YAML formats.

Options

-f FORMAT, --format FORMAT

specify the output format (json, yaml, or nml)

-g GROUP, --group GROUP

specify namelist group to modify. When absent, the first group is used

-h, --help

display this help and exit

-p, --patch

modify the existing namelist as a patch

-v EXPR, --variable EXPR

specify the namelist variable to add or modify, followed by the new value. Expressions are of the form "VARIABLE=VALUE"

--version

output version information and exit

Examples

The examples below use the namelist file config.nml with the following data.

&config_nml
input = 'wind.nc'
steps = 864
layout = 8, 16      ! (X, Y)
visc = 1e-4         ! m2 s-1
use_biharmonic = .false.
/

To display the formatted output of a namelist:

$ f90nml config.nml
&config_nml
    input = 'wind.nc'
    steps = 864
    layout = 8, 16
    visc = 0.0001
    use_biharmonic = .false.
/

To modify one of the values or add a new variable:

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

Multiple variables can be set with separate flags or separated by commas:

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

Spaces should not be used when assigning values.

When the namelist group is unspecified, the first group is assumed:

$ f90nml -v steps=432 config.nml
f90nml: warning: Assuming variables are in group 'config_nml'.
&config_nml
    input = 'wind.nc'
    steps = 432
    layout = 8, 16
    visc = 0.0001
    use_biharmonic = .false.
/

To save the modified namelist to a new file, say out.nml:

$ f90nml -v steps=432 config.nml out.nml

To patch the existing file and preserve comments:

$ f90nml -g config_nml -v steps=432 -p config.nml
&config_nml
input = 'wind.nc'
steps = 432
layout = 8, 16      ! (X, Y)
visc = 1e-4         ! m2 s-1
use_biharmonic = .false.
/

To convert the output to JSON format:

$ f90nml -g config_nml -v steps=432 config.nml -f json
{
    "config_nml": {
        "input": "wind.nc",
        "steps": 432,
        "layout": [
            8,
            16
        ],
        "visc": 0.0001,
        "use_biharmonic": false
    }
}

Output format is also inferred from the output extension.

$ f90nml -g config_nml -v steps=432 config.nml out.json
$ f90nml -g config_nml -v steps=432 config.nml out.yaml

JSON and YAML can also act as input files. Format is assumed by extension.

$ f90nml out.json
&config_nml
    input = 'wind.nc'
    layout = 8, 16
    steps = 864
    use_biharmonic = .false.
    visc = 0.0001
/