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

10.8 Examples

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

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 degrees
   hmsToDegrees(RA1950)
   dmsToDegrees(decDeg,decMin,decSec)
Conversion from degrees to sexagesimal
   degreesToDms($3)
   degreesToHms(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]
Converting spectral type to numeric value (e.g. "L3.5" -> 23.5, "M7" -> 17)
   "MLT".indexOf(spType.charAt(0)) * 10 + parseDouble(substring(spType,1)) + 10
Note this uses a couple of Java String instance methods (Section 10.9.2) which are not explicitly documented in this section.
Here are some examples of boolean expressions that could be used for row selection (appearing in a tpipe select command)
Within a numeric range
   RA > 100 && RA < 120 && Dec > 75 && Dec < 85
Within a circle
   $2*$2 + $3*$3 < 1
   skyDistanceDegrees(ra0,dec0,hmsToDegrees(RA),dmsToDegrees(DEC))<15./3600.
First 100 rows
   index <= 100
(though you could use tpipe cmd='head 100' instead)
Every tenth row
   index % 10 == 0
(though you could use tpipe cmd='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: VO

STILTS - Starlink Tables Infrastructure Library Tool Set
Starlink User Note256
STILTS web page: http://www.starlink.ac.uk/stilts/
Author email: m.b.taylor@bristol.ac.uk
Mailing list: topcat-user@jiscmail.ac.uk