Skip to content

Commit

Permalink
more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardhartnett committed Jun 27, 2024
1 parent ff3b18f commit 56d2dd6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/g2cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ g2c_rw_section6_metadata(FILE *f, int rw_flag, G2C_SECTION_INFO_T *sec)
/* Check input. */
if (!f || !sec)
return G2C_EINVAL;
LOG((6, "g2c_rw_section6_metadata rw_flag %d at file position %ld", rw_flag,
LOG((4, "g2c_rw_section6_metadata rw_flag %d at file position %ld", rw_flag,
ftell(f)));

/* When reading, allocate storage for a new section 6. When
Expand All @@ -766,10 +766,10 @@ g2c_rw_section6_metadata(FILE *f, int rw_flag, G2C_SECTION_INFO_T *sec)
else
sec6_info = sec->sec_info;

/* Read section 6. */
/* Read or write section 6. */
if ((ret = g2c_file_io_ubyte(f, rw_flag, &sec6_info->indicator)))
return ret;
LOG((5, "g2c_rw_section6_metadata indicator %d", sec6_info->indicator));
LOG((4, "g2c_rw_section6_metadata indicator %d", sec6_info->indicator));

/* When reading, attach sec6_info to our section data. */
if (!rw_flag)
Expand Down
19 changes: 10 additions & 9 deletions src/g2cindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,11 @@ g2c_open_index(const char *data_file, const char *index_file, int mode,
for (s = 3; s < 8; 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 (s < 6)
if (my_s < 6)
{
if ((ret = g2c_file_io_uint(f, G2C_FILE_READ, &sec_len)))
return ret;
Expand Down Expand Up @@ -1081,17 +1082,17 @@ 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)
if (my_s == 4)
bytes_to_sec = pds8;
else if (s == 5)
else if (my_s == 5)
bytes_to_sec = drs8;
else if (s == 6)
else if (my_s == 6)
bytes_to_sec = bms8;
else if (s == 7)
else if (my_s == 7)
bytes_to_sec = data8;

/* Check some stuff. */
if (s < 6 && sec_num != s)
if (my_s < 6 && sec_num != my_s)
{
ret = G2C_EBADSECTION;
break;
Expand All @@ -1106,9 +1107,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",
sec_id, sec_len, bytes_to_sec, s));
if ((ret = add_section(f, msgp, sec_id++, sec_len, bytes_to_sec, s)))
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)))
break;
} /* next section */

Expand Down
33 changes: 18 additions & 15 deletions tests/run_ftp_index_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ set -e
echo ""
echo "*** Running g2c_index test on FTP files"

ftp_files="blend.t19z.core.f001.co.grib2 \
aqm.t12z.max_8hr_o3.227.grib2 \
GLOBAL.grib2.2022103000.0000 \
hiresw.t00z.arw_5km.f00.hi.grib2 \
naefs_ge10pt.t12z.pgrb2a.0p50_bcf003 \
rap.t00z.awp130pgrbf00.grib2 \
seaice.t00z.grb.grib2 \
sgx_nwps_CG3_20221117_1200.grib2 \
cmc_geavg.t12z.pgrb2a.0p50.f000 \
WW3_Regional_US_West_Coast_20220718_0000.grib2 \
WW3_Regional_US_East_Coast_20220717_0600.grib2 \
gdas.t12z.pgrb2.1p00.anl.grib2 \
flxf2022111712.01.2022111712.grb2 \
ftp_files="gdas.t12z.pgrb2.1p00.anl.grib2 \
"
# ftp_files="blend.t19z.core.f001.co.grib2 \
# aqm.t12z.max_8hr_o3.227.grib2 \
# GLOBAL.grib2.2022103000.0000 \
# hiresw.t00z.arw_5km.f00.hi.grib2 \
# naefs_ge10pt.t12z.pgrb2a.0p50_bcf003 \
# rap.t00z.awp130pgrbf00.grib2 \
# seaice.t00z.grb.grib2 \
# sgx_nwps_CG3_20221117_1200.grib2 \
# cmc_geavg.t12z.pgrb2a.0p50.f000 \
# WW3_Regional_US_West_Coast_20220718_0000.grib2 \
# WW3_Regional_US_East_Coast_20220717_0600.grib2 \
# gdas.t12z.pgrb2.1p00.anl.grib2 \
# flxf2022111712.01.2022111712.grb2 \
# "

for f in $ftp_files
do
Expand All @@ -31,9 +33,10 @@ do
../utils/g2c_index -v -o ${f}.idx ../tests/data/$f

echo "Using g2c_degrib2 to create summary for file $f using index ${f}.idx."
../utils/g2c_degrib2 -v -o ${f}.degrib2 ../tests/data/$f ${f}.idx
../utils/g2c_degrib2 -v -o idx_${f}.degrib2 ../tests/data/$f ${f}.idx

#diff -w ${f}.degrib2 data/ref_${f}.degrib2
echo "Comparing degrib2 made with index to reference version."
diff -w idx_${f}.degrib2 data/ref_${f}.degrib2
done

echo "*** SUCCESS!"
Expand Down

0 comments on commit 56d2dd6

Please sign in to comment.