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.4
Read GRIB files in swift
⭐️ 0
🕓 1 week ago
macOS
.package(url: "https://github.com/patrick-zippenfenig/SwiftEccodes.git", from: "0.1.4")

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: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Add itterateMessages function to reduce memory consumption
2 weeks ago

Add itterageMessages function to reduce memory consumption

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