// // mjdpick - select lines in file based on MJD range. // // 10-Feb-2007 tvb // #include #include #include // MJD conversion macros. #define UNIX_TIME_TO_MJD(t) ( MJD_1970_01_01 + ((t) / 86400.0) ) #define MJD_1970_01_01 40587 void main (int argc, char *argv[]) { long In, Out; char Line[1000]; double mjd_now, mjd_low, mjd_high; mjd_now = UNIX_TIME_TO_MJD(time(NULL)); // Set start and end times. mjd_low = (argc > 1) ? atof(argv[1]) : 0; mjd_high = (argc > 2) ? atof(argv[2]) : mjd_now; // Special case: start or end N days before now. if (mjd_low < 0.0) { mjd_low += mjd_now; } if (mjd_high < 0.0) { mjd_high += mjd_now; } if (mjd_low > mjd_high) { double t = mjd_low; mjd_low = mjd_high; mjd_high = t; } fprintf(stderr, "Picking lines from MJD %.6lf to MJD %.6lf\n", mjd_low, mjd_high); In = Out = 0; while (fgets(Line, sizeof(Line), stdin) != NULL) { double mjd; int n; In += 1; n = sscanf(Line, "%lf", &mjd); if (n == 1 && mjd >= mjd_low && mjd < mjd_high) { fputs(Line, stdout); Out += 1; } } fprintf(stderr, "%ld lines in, %ld lines skipped, %ld lines out\n", In, In - Out, Out); }