thenamelisttool.namadapter¶
Adapter classes for namelist’s parsers.
Set of adapter classes that uses external namelist’s parsers to provide functionalities that fit the needs of TNT utilities.
Module Attributes¶
- thenamelisttool.namadapter.KNOWN_NAMELIST_MACROS = {'CEXP', 'FCSTOP', 'IDAT', 'JOUR', 'LLADAJ', 'LLADMON', 'LLARO', 'LLCAN', 'LLFLAG', 'LLVRP', 'MEMBER', 'NBE', 'NBPROC', 'NBPROCIN', 'NBPROCOUT', 'NBPROC_IO', 'NCPROC', 'NDPROC', 'NMODVAL', 'NPROC', 'NRESX', 'NUMOD', 'OUTPUTID', 'PERTURB', 'RES', 'SEED', 'TIMESTEP', 'XLOPT_SCALAR', 'XMP_TYPE', 'XNCOMBFLEN', '_lbias_', '_lincr_', 'substr6', 'substrA', 'substrC', 'val_sipr', 'val_sitr'}
TNT’s predefined list of macros
- thenamelisttool.namadapter.NO_SORTING = 0
Output namelist sorting option: NO_SORTING. Keep the initial ordering.
- thenamelisttool.namadapter.FIRST_ORDER_SORTING = 1
Output namelist sorting option: FIRST_ORDER_SORTING. Sort all keys within blocks.
- thenamelisttool.namadapter.SECOND_ORDER_SORTING = 2
Output namelist sorting option: SECOND_ORDER_SORTING. Sort only between indexes.
Classes¶
- class thenamelisttool.namadapter.AbstractMapableNamelistAdapter(namelistsfile, macros=None)[source]¶
Bases:
AbstractNamelistAdapterA generic NamelistAdapter that presumes that self._parser is itself some kind of Mapping object.
- Parameters:
namelistsfile (str) – The namelist itself or a path to a namelist file.
- class thenamelisttool.namadapter.AbstractNamelistAdapter(namelistsfile, macros=None)[source]¶
Bases:
MappingEvery Namelist adapter must derive from this abstract class.
- Parameters:
namelistsfile (str) – The namelist itself or a path to a namelist file.
- add_blocks(blocks)[source]¶
Add a set of new blocks in the present namelist’s set.
- Parameters:
blocks (list[str]) – [‘BLOCK1’, ‘BLOCK2’, …]
- add_keys(keys, doctor=False, indexes=None)[source]¶
Set a set of keys in the present namelist’s set.
- Parameters:
keys (dict[tuple]) – {(‘BLOCK’,’KEY’):value, …}
doctor (bool) – if true, try to convert value to DOCTOR norm according type
indexes (dict[tuple]) – if present, set the keys at given index in block {(‘BLOCK’,’KEY’):index, …}
- check_blocks(another, macros=None)[source]¶
Check that the present namelist’s set contains the same set of blocks as another does.
another can be either the filename of a namelist to be read, or any kind of
AbstractNamelistAdapterinstance.If macros is not None, it can contain the macros a.k.a. values to be replaced, e.g.: {‘NPROC’:8, ‘substrA’:None} will replace all NPROC values by 8 and will let substrA untouched.
- Return set:
The set of blocks that differ.
- abstract dumps(sorting=0)[source]¶
Returns a string that represent the namelist’s set (i.e. something readable by Fortran !)
- Parameters:
sorting (int) – The kind of sorting to apply within blocks
- abstract merge(other)[source]¶
Merge another namelist in the current one.
- Parameters:
other (AbstractNamelistAdapter) – Another namelist to merge in.
- move_blocks(blocks)[source]¶
Move/Rename a set of blocks within the present namelist’s set.
- Parameters:
blocks (dict[str]) – {‘BLOCK_OLD’:’BLOCK_NEW’, …}
- move_keys(keys, doctor=False, keep_index=False)[source]¶
Move a set of keys within the present namelist’s set.
- Parameters:
keys (dict[tuple]) – {(‘BLOCK_OLD’,’KEY_OLD’):(‘BLOCK_NEW’,’KEY_NEW’), …}
doctor (bool) – if True, try to convert value to DOCTOR norm according type
keep_index (bool) – if True, moved keys in identical block keep the original index of key in block (except a sorting is requested later on.
- property parser¶
The internal namelist’s parser.
- remove_blocks(blocks)[source]¶
Remove a set of blocks from the present namelist’s set.
- Parameters:
blocks (list[str]) – [‘BLOCK1’, ‘BLOCK2’, …]
- class thenamelisttool.namadapter.BronxNamelistAdapter(namelistsfile, macros=None)[source]¶
Bases:
AbstractMapableNamelistAdapterA NamelistAdapter that relies on the namelist parser provided by the
bronxpackage.- Parameters:
namelistsfile (str) – The namelist itself or a path to a namelist file.
- merge(other)[source]¶
Merge another namelist in the current one.
- Parameters:
other (AbstractNamelistAdapter) – Another namelist to merge in.