Giles,

Following is the list of server commands that Hertz has access to at the 
CSO, and the server program for the VAX.  We don't use all of the commands; 
I think just: EXIT, GET_ALL, GET_ALTAZ, GET_FOCUS, GET_OFFSETS, 
GET_PAR_ANGLE, GET_POSITION, GET_ROTATOR, GET_STATUS, GET_TAU225, 
SET_FIXED_OFFSETS, SET_RADEC_OFFSETS, SET_ROTATOR, and 
SET_SWITCHING_OFFSETS.

*** Giles adds:  SPARO will not need anything to do with the
parallactic (PAR_ANGLE) angle, or the rotator (ROTATOR) *** 

Darren

**********************************************************

   When the server starts, it will send a "1" to you, to tell you that it has
properly initialized, and is ready to accept commands.    The following com-
mands have been implemented:

Command					Function

EXIT			Types "1", then shuts down the TCP/IP connection
GET_ALL			Dumps all "header" information - effectively does
			a GET_ALTAZ, GET_FOCUS, GET_LST, GET_NAME,
			GET_OFFSETS, GET_POSITION, GET_ROTATOR, GET_TAU225,
			GET_UT and GET_PAR_ANGLE all at once (in that order).
GET_ALTAZ		Returns the azimuth and elevation in degrees
GET_FOCUS		Returns secondary position; X, Y and Z in mm, and
			theta in degrees, followed by the "focusing mode"
GET_LST			Returns the LST in degrees
GET_NAME		Returns the source name
GET_OFFSETS		Returns the RA, DEC, AZ, ZA and fixed offsets in arc
			seconds
GET_PAR_ANGLE		Returns the parallactic angle, in degrees.
GET_POSITION		Returns RA and Dec (unprecessed) in degrees
GET_ROTATOR		Returns the angle of the currently active rotator,
			and returns 1000.0 if no rotator is currently
			active
GET_ROTATOR_OFFSET	Returns the offset of the currently active rotator,
			and returns 1000.0 if no rotator is currently
			active
GET_STATUS		Returns 1 if the antenna has acquired the source,
			0 otherwise
GET_TAU225		Returns the tau at 225 GHz
GET_TRACK		Returns the tracking mode (0=IDLE, 1=TRACKING)
GET_UT			Returns the UT in degrees
MOVE_WAIT		Waits until the source is acquired.   Returns "1"
			when acquired.
SET_ALTAZ x y		If x and y are within the software limits, a move is
			initiated to an azimuth of x, and an elevation of y,
			and "1" is returned.   Otherwise 0 is returned.
SET_BLADE x		A hot load is placed into the beam if x is 1, and
			removed if x is 0.
SET_DELTA_FIXED x y	Adds x to the fixed azimuth offset, and y to the
			fized zenith angle offset.   Returns "1" always.
SET_FIXED_OFFSETS x y	Sets the fixed Az offset to x and the ZA offset to y.
			Returns "1".
SET_OFFSETS w x y z	Sets the RA offset to w, the Dec offset to x, the
			azimuth offset to y, and the zenith angle offset to
			z
SET_RADEC_OFFSETS x y	Sets the RA offset to x and the Dec offset to y.  Re-
			turns "1".
SET_ROTATOR xxx		If the number xxx is within the software limits
			of the instrument rotator, the rotator will move
			to position xxx, and a "1" will be returned after
			the move is complete.   If xxx is outside the software
			limits, a "0" is returned.
SET_ROTATOR_OFFSET xxx	If the number xxx is within the software limits
			of the instrument rotator, the rotator offset will be
			set to xxx, and a "1" will be returned before
			the move is complete.   If xxx is outside the software
			limits, a "0" is returned.
SET_SWITCHING_OFFSETS x y Sets the Az offset to x and the ZA offset to y.  Re-
			turns "1".
UPDATE_ROTATOR		Tells the antenna computer to adjust the rotator to
			correct for paralactic angle rotation.   Returns 1,
			but does not wait for the move to complete (you can
			use MOVE_WAIT for that).

**********************************************************

