Processing Binary (GRIB) files
Hi,
I am looking to develop a product that reads binary GRIB files (files that contain gridded weather forecast data -http://www.wmo.ch/web/www/WDM/Guides/Guide-binary-2.html) and displays weather data for certain sites around the world
I have been developing in .net for about 3 years (fairly well!) but have no idea of:
1. how to process these binary files
2. extract the correct data
3. how to understand how the data is organised
a description of the files can be found here -http://polar.ncep.noaa.gov/waves/products.html#grib and an exmaple file isftp://polar.ncep.noaa.gov/pub/waves/latest_run/nww3.HTSGW.grb
i have experimented with some code
| |
Dim fsAs System.IO.FileStream = IO.File.OpenRead(Server.MapPath("nww3.HTSGW.grb"))Dim brAs IO.BinaryReader =New IO.BinaryReader(fs)Response.Write(br.ReadInt32() & "<BR>") Response.Write(br.ReadInt32() & "<BR>") Response.Write(br.ReadInt32() & "<BR>") Response.Write(br.ReadInt32() & "<BR>") Response.Write(br.ReadInt32() & "<BR>") Response.Write(br.ReadInt32() & "<BR>") br.Close() fs.Close()
|
but all i get are integers (unsurprisingly!). How do you know which method of decoding to use? and how do you know how the information is organised
any help would be appreciated
thanks
[2602 byte] By [
Tarquin] at [2007-12-17]
I wrote a grib decoding library in Visual Basic 6 (I know VB very well and also code in Delphi) mainly because thats what I had on my machine at the time (and I was told it would not be possible!)
IN reading the grib spec , basically treat each 'octet' as a byte. I am about to port my VB code to c# which I am 'learning' at present. My approach at present is to use a filestream and load into a memorystream to speed things up on large files.
My approach in VB was to write a very simple function to turn each byte into a string of 1,s and 0s as there are a few parts of the grib spec when an individual bit is used as a flag.
The whoel file is made up of lots of individual records which are easily found by looking for the string GRIB (or a similar method) from the postion of these words you can treat the files sequentially to extract the data you need.
The hardest bit was exracting the actual data from the BDS section (where the data is actually packed) as this data can be packed into any number of bits (its a very compact format and the encoder decides the minimum number of bits required for each record). IN VB the approach is to deal with the individual bits as strings which is slow and memory inefficient but it works just fine. I am hoping for substantial improvement in performance in c# .
I then pack everything into OLE safe arrays and the whole thing is called from a variety of other programs as a dll. You pass it a file name and get back an array of arrays containing the extracted data matched with the lat, long grid and timstamps.
If I can be of any more help then please let me know; I am interetsed in developing this application further and would be interested to know your intended use of your code.