SailNet Community - Reply to Topic

   Search Sailnet:

 forums  store  


Quick Menu
Forums           
Articles          
Galleries        
Boat Reviews  
Classifieds     
Search SailNet 
Boat Search (new)

Shop the
SailNet Store
Anchor Locker
Boatbuilding & Repair
Charts
Clothing
Electrical
Electronics
Engine
Hatches and Portlights
Interior And Galley
Maintenance
Marine Electronics
Navigation
Other Items
Plumbing and Pumps
Rigging
Safety
Sailing Hardware
Trailer & Watersports
Clearance Items

Advertise Here






Go Back   SailNet Community > Skills and Seamanship > Seamanship & Navigation > Help reading Grib1 Data (win32)
 Not a Member? 

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


Thread: Help reading Grib1 Data (win32) Reply to Thread
Title:
  

By choosing to post the reply below you agree to the rules you agreed to when joining Sailnet.
Click Here to view those rules.

Message:
Trackback:
Send Trackbacks to (Separate multiple URLs with spaces) :
Post Icons
You may choose an icon for your message from the following list:
 

Register Now

In order to be able to post messages on the SailNet Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
Please note: After entering 3 characters a list of Usernames already in use will appear and the list will disappear once a valid Username is entered.
User Name:
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in

Human Verification

In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.



Click here to view the posting rules you are bound to when clicking the
'Submit Reply' button below


Additional Options
Miscellaneous Options

Click here to view the posting rules you are bound to when clicking the
'Submit Reply' button below


Topic Review (Newest First)
01-12-2014 02:26 AM
theonecalledtom
Help reading Grib1 Data (win32)

Hi There,

I'm trying to read Grib1 wind data downloaded from Grib.us. 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!

-Tom

Code:
float GribPower(int s, float n)
**
	float divisor = 1.0;
	while (s < 0)
	**
		divisor /= n;
		s++;
	}
	while (s > 0)
	**
		divisor *= n;
		s--;
	}
	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);
			--iCount;
		}
	}

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

		delete[]mp_Values;
		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;
}

 
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


All times are GMT -4. The time now is 03:30 PM.

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

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