#include #include #include #include #include #include struct plog_entry { int mjd; /* MJD at UTC midnight */ int mod; /* #minutes from UTC midnight */ int ticks; /* #ticks in the minute (10 ms) */ int flags; /* 5-bit flags */ int lst; /* local apparent sidereal time (10 ms) */ int ra; /* requested apparent right ascension (10 ms) */ int dec; /* requested apparent declination (100 mas) */ int pa; /* parallactic angle (100 mas) */ int az; /* requested azimuth (100 mas) */ int el; /* requested elevation (100 mas) */ int eaz; /* error in azimuth (100 mas) */ int eel; /* error in elevation (100 mas) */ }; #define PLOG_BASE_EPOCH (51543) /* MJD at 0 UTC, Jan. 0, 2000 */ #define PLOG_IS_TRACKING(x) ((x) & 0x10) #define PLOG_IS_ACQUIRED(x) ((x) & 0x08) #define PLOG_IS_SCANNING(x) ((x) & 0x04) #define PLOG_IS_TRANSITED(x) ((x) & 0x02) #define PLOG_IS_CELESTIAL(x) ((x) & 0x01) int plog_read(int fd, struct plog_entry *pe) { unsigned char b[30]; int n; if ((n = read(fd, b, 30)) != 30) { if (n == -1) { perror("read"); return errno; } return EOF; } pe->mjd = PLOG_BASE_EPOCH + (b[2] << 6) + (b[3] >> 2); pe->mod = ((b[3] & 0x3) << 9) + (b[4] << 1) + ((b[5] & 0x80) >> 7); pe->ticks = ((b[0] & 0x1f) << 8) + b[1]; pe->flags = (b[5] & 0x7c) >> 2; pe->lst = (b[6] << 16) + (b[7] << 8) + b[8]; if (b[6] & 0x80) /* extend sign bit */ { pe->lst |= 0xff000000; pe->lst += 8640000; } pe->ra = (b[9] << 16) + (b[10] << 8) + b[11]; if (b[9] & 0x80) /* extend sign bit */ { pe->ra |= 0xff000000; pe->ra += 8640000; } pe->dec = (b[12] << 15) + (b[13] << 7) + ((b[14] & 0xfe) >> 1); if (b[12] & 0x80) /* extend sign bit */ pe->dec |= 0xff800000; pe->pa = ((b[14] & 0x1) << 23) + (b[15] << 15) + (b[16] << 7) + ((b[17] & 0xfe) >> 1); if (b[14] & 0x1) /* extend sign bit */ pe->pa |= 0xff000000; pe->az = ((b[17] & 0x1) << 24) + (b[18] << 16) + (b[19] << 8) + b[20]; if (b[17] & 0x1) /* extend sign bit */ pe->az |= 0xfe000000; pe->el = (b[21] << 15) + (b[22] << 7) + ((b[23] & 0xfe) >> 1); if (b[21] & 0x80) /* extend sign bit */ pe->el |= 0xff800000; pe->eaz = ((b[23] & 0x1) << 24) + (b[24] << 16) + (b[25] << 8) + b[26]; if (b[23] & 0x1) /* extend sign bit */ pe->eaz |= 0xfe000000; pe->eel = (b[27] << 16) + (b[28] << 8) + b[29]; if (b[27] & 0x80) /* extend sign bit */ pe->eel |= 0xff000000; return 0; } int main() { struct plog_entry entry; fputs("MJD Time (s) flags LST (hr) R.A.(hr) Dec.(deg) P.A.(deg) " "Az.(deg) El.(deg) Az.Err.(\") El.Err.(\")\n", stdout); while (plog_read(0, &entry) == 0) { printf("%5d %8.2f %c%c%c%c%c " "%9.6f %9.6f %+9.5f %+10.5f %+10.5f %+9.5f %+10.1f %+10.1f\n", entry.mjd, (double) entry.mod * 60.0 + (double) entry.ticks / 100.0, PLOG_IS_TRACKING(entry.flags) ? '1' : '0', PLOG_IS_ACQUIRED(entry.flags) ? '1' : '0', PLOG_IS_SCANNING(entry.flags) ? '1' : '0', PLOG_IS_TRANSITED(entry.flags) ? '1' : '0', PLOG_IS_CELESTIAL(entry.flags) ? '1' : '0', (double) entry.lst / 360000.0, (double) entry.ra / 360000.0, (double) entry.dec / 36000.0, (double) entry.pa / 36000.0, (double) entry.az / 36000.0, (double) entry.el / 36000.0, (double) entry.eaz / 10.0, (double) entry.eel / 10.0); } return 0; }