How to use the nml.NmlDict function in nml

To help you get started, we’ve selected a few nml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github payu-org / payu / nml.py View on Github external
def __setitem__(self, key, value):
        super(NmlDict, self).__setitem__(key.lower(), value)
github payu-org / payu / nml.py View on Github external
tokens = iter(f90)

    # Store groups in case-insensitive dictionary
    nmls = NmlDict()

    for t in tokens:

        # Ignore tokens outside of namelist groups
        while t != '&':
            t = tokens.next()

        # Read group name following '&'
        t = tokens.next()

        g_name = t
        g_vars = NmlDict()

        v_name = None
        v_vals = []
        while t != '/':

            prior_t = t
            t = tokens.next()

            if v_name and not t == '=':

                # Test if varname contains a vector index
                # TODO: Do I need regex?
                match = re.search(r'\(\d+\)$', v_name)
                if match:
                    v_index = int(v_name[match.start()+1:-1])
                    v_name = v_name[:match.start()]
github payu-org / payu / nml.py View on Github external
def parse(nml_fname):

    f = open(nml_fname, 'r')

    f90 = shlex.shlex(f)
    f90.commenters = '!'
    f90.wordchars += '.-()'   # Numerical characters
    tokens = iter(f90)

    # Store groups in case-insensitive dictionary
    nmls = NmlDict()

    for t in tokens:

        # Ignore tokens outside of namelist groups
        while t != '&':
            t = tokens.next()

        # Read group name following '&'
        t = tokens.next()

        g_name = t
        g_vars = NmlDict()

        v_name = None
        v_vals = []
        while t != '/':