diff --git a/src/grib_date.c b/src/grib_date.c index c71d1a9da..0f3cb851c 100644 --- a/src/grib_date.c +++ b/src/grib_date.c @@ -82,7 +82,7 @@ int grib_datetime_to_julian_d( long year, long month, long day, long hour, long minute, double second, double* jd) { - double a, b, dday; + double a, b = 0, dday; long y, m; dday = (double)(hour * 3600 + minute * 60 + second) / 86400.0 + day; @@ -97,22 +97,10 @@ int grib_datetime_to_julian_d( } a = (long)(((double)y) / 100); - if (y > 1582) + if (y > 1582 || + (y == 1582 && ((m > 10) || (m == 10 && day > 14)))) { b = 2 - a + (long)(a / 4); - else if (y == 1582) { - if (m > 10) - b = 2 - a + (long)(a / 4); - else if (m == 10) { - if (day > 14) - b = 2 - a + (long)(a / 4); - else - b = 0; - } - else - b = 0; } - else - b = 0; *jd = (long)(365.25 * (y + 4716)) + (long)(30.6001 * (m + 1)) + dday + b - 1524.5; diff --git a/src/grib_templates.c b/src/grib_templates.c index a9d03ad6a..6d9fefa88 100644 --- a/src/grib_templates.c +++ b/src/grib_templates.c @@ -50,7 +50,7 @@ static grib_handle* try_template(grib_context* c, const char* dir, const char* n sprintf(path, "%s/%s.tmpl", dir, name); - if (c->debug == -1) { + if (c->debug) { fprintf(stderr, "ECCODES DEBUG: try_template path='%s'\n", path); } @@ -78,7 +78,7 @@ static grib_handle* try_bufr_template(grib_context* c, const char* dir, const ch sprintf(path, "%s/%s.tmpl", dir, name); - if (c->debug == -1) { + if (c->debug) { fprintf(stderr, "ECCODES DEBUG: try_template path='%s'\n", path); } diff --git a/tests/julian.c b/tests/julian.c index 9c723b0bc..3910bc5cd 100644 --- a/tests/julian.c +++ b/tests/julian.c @@ -181,12 +181,47 @@ static void Test3() } } +static void Test4() +{ + const long iyear = 1582; + + TestDateTime(iyear, 9, 1, 1, 0, 0); + TestDateTime(iyear, 9, 2, 1, 0, 0); + TestDateTime(iyear, 9, 3, 1, 0, 0); + TestDateTime(iyear, 9, 4, 1, 0, 0); + TestDateTime(iyear, 9, 4, 16, 0, 0); + + /* TODO */ + /* TestDateTime(iyear, 10, 5, 1, 0, 0); */ + TestDateTime(iyear, 10, 1, 1, 0, 0); + TestDateTime(iyear, 10, 2, 1, 0, 0); + TestDateTime(iyear, 10, 3, 1, 0, 0); + TestDateTime(iyear, 10, 4, 1, 0, 0); + TestDateTime(iyear, 10, 15, 1, 0, 0); + + TestDateTime(iyear, 11, 1, 1, 0, 0); + TestDateTime(iyear, 11, 2, 1, 0, 0); + TestDateTime(iyear, 11, 3, 1, 0, 0); + TestDateTime(iyear, 11, 4, 1, 0, 0); + TestDateTime(iyear, 11, 5, 1, 0, 0); + TestDateTime(iyear, 11, 5, 15, 0, 0); + + /* TODO + * for (imnth = 1; imnth <= 12; imnth += 1) { + * for (iday = 1; iday <= 28; iday += 1) { + * TestDateTime(iyear, imnth, iday, 1, 0, 0); + * } + * } + */ +} + int main(int argc, char* argv[]) { Test0(); Test1(); Test2(); Test3(); + Test4(); printf("All OK\n"); return 0; }