Skip to main content

An efficient package to read fortran-record files in Python.

Project description

# Cython fortran-file

This package is a fast and easy reader for record-based binary format, as written by Fortran.

## Installation

This packages requires a compiler to be installed on you system. If you're using Linux or MacOSX you should be fine. If you're using Windows, please get in touch with me or open an issue.
pip install cython_fortran_file
That's all!

## Using it
Here is a simple demonstration:

from cython_fortran_file import FortranFile as FF

f = FF('/path/to/my/fortran/file.dat')

# Skip 5 records

# Read one record (an array of `double`)
data = f.read_vector('d')
assert data.dtype == np.float64

# Read one record (an array of signed `int`)
data = f.read_vector('i')
assert data.dtype == np.int32

# Read one *single* int. This will fail if there is more to read!
v = f.read_int()

# f _looks_ like a regular file descriptor

## Data types

The argument of `read_vector` follows the convention of the python struct package (C convention). See for the full list. Here is a shorter version:

Argument | Fortran type | C type | Numpy dtype
`d` | `real(8)` | `double` | `np.float64`
`f` | `real(4)` | `float` | `np.float32`
`i` | `integer` | `int` | `np.int32`
`l` | `integer(8)` | `long` | `np.int64`

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cython-fortran-file, version 0.0.8
Filename, size File type Python version Upload date Hashes
Filename, size cython_fortran_file-0.0.8.tar.gz (62.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page