#define DEG_PER_RAD 57.2957795131
#define SEC_PER_RAD 206264.806247
/*
 *  Example TCP server.
 *
 *  This server is an alternative ECHO server which lets the MultiNet
 *  MULTINET_SERVER process listen for it. When a connection arrives,
 *  the MULTINET_SERVER will create a process running this image which
 *  processes the connection.
 *
 *  To compile and link this server:
 *
 *    $ CC TCPECHOSERVER
 *    $ LINK TCPECHOSERVER,SYS$INPUT:/OPT
 *    MULTINET:MULTINET_SOCKET_LIBRARY/SHARE
 *    SYS$SHARE:VAXCRTL/SHARE
 *    ^Z
 *
 *  To configure the MULTINET_SERVER process to automatically create
 *  a process running this image when a connection arrives:
 *
 *    $ MULTINET CONFIGURE/SERVER
 *    MultiNet Server Configuration Utility 2.2(19)
 *    [Reading in symbols from SERVER image MULTINET:SERVER.EXE]
 *    [Reading in configuration from MULTINET:SERVICES.MASTER_SERVER]
 *    SERVER-CONFIG>ADD TEST
 *    [Adding new configuration entry for service "TEST"]
 *    Protocol: [TCP] TCP
 *    TCP Port number: 500
 *    Program to run: USERS:[ADELMAN]TCPECHOSERVER.EXE
 *    [Added service TEST to configuration]
 *    [Selected service is now TEST]
 *    SERVER-CONFIG>RESTART
 *
 */

#include 
#include 
#include 
#include descrip
#include "multinet_root:[multinet.include.sys]types.h"
#include "multinet_root:[multinet.include.sys]socket.h"
#include "multinet_root:[multinet.include.netinet]in.h"
#include 
#include 
#include 
#include "multinet_root:[multinet.include]netdb.h"

#define True 1
#define False 0

unsigned short s;
int ant_first_call = True;
int lksb[2];
short int from_chan, to_chan;
char *resource_name = "ANT";
char *from_name = "FROM_ANT";
char *to_name = "TO_ANT";
char new_name[8];
struct dsc$descriptor_s resource_desc, from_desc, to_desc;

void init_ant()
{
    int errcode;

errcode = sys$enqw(		0,		/* any old event flag	      */
				LCK$K_NLMODE,   /* Just a null lock, for now  */
				&lksb,          /* Status block - a keepsake  */
				LCK$M_SYSTEM,   /* It's a sytem-wide lock     */
				&resource_desc, /* Name of resource           */
				0,              /* No parent lock             */
				0,              /* No AST routine             */
				0,              /* or AST parameters          */
				0,              /* No blocking AST            */
				0,              /* default access mode        */
				0);             /* Place holder               */
if (errcode != 1)
    printf("Error %d returned from initial ENQW\n", errcode);
errcode = SYS$ASSIGN(		&from_desc,
				&from_chan,
				0,
				0);
if (errcode != 1)
    printf("Error %d returned from initial ASSIGN (1)\n", errcode);
errcode = SYS$ASSIGN(		&to_desc,
				&to_chan,
				0,
				0);
if (errcode != 1)
    printf("Error %d returned from initial ASSIGN (2)\n", errcode);
ant_first_call = False;
}

void lock_antenna()
{
int errcode;

errcode = sys$enqw(		0,		/* any old event flag	      */
				LCK$K_EXMODE,   /* Just a null lock, for now  */
				&lksb,          /* Status block - a keepsake  */
		LCK$M_SYSTEM | LCK$M_CONVERT,   /* It's a sytem-wide lock     */
				&resource_desc, /* Name of resource           */
				0,              /* No parent lock             */
				0,              /* No AST routine             */
				0,              /* or AST parameters          */
				0,              /* No blocking AST            */
				0,              /* default access mode        */
				0);             /* Place holder               */
if (errcode != 1)
    printf("Error %d returned from initial ENQW\n", errcode);
}

void unlock_antenna()
{
int errcode;

errcode = sys$enqw(		0,		/* any old event flag	      */
				LCK$K_NLMODE,   /* Just a null lock, for now  */
				&lksb,          /* Status block - a keepsake  */
		LCK$M_SYSTEM | LCK$M_CONVERT,   /* It's a sytem-wide lock     */
				&resource_desc, /* Name of resource           */
				0,              /* No parent lock             */
				0,              /* No AST routine             */
				0,              /* or AST parameters          */
				0,              /* No blocking AST            */
				0,              /* default access mode        */
				0);             /* Place holder               */
if (errcode != 1)
    printf("Error %d returned from final ENQW\n", errcode);
}

