https://github.com/syrte/fortio
A Python IO for Fortran Unformatted Binary File with Variable-Length Records.
https://github.com/syrte/fortio
binary-data fortran io python
Last synced: 3 months ago
JSON representation
A Python IO for Fortran Unformatted Binary File with Variable-Length Records.
- Host: GitHub
- URL: https://github.com/syrte/fortio
- Owner: syrte
- License: gpl-2.0
- Created: 2015-01-10T15:58:40.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-02-12T15:31:15.000Z (almost 5 years ago)
- Last Synced: 2025-06-29T09:06:33.481Z (5 months ago)
- Topics: binary-data, fortran, io, python
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fortio
A Python IO for Fortran Unformatted Binary Files with Variable-Length Records.
## Features
- read and write Fortran unformatted file
- auto-detect endianness(byteorder)
- allow reading data into pre-allocated buffers
- allow skipping over records or jumping to wanted record directly without reading data
- support subrecords (which is necessary for long record whose size larger than
4GB with signed 4 bytes integer header)
- support numpy.memmap array for fast loading
## Installation
```bash
pip install fortio
```
## Usage
```
from fortio import FortranFile
with FortranFile(filename) as f:
a = f.read_record('i4')
f.skip_record()
b = f.read_record('f8')
```
Read file that contains subrecords (e.g., records greater than 4GB) by setting signed header,
```
with FortranFile(filename, header_dtype='int32') as f:
...
```
Please read the docstring of `FortranFile` for detailed documentation.
## Functions
- FortranFile(filename, mode='r', header_dtype='uint32',
auto_endian=True, check_file=True)
- methods
* write_record(data)
* read_record(dtype='byte', shape=None, rec=None, memmap=False)
* mmap_record(dtype='byte', shape=None, rec=None)
* read_record_into(into, offset=None, rec=None)
* get_record_size(rec=None)
* skip_record(nrec=1)
* goto_record(rec=None)
* close()
* flush()
- properties
* file
* filesize
* mode
* header_dtype
* long_records
* closed
* byteorder
- internal properties and methods
* _fp
* _offsets
* _lengths
* _read_header()
* _check_byteorder()
* _check_file()
* _read_record_data(data)