#!/bin/sh # ##1 radecbox - Search an starbase data table catalog for targets in an ra dec specified box. # # radecbox file ra dec width # ##1 radeccirc - Search an starbase data table catalog for targets in an ra dec specified circle. # # radeccirc file ra dec radius # #= radecbox radeccirc # PARAMETERS # *file Input catalog to search, this file must have ra and dec columns. # If the search parameter not set to "row" the input file must be # be a real file (not a pipe) and be numericly indexed on the ra # column. The ra column should be in units # of hours and the dec column should be in units of degrees. # *ra Right Ascension of the center of the search box in hours. # *dec Declination of the center of the search box in degrees. #= radecbox # *width Width of the search box in degrees. # *height Height of the search box in hours. This parameter is optional and the # height is computed from the width for create a square box on the sky if # the height is omitted. #= radeccirc # *radius The radius of the circle to search in degrees. #= radecbox radeccirc # *rcol The column name of the ra column defaults to "ra". # *dcol The column name of the dec column defaults to "dec". # *search The search method to use. Three search methods are # implemented. The default method is "fast" # *row The search is done sequentially with a single "row" command. # *fast The an initial search command is executed for the range of # ras. The ra column of the input file must be indexed. The # results of this search are passed to row and filtered on the # dec range. This method is excellent when retrieving a small # number of rows (<1000) from large datasets. # *debug Control debug output. The default is debug=0. When debug=1 # the commands that will be executec are printed out on the # standard error instead. When debug=2 the commands are printed # and executed. # # SEE ALSO #= radecbox # *<@radecbox.src@> Source text of #radecbox. # *<#@radeccirc#> Search an starbase data table catalog for targets in an ra dec specified circle. #= radeccirc # *<@radecbox.src@> Source text of #radeccirc. # *<#@radecbox#> Search an starbase data table catalog for targets in an ra dec specified box. #= radecbox radeccirc # *<#@slalink.1#> programs available with the slalink extensions to tawk. # *<#@starbase.1#> starbase data tables introduction. # *<#@tablefun.3#> starbase data table included functions. # if [ $# -lt 4 ] ; then echo "usage: radecbox file ra dec width [rcol dcol search debug]" echo exit 1 fi export TABLEFUNCTIONS TABLEFUNCTIONS="" # Here the first parameter must always be given as a positional. # so that the shell can get to it and provide it as the stdin # to table # File="$1" if [ "$1" = "-" ] ; then File="" Optn="-p" else File="$1" Optn="-H $File" if [ ! -f "$1" ] ; then echo "radecbox: can't access $1" echo exit 1 fi fi table $Optn ' BEGIN { rcol = "ra" dcol = "dec" search = "fast" debug = 0 # ARGV[1] is an accessible file or "-" # save the file name and then add it to ARGV after processing # the parameters so that the file is opened as the stdin. # fx = ARGV[1] paramcheck("radecbox", "file|ra|dec|width|rcol|dcol|search|raduis|height|debug|program") if ( fx != "-" ) ARGV[ARGC++] = fx Init=0 } !Init { sub("(/[^/]*)*/", "", program) paramrange(program, "ra" , "n", ra, 0, 24) paramrange(program, "dec" , "n", dec, 0, 360) # Handle width, height and radius explicitly # if ( program == "radecbox" ) { if ( width == "" ) { print program ": width not set." > "/dev/stderr"; exit(1); } if ( raduis != "" ) { print program ": no parameter: raduis" > "/dev/stderr"; exit(1); } if ( height != "" ) paramrange(program, "height", "n", height, 0, 24) } if ( program == "radeccirc" ) { if ( height != "" ) { print program ": no parameter: height" > "/dev/stderr"; exit(1); } if ( raduis != "" ) width = raduis * 2 else if ( width != "" ) raduis = width / 2 if ( raduis == "" ) { print program ": raduis not set." > "/dev/stderr"; exit(1); } } paramrange(program, "search", "s", search, "row|fast") if ( file == "-" ) search = "row" if ( !(_rcol = table_colnum(rcol)) ) { printf("%s: no column %s in file: %s\n", program, rcol, file) > "/dev/stderr" exit(1) } if ( !(_dcol = table_colnum(dcol)) ) { printf("%s: no column %s in file: %s\n", program, dcol, file) > "/dev/stderr" exit(1) } if ( program == "radeccirc" ) circle = 1 if ( search == "row" ) { [ r1, r2, d1, d2 ] = radecbox(ra, dec, width, height) if ( file != "-" ) system("header <" file) Init = 1 } else { if ( circle ) search = "search " file " -S2 " rcol " " dcol " " width else { if ( height == "" ) height = width width = d2h(width) search = "search " file " -S1h " rcol " " width " -S1d " dcol " " height } if ( debug ) { print search " << EOF" print "", rcol, dcol print "", "--", "--" print "", ra, dec print "EOF" } else { print rcol, dcol | search print "----", "----" | search print ra , dec | search close(search) } exit(0) } } # We come down here if the table to search is on the stdin. # $_dcol >= d1 && $_dcol <= d2 { if ( r1 < r2 ) if ( ($_rcol >= r1 && $_rcol <= r2) ) if ( !circle \ || (circle \ && sep($_rcol, $_dcol, ra, dec) < raduis ) ) print else if ( (($_rcol >= r1 && $_rcol <= 24:00:00) \ || ($_rcol >= 00:00:00 && $_rcol <= r2)) ) if ( !circle \ || (circle \ && sep($_rcol, $_dcol, ra, dec) < raduis ) ) print } include(../tablefun/paramcheck) include(../tablefun/paramrange) include(../tablefun/table_colnum) include(../tablefun/radecbox) ' $* program=$0