int get_int_from_antenna(char *prompt)
{
int errcode;
int temp_int = 0;
int done = False;
char responce[132];
char message[132];
int responce_length;
short int iosb[4];
int write_func = IO$_WRITEVBLK;
int read_func = IO$_READVBLK;

if ( ant_first_call )
    init_ant();
lock_antenna();
/* sprintf(message,"Prompt = \"%s\", len = %d\r", prompt, strlen(prompt));
socket_write(s, message, strlen(message)); */

errcode = sys$qiow(		0,		/* Who cares what event flag? */
				to_chan,
				write_func,
				iosb,
				0, 0,		/* No AST stuff		      */
				prompt,
				strlen(prompt),
				0, 0, 0, 0);

if (errcode != 1)
    printf("Error %d returned from QIO (1)\n", errcode);

while ( !done ) {
    responce_length = 132;
    errcode = sys$qiow(		0,		/* Who cares what event flag? */
				from_chan,
				read_func,
				&iosb,
				0, 0,
				responce,
				responce_length,
				0, 0, 0, 0);
    responce_length = iosb[1];
/*    sprintf(message, "length = %d\r", responce_length);
    socket_write(s, message, strlen(message));
    sprintf(message,"iosb = %d, %d, %d, %d\r",
	iosb[0], iosb[1], iosb[2], iosb[3]);
    socket_write(s, message, strlen(message)); */
    if (errcode != 1) {
	printf("Error %d returned from QIO (2)\n", errcode);
	done = True;
    }
    responce[responce_length] = 0;
/*    sprintf(message, "Got \"%s\" from antenna\r", responce);
    socket_write(s, message, strlen(message)); */
    if (iosb[0] == SS$_ENDOFFILE)
	done = True;
    else
	sscanf(responce,"%d", &temp_int);
}
/* sprintf(message, "Exiting loop\r");
socket_write(s, message, strlen(message)); */
unlock_antenna();
return(temp_int);
}

double get_double_from_antenna(char *prompt)
{
int errcode;
double temp_double = 0.0;
int done = False;
char responce[132];
char message[132];
int responce_length;
short int iosb[4];
int write_func = IO$_WRITEVBLK;
int read_func = IO$_READVBLK;

if ( ant_first_call )
    init_ant();
lock_antenna();
/* sprintf(message,"Prompt = \"%s\", len = %d\r", prompt, strlen(prompt));
socket_write(s, message, strlen(message)); */

errcode = sys$qiow(		0,		/* Who cares what event flag? */
				to_chan,
				write_func,
				iosb,
				0, 0,		/* No AST stuff		      */
				prompt,
				strlen(prompt),
				0, 0, 0, 0);

if (errcode != 1)
    printf("Error %d returned from QIO (1)\n", errcode);

while ( !done ) {
    responce_length = 132;
    errcode = sys$qiow(		0,		/* Who cares what event flag? */
				from_chan,
				read_func,
				&iosb,
				0, 0,
				responce,
				responce_length,
				0, 0, 0, 0);
    responce_length = iosb[1];
/*    sprintf(message, "length = %d\r", responce_length);
    socket_write(s, message, strlen(message));
    sprintf(message,"iosb = %d, %d, %d, %d\r",
	iosb[0], iosb[1], iosb[2], iosb[3]);
    socket_write(s, message, strlen(message)); */
    if (errcode != 1) {
	printf("Error %d returned from QIO (2)\n", errcode);
	done = True;
    }
    responce[responce_length] = 0;
/*    sprintf(message, "Got \"%s\" from antenna\r", responce);
    socket_write(s, message, strlen(message)); */
    if (iosb[0] == SS$_ENDOFFILE)
	done = True;
    else
	sscanf(responce,"%f", &temp_double);
}
/* sprintf(message, "Exiting loop\r");
socket_write(s, message, strlen(message)); */
unlock_antenna();
/* sprintf(message, "Returning %f\r", temp_double);
socket_write(s, message, strlen(message)); */
return(temp_double);
}

