metaf

package module
v0.0.0-...-1e18ef5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 6 Imported by: 0

README

GoMetaf

GoMetaf is a Go wrapper for the metaf C++ library, providing aviation weather report parsing capabilities for METAR and TAF formats in Go applications.

Overview

This library allows you to parse and explain METAR (Meteorological Aerodrome Report) and TAF (Terminal Aerodrome Forecast) reports in your Go applications. It uses SWIG to provide a Go interface to the C++ metaf library.

The project includes a command-line tool explain that demonstrates how to use the library to parse and explain METAR/TAF reports.

Features

  • Parse METAR and TAF reports
  • Get detailed explanations of each group in the report
  • Output explanations in plain text or HTML format
  • Handle standard aviation weather report formats

Installation

Prerequisites
  • Go
  • SWIG 4.0 or higher
  • C++ compiler (gcc, clang)
  • The original metaf C++ library (included for convenience)
Building

The included Makefile handles the building process:

# Clone the repository
git clone https://github.com/akhenakh/gometaf.git
cd gometaf

# Build the project
make

This will:

  1. Compile the C++ metaf library
  2. Generate the SWIG wrapper
  3. Compile the Go wrapper package
  4. Build the explain & metaf example command-line tool

Usage

Command-line Tool

The explain tool demonstrates how to use the library:

# Explain a METAR report
explain -report "METAR KSFO 081656Z 28011KT 10SM FEW013 BKN042 16/09 A3007 RMK AO2 SLP182 T01610094"

As As Code

package main

import (
	"encoding/json"
	"flag"
	"fmt"
	"os"

	metaf "github.com/akhenakh/gometaf"
)

func main() {
	reportStr := flag.String("report", "METAR KLAX 091953Z 25005KT 10SM FEW040 SCT060 BKN120 19/13 A2994 RMK AO2 SLP138 T01890133=", "METAR/TAF report string")
	pretty := flag.Bool("pretty", false, "Pretty-print JSON output")
	flag.Parse()

	if *reportStr == "" {
		fmt.Fprintln(os.Stderr, "Error: -report flag cannot be empty")
		flag.Usage()
		os.Exit(1)
	}

	explanation, err := metaf.ExplainReport(*reportStr)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error explaining report: %v\n", err)
		os.Exit(1)
	}

	var jsonData []byte
	if *pretty {
		jsonData, err = json.MarshalIndent(explanation, "", "  ")
	} else {
		jsonData, err = json.Marshal(explanation)
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error marshaling JSON: %v\n", err)
		os.Exit(1)
	}

	fmt.Println(string(jsonData))
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • This project is based on the metaf C++ library by Nikolai Naumenko
  • The original metaf library is included for convenience

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Swig_escape_always_false bool
View Source
var Swig_escape_val interface{}

Functions

func DeleteMetafResult

func DeleteMetafResult(arg1 MetafResult)

func DeleteStringVector

func DeleteStringVector(arg1 StringVector)

func Swig_free

func Swig_free(arg1 uintptr)

func Swig_malloc

func Swig_malloc(arg1 int) (_swig_ret uintptr)

Types

type GroupExplanation

type GroupExplanation struct {
	RawGroup    string `json:"raw_group"`
	Explanation string `json:"explanation"`
}

GroupExplanation holds the raw group string and its explanation. JSON tags are added for clear serialization.

type MetafResult

type MetafResult interface {
	Swigcptr() uintptr
	SwigIsMetafResult()
	SetReportType(arg2 string)
	GetReportType() (_swig_ret string)
	SetError(arg2 string)
	GetError() (_swig_ret string)
	SetLocation(arg2 string)
	GetLocation() (_swig_ret string)
	SetTimestamp(arg2 string)
	GetTimestamp() (_swig_ret string)
	SetIsSpeci(arg2 bool)
	GetIsSpeci() (_swig_ret bool)
	SetIsAutomated(arg2 bool)
	GetIsAutomated() (_swig_ret bool)
	SetIsNil(arg2 bool)
	GetIsNil() (_swig_ret bool)
	SetIsCancelled(arg2 bool)
	GetIsCancelled() (_swig_ret bool)
	SetIsAmended(arg2 bool)
	GetIsAmended() (_swig_ret bool)
	SetIsCorrectional(arg2 bool)
	GetIsCorrectional() (_swig_ret bool)
	SetRawGroups(arg2 StringVector)
	GetRawGroups() (_swig_ret StringVector)
}

func NewMetafResult

func NewMetafResult() (_swig_ret MetafResult)

func ParseMetaf

func ParseMetaf(arg1 string) (_swig_ret MetafResult)

type ReportExplanation

type ReportExplanation struct {
	ReportType     string             `json:"report_type"`
	Error          string             `json:"error,omitempty"`
	Location       string             `json:"location,omitempty"`
	Timestamp      string             `json:"timestamp,omitempty"`
	IsSpeci        bool               `json:"is_speci,omitempty"`
	IsAutomated    bool               `json:"is_automated,omitempty"`
	IsNil          bool               `json:"is_nil,omitempty"`
	IsCancelled    bool               `json:"is_cancelled,omitempty"`
	IsAmended      bool               `json:"is_amended,omitempty"`
	IsCorrectional bool               `json:"is_correctional,omitempty"`
	Groups         []GroupExplanation `json:"groups"`
}

ReportExplanation holds the full parsed and explained METAR/TAF report. JSON tags are added for clear serialization, using omitempty for optional fields.

func ExplainReport

func ExplainReport(input string) (*ReportExplanation, error)

ExplainReport parses a METAR/TAF string and returns a structured explanation suitable for serialization.

