nml 0.1.0

A parser for fortran's namelist format
Documentation

A serde library for Fortran namelist inputs.

Namelists are a Fortran 90 feature for input and output of groups of variables in a key-value assignment format.

&particle
timestep = 0,
mass = 1.0
position = 1.0, 1.0, 1.0,
velocity = -1.0, 0.0, 0.0
/

This namelist group assignes an integer variable timestep, a floating point/real variable masss and two arrays of reals position and velocity. Further data types supported by the namelist input format are bool/logical values (assinged with .TRUE. or .FALSE.) and strings (denoted by either single quotes 'hello', or double quotes "hello")

Usage

Namelist Groups

To serialize a Rust struct as a namelist group, you can:

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Particle {
timestep: i32,
mass: f32,
position: [f32; 3],
velocity: [f32; 3]
}

fn main() -> Result<(), nml::NamelistError> {
let p = Particle {
timestep: 0,
mass: 1.0,
position: [0.0, 0.0, 0.0],
velocity: [-1.0, 0.0, 0.0]
};

let serialized = nml::group_to_string(p)?;
let deserialized = nml::group_from_str(&serialized)?;

assert_eq!(p, deserialized);
Ok(())
}

Multiple Namelist Groups

Supported Namelist Syntax

Supported:

  • All basic data types, integer, logical, string, real
  • Arrays: Both Assigning sequences and individual elements using subscripts
  • Derived types

Not Supported:

  • Anything involving the slice operator :, for example: var(1:3) = 1, 2, 3,
  • Assignments of sequences to subscripted variables, i.e. var(1) = 1, 2, 3