double get_string_from_antenna(char *prompt, char *string)
{
int errcode;
int done = False;
char responce[132];
char message[132];
int responce_length;
short int iosb[4];
int write_func = IO$_WRITEVBLK;
int read_func = IO$_READVBLK;

if ( ant_first_call )
    init_ant();
lock_antenna();
/* sprintf(message,"Prompt = \"%s\", len = %d\r", prompt, strlen(prompt));
socket_write(s, message, strlen(message)); */

errcode = sys$qiow(		0,		/* Who cares what event flag? */
				to_chan,
				write_func,
				iosb,
				0, 0,		/* No AST stuff		      */
				prompt,
				strlen(prompt),
				0, 0, 0, 0);

if (errcode != 1)
    printf("Error %d returned from QIO (1)\n", errcode);

while ( !done ) {
    responce_length = 132;
    errcode = sys$qiow(		0,		/* Who cares what event flag? */
				from_chan,
				read_func,
				&iosb,
				0, 0,
				responce,
				responce_length,
				0, 0, 0, 0);
    responce_length = iosb[1];
/*    sprintf(message, "length = %d\r", responce_length);
    socket_write(s, message, strlen(message));
    sprintf(message,"iosb = %d, %d, %d, %d\r",
	iosb[0], iosb[1], iosb[2], iosb[3]);
    socket_write(s, message, strlen(message)); */
    if (errcode != 1) {
	printf("Error %d returned from QIO (2)\n", errcode);
	done = True;
    }
    responce[responce_length] = 0;
/*    sprintf(message, "Got \"%s\" from antenna\r", responce);
    socket_write(s, message, strlen(message)); */
    if (iosb[0] == SS$_ENDOFFILE)
	done = True;
    else
	sscanf(responce,"%s\0", string);
}
/* sprintf(message, "Exiting loop\r");
socket_write(s, message, strlen(message)); */
unlock_antenna();
/* sprintf(message, "Returning %f\r", temp_double);
socket_write(s, message, strlen(message)); */
return;
}

void send_to_antenna(char *text)
{
int errcode;
double temp_double = 0.0;
int done = False;
char responce[132];
char message[132];
int responce_length;
short int iosb[4];
int write_func = IO$_WRITEVBLK;
int read_func = IO$_READVBLK;

if ( ant_first_call )
    init_ant();
lock_antenna();
/* sprintf(message,"text = \"%s\", len = %d\r", text, strlen(text));
socket_write(s, message, strlen(message)); */

errcode = sys$qiow(		0,		/* Who cares what event flag? */
				to_chan,
				write_func,
				iosb,
				0, 0,		/* No AST stuff		      */
				text,
				strlen(text),
				0, 0, 0, 0);

if (errcode != 1)
    printf("Error %d returned from QIO (1)\n", errcode);

while ( !done ) {
    responce_length = 132;
    errcode = sys$qiow(		0,		/* Who cares what event flag? */
				from_chan,
				read_func,
				&iosb,
				0, 0,
				responce,
				responce_length,
				0, 0, 0, 0);
    responce_length = iosb[1];
/*    sprintf(message, "length = %d\r", responce_length);
    socket_write(s, message, strlen(message));
    sprintf(message,"iosb = %d, %d, %d, %d\r",
	iosb[0], iosb[1], iosb[2], iosb[3]);
    socket_write(s, message, strlen(message)); */
    if (errcode != 1) {
	printf("Error %d returned from QIO (2)\n", errcode);
	done = True;
    }
    responce[responce_length] = 0;
/*    sprintf(message, "Got \"%s\" from antenna\r", responce);
    socket_write(s, message, strlen(message)); */
    if (iosb[0] == SS$_ENDOFFILE)
	done = True;
}
/* sprintf(message, "Exiting loop\r");
socket_write(s, message, strlen(message)); */
unlock_antenna();
}

void get_altaz()
{
    char outline[256];
    double azimuth, elevation;

    azimuth = get_double_from_antenna("AAZ @. F..\r") * DEG_PER_RAD;
    elevation = 90.0 - (get_double_from_antenna("AZA @. F..\r") *
	DEG_PER_RAD); 
    sprintf(outline, "%f %f \r", azimuth, elevation);
    socket_write(s, outline, strlen(outline));
}

