#define EXTERN extern #include #include #include #include #include #include #include #include #include int tcs3_com( char * command, char * reply, int reply_size, char * tcshostname ); int parseFloat( float *fp, char *buf, const char *tok ); int parseDouble( double *dp, char *buf, const char *tok ); int parseInt( int * ip, char *buf, const char *tok ); int parseString( char *outb, int outb_size, char *buf, const char *tok ); #define HOSTNAME "tcs3_host" /* #define HOSTNAME "t1hilo" */ /*---------------------------------------------------------------------------- ** get_tcsaltaz() - same as tcs1.c's get_tcsaltaz() **---------------------------------------------------------------------------- */ int get_tcsaltaz(double *altitude, double *azimuth) { int rc; char buf[512]; char tbuf[40]; double obs_ra; /* Observed RA (radians) */ double obs_dec; /* Observed Dec (radians) */ double obs_ha; /* Observed HA (radians) */ double airmass; /* Airmass */ double obs_zenith; /* Observed zenith (degrees) */ double obs_azimuth; /* Observed azimuth (degrees) */ double par_angle; /* Parallactic Angel (deg) */ float dome_az; /* dome azimuth in degrees */ float dome_vel; /* dome velocity in degrees/seconds */ /* query tcs3 */ if( (rc = tcs3_com( " info opr do ", buf, sizeof(buf), HOSTNAME )) != ERR_NONE ) return rc; /* buf should start with with 'OK' */ if( parseString( tbuf, sizeof(tbuf), buf, " " ) != ERR_NONE ) { return ERR_INV_FORMAT; } if( stricmp ( tbuf, "OK" ) != ERR_NONE ) { return ERR_INV_FORMAT; } /* parse OPr */ /* obs_ra(radians) obs_dec(radians) obs_ha(radians) Am(1.00) Zn(deg) obs_azimuth(deg) pa(deg) */ { /* obs_ra */ rc = parseDouble( &obs_ra, NULL, " " ); if( rc != ERR_NONE) return rc; /* obs_dec */ rc = parseDouble( &obs_dec, NULL, " " ); if( rc != ERR_NONE) return rc; /* obs_ha */ rc = parseDouble( &obs_ha, NULL, " " ); if( rc != ERR_NONE) return rc; /* airmass */ rc = parseDouble( &airmass, NULL, " " ); if( rc != ERR_NONE) return rc; /* obs_zenith */ rc = parseDouble( &obs_zenith, NULL, " " ); if( rc != ERR_NONE) return rc; /* azimuth */ rc = parseDouble( &obs_azimuth, NULL, " " ); if( rc != ERR_NONE) return rc; /* par_angel */ rc = parseDouble( &par_angle, NULL, " " ); if( rc != ERR_NONE) return rc; } /* parse DO */ /* dome_az(deg) vel(deg/s) */ { rc = parseFloat( &dome_az, NULL, " " ); if( rc != ERR_NONE) return rc; rc = parseFloat( &dome_vel, NULL, " " ); if( rc != ERR_NONE) return rc; } *altitude = 90.0 - obs_zenith; *azimuth = obs_azimuth; printf("Tele Azimuth =%.1f Dome Azimuth =%.1f Elevation =%.1f \n", *azimuth, dome_az, *altitude); return rc; } /*---------------------------------------------------------------------------- ** get_tcspos() - same as tcs1.c's get_tcspos(). return ra, dec in radians. **---------------------------------------------------------------------------- */ int get_tcspos(double *pixra, double *pixdec) { int rc; char buf[512]; char tbuf[40]; double target_ra, target_dec, pmra, pmdec, epoch, equinox; char cs[20]; /* query tcs3 */ if( (rc = tcs3_com( " info opr do ", buf, sizeof(buf), HOSTNAME )) != ERR_NONE ) return rc; /* buf should start with with 'OK' */ if( parseString( tbuf, sizeof(tbuf), buf, " " ) != ERR_NONE ) { return ERR_INV_FORMAT; } if( stricmp ( tbuf, "OK" ) != ERR_NONE ) { return ERR_INV_FORMAT; } /* parse SPr output */ /* target_ra(radians) Target_dec(radinas) pm_ra(sec/year) pm_dec(arcsec/year) */ /* epoch(yyyy.y) equinox(yyyy.y) CS(string) */ { /* target_ra */ rc = parseDouble( &target_ra, NULL, " " ); if( rc != ERR_NONE) return rc; /* target_dec */ rc = parseDouble( &target_dec, NULL, " " ); if( rc != ERR_NONE) return rc; /* pm ra */ rc = parseDouble( &pmra, NULL, " " ); if( rc != ERR_NONE) return rc; /* pm dec */ rc = parseDouble( &pmdec, NULL, " " ); if( rc != ERR_NONE) return rc; /* epoch */ rc = parseDouble( &epoch, NULL, " " ); if( rc != ERR_NONE) return rc; /* equinox */ rc = parseDouble( &equinox, NULL, " " ); if( rc != ERR_NONE) return rc; /* CS */ rc = parseString( cs, sizeof(cs), NULL, " " ); if( rc != ERR_NONE) return rc; } *pixra = target_ra; *pixdec = target_dec; return rc; } /*---------------------------------------------------------------------------- ** set_tcshaslew() - like tcs1.c's set_tcshaslew(), but just ** print a message asking the TO to MP here. **---------------------------------------------------------------------------- */ int set_tcshaslew(float ha, float dec) { int rc; char cmd[40]; char reply[80]; sprintf(cmd, "MP %.3f %.3f ", ha, dec ); /* printf("TCS3 command ===> %s \n", cmd ); */ rc = tcs3_com( cmd, reply, sizeof(reply), HOSTNAME ); /* printf("TCS3 reply ===> %d %s\n", rc, reply ); */ return 0; } /*---------------------------------------------------------------------------- ** tcs3_com() - basic routine for communicating with TCS. **---------------------------------------------------------------------------- */ int tcs3_com( char * command, /* I: command to send to the tcs */ char * reply, /* O: reply is copied here (set to NULL to ignore reply). */ int reply_size, /* I: size of reply buffer */ char * tcshostname /* I: hostname of tcs */ ) { char buf[512]; /* max size returned by t3io */ FILE *fp = NULL; sprintf( buf, "./t3io/t3io -h %s %s ", tcshostname, command); if( (fp = popen( buf, "r")) == NULL ) { return ERR_INV_OPERATION; } /*----------------------------------- ** read reply and copy to user. */ buf[0] = 0; /* null the buffer. */ fgets( buf, sizeof(buf), fp); pclose(fp); /* printf("tcs3 com reply: %s \n", buf); */ if( reply ) { strxcpy( reply, buf, reply_size); } return ERR_NONE; } /*---------------------------------------------------------- ** parseFloat() - parse & convert to float. **---------------------------------------------------------- */ int parseFloat( float *fp, char *buf, const char *tok ) { char * c; float f; if( (c = strtok( buf, tok) ) == NULL) return ERR_INV_FORMAT; f = atof( c ); *fp = f; return ERR_NONE; } /*---------------------------------------------------------- ** parseDouble() - parse & convert to double. **---------------------------------------------------------- */ int parseDouble( double *dp, char *buf, const char *tok ) { char * c; double d; if( (c = strtok( buf, tok) ) == NULL) return ERR_INV_FORMAT; d = atof( c ); *dp = d; return ERR_NONE; } /*---------------------------------------------------------- ** parseInt() - parse & convert to int. **---------------------------------------------------------- */ int parseInt( int * ip, char *buf, const char *tok ) { char * c; long l; if( (c = strtok( buf, tok) ) == NULL) return ERR_INV_FORMAT; if( -1 == my_atol( c, &l)) return ERR_INV_FORMAT; *ip = (int)l; return ERR_NONE; } /*-------------------------------------------------------------------- ** parseString() - parse & copies a string into buf. **-------------------------------------------------------------------- */ int parseString( char *outb, int outb_size, char *buf, const char *tok ) { char *c; if( (c = strtok( buf, tok) ) == NULL) return ERR_INV_FORMAT; strxcpy( outb, c, outb_size); return ERR_NONE; }