- FortranFile.read_record(*dtypes, **kwargs)¶
Reads a record of a given type from the file.
- *dtypesdtypes, optional
Data type(s) specifying the size and endiness of the data.
A 1-D array object.
To signal that no further records are available
To signal that the end of the file was encountered part-way through a record
If the record contains a multidimensional array, you can specify the size in the dtype. For example:
can be read with:
Note that this function does not assume the file data is in Fortran column major order, so you need to (i) swap the order of dimensions when reading and (ii) transpose the resulting array.
Alternatively, you can read the data as a 1-D array and handle the ordering yourself. For example:
read_record('i4').reshape(5, 4, order='F')
For records that contain several variables or mixed types (as opposed to single scalar or array types), give them as separate arguments:
double precision :: a integer :: b write(1) a, b record = f.read_record('<f4', '<i4') a = record # first number b = record # second number
and if any of the variables are arrays, the shape can be specified as the third item in the relevant dtype:
double precision :: a integer :: b(3,4) write(1) a, b record = f.read_record('<f4', np.dtype(('<i4', (4, 3)))) a = record b = record.T
NumPy also supports a short syntax for this kind of type:
record = f.read_record('<f4', '(3,3)<i4')