idlastro / FITS ASCII & Binary Table I/O: TBPRINT

[Source code]

NAME
TBPRINT
SE:
Procedure to print specified columns & rows of a FITS binary table
CALLING SEQUENCE
TBPRINT, h, tab, columns, [ rows, TEXTOUT =, FMT=, NUM_HEADER= ]
        or
TBPRINT,tb_str, tab, columns, [ rows, TEXTOUT =, FMT=, NUM_HEADER =  ]
INPUTS
h - FITS header for table, string array
                or
tb_str - IDL structure extracted from FITS header by TBINFO, useful 
    when TBPRINT is called many times with the same header
tab - table array 
columns - string giving column names, or vector giving
        column numbers (beginning with 1).  If string 
        supplied then column names should be separated by comma's.
        If set to '*' then all columns are printed in table format 
        (1 row per line, binary tables only).
rows - (optional) vector of row numbers to print.  If
        not supplied or set to scalar, -1, then all rows
        are printed.
OUTPUTS
None
OPTIONAL INPUT KEYWORDS
FMT = Format string for print display.   If not supplied, then any 
        formats in the TDISP keyword fields of the table will be
        used, otherwise IDL default formats.   
NUM_HEADER_LINES - Number of lines to display the column headers 
        default = 1).  By setting NUM_HEADER_LINES to an integer larger
        than 1, one can avoid truncation of the column header labels.  
        In addition, setting NUM_HEADER_LINES will display commented 
        lines indicating a FORMAT for reading the data, and a 
        suggested call to  readfmt.pro.
NVAL_PER_LINE - The maximum number of values displayed from a multivalued
        column when printing in table format.   Default = 6
TEXTOUT - scalar number (0-7) or string (file name) determining
        output device (see TEXTOPEN).  Default is TEXTOUT=1, output 
        to the user's terminal    
SYSTEM VARIABLES
Uses nonstandard system variables !TEXTOUT and !TEXTOPEN
Set !TEXTOUT = 3 to direct output to a disk file.   The system
variable is overriden by the value of the keyword TEXTOUT
EXAMPLES
tab = readfits('test.fits',htab,/ext) ;Read first extension into vars
tbprint,h,tab,'STAR ID,RA,DEC'    ;print id,ra,dec for all stars
tbprint,h,tab,[2,3,4],indgen(100) ;print columns 2-4 for 
                                   first 100 stars
tbprint,h,tab,text="stars.dat"    ;Convert entire FITS table to
                                  ;an ASCII file named 'stars.dat'
PROCEDURES USED
GETTOK(), STRNUMBER(), TEXTOPEN, TEXTCLOSE, TBINFO
RESTRICTIONS
(1) Program does not check whether output length exceeds output
        device capacity (e.g. 80 or 132).
(2) Column heading may be truncated to fit in space defined by
        the FORMAT specified for the column.    Use NUM_HEADER_LINES
        to avoid truncation.
(3) Program does not check for null values
(4) Does not work with variable length columns
(5) Will only the display the first value of fields with multiple values
 (unless there is one row each with the same number of mulitple values)
 If printing in table format (column='*') then up to 6 values
 can be printed per line.
HISTORY
version 1  D. Lindler Feb. 1987
Accept undefined values of rows,columns W. Landsman  August 1997
Use new structure returned by TBINFO    W. Landsman  August 1997
Made formatting more robust    W. Landsman   March 2000
Use STRSPLIT to parse string column listing W. Landsman July 2002
Wasn't always printing last row   W. Landsman  Feb. 2003
Better formatting (space between columns) W. Landsman Oct. 2005
Use case-insensitive match with TTYPE, use STRJOIN W.L. June 2006
Fixed check for multiple values W.L. August 2006
Fixed bad index value in August 2006 fix  W.L Aug 15 2006
Free-up pointers after calling TBINFO  W.L. Mar 2007
Add table format capability  W.L. Mar 2010
Add NUM_HEADER_LINE keyword  P. Broos Apr 2010