Skip to main content

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

Project description

Cython fortran-file

Build and Test PyPI Conda-forge

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", mode="r")

# Skip 5 records
f.skip(5)

# 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
f.tell()
f.seek(0)
f.close()

It also supports with statement so that you can't forget to close the file handler

with FF("/path/to/my/fortran/file.dat") as f:
    f.skip(5)

    data = f.read_vector("d")  # Read a vector of doubles (as usual)

Data types

The argument of read_vector follows the convention of the python struct package (C convention). See https://docs.python.org/3.5/library/struct.html#format-characters 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.

Source Distribution

cython_fortran_file-0.2.7.tar.gz (104.9 kB view hashes)

Uploaded Source

Built Distributions

cython_fortran_file-0.2.7-cp312-cp312-win_amd64.whl (47.4 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

cython_fortran_file-0.2.7-cp312-cp312-win32.whl (43.3 kB view hashes)

Uploaded CPython 3.12 Windows x86

cython_fortran_file-0.2.7-cp312-cp312-musllinux_1_1_x86_64.whl (302.4 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

cython_fortran_file-0.2.7-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (303.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cython_fortran_file-0.2.7-cp312-cp312-macosx_10_9_x86_64.whl (53.8 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

cython_fortran_file-0.2.7-cp311-cp311-win_amd64.whl (47.8 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

cython_fortran_file-0.2.7-cp311-cp311-win32.whl (44.2 kB view hashes)

Uploaded CPython 3.11 Windows x86

cython_fortran_file-0.2.7-cp311-cp311-musllinux_1_1_x86_64.whl (293.7 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

cython_fortran_file-0.2.7-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (292.9 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cython_fortran_file-0.2.7-cp311-cp311-macosx_10_9_x86_64.whl (54.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

cython_fortran_file-0.2.7-cp310-cp310-win_amd64.whl (47.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

cython_fortran_file-0.2.7-cp310-cp310-win32.whl (44.4 kB view hashes)

Uploaded CPython 3.10 Windows x86

cython_fortran_file-0.2.7-cp310-cp310-musllinux_1_1_x86_64.whl (269.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

cython_fortran_file-0.2.7-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (269.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cython_fortran_file-0.2.7-cp310-cp310-macosx_10_9_x86_64.whl (54.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

cython_fortran_file-0.2.7-cp39-cp39-win_amd64.whl (47.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

cython_fortran_file-0.2.7-cp39-cp39-win32.whl (45.1 kB view hashes)

Uploaded CPython 3.9 Windows x86

cython_fortran_file-0.2.7-cp39-cp39-musllinux_1_1_x86_64.whl (272.7 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

cython_fortran_file-0.2.7-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (272.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

cython_fortran_file-0.2.7-cp39-cp39-macosx_10_9_x86_64.whl (54.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page