java -jar stilts.jar tpipe in='http://vizier.u-strasbg.fr/viz-bin/votable/-A?-source=II/246&-out.max=unlimited&verb=3&RA=127.5&DEC=+1.5&SR=0.2333333' out=2mass.xml

echo '2MASS uploaded'

java -jar stilts.jar tpipe in='http://vizier.u-strasbg.fr/viz-bin/votable/-A?-source=V/147&-out.max=unlimited&verb=3&RA=127.5&DEC=+1.5&SR=0.2333333' out=sdssdr12.xml

echo 'SDSS uploaded'

java -jar stilts.jar tskymatch2 ifmt1=votable in1=2mass.xml ifmt2=votable in2=sdssdr12.xml ra1=RAJ2000 dec1=DEJ2000 ra2=RA_ICRS dec2=DE_ICRS error=4 find=best join=1and2 ofmt=votable out=crossmatch.xml

echo 'xmatch done'

java -jar stilts.jar tpipe ifmt=votable in=crossmatch.xml cmd='select "class==6"' ofmt=votable out=filter1.xml

echo 'filter1 done'

java -jar stilts.jar tpipe ifmt=votable in=filter1.xml cmd='select " umag > 22.0 && gmag > 22.2 "' ofmt=votable out=filter2.xml

echo 'filter2 done'

java -jar stilts.jar tpipe ifmt=votable in=filter2.xml cmd='addcol Jmag-Hmag "(Jmag-Hmag)"' ofmt=votable out=addcol1.xml

echo 'first column added'

java -jar stilts.jar tpipe ifmt=votable in=addcol1.xml cmd='addcol Hmag-Kmag "(Hmag-Kmag)"' ofmt=votable out=addcol2.xml

echo 'second column added'

java -jar stilts.jar tpipe ifmt=votable in=addcol2.xml cmd='select "Jmag-Hmag < 0.3"' ofmt=votable out=filter3.xml

echo 'third filter done'

java -jar stilts.jar tpipe ifmt=votable in=filter3.xml cmd='select "Hmag-Kmag < 0.3"' ofmt=ascii out=candidates.txt

echo 'output file created'