#!/bin/csh -f
#+
# ampang -- compute distance + bearing between two locations on DEIMOS image
#
# Purpose:
#	Given two (x,y) pixel locations measured on a DEIMOS image,
#	compute the angular separation of the points and the angle
#	between them.
#
# Usage:
#	ampang x1 y1 x2 y2
# 
# Arguments:
#	x1 = column of first position
#	y1 = row of first position
#	x2 = column of second position
#	y2 = row of second position
# 
# Output:
#	The angular separation and angle (measured in various
#	coordinate systems) are written to stdout.
# 
# Restrictions:
# 
# Exit values:
#	0 = normal completion
#	1 = wrong number of arguments
#
# Example:
#	1) Compute the offset and direction between an object at pixel
#	(100,100) and another at (200,200):
#
#		> ampang 100 100 200 200
#		Normal coordinate system (0 deg to right, 90 deg up):
#		Amplitude = 30.2642 arcsec
#		Angle     = 45 deg
#		
#		Astronomical coordinate system (0 deg up, 90 deg to left):
#		Amplitude = 30.2642 arcsec
#		Angle     = 315 deg
#-
# Modification history:
#	Date Unknown	???	Original version
#	2000-Jul-05	GDW	Added description
#-----------------------------------------------------------------------

set buf = $0
set cmd = $buf:t
set usage = "Usage: $cmd x1 y1 x2 y2"

# verify args...
if (${#argv} != 4) then
  printf "$usage\n"
  exit 1
endif

# define constants...
set RtoD = `calc 180 / 3.1415926536`	# convert radians to degrees
set scale = 0.119			# arcsec/pixel on DEIMOS

# get variables...
set x1 = $1
set y1 = $2
set x2 = $3
set y2 = $4

# compute offsets...
set dx = `calc $x2 - $x1`
set dy = `calc $y2 - $y1`
set r = `calc "$scale * sqrt( ($dx)^2 + ($dy)^2)"`
set theta = `calc "(atan2d($dy,$dx)+360)%360"`

# output data for normal coordinate system...
echo ""
echo "Normal coordinate system (0 deg to right, 90 deg up):"
echo "Amplitude = $r arcsec"
echo "Angle     = $theta deg"

# output data for astronomical coordinate system...
set theta = `calc "($theta - 90 + 360)%360"`
echo ""
echo "Astronomical coordinate system (0 deg up, 90 deg to left):"
echo "Amplitude = $r arcsec"
echo "Angle     = $theta deg"