Help reading Grib1 Data (win32) - SailNet Community

   Search Sailnet:

 forums  store  

Quick Menu
Boat Reviews  
Search SailNet 
Boat Search (new)

Shop the
SailNet Store
Anchor Locker
Boatbuilding & Repair
Hatches and Portlights
Interior And Galley
Marine Electronics
Other Items
Plumbing and Pumps
Sailing Hardware
Trailer & Watersports
Clearance Items

Advertise Here

Go Back   SailNet Community > Skills and Seamanship > Seamanship & Navigation
 Not a Member? 

Seamanship & Navigation Forum devoted to seamanship and navigation topics, including paper and electronic charting tools.

LinkBack Thread Tools
Old 01-12-2014
Join Date: Jan 2008
Location: Oceanside CA
Posts: 119
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Power: 7
theonecalledtom is on a distinguished road
Help reading Grib1 Data (win32)

Hi There,

I'm trying to read Grib1 wind data downloaded from What I've looked at so far comes through as a simple long/lat grid with 16bit values and a float reference offset.

Only problem is I'm getting the wrong values. They bear some resemblance to the original data with wind patterns recognizable but it looks like I've got the powers or the references wrong I just don't understand how. Final results have the wrong magnitudes / directions.

I didn't intend on writing a decoder but didn't find code / libs I could easily include in a win32 program. So here I am.

Basic decoding of the binary data section is below - any hints or tips or pointers towards someone who can help appreciated!


float GribPower(int s, float n)
	float divisor = 1.0;
	while (s < 0)
		divisor /= n;
	while (s > 0)
		divisor *= n;
	return divisor;

bool Read(HANDLE hFile, int decimalScaleFactor)
	ReadItem(hFile, m_DataSize, 3);									//3
	ReadItem(hFile, m_Byte4.m_AsU8);								//4
	u16 bsf;
	ReadItem(hFile, bsf);											//6
	m_BinaryScaleFactor = bsf & 0x8000 ? -(bsf & ~0x8000) : bsf;
	ReadItem(hFile, m_RefValue);									//10
	ReadItem(hFile, m_NumBitsPerDatumPoint);						//11

	if (m_Byte4.m_Flags & 0x1)
		//Spherical harmonics
		return false;

	m_iNumValues = (m_DataSize - 12) / 2;

	if (m_Byte4.m_NumUnusedBits)
		int iCount = m_Byte4.m_NumUnusedBits / 8;
		while (iCount)
			u8 throwIt;
			ReadItem(hFile, throwIt);

	if (m_iNumValues)
		if (m_NumBitsPerDatumPoint != 16)
			return false;

		mp_Values = new float[m_iNumValues];

		//Y * 10^D = R + (X * 2^E)
		float fScale = GribPower(m_BinaryScaleFactor, 2.0f);
		float fDecimalScale = GribPower(-decimalScaleFactor, 10.0f);
		for (int i = 0; i < m_iNumValues; i++)
			u16 iDatum;
			ReadItem(hFile, iDatum);
			mp_Values[i] = (m_RefValue + (float(iDatum) * fScale)) * fDecimalScale;;
	return true;

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by theonecalledtom; 01-12-2014 at 01:31 AM.
Reply With Quote Share with Facebook

grib1 , programming , win32

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading the tides ltgoshen General Discussion (sailing related) 4 08-13-2012 06:13 PM
How to cruise reading deniseO30 General Discussion (sailing related) 24 07-30-2012 11:20 AM
Reading Charts stevemac00 Seamanship & Navigation 5 06-12-2010 09:14 AM
Reading chart GreatWhite Seamanship & Navigation 11 04-29-2008 01:18 AM

All times are GMT -4. The time now is 01:10 AM.

Add to My Yahoo!         
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.1
(c) LLC 2000-2012

The store is owned and operated by a company independent of the forum. You are now leaving the SailNet forum. Click OK to continue or Cancel to return to the SailNet forum.