type StringVector

type StringVector interface {
	Swigcptr() uintptr
	SwigIsStringVector()
	Size() (_swig_ret int64)
	Capacity() (_swig_ret int64)
	Reserve(arg2 int64)
	IsEmpty() (_swig_ret bool)
	Clear()
	Add(arg2 string)
	Get(arg2 int) (_swig_ret string)
	Set(arg2 int, arg3 string)
}

func NewStringVector

func NewStringVector(a ...interface{}) StringVector

func NewStringVector__SWIG_0

func NewStringVector__SWIG_0() (_swig_ret StringVector)

func NewStringVector__SWIG_1

func NewStringVector__SWIG_1(arg1 int64) (_swig_ret StringVector)

func NewStringVector__SWIG_2

func NewStringVector__SWIG_2(arg1 StringVector) (_swig_ret StringVector)

type SwigcptrMetafResult

type SwigcptrMetafResult uintptr

func (SwigcptrMetafResult) GetError

func (arg1 SwigcptrMetafResult) GetError() (_swig_ret string)

func (SwigcptrMetafResult) GetIsAmended

func (arg1 SwigcptrMetafResult) GetIsAmended() (_swig_ret bool)

func (SwigcptrMetafResult) GetIsAutomated

func (arg1 SwigcptrMetafResult) GetIsAutomated() (_swig_ret bool)

func (SwigcptrMetafResult) GetIsCancelled

func (arg1 SwigcptrMetafResult) GetIsCancelled() (_swig_ret bool)

func (SwigcptrMetafResult) GetIsCorrectional

func (arg1 SwigcptrMetafResult) GetIsCorrectional() (_swig_ret bool)

func (SwigcptrMetafResult) GetIsNil

func (arg1 SwigcptrMetafResult) GetIsNil() (_swig_ret bool)

func (SwigcptrMetafResult) GetIsSpeci

func (arg1 SwigcptrMetafResult) GetIsSpeci() (_swig_ret bool)

func (SwigcptrMetafResult) GetLocation

func (arg1 SwigcptrMetafResult) GetLocation() (_swig_ret string)

func (SwigcptrMetafResult) GetRawGroups

func (arg1 SwigcptrMetafResult) GetRawGroups() (_swig_ret StringVector)

func (SwigcptrMetafResult) GetReportType

func (arg1 SwigcptrMetafResult) GetReportType() (_swig_ret string)

func (SwigcptrMetafResult) GetTimestamp

func (arg1 SwigcptrMetafResult) GetTimestamp() (_swig_ret string)

func (SwigcptrMetafResult) SetError

func (arg1 SwigcptrMetafResult) SetError(arg2 string)

func (SwigcptrMetafResult) SetIsAmended

func (arg1 SwigcptrMetafResult) SetIsAmended(arg2 bool)

func (SwigcptrMetafResult) SetIsAutomated

func (arg1 SwigcptrMetafResult) SetIsAutomated(arg2 bool)

func (SwigcptrMetafResult) SetIsCancelled

func (arg1 SwigcptrMetafResult) SetIsCancelled(arg2 bool)

func (SwigcptrMetafResult) SetIsCorrectional

func (arg1 SwigcptrMetafResult) SetIsCorrectional(arg2 bool)

func (SwigcptrMetafResult) SetIsNil

func (arg1 SwigcptrMetafResult) SetIsNil(arg2 bool)

func (SwigcptrMetafResult) SetIsSpeci

func (arg1 SwigcptrMetafResult) SetIsSpeci(arg2 bool)

func (SwigcptrMetafResult) SetLocation

func (arg1 SwigcptrMetafResult) SetLocation(arg2 string)

func (SwigcptrMetafResult) SetRawGroups

func (arg1 SwigcptrMetafResult) SetRawGroups(arg2 StringVector)

func (SwigcptrMetafResult) SetReportType

func (arg1 SwigcptrMetafResult) SetReportType(arg2 string)

func (SwigcptrMetafResult) SetTimestamp

func (arg1 SwigcptrMetafResult) SetTimestamp(arg2 string)

func (SwigcptrMetafResult) SwigIsMetafResult

func (p SwigcptrMetafResult) SwigIsMetafResult()

func (SwigcptrMetafResult) Swigcptr

func (p SwigcptrMetafResult) Swigcptr() uintptr

type SwigcptrStringVector

type SwigcptrStringVector uintptr

func (SwigcptrStringVector) Add

func (arg1 SwigcptrStringVector) Add(arg2 string)

func (SwigcptrStringVector) Capacity

func (arg1 SwigcptrStringVector) Capacity() (_swig_ret int64)

func (SwigcptrStringVector) Clear

func (arg1 SwigcptrStringVector) Clear()

func (SwigcptrStringVector) Get

func (arg1 SwigcptrStringVector) Get(arg2 int) (_swig_ret string)

func (SwigcptrStringVector) IsEmpty

func (arg1 SwigcptrStringVector) IsEmpty() (_swig_ret bool)

func (SwigcptrStringVector) Reserve

func (arg1 SwigcptrStringVector) Reserve(arg2 int64)

func (SwigcptrStringVector) Set

func (arg1 SwigcptrStringVector) Set(arg2 int, arg3 string)

func (SwigcptrStringVector) Size

func (arg1 SwigcptrStringVector) Size() (_swig_ret int64)

func (SwigcptrStringVector) SwigIsStringVector

func (p SwigcptrStringVector) SwigIsStringVector()

func (SwigcptrStringVector) Swigcptr

func (p SwigcptrStringVector) Swigcptr() uintptr

Directories

Path Synopsis
cmd
explain command
explainfr command
explainlib command