Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down