https://github.com/scivision/fortran-namelist
Python and Matlab readers for Fortran namelist => dict / struct
https://github.com/scivision/fortran-namelist
fortran namelist
Last synced: 8 months ago
JSON representation
Python and Matlab readers for Fortran namelist => dict / struct
- Host: GitHub
- URL: https://github.com/scivision/fortran-namelist
- Owner: scivision
- License: mit
- Created: 2019-09-17T15:47:40.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2021-07-08T02:47:01.000Z (over 4 years ago)
- Last Synced: 2025-04-12T08:12:33.689Z (8 months ago)
- Topics: fortran, namelist
- Language: MATLAB
- Homepage:
- Size: 22.5 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fortran Namelist Reader

Pure Python and Matlab **readers** for
[Fortran namelist](https://github.com/scivision/fortran2018-examples/tree/master/namelist)
=> dict / struct
These are as basic as possible, for putting in your own program directly.
They output dict (Python) or struct (Matlab).
Consider
[f90nml](https://github.com/marshallward/f90nml)
for a full-featured read/write Fortran namelist Python package.
## Python
```python
from read_namelist import read_namelist
print(read_namelist('example.nml', 'base'))
```
## Matlab
```octave
read_namelist('example.nml', 'base')
```
## Examples
[read.f90](./read.f90)
example shows that one must allocate arrays before reading a namelist array variable.
Character can be read with a variable (much) longer than known needed, then trim() to another allocatable character variable.
Despite what some forums say, reading namelist directly into allocatable just segfaults with Intel or GCC compilers.