file_obj_bin


Synopsis


file_obj_bin (file, offset, type [,stride])

Description

file_obj_bin reads a binary array or binary scalar from the file object. It starts reading data at the offset position which is specified in bytes. file_obj_bin reads a number of bytes corresponding to the type value and dimensionality of the referencing object. It reports an error if it reaches the end of file before the target object is filled.

Note: file_obj_bin does not perform byte-swapping necessary to read binary files created on foreign platforms that use incompatible binary data formats.

Parameters

file

An object that identifies the file that will be accessed.

offset

Specifies, in bytes, an offset from the beginning of the file.

type

An integer that specifies the type of data. Acceptable values include:

 

 

 

 

0

Byte

1

Character

2

Short

3

Integer

4

Float

5

Double

 

stride

An optional integer value that specifies how many "strides" must be taken to get to the next data value. It is relevant only for binary files, if is omitted, 1 assumed.

Example 1

A binary file, myData, has an array of integers. The example below demonstrates how to read the third integer:


file data_file {
name = "myData";
};
int value => file_obj_bin (data_file, 8, 3);

Note that the offset is calculated in bytes. A value of 8 indicates that the first two integers in the file are ignored.

Example 2

The binary file, myData, contains an array of integers. The example below demonstrates how to read 100 integers, starting from position 200 in the file.


file data_file {
name = "myData";
};
int values[100] =>file_obj_bin (data_file,200,3);