void get_focus()
{
    char outline[256];
    int focus_mode;
    double X, Y, Z, theta;

    X = get_double_from_antenna("XPOS F?\r");
    Y = get_double_from_antenna("YPOS F?\r");
    Z = get_double_from_antenna("FOCUS F?\r");
    theta = get_double_from_antenna("THETA F?\r");
    if (get_int_from_antenna("AUTO_FOCUSING ?\r"))
	focus_mode = 1;
    else if (get_int_from_antenna("INC_FOCUS ?\r"))
	focus_mode = 2;
    else
	focus_mode = 0;
    sprintf(outline, "%f %f %f %f %d \r", X, Y, Z, theta,focus_mode);
    socket_write(s, outline, strlen(outline));
}

void get_offsets()
{
    char outline[256];
    double ra_offset, dec_offset, az_offset, el_offset, fixed_az, fixed_za;

    ra_offset = get_double_from_antenna("RAOF F?\r") * SEC_PER_RAD;
    dec_offset = get_double_from_antenna("DCOF F?\r") *	SEC_PER_RAD;
    az_offset = get_double_from_antenna("AZOF F?\r") * SEC_PER_RAD;
    el_offset = get_double_from_antenna("ZAOF F?\r") *	SEC_PER_RAD;
    fixed_az = get_double_from_antenna("FAZOF F?\r") * SEC_PER_RAD;
    fixed_za = get_double_from_antenna("FZAOF F?\r") *	SEC_PER_RAD;
    sprintf(outline, "%f %f %f %f %f %f\r", ra_offset, dec_offset,
	az_offset, el_offset, fixed_az, fixed_za);
    socket_write(s, outline, strlen(outline));
}

void get_position()
{
    char outline[256];
    double ra_epoch, dec_epoch;

    ra_epoch = get_double_from_antenna("RA0RAD F?\r") * DEG_PER_RAD;
    dec_epoch = get_double_from_antenna("DEC0RAD F?\r") * DEG_PER_RAD;
    sprintf(outline, "%f %f\r", ra_epoch, dec_epoch);
    socket_write(s, outline, strlen(outline));
}

void get_lst()
{
    char outline[256];
    double lst;

    lst = get_double_from_antenna("LSTRAD F?\r") * DEG_PER_RAD;
    sprintf(outline, "%f\r", lst);
    socket_write(s, outline, strlen(outline));
}

void get_ut()
{
    char outline[256];
    double utc;

    utc = get_double_from_antenna("UTCRAD F?\r") * DEG_PER_RAD;
    sprintf(outline, "%f\r", utc);
    socket_write(s, outline, strlen(outline));
}

void get_tau()
{
    char outline[256];
    double tau225;

    tau225 = get_double_from_antenna("TAU_225 F?\r");
    sprintf(outline, "%f\r", tau225);
    socket_write(s, outline, strlen(outline));
}

void get_rotator()
{
    char outline[256];
    double angle;

    angle = get_double_from_antenna("SAY_ROTATOR_ANGLE\r");
    sprintf(outline, "%f\r", angle);
    socket_write(s, outline, strlen(outline));
}

void get_par_angle()
{
    char outline[256];
    double angle;

    angle = get_double_from_antenna(
	"CALC_PARALACTIC_ANGLE DROP. PARALACTIC_ANGLE F?\r");
    sprintf(outline, "%f\r", angle);
    socket_write(s, outline, strlen(outline));
}

void get_rotator_offset()
{
    char outline[256];
    double angle;

    angle = get_double_from_antenna("SAY_ROTATOR_OFSET\r");
    sprintf(outline, "%f\r", angle);
    socket_write(s, outline, strlen(outline));
}

void get_name()
{
    char outline[256];
    char name_string[80];

    get_string_from_antenna("SNAME 8 TYPE\r",name_string);
    sprintf(outline, "%s\r", name_string);
    socket_write(s, outline, strlen(outline));
}

void get_status()
{
    char outline[256];
    int status;

    status = get_int_from_antenna("ACQF ?\r");
    sprintf(outline, "%d \r", status);
    socket_write(s, outline, strlen(outline));
}

