Commit 8b94fbba authored by Martin Claus's avatar Martin Claus
Browse files

Merge branch '5-create-example-for-parsing-nemo-namelists' into 'develop'

Resolve "Create example for parsing nemo namelists"

Closes #5

See merge request !7
parents c6d57bd2 8d2cd963
Loading
Loading
Loading
Loading
Loading

examples/context.py

0 → 100644
+12 −0
Original line number Diff line number Diff line
"""Context for examples."""

import os
import sys
sys.path.insert(
    0,
    os.path.abspath(
        os.path.join(os.path.dirname(__file__), '..')
    )
)

import namelist

examples/namelist_cfg

0 → 100644
+604 −0

File added.

Preview size limit exceeded, changes collapsed.

examples/namelist_ref

0 → 100644
+1279 −0

File added.

Preview size limit exceeded, changes collapsed.

+21 −0
Original line number Diff line number Diff line
from context import namelist
import json

in_file_ref = "namelist_ref"
in_file_cfg = "namelist_cfg"

with open(in_file_ref) as f:
    ref_nmls = namelist.parse_namelist_file(f)

with open(in_file_cfg) as f:
    cfg_nmls = namelist.parse_namelist_file(f)

nmls = ref_nmls.copy()

for k in cfg_nmls:
    if k in nmls:
        nmls[k].update(cfg_nmls[k])
    else:
        nmls[k] = cfg_nmls[k]

print(json.dumps(nmls, indent=4))