Contents Previous Next Subchapters

Reading Binary Files
Syntax bread
bread(
file)
bread(
dtypenbytednum)
See Also: read , xlread , bwrite

Description
If no arguments are present, the file currently open for binary reading is closed.

If one argument is present, the specified file is opened for binary input where file is a character row vector. If a file is already open for reading its is closed before file is opened.

If three arguments are present, a specified number of elements are read from the file. The character row vector dtype specifies the type of data that is being read from the file and must be either "char", "int", or "real". The integer scalar nbyte specifies the number of bytes corresponding to each data value in the file. If dtype is "char", nbyte must be 1. If dtype is "int", nbyte may be 2 or 4. If dtype is "real", nbyte may be 4 or 8. The integer scalar dnum specifies the number of data elements that are read. The return value is a double-precision column vector of length dnum containing the data. If dtype is "char", the return value can be converted to character using the char function.

Example
The function bread is linked according to the convention in linkdll . If you enter
     file  = "temp.dat"
     rmfile(file);
     write(file, "abcd")
     close(file)
     dll dll\sample.dll, bread
     bread(file)
     bread("char", 1, 4)
O-Matrix will respond
     {
     97
     98
     99
     100
     }
which are the ASCII codes of the letters a, b, c, and d respectively.