void get_track()
{
    char outline[256];
    int status;

    status = get_int_from_antenna("TRKMODE ?\r");
    sprintf(outline, "%d \r", status);
    socket_write(s, outline, strlen(outline));
}

main()
{

int i, n, Status, int_returned;
char buf[256], outline[256];
struct sockaddr_in sin;
struct hostent *hp;
static struct {int Size; char *Ptr;} Descr={9 ,"SYS$INPUT"};
double azimuth, elevation;
double X, Y, Z, theta;
double Frest, Flo, Fif, Voffset, Foffset, Vrad;
double ra_offset, dec_offset, az_offset, el_offset, lst, utc,
    tau225;
double ra_epoch, dec_epoch, Vlsr, hp_synth, new_angle;
int harmonic, sideband, locked;
int focus_mode, status;
int errcode;
int ra_hh, ra_mm, dec_dd, dec_mm;
double ra_ss, dec_ss;
/* int read_noecho = IO$_READVBLK | IO$M_NOECHO; */
int read_noecho;
short int iosb[4];

	resource_desc.dsc$b_class = to_desc.dsc$b_class =
	from_desc.dsc$b_class = 
	DSC$K_CLASS_S;
	resource_desc.dsc$b_dtype = to_desc.dsc$b_dtype =
	from_desc.dsc$b_dtype =
	DSC$K_DTYPE_T;
	resource_desc.dsc$a_pointer = resource_name;
	resource_desc.dsc$w_length = strlen(resource_name);
	to_desc.dsc$a_pointer = to_name;
	to_desc.dsc$w_length = strlen(to_name);
	from_desc.dsc$a_pointer = from_name;
	from_desc.dsc$w_length = strlen(from_name);

	/*
	 *  $ASSIGN a channel to SYS$INPUT. This channel is the channel
	 *  to the network connection.
	 */

	Status = SYS$ASSIGN(&Descr, &s, 0, 0);
	if (!(Status&1)) {
		exit(Status);
	}

	/*
	 *  Use getpeername() to find out who made the connection to
	 *  us, so we can act exactly like the example tcpechoserver-standalone.
	 */

	n = sizeof(sin);	   /* Pass in the length */
	if (getpeername(s, &sin, &n) < 0) {
		socket_perror("tcpechoserver: getpeername");
		exit(0x10000000);
	}

	/*
	 *  `sin' will be a sockaddr_in structure describing the
	 *  remote IP address (and port #) which the connection
	 *  was made from. Before we start to echo data, write a
	 *  string into the network describing this port.
	 */

	hp = gethostbyaddr(&sin.sin_addr, sizeof(sin.sin_addr), AF_INET);

	/*
	 *  Now go into a loop, reading data from the network and sending
	 *  it right back...
	 */

	read_noecho = IO$_READVBLK | IO$M_NOECHO;
	iosb[1] = 10;
	sprintf(outline, "1 \r");
	socket_write(s, outline, strlen(outline));
	while (iosb[1] > 0) {
	    errcode = sys$qiow(	1,		/* Who cares what event flag? */
				s,
				read_noecho,
				&iosb,
				0, 0,
				buf,
				256,
				0, 0, 0, 0);
	    if (errcode != 1)
		printf("Error %d returned by QIO\r");
	    if (iosb[1] <= 0)
		break;
	    if (iosb[0] == SS$_ENDOFFILE)
		break;
	    n = iosb[1];
	    buf[n] = 0;
	    for (i = 0; i < n; i++)
		if (islower(buf[i]))
		   buf[i] -= 32;
	    if (!strncmp(buf, "GET_ALTAZ", strlen("GET_ALTAZ"))){
		get_altaz();
	    }
	    else if (!strncmp(buf, "GET_FOCUS", strlen("GET_FOCUS"))){
		get_focus();
	    }
	    else if (!strncmp(buf, "GET_OFFSETS", strlen("GET_OFFSETS"))){
		get_offsets();
	    }
	    else if (!strncmp(buf, "GET_POSITION", strlen("GET_POSITION"))){
		get_position();
	    }
	    else if (!strncmp(buf, "GET_LST", strlen("GET_LST"))){
		get_lst();
	    }
	    else if (!strncmp(buf, "GET_UT", strlen("GET_UT"))){
		get_ut();
	    }
	    else if (!strncmp(buf, "GET_TAU225", strlen("GET_TAU225"))){
		get_tau();
	    }
	    else if (!strncmp(buf, "GET_NAME", strlen("GET_NAME"))){
		get_name();
	    }
	    else if (!strncmp(buf, "GET_STATUS", strlen("GET_STATUS"))){
		get_status();
	    }
	    else if (!strncmp(buf, "GET_TRACK", strlen("GET_TRACK"))){
		get_track();
	    }
	    else if (!strncmp(buf, "GET_ROTATOR", strlen("GET_ROTATOR"))){
		get_rotator();
	    }
	    else if (!strncmp(buf,
		"GET_PAR_ANGLE", strlen("GET_PAR_ANGLE"))){
		get_par_angle();
	    }
	    else if (!strncmp(buf, "GET_ROTATOR_OFFSET",
		strlen("GET_ROTATOR_OFFSET"))){
		get_rotator_offset();
	    }
	    else if (!strncmp(buf, "GET_ALL", strlen("GET_ALL"))){
		get_altaz();
		get_focus();
		get_lst();
		get_name();
		get_offsets();
		get_position();
		get_rotator();
		get_tau();
		get_ut();
		get_par_angle();
	    }
	    else if (!strncmp(buf, "SET_ALTAZ", strlen("SET_ALTAZ"))){
		sscanf(strchr(buf,' '),"%f %f", &azimuth, &elevation);
		if ( (azimuth > -40.0) && (azimuth < 350.0) &&
		     (elevation > 3.0) && (elevation < 90.0) ) {
		    sprintf(outline, "%f AZ\r", azimuth);
		    send_to_antenna(outline);
		    sprintf(outline, "%f ZA\r", (90.0 - elevation));
		    send_to_antenna(outline);
		    sprintf(outline, "1 \r");
		}
		else
		    sprintf(outline, "0 \r");
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_BLADE", strlen("SET_BLADE"))){
		sscanf(strchr(buf,' '),"%d", &status);
		move_chopper(status);
		sprintf(outline, "%d \r", status);
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_FOCUS", strlen("SET_FOCUS"))){
		if (strchr(buf,' ') == NULL) {
		    sprintf(outline, "ADJUST_FOCUS\r");
		    send_to_antenna(outline);
		    status = 0;
/*		    while (status == 0) {
			sleep(1);
			status = get_int_from_antenna("ACQF ?\r");
		    } */
		    sprintf(outline, "1 \r");
		}
		else {
		    sscanf(strchr(buf,' '),"%f %f %f %f %d", &X, &Y, &Z, &theta,
			&focus_mode);
		    if ( (X > -19.3) && (X < 1.10) && (Y > -3.2) &&
			 (Y < 16.5) && (Z > -15.6) && (Z < 3.8) &&
			 (theta > 85.72) && (theta < 275.72) &&
			 (focus_mode >= 0) && (focus_mode <= 2) ) {
			sprintf(outline, "%f NEW_XPOS\r", X);
			send_to_antenna(outline);
			sprintf(outline, "%f NEW_YPOS\r", Y);
			send_to_antenna(outline);
			sprintf(outline, "%f NEW_FOCUS\r", Z);
			send_to_antenna(outline);
			sprintf(outline, "%f NEW_THETA\r", theta);
			send_to_antenna(outline);
			if (focus_mode == 0)
			    sprintf(outline, "NO_AUTO_FOCUS INC_FOCUS 0SET\r");
			else if (focus_mode == 1)
			    sprintf(outline, "AUTO_FOCUS INC_FOCUS 0SET\r");
			else
			    sprintf(outline, "NO_AUTO_FOCUS INC_FOCUS 1SET\r");
			send_to_antenna(outline);
			status = 0;
/*			while (status == 0) {
			    sleep(1);
			    status = get_int_from_antenna("ACQF ?\r");
			} */
			sprintf(outline, "1 \r");
		    }
		    else
			sprintf(outline, "0 \r");
		}
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_OFFSETS", strlen("SET_OFFSETS"))){
		sscanf(strchr(buf,' '),"%f %f %f %f", &ra_offset, &dec_offset,
		    &az_offset, &el_offset);
		sprintf(outline,"%f RAO\r", ra_offset);
		send_to_antenna(outline);
		sprintf(outline,"%f DECO\r", dec_offset);
		send_to_antenna(outline);
		sprintf(outline,"%f AZO\r", az_offset);
		send_to_antenna(outline);
		sprintf(outline,"%f ZAO\r", el_offset);
		send_to_antenna(outline);
		sprintf(outline, "1 \r");
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_RADEC_OFFSETS",
		strlen("SET_RADEC_OFFSETS"))){
		sscanf(strchr(buf,' '),"%f %f", &ra_offset, &dec_offset);
		sprintf(outline,"%f RAO\r", ra_offset);
		send_to_antenna(outline);
		sprintf(outline,"%f DECO\r", dec_offset);
		send_to_antenna(outline);
		sprintf(outline, "1 \r");
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_FIXED_OFFSETS",
		strlen("SET_FIXED_OFFSETS"))){
		sscanf(strchr(buf,' '),"%f %f", &az_offset, &el_offset);
		sprintf(outline,"%f FAZO\r", az_offset);
		send_to_antenna(outline);
		sprintf(outline,"%f FZAO\r", el_offset);
		send_to_antenna(outline);
		sprintf(outline, "1 \r");
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_DELTA_FIXED",
		strlen("SET_DELTA_FIXED"))){
		sscanf(strchr(buf,' '),"%f %f", &az_offset, &el_offset);
		sprintf(outline,"FAZOF @. RD>SEC %f F+ FAZO\r", az_offset);
		send_to_antenna(outline);
		sprintf(outline,"FZAOF @. RD>SEC %f F+ FZAO\r", el_offset);
		send_to_antenna(outline);
		sprintf(outline, "1 \r");
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_SWITCHING_OFFSETS",
		strlen("SET_SWITCHING_OFFSETS"))){
		sscanf(strchr(buf,' '),"%f %f",
		    &az_offset, &el_offset);
		sprintf(outline,"%f AZO\r", az_offset);
		send_to_antenna(outline);
		sprintf(outline,"%f ZAO\r", el_offset);
		send_to_antenna(outline);
		sprintf(outline, "1 \r");
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_ROTATOR", strlen("SET_ROTATOR"))){
		sscanf(strchr(buf,' '),"%F", &new_angle);
		if ( ( new_angle > -120.0) && (new_angle < 91.0) ) {
		    sprintf(outline,"%11.9f SET_ROTATOR_ANGLE\r",
			new_angle);
		    send_to_antenna(outline);
/*		    printf("%s\r", outline); */
/*			status = 0;
		    while (status == 0) {
			sleep(1);
			status = get_int_from_antenna("ACQF ?\r");
		    } */
		    sprintf(outline, "1 \r", status);
		}
		else
		    sprintf(outline, "0 \r", status);
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "SET_ROTATOR_OFFSET",
		strlen("SET_ROTATOR_OFFSET"))){
		sscanf(strchr(buf,' '),"%F", &new_angle);
		sprintf(outline,"%11.9f SET_ROTATOR_OFFSET\r",new_angle);
		send_to_antenna(outline);
		sprintf(outline, "1 \r", status);
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "MOVE_WAIT", strlen("MOVE_WAIT"))){
		status = 0;
		while (status == 0) {
		    sleep(1);
		    status = get_int_from_antenna("ACQF ?\r");
		}
		sprintf(outline, "1 \r", status);
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "UPDATE_ROTATOR",
		strlen("UPDATE_ROTATOR"))){
		send_to_antenna("% UPDATE_ROTATOR 31 10 FQUEUE\r");
		sprintf(outline, "1 \r", status);
		socket_write(s, outline, strlen(outline));
	    }
	    else if (!strncmp(buf, "EXIT", strlen("EXIT"))){
		sprintf(outline, "1 \r");
		socket_write(s, outline, strlen(outline));
		break;
	    }
	}

	if (n < 0) {
	    socket_perror("tcpechoserver: read");
	}

	/*
	 *  Now close down the connection...
	 */

	socket_close(s);

	/*
	 *  Exit successfully.
	 */

	exit(1);
}