#!/bin/bash # nearest Gaia star for given RA, DEC # nsGaia [-v VERBOSITY] [-d DFS] [-g GaiaVersion] {-h} RAdeg DECdeg (or pipe) # -r initial CONERADIUS in integer arcseconds [30] # -d DFS is the field separator for output file # -v VERBOSITY, [1],2,3 # -g Gaia verson, 1,2,[E] # 1 February 2021 #----------------------------------------------------------------------- RADIUS=30; DFS="\t"; VERBOSITY=1; GaiaVersion="E" JSONFILE="nsGaia.json" #----------------------------------------------------------------------- TF="OUT_nsGaia" TFt=${TF}".tmp" TFj=${TF}".json" TFd=${TF}.dat #----------------------------------------------------------------------- :> $TFt; :> $TFj; :> $TFd echo "nada">$TFt #trap "rm $TFt" EXIT #----------------------------------------------------------------------- while getopts r:d:v:g:h optval do case $optval in r) RADIUS=$OPTARG;; d) DFS=$OPTARG;; v) VERBOSITY=$OPTARG;; g) GaiaVersion=$OPTARG;; h) HELP=1;; *) echo "nsGaia -h for help"; exit -1 esac done shift $((OPTIND-1)) if [ $HELP ]; then echo "nsGaia [-r RADIUS][-d DFS] [-v VERBOSITY] [-g GaiaV] {-h} RAd DECd ..| pipe" echo "-r radius of cone search in arcseconds [30]" echo '-d DFS, the field separator for output ["\t"]' echo "-v VERBOSITY, [1],2,3 for increasing columns" echo "-g GaiaVersion, 1 for DR1 ,2,[E] for EDR3" exit fi #----------------------------------------------------------------------- #input from pipe? if so, convert to positional parameters #----------------------------------------------------------------------- if [ $# -eq 0 ]; then if [ -p /dev/stdin ]; then PIPE=$(cat -) set -- $PIPE else echo "mergeGaia: no inputs from pipe or command line"; exit -1 fi fi if [ $# -lt 2 ]; then echo "csGia: need a minimum pair of RA, DEC" exit -1 fi RA=$1; DEC=$2;shift 2 while grep "^nada" $TFt > /dev/null do csGaia -r $RADIUS -d $DFS -v $VERBOSITY -g $GaiaVersion $RA $DEC > $TFt RADIUS=$((2*RADIUS)) done RADIUS=$((RADIUS/2)) head -2 $TFt | dlm2json > $JSONFILE #number of objects (recall, first line is header) nobj=$(wc -l <$TFt) nobj=$((nobj-1)) #printf "RADIUS %d arcsec; number of objects %d\n" $RADIUS $nobj awk -F"$DFS" -v RA=$RA -v DEC=$DEC \ 'BEGIN{pi=3.141592653589793} NR==2 {ra=$3; dec=$4 dra=(ra-RA)*cos(dec*pi/180)*3600; ddec=(dec-DEC)*3600 theta=sqrt(dra*dra+ddec*ddec) printf ("%0.7f %0.7f %0.1f\"\n", ra,dec, theta)}' $TFt