static double UT_strings_to_MJD(char *date, char *start_time, int *mjd_day, double *mjd_fracday) { int mtab[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int julday, year, month = 1, day, hour, min, sec, err; sscanf(date, "%3d:%4d", &julday, &year); julday++; /* UT date starts from 0, I believe */ /* Allow for leap years */ if (year % 4 == 0) mtab[1] = 29; if (year % 100 == 0 && year % 400 != 0) mtab[1] = 28; /* Convert Julian day to day and month */ while (julday - mtab[month - 1] > 0) { julday -= mtab[month - 1]; month++; } day = julday; sscanf(start_time, "%2d:%2d:%2d", &hour, &min, &sec); /* Recorded BCPM start time is 1 second late */ *mjd_fracday = (hour + (min + ((sec + 1) / 60.0)) / 60.0) / 24.0; *mjd_day = slaCldj(year, month, day, &err); return *mjd_day + *mjd_fracday; }
double DATEOBS_to_MJD(char *dateobs, int *mjd_day, double *mjd_fracday) // Convert DATE-OBS string from PSRFITS primary HDU to a MJD { int year, month, day, hour, min, err; double sec; sscanf(dateobs, "%4d-%2d-%2dT%2d:%2d:%lf", &year, &month, &day, &hour, &min, &sec); *mjd_fracday = (hour + (min + (sec / 60.0)) / 60.0) / 24.0; *mjd_day = slaCldj(year, month, day, &err); return *mjd_day + *mjd_fracday; }