Skip to content

Commit

Permalink
changes to grb2index (#317)
Browse files Browse the repository at this point in the history
* changes to grb2index

* changed to idxver 2 by default with grb2index

* more testing

* fixed comments
  • Loading branch information
edwardhartnett authored Mar 21, 2024
1 parent 2acaac2 commit 12c0159
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/grb2index/docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ grb2index \<GRIB2 file\> \<index filename\>
The first argument is the name of the input GRIB2 file. The second argument is
the name of the output index file.

or

@code
grb2index \<idxver\> \<GRIB2 file\> \<index filename\>
@endcode

The first argument is the index format, 1 or 2. The second is the name
of the input GRIB2 file. The third argument is the name of the output
index file.

# Index File Format

The index file has two header records:
Expand Down
21 changes: 14 additions & 7 deletions src/grb2index/grb2index.F90
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
program grb2index
implicit none
integer narg, iargc
character cgb*256,cgi*256
integer :: idxver = 1
character cgb * 256, cgi * 256
character cidxver * 1
integer :: idxver = 2
integer :: lugb = 11, lugi = 12
integer :: ncgb, ncgb1
integer :: iret, ios, ncbase
integer :: iret, ios, ncbase, argnum = 0

interface
subroutine g2_create_index(lugb, lugi, idxver, filename, iret)
Expand All @@ -29,15 +30,21 @@ subroutine g2_create_index(lugb, lugi, idxver, filename, iret)
end subroutine g2_create_index
end interface

! get arguments
! Get arguments.
narg = iargc()
if (narg .ne. 2) then
if (narg .ne. 2 .and. narg .ne. 3) then
call errmsg('grb2index: Incorrect usage')
call errmsg('Usage: grb2index gribfile indexfile')
call errmsg('or: grb2index idxver gribfile indexfile')
call exit(2)
endif
call getarg(1, cgb)
call getarg(2, cgi)
if (narg .eq. 3) then
call getarg(1, cidxver)
read(cidxver, '(i1)') idxver
argnum = 1
end if
call getarg(argnum + 1, cgb)
call getarg(argnum + 2, cgi)

! Open binary GRIB2 file for input.
call baopenr(lugb, trim(cgb), ios)
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ gu_copy_test_data(ref_gdaswave_2.idx)
gu_copy_test_data(ref_gdaswave.degrib2.txt)
gu_copy_test_data(ref_gdaswave_grib1_inventory.txt)
gu_copy_test_data(ref_gdaswave.grb2index.idx)
gu_copy_test_data(ref_gdaswave.grb2index.idx2)
gu_copy_test_data(ref_gdaswave.grbindex.grib1.idx)
gu_copy_test_data(ref_gdaswave_2.grib1.idx)
gu_copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2.idx)
Expand Down
Binary file added tests/data/ref_gdaswave.grb2index.idx2
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/run_cnvgrib_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cmp test_gdaswave.t00z.wcoast.0p16.f000.grib1.inventory.txt data/ref_gdaswave_gr
../src/cnvgrib/cnvgrib -g12 test_gdaswave.t00z.wcoast.0p16.f000.grib1 test_gdaswave.t00z.wcoast.0p16.f000.grib2

# Create an index of a GRIB2 file.
../src/grb2index/grb2index test_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.t00z.wcoast.0p16.f000.grib2.idx
../src/grb2index/grb2index 1 test_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.t00z.wcoast.0p16.f000.grib2.idx

# Check against expected output. First 120 bytes contain differences,
# so ignore them.
Expand All @@ -30,7 +30,7 @@ cmp -i 120 test_gdaswave.t00z.wcoast.0p16.f000.grib2.idx data/ref_gdaswave.t00z.
../src/cnvgrib/cnvgrib -g22 data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.t00z.wcoast.0p16.f000_2.grib2

# Create an index of the new GRIB2 file.
../src/grb2index/grb2index test_gdaswave.t00z.wcoast.0p16.f000_2.grib2 test_gdaswave.t00z.wcoast.0p16.f000_2.grib2.idx
../src/grb2index/grb2index 1 test_gdaswave.t00z.wcoast.0p16.f000_2.grib2 test_gdaswave.t00z.wcoast.0p16.f000_2.grib2.idx

# Check against expected output. First 120 bytes contain differences,
# so ignore them.
Expand Down
2 changes: 1 addition & 1 deletion tests/run_ftp_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cmp test_gdaswave.t00z.wcoast.0p16.f000.grib1.inventory.txt data/ref_gdaswave_gr
../src/cnvgrib/cnvgrib -g12 test_WW3_West.grib1 test_WW3_West.grib2

# Create an index of a GRIB2 file.
../src/grb2index/grb2index test_WW3_West.grib2 test_WW3_West.grib2.idx
../src/grb2index/grb2index 1 test_WW3_West.grib2 test_WW3_West.grib2.idx

# Check against expected output. First 120 bytes contain differences,
# so ignore them.
Expand Down
11 changes: 9 additions & 2 deletions tests/run_grb2index_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ echo "*** Running grb2index tests"
[ $? -ne 1 ] && exit 2

# Create an index of a GRIB2 file.
../src/grb2index/grb2index data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.grb2index.idx
../src/grb2index/grb2index 1 data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.grb2index.idx

# Check against expected output. First 120 bytes contain differences,
# Check against expected output. First 140 bytes contain differences,
# so ignore them.
cmp -i 140 test_gdaswave.grb2index.idx data/ref_gdaswave.grb2index.idx

# Create an index of a GRIB2 file.
../src/grb2index/grb2index 2 data/ref_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.grb2index.idx2

# Check against expected output. First 140 bytes contain differences,
# so ignore them.
cmp -i 140 test_gdaswave.grb2index.idx2 data/ref_gdaswave.grb2index.idx2

echo "*** SUCCESS!"
exit 0

0 comments on commit 12c0159

Please sign in to comment.