1 """A Fortran 90 namelist parser and generator. 3 :copyright: Copyright 2014 Marshall Ward, see AUTHORS for details. 4 :license: Apache License, Version 2.0, see LICENSE for details. 13 """Parse a Fortran namelist file and return its contents. 17 >>> with open(nml_path) as nml_file: 18 >>> nml = f90nml.read(nml_file) 22 >>> nml = f90nml.read(nml_path) 24 This function is equivalent to the ``read`` function of the ``Parser`` 27 >>> parser = f90nml.Parser() 28 >>> nml = parser.read(nml_file) 32 return parser.read(nml_path)
35 def write(nml, nml_path, force=False, sort=False):
36 """Save a namelist to disk using either a file object or its file path. 40 >>> with open(nml_path, 'w') as nml_file: 41 >>> f90nml.write(nml, nml_file) 45 >>> f90nml.write(nml, 'data.nml') 47 This function is equivalent to the ``write`` function of the ``Namelist`` 50 >>> nml.write('data.nml') 52 By default, ``write`` will not overwrite an existing file. To override 53 this, use the ``force`` flag. 55 >>> nml.write('data.nml', force=True) 57 To alphabetically sort the ``Namelist`` keys, use the ``sort`` flag. 59 >>> nml.write('data.nml', sort=True) 62 if not isinstance(nml, Namelist)
and isinstance(nml, dict):
67 nml_in.write(nml_path, force=force, sort=sort)
70 def patch(nml_path, nml_patch, out_path=None):
71 """Create a new namelist based on an input namelist and reference dict. 73 >>> f90nml.patch('data.nml', nml_patch, 'patched_data.nml') 75 This function is equivalent to the ``read`` function of the ``Parser`` 76 object with the patch output arguments. 78 >>> parser = f90nml.Parser() 79 >>> nml = parser.read('data.nml', nml_patch, 'patched_data.nml') 81 A patched namelist file will retain any formatting or comments from the 82 original namelist file. Any modified values will be formatted based on the 83 settings of the ``Namelist`` object. 87 return parser.read(nml_path, nml_patch, out_path)
def patch(nml_path, nml_patch, out_path=None)
def write(nml, nml_path, force=False, sort=False)