GXLTB class¶
- class GXLTB(handle=0)[source]¶
GXLTB class.
An
GXLTB
object is typically created from a CSV (comma-separated values) file, and is a table of information that may be accessed by row or column. TheGXLTB
class is recommended for use with small tables produced from short lists (of the order of 1000’s or records) such as the different geographic projections and their defining parameters. Large tables, such as those required for table-lookup functions, should be accessed using theGXTB
class.Note:
An
GXLTB
ASCII table file has the following structure:/ comments key_name,col_1,col_2,col_3,etc… /field names key_1,token,token,token,etc… /data lines key_2,token,token,token,etc… etc…
The first column must be the key column (all entries unique).
The header line is optional and can be used to find entries.
Comment and empty lines are ignored.
- add_record(key, rec)[source]¶
Add a new record.
- Parameters:
key (str) – Key name
rec (int_ref) – Returned record number
New in version 5.0.
License: Geosoft Open License
Note: If the record exists, the existing record is cleared and the record number is returned.
- contract(lt_bc)[source]¶
Contract the contents of two same-key and same-fields tables.
- Parameters:
- Returns:
x - Handle to
GXLTB
object NULL - Error of some kind- Return type:
New in version 5.1.
License: Geosoft Open License
Note: The “Key” of the child must be the same as the “Key” of the Master. The fields of two
GXLTB
must be the same.Contracting takes place as follows:
- classmethod create(file, type, delim, key)[source]¶
Creates a
GXLTB
object from a file.- Parameters:
file (str) – File name, .csv assumed, searched locally then in GEOSOFT.
type (int) – LTB_TYPE constants
delim (int) – LTB_DELIM constants
key (str) – Key to find if only one record required, “” to read entire table.
- Returns:
x - Handle to
GXLTB
object NULL - Error of some kind- Return type:
New in version 5.0.
License: Geosoft Open License
Note: If the file has no header, field names are assumed to be “0”, “1”, etc.
- classmethod create_crypt(file, type, delim, case_sensitive, key, crypt)[source]¶
Creates a
GXLTB
object from an encrypted file.- Parameters:
file (str) – File name, .csv assumed, searched locally then in GEOSOFT.
type (int) – LTB_TYPE constants
delim (int) – LTB_DELIM constants
case_sensitive (int) – LTB_CASE constants
key (str) – Key to find if only one record required, “” to read entire table.
crypt (str) – Decryption Key SYS_CRYPT_KEY constants
- Returns:
x - Handle to
GXLTB
object NULL - Error of some kind- Return type:
New in version 6.2.
License: Geosoft Open License
Note: If the file has no header, field names are assumed to be “0”, “1”, etc.
- classmethod create_ex(file, type, delim, case_sensitive, key)[source]¶
Creates a
GXLTB
object from a file.- Parameters:
file (str) – File name, .csv assumed, searched locally then in GEOSOFT.
type (int) – LTB_TYPE constants
delim (int) – LTB_DELIM constants
case_sensitive (int) – LTB_CASE constants
key (str) – Key to find if only one record required, “” to read entire table.
- Returns:
x - Handle to
GXLTB
object NULL - Error of some kind- Return type:
New in version 6.1.
License: Geosoft Open License
Note: If the file has no header, field names are assumed to be “0”, “1”, etc.
- delete_record(rec)[source]¶
Delete a record.
- Parameters:
rec (int) – Record number to delete
New in version 5.0.
License: Geosoft Open License
Note: Record numbers after the deleted record will be reduced by 1.
- fields()[source]¶
Get number of fields.
- Returns:
Number of fields in the
GXLTB
.- Return type:
int
New in version 5.0.
License: Geosoft Open License
- find_field(field)[source]¶
Return the field number for the specified field.
- Parameters:
field (str) – Field name
- Returns:
-1 if field does not exist. field number if field does exist.
- Return type:
int
New in version 5.0.
License: Geosoft Open License
- find_key(key)[source]¶
Return the key index of a record.
- Parameters:
key (str) – Key name
- Returns:
-1 if key does not exist. record number if key does exist.
- Return type:
int
New in version 5.0.
License: Geosoft Open License
- get_con_lst(fld, match, match_type, lst)[source]¶
Populate a
GXLST
withGXLTB
names from matching fields.- Parameters:
fld (int) – Field
match (str) – String to match to field, must be lower-case
match_type (int) – LTB_CONLST constants
lst (GXLST) – List to populate
New in version 5.0.
License: Geosoft Open License
Note: The
GXLST
object will be in the order of the file. TheGXLST
names will be theGXLTB
key fields and theGXLST
values will be theGXLTB
record numbers.
- get_double(record, field)[source]¶
Get a real entry from the
GXLTB
- Parameters:
record (int) – Record number
field (int) – Field number
- Returns:
If the record or field are out of range, an empty string or dummy value is returned.
- Return type:
float
New in version 5.0.
License: Geosoft Open License
- get_english_string(record, field, token)[source]¶
Get the English entry from the
GXLTB
- Parameters:
record (int) – Record number
field (int) – Field number
token (str_ref) – Returned field token
New in version 8.2.
License: Geosoft Open License
Note: If the record or field are out of range, an empty string or dummy value is returned.
- get_field(field_num, field)[source]¶
Get a field name by index.
- Parameters:
field_num (int) – Field number
field (str_ref) – Returned field name
New in version 5.0.
License: Geosoft Open License
Note: If the record or field are out of range, an empty string is returned.
- get_int(record, field)[source]¶
Get a int entry from the
GXLTB
- Parameters:
record (int) – Record number
field (int) – Field number
- Returns:
If the record or field are out of range, an empty string or dummy value is returned.
- Return type:
int
New in version 5.0.
License: Geosoft Open License
- get_lst(fld, lst)[source]¶
Populate an
GXLST
withGXLTB
names- Parameters:
fld (int) – Field to get, 0 for key field
lst (GXLST) – List to populate
New in version 5.0.
License: Geosoft Open License
Note: The
GXLST
object will be in the order of the file. TheGXLST
names will be theGXLTB
fields and theGXLST
values will be theGXLTB
record numbers.
- get_lst2(fld_n, fld_v, lst)[source]¶
Populate an
GXLST
withGXLTB
names and values- Parameters:
fld_n (int) – Field for names, 0 for key field
fld_v (int) – Field for values, 0 for key field
lst (GXLST) – List to populate
New in version 5.0.
License: Geosoft Open License
Note: The
GXLST
object will be in the order of the file. TheGXLST
names will come from theGXLTB
name field and theGXLST
values will come from value field specified.
- get_string(record, field, token)[source]¶
Get an entry from the
GXLTB
- Parameters:
record (int) – Record number
field (int) – Field number
token (str_ref) – Returned field token
New in version 5.0.
License: Geosoft Open License
Note: If the record or field are out of range, an empty string or dummy value is returned.
- is_null()[source]¶
Check if this is a null (undefined) instance
- Returns:
True if this is a null (undefined) instance, False otherwise.
- Return type:
bool
- merge(lt_bc)[source]¶
Merge the contents of two same-key tables.
- Parameters:
- Returns:
x - Handle to
GXLTB
object NULL - Error of some kind- Return type:
New in version 5.0.
License: Geosoft Open License
Note: Merging takes place as follows:
The “Key” of the child must be the same as the “Key” of the Master.
The fields of the Master
GXLTB
are collected in-order.Any new fields of the Child
GXLTB
are added to the end of the list.A new
GXLTB
is created to contain the new field list (in-order).The Child table contents are added to the New
GXLTB
.The Master table contents are added/replace the New
GXLTB
.The New
GXLTB
is returned.
If the fields of the Master and Child are the same, steps 4, 5, 6 are replaced by:
- records()[source]¶
Get number of records in
GXLTB
.- Returns:
Number of records in the
GXLTB
.- Return type:
int
New in version 5.0.
License: Geosoft Open License
- save(file)[source]¶
Save
GXLTB
changes to existing or new file- Parameters:
file (str) – File name, .csv assumed. If “”, save to original file.
New in version 5.0.
License: Geosoft Open License
- save_crypt(file, crypt)[source]¶
Save
GXLTB
to a new file using encryption- Parameters:
file (str) – File name, .csv assumed. If “”, save to original file.
crypt (str) – Encryption key SYS_CRYPT_KEY constants
New in version 6.2.
License: Geosoft Open License
- search(rec, fld, field)[source]¶
Search for a record containing field value
- Parameters:
rec (int) – Search start record
fld (int) – Field number
field (str) – Search string (case sensitive)
- Returns:
-1 if search failed. record number if search succeeds
- Return type:
int
New in version 5.0.
License: Geosoft Open License
- set_double(record, field, data)[source]¶
Set a double entry
- Parameters:
record (int) – Record number
field (int) – Field number
data (float) – Entry
New in version 5.0.
License: Geosoft Open License
- set_int(record, field, data)[source]¶
Set a long entry
- Parameters:
record (int) – Record number
field (int) – Field number
data (int) – Entry
New in version 5.0.
License: Geosoft Open License
- set_string(record, field, token)[source]¶
Set an entry
- Parameters:
record (int) – Record number
field (int) – Field number
token (str) – Entry
New in version 5.0.
License: Geosoft Open License
LTB_CASE constants¶
Case handling of GXLTB
strings
LTB_CONLST constants¶
Matching types
LTB_DELIM constants¶
Types of GXLTB
Delimiters
LTB_TYPE constants¶
Types of GXLTB
Headers