Attributes
- fread
fread = read
- fwrite
fwrite = write
Method summary
- __del__(self)
- __init__(self, file_name, permission = 'rb', format = 'n')
- close(self)
- fort_read(self, fmt, dtype = None)
- fort_write(self, fmt, *args)
- raw_read(self, size = -Const(1))
- raw_write(self, str)
- read(self, count, stype, rtype = None, bs = None, c_is_b = 0)
- rewind(self, howmany = None)
- seek(self, *args)
- setformat(self, format)
- size(self)
- tell(self)
- write(self, data, mtype = None, bs = None)
Methods
- __del__(self)
- __init__(self, file_name, permission = 'rb', format = 'n')
- close(self)
- fort_read(self, fmt, dtype = None)
Read a Fortran binary record.
Inputs:
- fmt -- If dtype is not given this represents a struct.pack
- format string to interpret the next record. Otherwise this argument is ignored.
- dtype -- If dtype is not None, then read in the next record as
- an array of type dtype.
Outputs: (data,)
- data -- If dtype is None, then data is a tuple containing the output
- of struct.unpack on the next Fortan record. If dtype is a datatype string, then the next record is read in as a 1-D array of type datatype.
- fort_write(self, fmt, *args)
Write a Fortran binary record. Inputs: fmt -- If a string then it represents the same format string as used by struct.pack. The remaining arguments are passed to struct.pack. If fmt is an array, then this array will be written as a Fortran record using the output type args[0]. *args -- Arguments representing data to write. - raw_read(self, size = -Const(1))
Read raw bytes from file as string.
- raw_write(self, str)
Write string to file as raw bytes.
- read(self, count, stype, rtype = None, bs = None, c_is_b = 0)
Read data from file and return it in a numpy array. Inputs: count -- an integer specifying the number of elements of type stype to read or a tuple indicating the shape of the output array. stype -- The data type of the stored data (see fwrite method). rtype -- The type of the output array. Same as stype if None. bs -- Whether or not to byteswap (or use self.bs if None) c_is_b --- If non-zero then the count is an integer specifying the total number of bytes to read (must be a multiple of the size of stype). Outputs: (output,) output -- a numpy array of type rtype. - rewind(self, howmany = None)
Rewind a file to its beginning or by a specified amount.
- seek(self, *args)
- setformat(self, format)
Set the byte-order of the file.
- size(self)
Return the size of the file.
- tell(self)
- write(self, data, mtype = None, bs = None)
Write to open file object the flattened numpy array data. Inputs: data -- the numpy array to write. mtype -- a string indicating the binary type to write. The default is the type of data. If necessary a cast is made. unsigned byte : 'B', 'uchar', 'byte' 'unsigned char', 'int8', 'integer*1' character : 'S1', 'char', 'char*1' signed char : 'b', 'schar', 'signed char' short : 'h', 'short', 'int16', 'integer*2' unsigned short : 'H', 'ushort','uint16','unsigned short' int : 'i', 'int' unsigned int : 'I', 'uint32','uint','unsigned int' int32 : 'u4', 'int32', 'integer*4' float : 'f', 'float', 'float32', 'real*4' double : 'd', 'double', 'float64', 'real*8' complex float : 'F', 'complex float', 'complex*8', 'complex64' complex double : 'D', 'complex', 'complex double', 'complex*16', 'complex128'
