Next Previous Up Contents
Next: Advanced Topics
Up: Algebraic Expression Syntax
Previous: Arithmetic

4.5 Examples

Here are some examples for defining new columns; the expressions below could appear as the <expr> in a tpipe -addcol or -sortexpr filter specifier.

Average
    (first + second) * 0.5
Square root
    sqrt(variance)
Angle conversion
    radiansToDegrees(DEC_radians)
    degreesToRadians(RA_degrees)
Conversion from string to number
    parseInt($12)
    parseDouble(ident)
Conversion from number to string
    toString(index)
Conversion between numeric types
     toShort(obs_type)
     toDouble(range)
or
    (short) obs_type
    (double) range
Conversion from sexagesimal to radians
    hmsToRadians(RA1950)
    dmsToRadians(decDeg,decMin,decSec)
Conversion from radians to sexagesimal
    radiansToDms($3)
    radiansToHms(RA,2)
Outlier clipping
    min(1000, max(value, 0))
Converting a magic value to null
    jmag == 9999 ? NULL : jmag
Converting a null value to a magic one
    NULL_jmag ? 9999 : jmag
Taking the third scalar element from an array-valued column
    psfCounts[2]
and here are some examples of boolean expressions that could be used for row selection (appearing in a tpipe -select filter specifier)
Within a numeric range
    RA > 100 && RA < 120 && Dec > 75 && Dec < 85
Within a circle
    $2*$2 + $3*$3 < 1
    skyDistance(ra0,dec0,degreesToRadians(RA),degreesToRadians(DEC))<15*ARC_MINUTE
First 100 rows
    index <= 100
(though you could use tpipe -head 100 instead)
Every tenth row
    index % 10 == 0
(though you could use tpipe -every 10 instead)
String equality/matching
    equals(SECTOR, "ZZ9 Plural Z Alpha")
    equalsIgnoreCase(SECTOR, "zz9 plural z alpha")
    startsWith(SECTOR, "ZZ")
    contains(ph_qual, "U")
String regular expression matching
    matches(SECTOR, "[XYZ] Alpha")
Test for non-blank value
    ! NULL_ellipticity


Next Previous Up Contents
Next: Advanced Topics
Up: Algebraic Expression Syntax
Previous: Arithmetic

STILTS - Starlink Tables Infrastructure Library Tool Set
Starlink User Note 256
STILTS web page: http://www.starlink.ac.uk/stilts/
Author email: m.b.taylor@bristol.ac.uk