From 3266c0adc662a59b5be16e6a3eb606b900091e1b Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Wed, 25 Oct 2023 14:51:51 -0600 Subject: [PATCH] fixed negative time in g2cdegrib2 --- src/g2cdegrib2.c | 1 + tests/tst_degrib2_int.c | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/g2cdegrib2.c b/src/g2cdegrib2.c index fa6b1305..66275d39 100644 --- a/src/g2cdegrib2.c +++ b/src/g2cdegrib2.c @@ -225,6 +225,7 @@ g2c_get_datetime(int ipdtn, long long int *ipdtmpl, short year, unsigned char mo if (ipdtn == 8 && ipdtmpl[8] < 0) { /* tabbrev = "(" // trim(tmpval) // " -" // trim(tmpval2) // ") valid " // trim(tmpval) // " " // trim(tunit) // " before " // reftime // " to " //endtime */ + sprintf(tabbrev, "(%d -%d) valid %d %s before %s to %s", itemp, itemp2, itemp, tunit, reftime, endtime); } else if ((ipdtn >= 8 && ipdtn <= 14) || (ipdtn >= 42 && ipdtn <= 47) || ipdtn == 91) /* Continuous time interval */ diff --git a/tests/tst_degrib2_int.c b/tests/tst_degrib2_int.c index 36f41539..6509dc58 100644 --- a/tests/tst_degrib2_int.c +++ b/tests/tst_degrib2_int.c @@ -7,7 +7,7 @@ */ #include "grib2_int.h" -#define NUM_PROD_TEST 12 +#define NUM_PROD_TEST 13 int main() @@ -16,7 +16,7 @@ main() printf("Testing g2c_get_level_desc()...\n"); { #define DATE_TIME_LEN 100 - int prod_template_num[NUM_PROD_TEST] = {0, 0, 0, 0, 8, 2, 0, 2, 15, 9, 0, 0}; + int prod_template_num[NUM_PROD_TEST] = {0, 0, 0, 0, 8, 2, 0, 2, 15, 9, 0, 0, 8}; long long int prod_template_value[NUM_PROD_TEST][G2C_MAX_PDS_TEMPLATE_MAPLEN] = { {2, 1, 2, 0, 11, 0, 0, 1, 0, 1, 0, 1, 255, 0, 0}, {2, 10, 0, 0, 81, 0, 0, 1, 0, 100, 0, 80000, 255, 0, 0}, @@ -29,19 +29,20 @@ main() {0, 27, 2, 255, 104, 65535, 255, 1, 1, 103, 0, 610, 100, 0, 40000, 241, 241, 241}, {1, 8, 2, 255, 104, 65535, 255, 1, 0, 1, 0, 0, 255, 0, 0, 255, 255, 1, -127, 255, 3, 254, 2022, 11, 17, 20, 0, 0, 1, 0, 1, 2, 1, 1, 1, 0}, {19, 236, 2, 255, 104, 65535, 255, 1, 1, 102, 0, 0, 255, 0, 0}, - {0, 0, 2, 0, 116, 0, 0, 1, 0, 108, 0, 3000, 108, 0, 0} + {0, 0, 2, 0, 116, 0, 0, 1, 0, 108, 0, 3000, 108, 0, 0}, + {14, 201, 2, 0, 89, 0, 0, 1, -1, 105, 0, 1, 255, -127, -2147483647, 2022, 11, 2, 10, 0, 0, 1, 0, 0, 2, 1, 23, 255, 0} }; char expected_level_desc[NUM_PROD_TEST][G2C_MAX_GRIB_LEVEL_DESC_LEN + 1] = { " Surface", " 800 mb", "2 m above ground", " 400 - 300 mb", " Surface", "0 - .1 m DBLY", " 0 - .10 m DBLY", " Mean Sea Level", " 103 (Unknown Lvl)", - " Surface", "0 m above MSL", " 30 - 0 mb SPDY"}; + " Surface", "0 m above MSL", " 30 - 0 mb SPDY", "1 hybrid lvl"}; char level_desc[G2C_MAX_GRIB_LEVEL_DESC_LEN + 1]; - short year[NUM_PROD_TEST] = {2021, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022}; - unsigned char month[NUM_PROD_TEST] = {11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}; - unsigned char day[NUM_PROD_TEST] = {30, 6, 6, 6, 17, 17, 17, 17, 17, 17, 17, 17}; - unsigned char hour[NUM_PROD_TEST] = {0, 12, 12, 12, 19, 12, 12, 12, 19, 19, 19, 0}; - unsigned char minute[NUM_PROD_TEST] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - unsigned char second[NUM_PROD_TEST] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + short year[NUM_PROD_TEST] = {2021, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022}; + unsigned char month[NUM_PROD_TEST] = {11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11}; + unsigned char day[NUM_PROD_TEST] = {30, 6, 6, 6, 17, 17, 17, 17, 17, 17, 17, 17, 01}; + unsigned char hour[NUM_PROD_TEST] = {0, 12, 12, 12, 19, 12, 12, 12, 19, 19, 19, 0, 12}; + unsigned char minute[NUM_PROD_TEST] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + unsigned char second[NUM_PROD_TEST] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; char expected_date_time[NUM_PROD_TEST][DATE_TIME_LEN + 1] = { "valid 0 hour after 2021113000:00:00", "valid 0 hour after 2022110612:00:00", @@ -54,7 +55,8 @@ main() "valid 1 hour after 2022111719:00:00", "(0 -1 hr) valid 0 hour after 2022111719:00:00 to 2022111720:00:00", "valid 1 hour after 2022111719:00:00", - "valid 0 hour after 2022111700:00:00" + "valid 0 hour after 2022111700:00:00", + "(1 -24) valid 1 hour before 2022110112:00:00 to 2022110210:00:00" }; int t; int ret; @@ -62,6 +64,7 @@ main() for (t = 0; t < NUM_PROD_TEST; t++) { char date_time[DATE_TIME_LEN + 1]; + /* printf("\nt %d\n", t); */ /* First test the level description. */ if ((ret = g2c_get_level_desc(prod_template_num[t], prod_template_value[t], level_desc)))