Table Look-up Expressions

Two additional table manipulation functions—findrow and tablelookup— are available for reading data from CSV files.

These functions are not shown on the Operators tabs of the Math Expression Builders.

Function

Description

findrow

(tablename,fieldname,match)

Returns the row number in the table where a specified field matches a given value.

Rows are indexed starting at 0.

tablelookup

(tablename,fieldname,row)

Retrieves a value from a specific field and row in the table.

Application Notes

When using the table look-up expressions, the "tables" are identified by name. For demonstration, consider the table named datum.csv.

Here are the first six lines of the file:

Datum,Code,ESRI,MapInfo,Area_of_use,Geoid,Ellipsoid,Prime_meridian,Datum_trf

*Airy 1830,4001,D_Airy_1830,0,Ellipsoid,,Airy 1830,0,

*Airy Modified 1849,4002,D_Airy_Modified,0,Ellipsoid,,Airy Modified 1849,0,

*AMMP/SAMMP grid,,,0,"Africa,South America",,*AMMP/SAMMP,0,

*Australian National Spheroid,4003,,0,Ellipsoid,,Australian National Spheroid,0,

*Authalic Sphere,4035,,0,Ellipsoid,,Sphere,0,

The first row contains the column headers.

Table Look-up Examples

Using findrow

     findrow (“datum”, “Code”, “4003”) returns 3 (match at row 3)

     findrow (“datum”, “Datum”, “AMMP/SAMMP grid”) returns 2 (match at row 2)

     findrow (“datum”, “Datum”, “COOL”) returns DUMMY (value not found)

Using tablelookup

      tablelookup (“datum”, “Code”, 0) returns 4001

      tablelookup (“datum”, “Code”,10000) returns DUMMY (beyond table range)

      tablelookup (“datum”, “Code,” 2) returns DUMMY (no valid data at that location)

Using both together

Most of the time, tablelookup and findrow are used together—for example, to translate a Datum name to its Code:

     projcode = tablelookup (“datum”, “Code”, findrow(“datum”, “Datum”, projchan));

For more details on table and channel look-ups, see the LOOKUP1 GX, LOOKUP2 GX, and LOOKUPDBCH GX help topics.