Skip to content

Alexander-Barth/UDUnits.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UDUnits

Build Status codecov.io documentation stable documentation dev

Installation

Inside the Julia shell, you can download and install the package by issuing:

using Pkg
Pkg.add("UDUnits")

Latest development version

If you want to try the latest development version, you can do this with the following commands:

using Pkg
Pkg.add(PackageSpec(url="https://github.com/Alexander-Barth/UDUnits.jl", rev="master"))
Pkg.build("UDUnits")

Loading the module

The first step is to load the module UDUnits and to initialize the unit system sys which correspond to the SI unit system.

using UDUnits
sys = System()

Units

The unit objects can be created for m and cm using either their symbol or their full name by indexing the sys object as if sys is a dictionary.

m = sys["meter"]
cm = sys["cm"]

Similarily to a dictionary, the function haskey is defined to determine if a unit is valid:

haskey(sys,"μm") # returns true since UDUnits knows about micrometers

Derived units

Units can be derived using the usual mathemical operators. Of course, m_per_s could have been also create simply by using sys["m/s"].

m = sys["m"]
km = sys["km"]
s = sys["s"]
h = sys["h"]
m_per_s = m/s
km_per_h = km/h

Converting data

The function areconvertible returns true if two units are convertible:

@show areconvertible(m_per_s,km_per_h)

To convert units, create a converter object and then apply the object to some data.

conv = Converter(m_per_s,km_per_h)
speed_in_m_per_s = 100.
speed_in_km_per_h = conv(speed_in_m_per_s)

The dot syntax can be used for an array as input:

speed_in_m_per_s = [100.,110.,120.]
speed_in_km_per_h = conv.(speed_in_m_per_s)

Alternatives

Resources

About

A Julia interface for UDUnits2 for units of physical quantities

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages