A .NET library to decode TAF (Terminal Aerodrome Forecast) strings, fully unit tested (100% code coverage)
This is largely based on SafranCassiopee/php-taf-decoder
They use csharp-taf-decoder in production:
- Safran AGS (private)
- Your service here ? Submit a pull request or open an issue !
This piece of software is a library package that provides a parser to decode raw TAF messages.
TAF is a format made for weather information forecast. It is predominantly used by in aviation, during flight preparation. Raw TAF format is highly standardized through the International Civil Aviation Organization (ICAO).
This library package only requires .NET >= 4.5
It is currently tested automatically for .NET >= 4.5 using nUnit 3.9.0.
Although this is provided as a library project, a command line version (StartTafDecoder) is also included that can be used as both an example and a starting point. StartTafDecoder requires CommandLineParser.
Usage:
StartTafDecoder.exe --TAF "TAF LEMD 080500Z 0806/0912 23010KT 9999 SCT025 TX12/0816Z TN04/0807Z"
If you want to integrate the library easily in your project, you should consider using the official nuget package available from https://www.nuget.org/.
nuget install csharp-taf-decoder
It is not mandatory though.
- With nuget.exe (recommended)
From the Package Manager Console in Visual Studio
nuget install csharp-taf-decoder
Add a reference to the library, then add the following using directives:
using csharp_taf_decoder;
using csharp_taf_decoder.entity;
- By hand
Download the latest release from github
Extract it wherever you want in your project. The library itself is in the csharp-taf-decoder/ directory, the other directories are not mandatory for the library to work.
Add the csharp-taf-decoder project to your solution, then add a reference to it in your own project. Finally, add the same using directives than above.
Instantiate the decoder and launch it on a TAF string. The returned object is a DecodedTAF object from which you can retrieve all the weather properties that have been decoded.
All values who have a unit are based on the Value
object which provides the ActualValue and ActualUnit properties
Please check the DecodedTAF class for the structure of the resulting object
var d = TAFDecoder.ParseWithMode("TAF LEMD 080500Z 0806/0912 23010KT 9999 SCT025 TX12/0816Z TN04/0807Z");
(TODO)
In the example above, it is assumed that all requested parameters are available. In the real world, some fields are not mandatory thus it is important to check that the Value object (containing both the value and its unit) is not null before using it. What you do in case it's null is totally up to you.
Here is an example:
(TODO)
Value objects also contain their unit, that you can access with the ActualUnit
property. When you access the ActualValue
property, you'll get the value in this unit.
If you want to get the value directly in another unit you can call GetConvertedValue(unit)
. Supported values are speed, distance and pressure.
Here are all available units for conversion:
// speed units:
// Value.Unit.MeterPerSecond
// Value.Unit.KilometerPerHour
// Value.Unit.Knot
// distance units:
// Value.Unit.Meter
// Value.Unit.Feet
// Value.Unit.StatuteMile
// pressure units:
// Value.Unit.HectoPascal
// Value.Unit.MercuryInch
// use on-the-fly conversion
var distance_in_sm = visibility.GetConvertedValue(Value.Unit.StatuteMile);
var speed_kph = speed.GetConvertedValue(Value.Unit.KilometerPerHour);
When an unexpected format is encountered for a part of the TAF, the parsing error is logged into the DecodedTaf object itself.
All parsing errors for one TAF can be accessed through the DecodingExceptions
property.
By default parsing will continue when a bad format is encountered. But the parser also provides a "strict" mode where parsing stops as soon as an error occurs. The mode can be set globally for a TafDecoder object, or just once as you can see in this example:
var decoder = new TAFDecoder();
(TODO)
(TODO)
If you find a valid TAF that is badly parsed by this library, please open a github issue with all possible details:
- the full TAF causing problem
- the parsing exception returned by the library
- how you expected the decoder to behave
- anything to support your proposal (links to official websites appreciated)
If you want to improve or enrich the test suite, fork the repository and submit your changes with a pull request.
If you have any other idea to improve the library, please use github issues or directly pull requests depending on what you're more comfortable with.
In order to contribute to the codebase, you must fork the repository on github, than clone it locally with:
git clone https://github.com/<username>/csharp-taf-decoder
Install all the dependencies using nuget :
nuget restore csharp-taf-decoder\
You're ready to launch the test suite with:
nunit-console.exe /xml:results.xml csharp-taf-decoder-tests\bin\debug\csharp-taf-decoder-tests.dll
This library is fully unit tested, and uses nUnit to launch the tests.
Travis CI is used for continuous integration, which triggers tests for .NET 4.5 for each push to the repo.