#include #include #include #include #define MAXVALUES 1600 struct time_rec { unsigned short rec_size; unsigned short millisec; unsigned short flag; unsigned short num_samp; }; void ms2hms (b, c, d, e) int *b, *c; float *d; double e; { *d = (float) fmod ((double) (e / 1000.0), 60.0); *c = (int) fmod ((double) (e / 60000.0), 60.0); *b = (int) fmod ((double) (e / 3600000.0), 24.0); } int main (int argc, char *argv[]) { int length, year, day, hour, minute, hr, mn, flag, rec_size, nsamps; int i,j,k; float ss; double ms, st_ms, basems; unsigned char data [MAXVALUES]; struct time_rec trc; char name [80]; FILE *infp; /* See if we were passed the correct number of arguments */ if (argc != 2) { (void) fprintf (stderr, "Usage: %s input\n", argv [0]); exit (0); } /* Open the input file */ if (!(infp = fopen (argv [1], "r"))) { (void) fprintf (stderr, "Can't open input file.\n"); exit (0); } length = strlen (argv [1]); name [0] = argv [1][(length - 3)]; name [1] = argv [1][(length - 2)]; name [2] = '\0'; year = (int) atoi (name); year += 1900; name [0] = argv [1][(length - 11)]; name [1] = argv [1][(length - 10)]; name [2] = argv [1][(length - 9)]; name [3] = '\0'; day = (int) atoi (name); name [0] = argv [1][(length - 8)]; name [1] = argv [1][(length - 7)]; name [2] = '\0'; hour = (int) atoi (name); name [0] = argv [1][(length - 6)]; name [1] = argv [1][(length - 5)]; name [2] = '\0'; minute = (int) atoi (name); basems = (double) (hour*3600000.0) + (double) (minute*60000.0); while (!feof (infp)) { if (!fread (&trc, sizeof (trc), 1, infp)) continue; ms = (double) trc.millisec; st_ms = basems; st_ms += ms; flag = (int) trc.flag; rec_size = (int) trc.rec_size; nsamps = (int) trc.num_samp; ms2hms (&hr, &mn, &ss, st_ms); fprintf (stdout, "%04d %03d %02d %02d %06.3f %1d %4d %4d \n", year, day, hr, mn, ss, flag, rec_size, nsamps); if (!fread (data, (trc.rec_size - 6), 1, infp)) continue; for(j=0;j