HWRF
trunk@4391
|
This module provides two different ways to generate Fortran namelist files from HWRFConfig sections: More...
This module provides two different ways to generate Fortran namelist files from HWRFConfig sections:
NamelistInserter - given a file, or a multi-line string, finds angle bracket (<vartype:stuff>) strings with values from an HWRFConfig section. This is the suggested method for namelists with very few configurable items.
Conf2Namelist - given one or more Config sections, find values of the form nlsec.nlkey=value. The nlsec specifies the namelist &nlsec, the nlkey specifies the namelist variable name, and the value is converted to a Python value and then a Fortran namelist value. The Conf2Namelist provides ways to append multiple Conf2Namelist objects' data to form Fortran one-dimensional arrays. This is to support WRF namelists, where one specifies each domain's data in a 1D array.
In addition, this module provides two functions to_fortnml and from_fortnml to convert between in-memory Python objects and strings suitable for pasting in a Fortran namelist to achieve the same value in Fortran.
Classes | |
class | Conf2Namelist |
Generates a Fortran namelist entirely from config files. More... | |
class | NamelistInserter |
Insert config file data into a Fortran namelist file. More... | |
class | NamelistRecursion |
used to indicate namelist recursion More... | |
Functions | |
def | to_fortnml |
converts a Python object to fortran namelist format More... | |
def | from_fortnml (py) |
Converts a fortran namelist value to a Python object. More... | |
Variables | |
list | __all__ = ['to_fortnml','from_fortnml','Conf2Namelist','NamelistInserter'] |
Symbols exported by "from hwrf.namelist import *". | |
tuple | emptydict = dict() |
used for efficiency in a few places that need an empty dict() | |
tuple | fortnml_parse = re.compile() |
a regular expression for tokenizing a fortran namelist scalar value | |
def hwrf.namelist.from_fortnml | ( | py | ) |
Converts a fortran namelist value to a Python object.
This is the inverse function for to_fortnml. Given a string from a Fortran namelist value, returns an equivalent python object. Will throw NamelistValueError if an unrecognized object is present, or NamelistRecursion if you send a nested container (such as a list of lists).
py | the string to convert |
Definition at line 121 of file namelist.py.
def hwrf.namelist.to_fortnml | ( | py, | |
exc_hint = '' |
|||
) |
converts a Python object to fortran namelist format
Converts the given python data structure to a string suitable for representing in a Fortran namelist. It can handle bool, int, float, string, datetime, fraction and a list (or tuple) of those. A datetime is converted via strftime('"%Y-%m-%d_%H:%M:%S"'). The optional exc_hint is used when raising exceptions to give an idea of what file and line number, or config option name, generated the exception.
Conversions:
Anything else will raise an exception.
py | the object to convert |
exc_hint | prepended to exception messages when exceptions are raised. Should contain file and line information. |
Definition at line 44 of file namelist.py.
Referenced by hwrf.namelist.Conf2Namelist.make_namelist().