Skip to content

Commit

Permalink
pds 4.115
Browse files Browse the repository at this point in the history
  • Loading branch information
AlysonStahl-NOAA committed Dec 6, 2024
1 parent 454c491 commit 9ce2805
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/grib2.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ g2int g2_gribend(unsigned char *cgrib);
/* Constants to help with templates. */
#define G2C_MAX_GDS_TEMPLATE 31 /**< Maximum number of grid templates. */
#define G2C_MAX_GDS_TEMPLATE_MAPLEN 28 /**< Maximum grid template map length. */
#define G2C_MAX_PDS_TEMPLATE 91 /**< Maximum number of PDS templates. */
#define G2C_MAX_PDS_TEMPLATE 92 /**< Maximum number of PDS templates. */
#define G2C_MAX_PDS_TEMPLATE_MAPLEN 45 /**< Maximum template map length. */
#define G2C_MAX_DRS_TEMPLATE 10 /**< Maximum number of DRS templates. */
#define G2C_MAX_DRS_TEMPLATE_MAPLEN 18 /**< Maximum DRS template map length. */
Expand Down
33 changes: 33 additions & 0 deletions src/pdstemplates.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ static const struct pdstemplate templatespds[G2C_MAX_PDS_TEMPLATE] =
4.114: Average, accumulation, and/or extreme values or other statistically processed values on generalized tiles at a
horizontal level or in a horizontal layer in a continuous or non-continuous time interval */
{114, 7, 1, {1, 1, 1, 2, 1, 1, 1}},
/** PDT 4.115 (12/04/2024)
4.115: Individual ensemble forecast, control and perturbed on generalized tiles at a horizontal level or in a horizontal
layer at a point in time */
{115, 7, 1, {1, 1, 1, 2, 1, 1, 1}},
};

/**
Expand Down Expand Up @@ -1502,6 +1506,35 @@ extpdstemplate(g2int number, g2int *list)
new->ext[l + 28] = 1;
new->ext[l + 29] = 4;
}
else if (number == 115)
{
new->extlen = list[6] + 19;
new->ext = malloc(sizeof(g2int) * new->extlen);
for (i = 0; i < list[6]; i++)
{
new->ext[i] = 1;
}
l = list[6];
new->ext[l] = 1;
new->ext[l + 1] = 1;
new->ext[l + 2] = 16;
new->ext[l + 3] = 1;
new->ext[l + 4] = 1;
new->ext[l + 5] = 1;
new->ext[l + 6] = 2;
new->ext[l + 7] = 1;
new->ext[l + 8] = 1;
new->ext[l + 9] = -4;
new->ext[l + 10] = 1;
new->ext[l + 11] = -1;
new->ext[l + 12] = -4;
new->ext[l + 13] = 1;
new->ext[l + 14] = -1;
new->ext[l + 15] = -4;
new->ext[l + 16] = 1;
new->ext[l + 17] = 1;
new->ext[l + 18] = 1;
}
return new;
}

Expand Down
27 changes: 22 additions & 5 deletions tests/tst_pdstemplates.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,28 +671,40 @@ main()
return G2C_ERROR;
free(tmpl->ext);
free(tmpl);

/* Check for one that's there but does need an extension. */
tmpl = extpdstemplate(115, list);
if (!tmpl)
return G2C_ERROR;
if (tmpl->num != 115 || tmpl->maplen != 7 || !tmpl->needext)
return G2C_ERROR;
if (!tmpl->ext)
return G2C_ERROR;
free(tmpl->ext);
free(tmpl);
}
printf("ok!\n");
printf("Testing all getpdstemplate() calls with extensions...\n");
{
#define NUM_TEST 91
#define NUM_TEST 92
int number[NUM_TEST] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 20, 30, 31, 40, 41,
42, 43, 254, 1000, 1001, 1002, 1100, 1101, 32, 44, 45, 46, 47, 48, 50, 52,
51, 91, 33, 34, 53, 54, 57, 60, 61, 35, 49, 55, 58, 59, 62, 63, 67, 68, 70,
71, 72, 73, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92,
93, 94, 95, 96, 97, 98, 99, 100, 103, 104, 108, 109, 110, 111, 113, 114};
93, 94, 95, 96, 97, 98, 99, 100, 103, 104, 108, 109, 110, 111, 113, 114,
115};
int expected_maplen[NUM_TEST] = {
15, 18, 17, 31, 30, 22, 16, 15, 29, 36, 30, 32, 31, 45, 44, 18, 19, 5, 5,
16, 19, 30, 33, 3, 9, 16, 15, 15, 22, 10, 21, 24, 35, 38, 26, 21, 15, 16,
36, 18, 32, 19, 22, 7, 24, 38, 6, 29, 21, 7, 24, 35, 38, 7, 7, 19, 21, 32,
34, 17, 20, 31, 34, 27, 30, 36, 40, 39, 38, 17, 31, 24, 20, 34, 27, 27, 30,
28, 31, 31, 34, 14, 17, 20, 23, 20, 23, 34, 37, 7, 7};
28, 31, 31, 34, 14, 17, 20, 23, 20, 23, 34, 37, 7, 7, 7};
int expected_needext[NUM_TEST] = {
0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,
0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1,
0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1};
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1};
int expected_map[NUM_TEST][48] = {
{1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 0 */
{1, 1, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 1 */
Expand Down Expand Up @@ -785,6 +797,7 @@ main()
{1, 1, 1, -1, -4, -1, -4, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 111 */
{1, 1, 1, 2, 1, 1, 1}, /* 113 */
{1, 1, 1, 2, 1, 1, 1}, /* 114 */
{1, 1, 1, 2, 1, 1, 1}, /* 115 */
};
int t;
int ext_t = 0;
Expand Down Expand Up @@ -831,7 +844,7 @@ main()
int expected_extlen[NUM_EXT_TEST] = {
2, 2, 6, 6, 6, 6, 6, 8, 8, 10, 10, 6, 6, 10, 6, 6, 12, 8, 2, 8, 2, 2, 30, 6,
10, 20, 6, 6, 31, 34, 6, 6, 6, 6, 6, 6, 6, 6, 6, 11, 6, 11, 11, 11, 11, 11,
11, 11, 5, 5, 6, 6, 18, 32};
11, 11, 5, 5, 6, 6, 18, 32, 21};
int expected_ext[NUM_EXT_TEST][48] = {
{1, 1}, /* 3 */
{1, 1}, /* 4 */
Expand Down Expand Up @@ -887,6 +900,7 @@ main()
{1, 1, 1, 4, 1, 4}, /* 111 */
{1, 1, 1, 1, 16, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4}, /* 113 */
{1, 1, 1, 1, 16, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 1, 4, 1, 4}, /* 114 */
{1, 1, 1, 1, 16, 1, 1, 1, 2, 1, 1, -4, 1, -1, -4, 1, -1, -4, 1, 1, 1}, /* 115 */
};

if (needext)
Expand Down Expand Up @@ -1067,6 +1081,9 @@ main()
case 114:
template[6] = 2;
break;
case 115:
template[6] = 2;
break;
default:
return G2C_ERROR;
}
Expand Down

0 comments on commit 9ce2805

Please sign in to comment.