GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - leifdenby/namelist_python: Fortran namelist parser in Python

BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
namelist_python
namelist_python
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
setup.cfg
setup.cfg
 
 
setup.py
setup.py
 
 

Repository files navigation

Fortran namelist files in Python

Build Status

Install with pip

pip install namelist_python

Read in a namelist file:

from namelist_python import read_namelist_file
namelist = read_namelist_file('SIM_CONFIG.nl')

namelist is an instance of namelist_python.Namelist and all groups are stored in the attribute groups with each variable in a nested dictionary structure (using OrderedDict so that the order will be remembered).

Write a Namelist object back to a file:

with open('NEW_FILE.nl', 'w') as f:
	f.write(namelist.dump())

dump takes an optional argument array_inline a boolean which sets whether arrays should be inline or given in index notation.

If you use ipython there is usefull attribute called data which allows you to do tab completion on the group and variable names, and do assignment:

In [7]: namelist.data.ATHAM_SETUP.dt
namelist.data.ATHAM_SETUP.dt
namelist.data.ATHAM_SETUP.dtmax
namelist.data.ATHAM_SETUP.dtmin
In [7]: namelist.data.ATHAM_SETUP.dt
Out[7]: 3.0

In [8]: namelist.data.ATHAM_SETUP.dt = 4.0

In [9]: namelist.data.ATHAM_SETUP.dt
Out[9]: 4.0

Features

  • Parses ints, floats, booleans, escaped strings and complex numbers.
  • Parses arrays in index notation and inlined.
  • Can output in namelist format.
  • Tab-completion and variable assignment in interactive console

Missing features

  • Currently can't handle complex variable definitions across multiple lines
  • Comments are not kept, and so won't exist in output.

Contribute

Please send any namelist files that don't parse correctly or fix the code yourself and send me a pull request :)

Thanks, Leif

About

Fortran namelist parser in Python

Resources

Readme
GPL-3.0 license
Activity

Stars

18 stars

Watchers

3 watching

Forks

6 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.