Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Jun 28, 2024
1 parent 56d2dd6 commit 7452f24
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/g2cdegrib2.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,9 @@ g2c_degrib2(int g2cid, const char *fileout)

/* Section 5 and 6 info. */
sec5_info = (G2C_SECTION5_INFO_T *)sec5->sec_info;
sec6_info = (G2C_SECTION6_INFO_T *)sec6->sec_info;
if (sec6_info->indicator != 255)
if (sec6)
sec6_info = (G2C_SECTION6_INFO_T *)sec6->sec_info;
if (sec6 && sec6_info->indicator != 255)
fprintf(f, " Num. of Data Points = %d with BIT-MAP 0\n", sec5_info->num_data_points);
else
fprintf(f, " Num. of Data Points = %d NO BIT-MAP \n", sec5_info->num_data_points);
Expand Down
24 changes: 13 additions & 11 deletions src/g2cindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
int s;
G2C_MESSAGE_INFO_T *msgp;
int sec_id = 0;
int sec8_found = 0;

/* Allocate storage for message. */
if ((ret = add_msg(&g2c_file[*g2cid], rec, msg, msglen, 0, &msgp)))
Expand All @@ -1044,14 +1045,13 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
LOG((4, "reading section info at file position %ld", ftell(f)));

/* Add a new section to our list of sections. */
for (s = 3; s < 8; s++)
for (s = 3; s < 8 && !sec8_found; s++)
{
size_t bytes_to_sec = gds8; /* Correct value for section 3. */
int my_s = s;

/* For sections 3, 4, 5, read the section length
* and number from the index record. */
if (my_s < 6)
if (s < 7)
{
if ((ret = g2c_file_io_uint(f, G2C_FILE_READ, &sec_len)))
return ret;
Expand Down Expand Up @@ -1082,17 +1082,19 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,

/* Select the value from the index record which is
* the number of bytes to section s. */
if (my_s == 4)
if (sec_num == 4)
bytes_to_sec = pds8;
else if (my_s == 5)
else if (sec_num == 5)
bytes_to_sec = drs8;
else if (my_s == 6)
else if (sec_num == 6)
bytes_to_sec = bms8;
else if (my_s == 7)
else if (sec_num == 7)
bytes_to_sec = data8;
else if (sec_num == 8)
sec8_found++;

/* Check some stuff. */
if (my_s < 6 && sec_num != my_s)
if (s < 6 && sec_num != s)
{
ret = G2C_EBADSECTION;
break;
Expand All @@ -1107,9 +1109,9 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
/* Read the section info from the index file,
* using the same functions that read it from the
* GRIB2 data file. */
LOG((4, "about to add_section sec_id %d sec_len %d bytes_to_sec %ld, s %d my_s %d",
sec_id, sec_len, bytes_to_sec, s, my_s));
if ((ret = add_section(f, msgp, sec_id++, sec_len, bytes_to_sec, my_s)))
LOG((4, "about to add_section sec_id %d sec_len %d bytes_to_sec %ld sec_num %d",
sec_id, sec_len, bytes_to_sec, sec_num));
if ((ret = add_section(f, msgp, sec_id++, sec_len, bytes_to_sec, sec_num)))
break;
} /* next section */

Expand Down
Binary file modified tests/data/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index
Binary file not shown.
26 changes: 25 additions & 1 deletion tests/tst_degrib2_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@
#define REF_INDEX_FILE "data/ref_gdaswave.t00z.wcoast.0p16.f000.grb2index"
#define TEST_INDEX_FILE "tst_gdaswave.t00z.wcoast.0p16.f000.grb2index"

/* The first message of the file has the following degrib2 output in the g2 project:
GRIB MESSAGE 1 starts at 1
SECTION 0: 0 2 15254
SECTION 1: 7 0 2 1 1 2021 11 30 0 0 0 0 1
Contains 0 Local Sections and 1 data fields.
FIELD 1
SECTION 0: 0 2
SECTION 1: 7 0 2 1 1 2021 11 30 0 0 0 0 1
SECTION 3: 0 36391 0 0 0
GRID TEMPLATE 3. 0 : 6 0 0 0 0 0 0 241 151 0 0 50000000 210000000 48 25000000 250000000 166667 166667 0
NO Optional List Defining Number of Data Points.
PRODUCT TEMPLATE 4. 0: ( PARAMETER = WIND 0 2 1 ) 2 1 2 0 11 0 0 1 0 1 0 1 255 0 0
FIELD: WIND Surface valid 0 hour after 2021113000:00:00
NO Optional Vertical Coordinate List.
Num. of Data Points = 11041 with BIT-MAP 0
DRS TEMPLATE 5. 40 : 1092616192 0 2 11 0 0 255
Data Values:
Num. of Data Points = 11041 Num. of Data Undefined = 0
( PARM= WIND ) : MIN= 0.09999999 AVE= 5.64625025 MAX= 16.43000031
*/

int
main()
{
Expand Down Expand Up @@ -43,7 +67,7 @@ main()
int num_msg;
int ret;

/* g2c_set_log_level(10); */
/* g2c_set_log_level(4); */
/* Open the data file using the index file. */
if ((ret = g2c_open_index(WAVE_FILE, REF_INDEX_FILE, 0, &g2cid)))
return ret;
Expand Down

0 comments on commit 7452f24

Please sign in to comment.