Skip to content

Commit

Permalink
getting test working
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Jun 17, 2024
1 parent e83da1e commit 0c4700c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
36 changes: 23 additions & 13 deletions src/g2cindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,10 @@ g2c_write_index(int g2cid, int mode, const char *index_file)
else
{
int bytes_to_msg = (int)msg->bytes_to_msg;
if ((ret = g2c_start_index_record(f, G2C_FILE_WRITE, &reclen, &bytes_to_msg, &msg->bytes_to_local,
int b2l;

b2l = (int)msg->bytes_to_local;
if ((ret = g2c_start_index_record(f, G2C_FILE_WRITE, &reclen, &bytes_to_msg, &b2l,
&bs3, &bs4, &bs5, &bs6, &bs7, &msg->bytes_in_msg, &msg->master_version,
&msg->discipline, &fieldnum)))
break;
Expand Down Expand Up @@ -974,6 +977,7 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
for (rec = 0; rec < num_rec; rec++)
{
int reclen, msgint, local, gds, pds, drs, bms, data;
size_t local8, gds8, pds8, drs8, bms8, data8;
size_t msglen, msg;
unsigned char version, discipline;
short fieldnum;
Expand All @@ -994,17 +998,23 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
&drs, &bms, &data, &msglen, &version, &discipline, &fieldnum)))
break;
msg = msgint;
local8 = local;
gds8 = gds;
pds8 = pds;
drs8 = drs;
bms8 = bms;
data8 = data;
}
else
{
if ((ret = g2c_start_index_record_lf(f, G2C_FILE_READ, &reclen, &msg, &local, &gds, &pds,
&drs, &bms, &data, &msglen, &version, &discipline, &fieldnum)))
if ((ret = g2c_start_index_record_lf(f, G2C_FILE_READ, &reclen, &msg, &local8, &gds8, &pds8,
&drs8, &bms8, &data8, &msglen, &version, &discipline, &fieldnum)))
break;
}

LOG((1, "reclen %d msg %ld local %d gds %d pds %d drs %d bms %d data %d "
LOG((1, "reclen %d msg %ld local8 %d gds8 %d pds8 %d drs8 %d bms8 %d data8 %d "
"msglen %ld version %d discipline %d fieldnum %d",
reclen, msg, local, gds, pds, drs, bms, data, msglen,
reclen, msg, local8, gds8, pds8, drs8, bms8, data8, msglen,
version, discipline, fieldnum));

/* Read the metadata for sections 3, 4, and 5 from
Expand All @@ -1020,9 +1030,9 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
if ((ret = add_msg(&g2c_file[*g2cid], rec, msg, msglen, 0, &msgp)))
break;
msgp->discipline = discipline;
msgp->bytes_to_local = local;
msgp->bytes_to_bms = bms;
msgp->bytes_to_data = data;
msgp->bytes_to_local = local8;
msgp->bytes_to_bms = bms8;
msgp->bytes_to_data = data8;
msgp->master_version = version;

/* Read section 1. */
Expand All @@ -1036,7 +1046,7 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
/* Add a new section to our list of sections. */
for (s = 3; s < 8; s++)
{
size_t bytes_to_sec = gds; /* Correct value for section 3. */
size_t bytes_to_sec = gds8; /* Correct value for section 3. */

/* For sections 3, 4, 5, read the section length
* and number from the index record. */
Expand Down Expand Up @@ -1070,13 +1080,13 @@ 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 (s == 4)
bytes_to_sec = pds;
bytes_to_sec = pds8;
else if (s == 5)
bytes_to_sec = drs;
bytes_to_sec = drs8;
else if (s == 6)
bytes_to_sec = bms;
bytes_to_sec = bms8;
else if (s == 7)
bytes_to_sec = data;
bytes_to_sec = data8;

/* Check some stuff. */
if (s < 6 && sec_num != s)
Expand Down
6 changes: 3 additions & 3 deletions src/grib2_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ typedef struct g2c_message_info
int section1[G2C_SECTION1_ARRAY_LEN]; /**< Section 1 array. */
int num_fields; /**< Number of fields in the message. */
int num_local; /**< Number of local sections in the message. */
int bytes_to_local; /**< Number of bytes in the message before the (first) local section. */
int bytes_to_bms; /**< Number of bytes in the message to the bitmap section. */
int bytes_to_data; /**< Number of bytes in the message to the (first) data section. */
size_t bytes_to_local; /**< Number of bytes in the message before the (first) local section. */
size_t bytes_to_bms; /**< Number of bytes in the message to the bitmap section. */
size_t bytes_to_data; /**< Number of bytes in the message to the (first) data section. */
int num_sections; /**< Number of sections in the file. */
int *section_number; /**< Array (length num_sections) of section numbers. */
size_t *section_offset; /**< Array (length num_sections) of byte offsets from start of message to section. */
Expand Down
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ if(BUILD_G2C)
endif()

# Run these extra tests if you have the data files to do so.
if(FTP_EXTRA_TEST_FILES)
g2c_test(tst_mrms)
if (BUILD_G2C)
if(FTP_EXTRA_TEST_FILES)
g2c_test(tst_mrms)
endif()
endif()


Expand Down
2 changes: 1 addition & 1 deletion tests/run_large_index_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ echo "*** Running g2c_index large file test"
../utils/g2c_index -o fv3lam.t00z.prslev.f000.grib2.idx -l -v data/fv3lam.t00z.prslev.f000.grib2

# Summarize the index data.
../utils/g2c_degrib2 -o fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx
#../utils/g2c_degrib2 -o fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/fv3lam.t00z.prslev.f000.grib2 fv3lam.t00z.prslev.f000.grib2.idx

# Check against expected output.
#diff -w fv3lam.t00z.prslev.f000.grib2.idx.degrib2 data/ref_fv3lam.t00z.prslev.f000.grib2.degrib2
Expand Down

0 comments on commit 0c4700c

Please sign in to comment.