Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit e28bc0c

Browse files
authored
Update README.md
1 parent e2b496a commit e28bc0c

File tree

1 file changed

+193
-2
lines changed

1 file changed

+193
-2
lines changed

README.md

+193-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,193 @@
1-
# THIS REPOSITORY HAS MOVED
2-
https://github.com/GribApiDotNet/GribApi.NET
1+
# GribApi.NET
2+
3+
## What it is
4+
GribApi.NET is a C# wrapper around the [European Centre for Medium Range Weather Forecasting's](http://www.ecmwf.int/) powerful [grib_api](https://software.ecmwf.int/wiki/display/GRIB/Home), a C library for reading, writing, and converting GRIB1 and GRIB2 files.
5+
6+
GRIB is a format commonly used in meteorology to store weather data. GribApi.NET makes it easy to encode and decode these data by providing access to both GRIB editions through a set of [GRIB API keys](https://software.ecmwf.int/wiki/display/GRIB/GRIB%20API%20keys). GribApi.NET and grib_api are licensed under the friendly [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
7+
8+
Special thanks to John L'Heureux, Meteorological Data Analyst at aWhere, Inc., for his contributions as scientific advisor.
9+
10+
#### Features
11+
* Read and write GRIB 1 and 2 messages
12+
* Easy to understand API
13+
* Supports x86, x64, and "All CPU"
14+
* Thread safe
15+
* JPEG and PNG compression support
16+
* Multi-field support
17+
18+
#### GRIB Tools
19+
You can also use grib_api via CLI. Checkout the GRIB tools package on [Chocolatey](https://chocolatey.org/packages/grib-tools). At the very least, you'll find it very helpful for debugging.
20+
21+
--------------------------
22+
23+
## Docs
24+
The documentation is very much a WIP, but you'll find [grib_api's wiki](https://software.ecmwf.int/wiki/display/GRIB/Home), helpful.
25+
26+
* [Key Concepts](https://github.com/0x1mason/GribApi.NET/blob/master/docs/KeyConcepts.md)
27+
* [Example Key Dump](https://github.com/0x1mason/GribApi.NET/blob/master/docs/TypicalKeyDump.md)
28+
29+
--------------------------
30+
31+
## Usage
32+
Make sure you have the [MSVC 2015 redistributables](https://www.microsoft.com/en-us/download/details.aspx?id=48145) installed. If you don't, you can use `chocolatey`,
33+
```shell
34+
C:\> choco install vcredist2015
35+
```
36+
37+
Install [GribApi.NET using Nuget](https://www.nuget.org/packages/Grib.Api). From Package Manager Console run
38+
```shell
39+
PM> Install-Package Grib.Api
40+
```
41+
42+
#### Troubleshooting
43+
In general, GribApi.NET should "just work". In rare cases, GribApi.NET may have difficulty locating the `Grib.Api` directory, which contains a number of dependencies.
44+
45+
To solve this problem, set the environment variable `GRIB_API_DIR_ROOT` before calling GribApi.NET for the first time. The value should be the directory *containing* the `Grib.Api` directory. E.g., for `C:\Some\Path\Grib.Api`, set:
46+
```csharp
47+
Environment.SetEnvironmentVariable("GRIB_API_DIR_ROOT", "C:\\Some\\Path", EnvironmentVariableTarget.Process);
48+
```
49+
50+
### Examples
51+
52+
#### Getting grid information from a GRIB message:
53+
```csharp
54+
using (GribFile file = new GribFile("mygrib.grb"))
55+
{
56+
GribMessage msg = file.First();
57+
58+
Console.WriteLine("Grid Type: " + msg.GridType);
59+
60+
double latInDegrees = msg["latitudeOfFirstGridPoint"].AsDouble();
61+
// GribApi.NET normalizes the coordinate values to degrees. This follows the best practice advised by ECMWF.
62+
63+
// values are also accessible as strings
64+
Console.WriteLine("latitudeOfFirstGridPointInDegrees = " + msg["latitudeOfFirstGridPoint"].AsString());
65+
}
66+
```
67+
68+
#### Iterating multiple messages:
69+
```csharp
70+
using (GribFile file = new GribFile("mygrib.grb"))
71+
{
72+
foreach (GribMessage msg in file)
73+
{
74+
// do something
75+
}
76+
}
77+
```
78+
79+
#### Iterating lat/lon/value:
80+
```csharp
81+
82+
GribMessage msg = gribFile.First();
83+
84+
// the values in GeoSpatialValues are calculated by grid type
85+
foreach (GeoSpatialValue val in msg.GeoSpatialValues)
86+
{
87+
if (val.IsMissing) { continue; }
88+
89+
Console.WriteLine("Lat: {0} Lon: {1} Val: {2}", val.Latitude, val.Longitude, val.Value);
90+
}
91+
```
92+
93+
#### Cherry-picking messages by parameter name
94+
```csharp
95+
using(GribFile file = new GribFile(@".\TestData\Pacific.wind.7days.grb"))
96+
{
97+
var vComp = file.Where(m => m.Name.Contains("V-component of wind m s**-1")).First();
98+
99+
foreach (var val in vComp.GeoSpatialValues)
100+
{
101+
Console.WriteLine("Lat: {0} Lon: {1} Val: {2}", val.Latitude, val.Longitude, val.Value);
102+
}
103+
}
104+
```
105+
106+
#### Key dump:
107+
```csharp
108+
using (GribFile file = new GribFile("mygrib.grb"))
109+
{
110+
GribMessage msg = file.First();
111+
112+
foreach (var msg in file)
113+
{
114+
foreach (var key in msg)
115+
{
116+
Console.WriteLine("Key: {0}, Value: {1}", key.Name, key.Value.AsString());
117+
}
118+
}
119+
}
120+
```
121+
122+
#### Getting raw data:
123+
```csharp
124+
125+
GribMessage msg = gribFile.First();
126+
double[] rawValues;
127+
128+
// a copy of the raw values stored in the message
129+
msg.Values(out rawValues);
130+
```
131+
132+
#### Editing a single message and saving to a new file:
133+
```csharp
134+
string outPath = "out.grb";
135+
string readPath = "some.grb";
136+
137+
using (GribFile readFile = new GribFile(readPath))
138+
{
139+
Console.WriteLine("Writing 1 message from {0} to {1}", readPath, outPath);
140+
141+
var msg = readFile.First();
142+
msg["latitudeOfFirstGridPoint"].AsDouble(42);
143+
GribFile.Write(outPath, msg);
144+
}
145+
```
146+
147+
#### Appending multiple messages to an existing file:
148+
```csharp
149+
using (GribFile readFile = new GribFile(readPath))
150+
{
151+
Console.WriteLine("Appending {0} messages from {1} to {2}", readFile.MessageCount, readPath, outPath);
152+
153+
GribFile.Write(outPath, readFile as IEnumerable<GribMessage>, FileMode.Append);
154+
// or, more simply:
155+
// GribFile.Write(outPath, readFile, FileMode.Append);
156+
}
157+
```
158+
159+
For more examples, checkout the tests.
160+
161+
--------------------------
162+
163+
## Building
164+
The current build is only designed for Windows and Visual Studio. I am eager to get it converted to CMake and make it cross-platform. Even a consistent build using make under msys2 would be great. I'd love some help doing this. :)
165+
166+
First, install the Nuget packages (this assumes you have nuget on PATH):
167+
```shell
168+
nuget install NUnit -Version 2.6.4 -O src\GribApi.NET\packages\
169+
```
170+
171+
Install [NUnit 2.6.4](http://www.nunit.org/). Then run:
172+
```shell
173+
build\build_gribapi.cmd [build|rebuild] [VS version, 11|12|14] [Debug|Release] [nuget package version]
174+
```
175+
176+
E.g., to build with Visual Studio 2013 (VS version 12):
177+
```shell
178+
build\build_gribapi.cmd build 12 Debug
179+
```
180+
181+
### Running SWIG
182+
Most of the interop interfaces are generated using `SWIG` and included in the repository. You shouldn't need to create them. However, if you want to generate the interfaces yourself, you'll need `SWIG` installed and available on PATH. Then run `build/swig_gen.cmd`.
183+
184+
### Running Tests
185+
1. Install [NUnit](http://www.nunit.org/) and expose it on PATH.
186+
2. Run `build/run_tests <architecture> <configuration> [optional "1" to break the tests on start]`, e.g.
187+
```shell
188+
build/run_tests x64 Debug
189+
```
190+
or
191+
```shell
192+
build/run_tests x86 Debug 1
193+
```

0 commit comments

Comments
 (0)