Swiftpack.co - patrick-zippenfenig/SwiftEccodes as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by patrick-zippenfenig.
patrick-zippenfenig/SwiftEccodes 0.1.6
Read GRIB files in swift
⭐️ 2
🕓 2 weeks ago
macOS
.package(url: "https://github.com/patrick-zippenfenig/SwiftEccodes.git", from: "0.1.6")

SwiftEccodes

A very basic library to read GRIB files in Swift. This library is a wrapper for eccodes.

WARNING: No stable interface declared yet

Usage

Install eccodes via brew install eccodes or apt install libeccodes-dev

Add SwiftEccodes as a dependency to your Package.swift

  dependencies: [
    .package(url: "https://github.com/patrick-zippenfenig/SwiftEccodes.git", from: "0.0.0")
  ],
  targets: [
    .target(name: "MyApp", dependencies: [
      .product(name: "SwiftEccodes", package: "SwiftEccodes"),
    ])
  ]

Read GRIB messages and data from files:

import SwiftEccodes

let messages = try SwiftEccodes.getMessages(fileName: "test.grib", multiSupport: true)
for message in messages {
    message.iterate(namespace: .ls).forEach({
        print($0)
    })
    print(message.get(attribute: "name")!)
    let data = try message.getDouble()
    print(data[0..<10])
}

Or read directly from memory:

import SwiftEccodes

let data = try Data(contentsOf: URL(fileURLWithPath: "test.grib"))
try data.withUnsafeBytes { ptr in
    let messages = try SwiftEccodes.getMessages(memory: ptr, multiSupport: true)
    for message in messages {
        message.iterate(namespace: .ls).forEach({
            print($0)
        })
        message.iterate(namespace: .geography).forEach({
            print($0)
        })
        print(message.get(attribute: "name")!)
        let data = try message.getDouble()
        print(data.count)
        print(data[0..<10])
    }
}

GitHub

link
Stars: 2
Last commit: 2 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Fix concurrent access to `grib_context`
2 weeks ago

If multiple files at the same time are opened, it may result in double free internally in eccodes. An additional lock, prevents concurrent access to grib_context

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics