Skip to content

Commit

Permalink
Fix and test negative forecast time bug (#456)
Browse files Browse the repository at this point in the history
* adding aqm test

* commenting out aqm file test

* fixed negative time in g2cdegrib2
  • Loading branch information
edwardhartnett authored Oct 26, 2023
1 parent 2a77f7d commit 824efa3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/g2cdegrib2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
65 changes: 65 additions & 0 deletions tests/data/ref_aqm.t12z.max_8hr_o3.227.grib2.degrib2
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

GRIB MESSAGE 1 starts at 1

SECTION 0: 0 2 757557
SECTION 1: 7 0 0 1 1 2022 11 1 12 0 0 0 1
Contains 0 Local Sections and 1 data fields.

FIELD 1
SECTION 0: 0 2
SECTION 1: 7 0 0 1 1 2022 11 1 12 0 0 0 1
SECTION 3: 0 1509825 0 0 30
GRID TEMPLATE 3. 30 : 6 0 0 0 0 0 0 1473 1025 12190000 226541000 48 25000000 265000000 5079000 5079000 0 64 25000000 25000000 -90000000 0
NO Optional List Defining Number of Data Points.
PRODUCT TEMPLATE 4. 8: ( PARAMETER = OZMAX8 0 14 201 ) 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
FIELD: OZMAX8 1 hybrid lvl (1 -24) valid 1 hour before 2022110112:00:00 to 2022110210:00:00
NO Optional Vertical Coordinate List.
Num. of Data Points = 1509825 NO BIT-MAP
DRS TEMPLATE 5. 3 : 1102324794 -5 0 11 0 1 1 1649987994 -1 51278 0 4 1 1 40 7 1 2
Data Values:
Num. of Data Points = 1509825 Num. of Data Undefined = 129961
( PARM= OZMAX8 ) : MIN= 22.51768875 AVE= 44.23855591 MAX= 79.61143494

GRIB MESSAGE 2 starts at 757558

SECTION 0: 0 2 872297
SECTION 1: 7 0 0 1 1 2022 11 1 12 0 0 0 1
Contains 0 Local Sections and 1 data fields.

FIELD 1
SECTION 0: 0 2
SECTION 1: 7 0 0 1 1 2022 11 1 12 0 0 0 1
SECTION 3: 0 1509825 0 0 30
GRID TEMPLATE 3. 30 : 6 0 0 0 0 0 0 1473 1025 12190000 226541000 48 25000000 265000000 5079000 5079000 0 64 25000000 25000000 -90000000 0
NO Optional List Defining Number of Data Points.
PRODUCT TEMPLATE 4. 8: ( PARAMETER = OZMAX8 0 14 201 ) 14 201 2 0 89 0 0 1 23 105 0 1 255 -127 -2147483647 2022 11 3 10 0 0 1 0 0 2 1 23 255 0
FIELD: OZMAX8 1 hybrid lvl (23 -46 hr) valid 23 hour after 2022110112:00:00 to 2022110310:00:00
NO Optional Vertical Coordinate List.
Num. of Data Points = 1509825 NO BIT-MAP
DRS TEMPLATE 5. 3 : 1101446063 -6 0 12 0 1 1 1649987994 -1 53209 0 4 1 1 14 7 1 2
Data Values:
Num. of Data Points = 1509825 Num. of Data Undefined = 129961
( PARM= OZMAX8 ) : MIN= 20.84164238 AVE= 44.12677002 MAX= 73.31039429

GRIB MESSAGE 3 starts at 1629855

SECTION 0: 0 2 863685
SECTION 1: 7 0 0 1 1 2022 11 1 12 0 0 0 1
Contains 0 Local Sections and 1 data fields.

FIELD 1
SECTION 0: 0 2
SECTION 1: 7 0 0 1 1 2022 11 1 12 0 0 0 1
SECTION 3: 0 1509825 0 0 30
GRID TEMPLATE 3. 30 : 6 0 0 0 0 0 0 1473 1025 12190000 226541000 48 25000000 265000000 5079000 5079000 0 64 25000000 25000000 -90000000 0
NO Optional List Defining Number of Data Points.
PRODUCT TEMPLATE 4. 8: ( PARAMETER = OZMAX8 0 14 201 ) 14 201 2 0 89 0 0 1 47 105 0 1 255 -127 -2147483647 2022 11 4 10 0 0 1 0 0 2 1 23 255 0
FIELD: OZMAX8 1 hybrid lvl (47 -70 hr) valid 47 hour after 2022110112:00:00 to 2022110410:00:00
NO Optional Vertical Coordinate List.
Num. of Data Points = 1509825 NO BIT-MAP
DRS TEMPLATE 5. 3 : 1099993774 -6 0 12 0 1 1 1649987994 -1 52355 0 4 1 1 15 7 1 2
Data Values:
Num. of Data Points = 1509825 Num. of Data Undefined = 129961
( PARM= OZMAX8 ) : MIN= 18.07162094 AVE= 43.54134750 MAX= 70.52474976

Total Number of Fields Found = 3
12 changes: 5 additions & 7 deletions tests/tst_degrib2_ftp_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ main()
#ifdef FTP_TEST_FILES
printf("Testing degrib2 on files downloaded via FTP...\n");
{
#define NUM_FILES 9
#define NUM_FILES 10
char file[NUM_FILES][MAX_FILENAME_LEN + 1] = {
"data/blend.t19z.core.f001.co.grib2", "data/cmc_geavg.t12z.pgrb2a.0p50.f000",
"data/flxf2022111712.01.2022111712.grb2", "data/GLOBAL.grib2.2022103000.0000",
"data/hiresw.t00z.arw_5km.f00.hi.grib2", "data/naefs_ge10pt.t12z.pgrb2a.0p50_bcf003",
"data/rap.t00z.awp130pgrbf00.grib2", "data/seaice.t00z.grb.grib2",
"data/sgx_nwps_CG3_20221117_1200.grib2"
"data/sgx_nwps_CG3_20221117_1200.grib2", "data/aqm.t12z.max_8hr_o3.227.grib2"
};
int g2cid;
int num_msg;
int f;
int t;
int ret;

for (f = 0; f < NUM_FILES; f++)
/* for (f = 0; f < NUM_FILES; f++) */
for (f = 0; f < 9; f++)
{
/* for (t = 0; t < NUM_FILES; t++) */
for (t = 0; t < 1; t++)
{
char degrib2_file[MAX_FILENAME_LEN + 9];
Expand All @@ -44,7 +44,7 @@ main()
/* Open the data file with and without the index file. */
if (t)
{
printf("\ttesting degrib2 on file %s downloaded via FTP using index...", file[f]);
/* printf("\ttesting degrib2 on file %s downloaded via FTP using index...", file[f]); */
/* if ((ret = g2c_open_index(file[f], REF_GDAS_INDEX_FILE, 0, &g2cid))) */
/* return ret; */
}
Expand All @@ -59,8 +59,6 @@ main()
if ((ret = g2c_inq(g2cid, &num_msg)))
return ret;
printf("num_msg %d\n", num_msg);
/* if (num_msg != GDAS_NUM_MSG) */
/* return G2C_ERROR; */

/* Output a degrib2 file. */
/* g2c_set_log_level(15); */
Expand Down
25 changes: 14 additions & 11 deletions tests/tst_degrib2_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#include "grib2_int.h"

#define NUM_PROD_TEST 12
#define NUM_PROD_TEST 13

int
main()
Expand All @@ -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},
Expand All @@ -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",
Expand All @@ -54,14 +55,16 @@ 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;

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)))
Expand Down

0 comments on commit 824efa3

Please sign in to comment.