diff --git a/index.js b/index.js index 1ab5ba9..aad00df 100644 --- a/index.js +++ b/index.js @@ -300,8 +300,18 @@ function parseAllSections(gribBuffer, startIndex) { } const section1 = parseSection1(gribBuffer, section0.startIndex + section0.lengthOfRawData) - const section2 = parseSection2(gribBuffer, section1.startIndex + section1.lengthOfRawData) - const section3 = parseSection3(gribBuffer, section2.startIndex + section2.lengthOfRawData) + + // Check if Section 2 (Local Use Section) is present - it's optional in GRIB2 + let nextPos = section1.startIndex + section1.lengthOfRawData + const nextSectionNumber = gribBuffer[nextPos + 4] + + let section2 = null + if (nextSectionNumber === 2) { + section2 = parseSection2(gribBuffer, nextPos) + nextPos = section2.startIndex + section2.lengthOfRawData + } + + const section3 = parseSection3(gribBuffer, nextPos) const section4 = parseSection4(gribBuffer, section3.startIndex + section3.lengthOfRawData, section1.data.referenceTimestamp) const section5 = parseSection5(gribBuffer, section4.startIndex + section4.lengthOfRawData) const section6 = parseSection6(gribBuffer, section5.startIndex + section5.lengthOfRawData)