Skip to content

SI Units support #166

Open
Open

Description

@jbfaden

Chris showed me that the C Das2 library supports SI units, where it knows "1 meter" divided by "1 second" is "1 meter/second". I've got code in the Das2Datum library that does this, and I should make sure it considers what Chris is supporting in the C library. For example, he has a parser and I should support strings formatted and parsed with that code. See https://github.com/das-developers/das2C/blob/master/test/TestUnits.c

Activity

  1. cpiker commented on Feb 24, 2026

    @cpiker
    Member

    It a tangent, but a companion issue has been opened in das2C to add support for offset units: das-developers/das2C#19 .

  2. cpiker commented on Feb 24, 2026

    @cpiker
    Member

    The units module in das2C was originally written to support the das2_psd utility. I wanted the units on the resulting spectrograms to be correct without human intervention but didn't want special case code in das2_psd, thus a generalized units module was written.

    The code in units.c consists of six sections:

    1. SI Prefix handling, both as symbols and names, i.e: micro and μ
    2. SI Unit handling, both as symbols and names, i.e.: ohms and Ω
    3. Mathematical operations: i.e. div( "meters", "second") => "m s**-1"
    4. Reduction, i.e. "m/s" * "s" -> "m"
    5. Conversion: ratio = convert(1.0, "meters/sec", "km/day")
    6. Singleton assignment

    The fundamental assumption on all the parsing code is that units strings are encoded as UTF-8, period. There is no handling of any other encodings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions