bundles / scipy 1.17.1 / scipy / io / _fortran / FortranFile / read_record
function
scipy.io._fortran:FortranFile.read_record
source: /scipy/io/_fortran.py :170
Signature
def read_record ( self , * dtypes , ** kwargs ) Summary
Reads a record of a given type from the file.
Parameters
*dtypes: dtypes, optionalData type(s) specifying the size and endianness of the data.
Returns
data: ndarrayA 1-D array object.
Raises
: FortranEOFErrorTo signal that no further records are available
: FortranFormattingErrorTo signal that the end of the file was encountered part-way through a record
Notes
If the record contains a multidimensional array, you can specify the size in the dtype. For example
INTEGER var(5,4)can be read with
read_record('(4,5)i4').TNote 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[0] # first number b = record[1] # 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[0] b = record[1].T
NumPy also supports a short syntax for this kind of type
record = f.read_record('<f4', '(3,3)<i4')See also
Aliases
-
scipy.io.FortranFile.read_record