GXBF class¶
-
class
GXBF
(handle=0)¶ GXBF class.
The
GXBF
class is used to access (or create) Binary files and remove (or destroy) files from use. You can also perform a variety of additional tasks, such as positioning within files, reading from files and writing to files.-
ch_size
(size)¶ Changes the size of a file
Parameters: size (int) – New length in bytes New in version 5.0.
License: Geosoft Open License
-
copy
(b_fw)¶ Copy entire contents of a source
GXBF
to a destinationGXBF
Parameters: b_fw (GXBF) – Destination GXBF
New in version 5.0.
License: Geosoft Open License
-
crc
(size, crc)¶ Compute CRC of a file.
Parameters: - size (int) – Number of bytes to CRC
- crc (int) – CRC start (use
CRC_INIT_VALUE
for new)
Returns: CRC Value
Return type: int
New in version 5.0.
License: Geosoft Open License
-
classmethod
create
(file, status)¶ Create
GXBF
object.Parameters: - file (str) – File name to open (“” is a temporary file)
- status (int) – BF_OPEN_MODE constants
Returns: GXBF
ObjectReturn type: New in version 5.0.
License: Geosoft Open License
Note: Run-time specific directory paths may be added the the front of file names as follows:
<geosoft> the main Geosoft installation directory <geosoft2> the secondary Geosoft installation directory <geotemp> the Geosoft temporary file directory <windows> the operating system Windows directory <system> the operating system system directory <other> other environment variables
For example “<geosoft>/user/csv/datum.csv”
-
classmethod
create_sbf
(sbf, file, status)¶ Create
GXBF
object inside anGXSBF
.Parameters: - sbf (GXSBF) – Storage
- file (str) – File name to open (“” is a temporary file)
- status (int) – BF_OPEN_MODE constants
Returns: GXBF
ObjectReturn type: New in version 5.0.
License: Geosoft Open License
Note: see sbf.gxh
-
eof
()¶ Returns 1 if at the end of the file
Returns: 1 if at the end of the file, 0 if not at the end of the file Return type: int New in version 5.0.
License: Geosoft Open License
-
is_null
()¶ Check if this is a null (undefined) instance
Returns: True if this is a null (undefined) instance, False otherwise. Return type: bool
-
query_write
()¶ Check if you can write to the
GXBF
.Returns: 0 - No 1 - Yes Return type: int New in version 5.1.1.
License: Geosoft Open License
-
read_binary_string
(bytes, encoding, data)¶ Reads string data from current position in
GXBF
Parameters: - bytes (int) – Number of bytes to read
- encoding (int) – BF_ENCODE constants
- data (str_ref) – Data
New in version 6.3.
License: Geosoft Open License
-
read_double
(type, data)¶ Reads real data from current position in
GXBF
Parameters: - type (int) – GS_TYPES constants and BF_BYTEORDER constants
- data (float_ref) – Data
New in version 5.0.
License: Geosoft Open License
Note: If the data source may be in byte order different from that required by the reader, you can add the source byte-order to the
GXBF
elelment type. The byte order will be swapped if required. For example, to write out a real number 3.5 with Most-Significant_Byte first (Mortorola) convention:write_double
,3.5).If a byte order is not specified, the source is assumed to be in the native byte order of the reading/writing computer.
-
read_int
(type, data)¶ Reads int data from current position in
GXBF
Parameters: - type (int) – GS_TYPES constants and BF_BYTEORDER constants
- data (int_ref) – Data
New in version 5.0.
License: Geosoft Open License
Note: If the data source may be in byte order different from that required by the reader, you can add the source byte-order to the
GXBF
elelment type. The byte order will be swapped if required. For example, to write out a real number 3.5 with Most-Significant_Byte first (Mortorola) convention:write_double
,3.5).If a byte order is not specified, the source is assumed to be in the native byte order of the reading/writing computer.
-
read_vv
(type, vv)¶ Read data to a
GXVV
from current position inGXBF
Parameters: - type (int) – GS_TYPES constants and BF_BYTEORDER constants
- vv (GXVV) –
GXVV
data to read,GXVV
length is read
New in version 5.0.
License: Geosoft Open License
Note: If the data source may be in byte order different from that required by the reader, you can add the source byte-order to the
GXBF
elelment type. The byte order will be swapped if required. For example, to write out a real number 3.5 with Most-Significant_Byte first (Mortorola) convention:write_double
,3.5).If a byte order is not specified, the source is assumed to be in the native byte order of the reading/writing computer.
-
seek
(offset, ref)¶ Moves file position
Parameters: - offset (int) – Number of bytes from reference point
- ref (int) – BF_SEEK constants
New in version 5.0.
License: Geosoft Open License
Note: Terminates if attempt to move past the end of a read-only file.
-
set_destroy_status
(status)¶ Set the flag to delete the file on close
Parameters: status (int) – BF_CLOSE constants New in version 6.0.
License: Geosoft Open License
-
size
()¶ Returns the file length
Returns: File size in bytes. Return type: int New in version 5.0.
License: Geosoft Open License
-
tell
()¶ Returns current position of file pointer in bytes
Returns: Current file pointer location Return type: int New in version 5.0.
License: Geosoft Open License
-
write_binary_string
(encoding, data)¶ Write a binary string to a
GXBF
Parameters: - encoding (int) – BF_ENCODE constants
- data (str) – String to write out
New in version 6.3.
License: Geosoft Open License
-
write_data_null
()¶ Writes a null byte (0) to
GXBF
New in version 5.0.
License: Geosoft Open License
-
write_double
(type, data)¶ Writes real to the
GXBF
Parameters: - type (int) – GS_TYPES constants and BF_BYTEORDER constants
- data (float) – Data
New in version 5.0.
License: Geosoft Open License
Note: See comments on byte order for the Read.. functions if you want to enforce a certain byte order.
If a byte order is not specified, the data is written in the native byte order of the writing computer.
-
write_int
(type, data)¶ Writes int to the
GXBF
Parameters: - type (int) – GS_TYPES constants and BF_BYTEORDER constants
- data (int) – Data
New in version 5.0.
License: Geosoft Open License
Note: See comments on byte order for the Read.. functions if you want to enforce a certain byte order.
If a byte order is not specified, the data is written in the native byte order of the writing computer.
-
write_vv
(type, vv)¶ -
Parameters: - type (int) – GS_TYPES constants and BF_BYTEORDER constants
- vv (GXVV) – Data
New in version 5.0.
License: Geosoft Open License
Note: See comments on byte order for the Read.. functions if you want to enforce a certain byte order.
If a byte order is not specified, the data is written in the native byte order of the writing computer.
-
BF_BYTEORDER constants¶
Byte order for read/write
-
BF_BYTEORDER_LSB
¶ Least significant byte first (Intel, Windows)
-
gxapi.
BF_BYTEORDER_LSB
= 256
-
-
BF_BYTEORDER_MSB
¶ Most significant byte first (Mororola, Sun)
-
gxapi.
BF_BYTEORDER_MSB
= 512
-
BF_CLOSE constants¶
Close Flags
-
BF_KEEP
¶ Bf keep
-
gxapi.
BF_KEEP
= 0
-
-
BF_DELETE
¶ Bf delete
-
gxapi.
BF_DELETE
= 1
-
BF_ENCODE constants¶
The way a string is encoded
-
BF_ENCODE_ANSI
¶ String is stored as ANSI code page
-
gxapi.
BF_ENCODE_ANSI
= 0
-
-
BF_ENCODE_UTF8
¶ String is stored as UTF8 constants
-
gxapi.
BF_ENCODE_UTF8
= 1
-
BF_OPEN_MODE constants¶
Open Status
-
BF_READ
¶ Read only
-
gxapi.
BF_READ
= 0
-
-
BF_READWRITE_NEW
¶ Erases existing file
-
gxapi.
BF_READWRITE_NEW
= 1
-
-
BF_READWRITE_OLD
¶ File must pre-exist
-
gxapi.
BF_READWRITE_OLD
= 2
-
-
BF_READWRITE_APP
¶ Open and append onto pre-existing file (cannot be read from)
-
gxapi.
BF_READWRITE_APP
= 4
-