next up previous contents
Next: Advanced Table Row Selection Up: CFITSIO Table Row Selection Previous: CFITSIO Table Row Selection   Contents

Basic Table Row Selection

Attributes and columns are referenced by name in the expression. Any string of characters not surrounded by quotes (i.e., a constant string) or followed by open parentheses (i.e., a function name) will be initially interpreted as a table column name and its content for the current row will be inserted into the expression before evaluation. If no such table column exists, an attribute of that name will be searched for - and its value used, if found. To force the string to be interpreted as an attribute name (in case there is both a table column and attribute with the same name), precede the attribute name with a single pound sign, '#', as in '#RA'. If the column or attribute name contains a space or a character which might appear as an arithmetic term then enclose the name in '$' characters as in $MAX-PHA$ or #$MAX-PHA$. Names are case insensitive. The following boolean operators are available:


"equal" .eq. .EQ. == "not equal" .ne. .NE. !=
"less than" .lt. .LT. < "less than/equal" .le. .LE. <= =<
"greater than" .gt. .GT. > "greater than/equal" .ge. .GE. >= =>
"or" .or. .OR. || "and" .and. .AND. &&
"negation" .not. .NOT. ! "approx. equal(1e-7)"

The expression may also include arithmetic operators and functions. Trigonometric functions use radians, not degrees. The following arithmetic operators and functions can be used in the expression (function names are case insensitive):


"addition" + "subtraction" -
"multiplication"   "division" /
"negation" - "exponentiation"   ^
"absolute value" abs(x) "cosine" cos(x)
"sine" sin(x) "tangent" tan(x)
"arc cosine" arccos(x) "arc sine" arcsin(x)
"arc tangent" arctan(x) "arc tangent" arctan2(x,y)
"exponential" exp(x) "square root" sqrt(x)
"natural log" log(x) "common log" log10(x)
"modulus" i % j "random # [0.0,1.0)" random()

Conditional arithmetic can be performed by multiplying, '*', boolean and arithmetic expressions together. If the boolean subexpression evaluates to TRUE, the larger expression has the value of the arithmetic subexpression. If the boolean is FALSE, the expression evaluates to zero. For example, equals 7 whereas equals 0. In addition, several constants are built in for use in numerical expressions:


#pi 3.1415... #e 2.7182...
#deg #pi/180 #row current row number

A string constant must be enclosed in quotes as in 'Crab'.

Table columns with vector bins (i.e., more than one data value per bin) can also be used in building the expression. No special syntax is required to operate on all data values of the bin. Simply use the table column name as for a scalar column. Vector bin columns can be freely intermixed with scalar bin columns or constants in virtually all expressions. The result will be of the same dimension as the vector. Two vector bin columns in an expression, though, need to have the same number of data values.

Arithmetic and logical operations are all performed on a data value by data value basis. Two special functions are available to operate on table columns with vector bins: SUM(x) and NELEM(x). The former literally sums all the data values belonging to the bin of column X, returning a scalar value. If X is column of DAL data type DAL_BOOL, SUM(x) returns the number of TRUE elements. The latter, NELEM(), returns the number of data values in each bin of column X (NELEM() also operates on DAL_BIT and DAL_CHAR columns, returning their column widths). As an example, to test whether all data values of a bin vector satisfy a given logical comparison, one can use the expression:

SUM( COL1 > COL2 ) == NELEM( COL1 )

which will return TRUE if all data values in the bin of table column COL1 are greater than their corresponding data values in COL2.

Note that table columns with variable length bins are not supported under the algebraic expression syntax.

Some examples of basic row filter expressions follow. All string quantities represent table column names or attribute names in the table elements to be evaluated. Remember that each of these expressions is to evaluate to either TRUE or FALSE for a given table row.


[TIME > 123456 && TIME <= 555555] - Extract all table rows where the    
  column TIME has values between    
  123456 and 555556 (exclusive)    
       
[#row >= 125 && #row <= 175] - Extract row numbers 125 through 175    
  from all tables examined    
       
[OBJECT == 'CRAB'] - Extract all table rows if the attribute    
  ``OBJECT'' has the value of ``CRAB''    
       
[abs(sin(theta * #deg)) < 0.5 ] - Extract all table rows having the    
  absolute value of the sine of THETA    
  less than 0.5 where the angles    
  are tabulated in degrees    
       
[SUM( SPEC > 3*BACKGRND) >=1] - Extract all table rows containing a    
  spectrum, held in vector column    
  SPEC, with at least one data value 3    
  times greater than the background    
  level held in the attribute BACKGRND    
       
[log(PHA) - log(PHI) > 3.75] - Extract all table rows where the    
  difference between the log of the    
  PHA and PHI column values is greater    
  than 3.75    
       
[X 36.3 && Y 05.34 && - Extract all table rows with detector    
sin(#ROTATION) < pi/2.0] X coordinates of approx. 36.3, Y    
  detector coordinates of approx. 5.34    
  and the sine of the image rotation    
  is less than 90 degrees    


next up previous contents
Next: Advanced Table Row Selection Up: CFITSIO Table Row Selection Previous: CFITSIO Table Row Selection   Contents
inthelp@sciops.esa.int