Skip to content

Commit 284c08a

Browse files
authored
Merge pull request #1570 from lesserwhirls/gh-1568
Add tests for GRIB2 PDS 40
2 parents d90cf55 + bc38170 commit 284c08a

3 files changed

Lines changed: 134 additions & 1 deletion

File tree

grib/src/main/java/ucar/nc2/grib/grib2/Grib2Pds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998-2018 John Caron and University Corporation for Atmospheric Research/Unidata
2+
* Copyright (c) 1998-2026 John Caron and University Corporation for Atmospheric Research/Unidata
33
* See LICENSE for license information.
44
*/
55

Binary file not shown.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (c) 2026 University Corporation for Atmospheric Research/Unidata
3+
* See LICENSE for license information.
4+
*/
5+
6+
package ucar.nc2.grib.grib2;
7+
8+
import static com.google.common.truth.Truth.assertThat;
9+
10+
import java.io.IOException;
11+
import java.util.List;
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
import org.junit.runner.RunWith;
15+
import org.junit.runners.JUnit4;
16+
17+
/**
18+
* Test data from github issue https://github.com/Unidata/netcdf-java/pull/1568
19+
* Data was used to create a .gbx9 file for testing.
20+
* <p>
21+
* PDS (Secton 4) output from ecCodes grib_dump at the end of the file, uses as a basis for
22+
* testing PDS (Secton 4) parsing
23+
*/
24+
@RunWith(JUnit4.class)
25+
public class TestPds40 {
26+
27+
private Grib2Pds pds;
28+
29+
@Before
30+
public void openTestFile() throws IOException {
31+
String testfile = "../grib/src/test/data/index/kenda-ch1-202606181100-0-poacsnc-ctrl.grib2.gbx9";
32+
33+
Grib2Index gi = new Grib2Index();
34+
boolean success = gi.readIndex(testfile, -1);
35+
assertThat(success).isTrue();
36+
List<Grib2Record> records = gi.getRecords();
37+
Grib2Record record = records.get(0);
38+
pds = record.getPDS();
39+
}
40+
41+
@Test
42+
public void testPdsBasic() {
43+
assertThat(pds.getRawLength()).isEqualTo(60);
44+
assertThat(pds.getTemplateNumber()).isEqualTo(40);
45+
}
46+
47+
// check overrides
48+
@Test
49+
public void testGenProcessType() {
50+
assertThat(pds.getGenProcessType()).isEqualTo(2);;
51+
}
52+
53+
@Test
54+
public void testBackProcessId() {
55+
assertThat(pds.getBackProcessId()).isEqualTo(0);;
56+
}
57+
58+
@Test
59+
public void testGenProcessId() {
60+
assertThat(pds.getGenProcessId()).isEqualTo(151);;
61+
}
62+
63+
@Test
64+
public void testTimeUnit() {
65+
assertThat(pds.getTimeUnit()).isEqualTo(0);
66+
}
67+
68+
@Test
69+
public void testLevelType1() {
70+
assertThat(pds.getLevelType1()).isEqualTo(150);
71+
}
72+
73+
@Test
74+
public void testLevelScale1() {
75+
assertThat(pds.getLevelScale1()).isEqualTo(0);
76+
}
77+
78+
@Test
79+
public void testLevelValue1() {
80+
assertThat(pds.getLevelValue1()).isEqualTo(80);
81+
}
82+
83+
@Test
84+
public void testLevelType2() {
85+
assertThat(pds.getLevelType2()).isEqualTo(150);
86+
}
87+
88+
@Test
89+
public void testLevelScale2() {
90+
assertThat(pds.getLevelScale2()).isEqualTo(0);
91+
}
92+
93+
@Test
94+
public void testLevelValue2() {
95+
assertThat(pds.getLevelValue2()).isEqualTo(81);
96+
}
97+
98+
@Test
99+
public void testTemplateLength() {
100+
assertThat(pds.templateLength()).isEqualTo(36);
101+
}
102+
}
103+
104+
// grib_dump -O kenda-ch1-202606181100-0-poacsnc-ctrl.grib2
105+
// ***** FILE: kenda-ch1-202606181100-0-poacsnc-ctrl.grib2
106+
// ...
107+
// ====================== SECTION_4 ( length=60, padding=0 ) ======================
108+
// 1-4 section4Length = 60
109+
// 5 numberOfSection = 4
110+
// 6-7 NV = 6
111+
// 8-9 productDefinitionTemplateNumber = 40 [Analysis or forecast at a horizontal level or in a horizontal layer at a
112+
// point in time for atmospheric chemical constituents (grib2/tables/15/4.0.table) ]
113+
// 10 parameterCategory = 20 [Atmospheric chemical constituents (grib2/tables/15/4.1.0.table) ]
114+
// 11 parameterNumber = 60 [Unknown code table entry (grib2/tables/15/4.2.0.20.table) ]
115+
// 12-13 constituentType = 62300 [Unknown code table entry (grib2/tables/15/4.230.table) ]
116+
// 14 typeOfGeneratingProcess = 2 [Forecast (grib2/tables/15/4.3.table) ]
117+
// 15 backgroundProcess = 0
118+
// 16 generatingProcessIdentifier = 151
119+
// 17-18 hoursAfterDataCutoff = 0
120+
// 19 minutesAfterDataCutoff = 0
121+
// 20 indicatorOfUnitForForecastTime = 0 [Minute (grib2/tables/15/4.4.table) ]
122+
// 21-24 forecastTime = 0
123+
// 25 typeOfFirstFixedSurface = 150 [Generalized vertical height coordinate (grib2/tables/15/4.5.table) ]
124+
// 26 scaleFactorOfFirstFixedSurface = 0
125+
// 27-30 scaledValueOfFirstFixedSurface = 80
126+
// 31 typeOfSecondFixedSurface = 150 [Generalized vertical height coordinate (grib2/tables/15/4.5.table) ]
127+
// 32 scaleFactorOfSecondFixedSurface = 0
128+
// 33-36 scaledValueOfSecondFixedSurface = 81
129+
// 37-40 nlev = 81
130+
// 41-44 numberOfVGridUsed = 4
131+
// 45-60 uuidOfVGrid = 16 {
132+
// 6f, a9, e9, b5, 8a, d4, 5b, 2a, 94, 7c, 0e, 86, aa, db, 2d, e0
133+
// } # bytes uuidOfVGrid

0 commit comments

Comments
 (0)