#!/bin/csh -f

#Informix 'dbaccess' script to subset from 
#2MASS Catalog Generation (Working) Database 
#tmasss@rmt_levi:ext_src into tmasss@rmt_levi:ext_cat

#The following conditions are to be used to select objects from the
#Spring 99 Working Extended Source DB for inclusion in the first draft
#extended source catalog.
#
#Last Update - 10 March 1999
#
#I. Magnitude limits
#
#Source has 7" radius circular aperture magnitude brighter than J<15.1 or 
#Ks<13.5 magnitudes.
#
#(j_m_7_e <= 15.1 OR k_m_7_e <= 13.5)
#
###### NOT YET:
#II. Extended and Galaxy scores
#
#These scores are contained in the ext_class_tbl in the tmasss DB.
#Also available in the ext_src/ext_class_tbl join called j_ext_class in tmasss.
#
#(e_score > 0 AND e_score <= 1.4) OR (g_score > 0 AND g_score <= 1.4)

setenv INFORMIXDIR /usr/local/informix
setenv INFORMIXSERVER rmt_levi
setenv PDQPRIORITY 100

echo 'Starting at'
date

dbaccess - - << EOF
database tmasss@rmt_levi;
INSERT INTO ext_src_01
SELECT tmass:ext_src.*
FROM tmass:ext_src, scan_dat
WHERE 
tmass:ext_src.scan_key = scan_dat.cntr
AND
(
 (j_msig_7 <= 0.155 AND j_m_7 <= 15.1) 
 OR
 (k_msig_7 <= 0.155 AND k_m_7 <= 13.5)
)
AND
(rel_num > 0)
AND
((dist_edge_ns >= 15.0) AND (dist_edge_ew >= 15.0))
;
EOF
echo 'Finished at'
date

echo 'Done'

