1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
#!/bin/bash
function get_xpa_method()
{
cat /proc/net/tcp | tr ":" " " | tail -n +2 | \
awk -v uid=`id -u` \
'{ port=strtonum("0x" $3);
if ( $2=="00000000" && $6=="0A" && $12==uid && 32768 <= port )
printf("localhost:%d\n",port);
}' | \
head -n 1
}
TVMARK_VERSION=0.3
TVMARK_RELEASE=2018.10.01
XPASET=xpaset
METHOD=`get_xpa_method`
if ! [ -n "$METHOD" ]; then
echo "$0: unable to fetch DS9 XPA listen port autmatically." >> /dev/stderr
exit 1
fi
CX=1
CY=2
CL=0
LD=10
LF=""
WIDTH=1
RAD=4
COLOR="green"
LCOLOR="red"
IN=
IS_DELETE=
SHAPE=circle
SELF=$0
function print_error()
{
echo "${SELF}: error: $*." >/dev/stderr
}
while [ -n "$1" ] ; do
case "$1" in
-x|--col-xy)
CC=($(echo $2 | tr "," " "))
CX=${CC[0]}
CY=${CC[1]}
( test $CX -gt 0 -a $CY -gt 0 &>/dev/null ) || \
{ print_error "invalid column format: '$2'"
exit 1;
}
shift
;;
-p|--separation)
LD="$2"
( test $LD -gt 0 &>/dev/null ) || \
{ print_error "invalid label separatio: '$2'"
exit 1;
}
shift
;;
-l|--col-label)
CL=$2
( test $CL -gt 0 &>/dev/null ) || \
{ print_error "invalid label column: '$2'"
exit 1;
}
shift
;;
-f|--label)
LF="$2"
shift
;;
-r|--radius|-s|--size)
RAD=$2
#( test $RAD -gt 0 &>/dev/null ) || \
# { print_error "invalid radius or size: '$2'"
# exit 1;
# }
shift
;;
-w|--width)
WIDTH="$2"
shift
;;
-c|--color|--colour)
[ -n "$2" ] ||
{ print_error "invalid color: '$2'"
exit 1;
}
COLOR=$2
shift
;;
-a|--label-color|--label-colour)
[ -n "$2" ] ||
{ print_error "invalid color: '$2'"
exit 1;
}
LCOLOR=$2
shift
;;
-d|--delete)
IS_DELETE=1
;;
-e|--circle)
SHAPE=circle
;;
-q|--square|--box)
SHAPE=square
;;
-v|--version)
echo -e "$0 ${TVMARK_VERSION} (${TVMARK_RELEASE})"
echo -e "(c) 2007, 2013; Pal, A. <apal@szofi.net>"
exit 0
;;
-h|--help)
echo -e "Usage:\t$0 [-h|--help] [-v|--version]"
echo -e "\t[<input>]"
echo -e "\t[-x|--col-xy <column_index_x>,<column_index_y>] "
echo -e "\t[-e|--circle [-r|--radius <r>]]"
echo -e "\t[-q|--square [-s|--size <s>]]"
echo -e "\t[-w|--width <width>] [-c|--color <c>]"
echo -e "\t[-l|--col-label <column_index_label>"
echo -e "\t[-f|--label '<label_format>']"
echo -e "\t[-p|--separation <label_separation>"
echo -e "\t[-a|--label-color <c>]"
echo -e "\t[-d|--delete]"
echo -e "Notes:"
echo -e " - in the label string, \$<N> is replaced by the content of the <N>th column"
echo -e " (like in AWK)"
echo -e " - default format: --col-xy $CX,$CY --circle --color $COLOR --radius $RAD"
exit 0
;;
-*)
print_error "invalid command line argument near '$1'"
exit 1
;;
*)
[ -n "$IN" ] &&
{ print_error "input file has been specified yet"
exit 1;
}
IN=$1
;;
esac ; shift
done
( ${XPASET} -h 2>&1 > /dev/null ) >/dev/null
if test $? == 127; then
print_error "program ${XPASET} is not available, exiting"
exit 1
fi
if [ -n "$IS_DELETE" ] ; then
${XPASET} ${METHOD} regions delete all </dev/null 2>/dev/null || \
{ print_error "${XPASET} failed (maybe DS9 is not running?)"
exit 1;
}
exit 0
fi
[ -n "$IN" ] && { [ -f "$IN" ] || \
{ print_error "file '$IN' not exists"
exit 1;
}; }
if [ ! -n "$IN" -o "$IN" == "-" ] ; then
TMP=`mktemp`
cat $IN >$TMP
IN="$TMP"
else
TMP=""
fi
( echo "global color=$COLOR width=$WIDTH"
echo "image"
case $SHAPE in
square)
cat $IN | awk -v CX=$CX -v CY=$CY -v RAD=$RAD \
'!/^#/{ printf ("box(%g,%g,%g,%g)\n",$(CX)+0.5,$(CY)+0.5,RAD,RAD); }'
;;
circle|*)
cat $IN | awk -v CX=$CX -v CY=$CY -v RAD=$RAD \
'!/^#/{ printf ("circle(%g,%g,%g)\n",$(CX)+0.5,$(CY)+0.5,RAD); }'
;;
esac
if [ $CL -gt 0 ] || [ -n "$LF" ] ; then
echo "global color=$LCOLOR width=$WIDTH"
cat $IN | awk -v CX=$CX -v CY=$CY -v CL=$CL -v LF="$LF" -v RAD=$RAD -v LD="$LD" \
'!/^#/{
if ( LF != "" )
{ f=LF;
for ( i=NF ; i>=1 ; i-- )
{ r=sprintf("\\$%d",i);
gsub(r,$(i),f);
}
printf("text(%g,%g,\"%s\")\n",$(CX),$(CY)-RAD/2-LD,f);
}
else if ( CL>0 )
printf("text(%g,%g,\"%s\")\n",$(CX),$(CY)-RAD/2-LD,$(CL));
}'
fi
) | ${XPASET} ${METHOD} regions 2>/dev/null || \
{ print_error "${XPASET} failed (maybe DS9 is not running)"
exit 1;
}
test -n "$TMP" && rm -f "$TMP"
|