Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: table.putinfo - Function Up: table - Tool Previous: table.calc - Function


table.selectrows - Function



Package utility
Module table
Tool table


Make a table from a selection of rows


Synopsis
selectrows(rownrs, name)


Description
Create a (reference) table containing a given subset of rows. It is, for instance, useful when a selection is done on another table containing the row numbers in the main table. It can be useful to apply the Glish function unique to those row numbers, otherwise the same row might be included multiple times (see example).

Note that usually such referencing row numbers are 0-based, while the selectrows function expects 1-based row numbers. It means that in such cases 1 should be added (see example).

It is possible to give a name to the resulting table. If given, the resulting table is made persistent with that table name. Otherwise the table is transient and disappears when closed or when Glish exits.

The rownumbers function returns a vector containing the row number in the main table for each row in the selection table. Thus given a row number vector rownrs, the following is always true.

  rownrs == maintable.selectrows(rownrs).rownumbers()
However, it is not true when selectrows is used on a selection table. because rownumbers does not return the row number in that selection table but in the main table.
It means that one has to take great care when using selectrows on a selection table.



Arguments

rownrs in 1-based Row Numbers
    Allowed: Vector of Ints
name in Name of resulting table
    Allowed: Any String
    Default: ''


Example
#   Do the query on the main table.
  maintable := table('SOMENAME');
  scantable := maintable.query(command);
#   Get the column containing the 0-based row numbers in the BACKEND table.
#   Make the row numbers unique and make them 1-based.
  backrows := unique(scantable.getcol('NS_GBT_BACKEND_ID')) + 1;
#   Form the table subset of the BACKEND table containing those rows.
  backtable := table('SOMENAME/GBT_BACKEND');
  scanback := backtable.selectrows(backrows);
#   Do something with that table.
  print scanback.nrows();

The last statement is equivalent to the query command:

  scanback := backtable.query("rownumber() in $backrows");
However, the query takes much, much, much more time to execute, especially for larger tables and larger row number vectors. Furthermore, the backrows variable need to be global to be able to substitute it in the query command.



Returns
table tool




next up previous contents index
Next: table.putinfo - Function Up: table - Tool Previous: table.calc - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15