------------------------------------------------------------------------------ -- Test specification of H5MD units module. -- Copyright © 2013 Peter Colberg. -- For conditions of distribution and use, see copyright notice in LICENSE. ------------------------------------------------------------------------------ local units = require("units") local system = units.read_xml('udunits-h5md/udunits2.xml') local U = function(s) return system:parse(s) end local N = function(s) return system:get_unit_by_name(s) end -- http://h5md.nongnu.org/modules/units.html print("Starting h5md.lua") assert(U"nm+3" == U"nm" ^ 3) assert(U"um+2 s-1" == (1e-6 * U"m") ^ 2 / U"s") assert(U"60 s" == 60 * U"s") assert(U"10+3 m" == 1000 * U"m") assert(U"m" == N"meter") assert(U"Ang" == N"angstrom") assert(U"L"== N"liter") assert(U"s"== N"second") assert(U"min"== N"minute") assert(U"h"== N"hour") assert(U"Hz"== N"hertz") assert(U"kg"== N"kilogram") assert(U"g"== N"gram") assert(U"u"== N"unified_atomic_mass_unit") assert(U"N"== N"newton") assert(U"dyn" == N"dyne") assert(U"Pa"== N"pascal") assert(U"bar"== N"bar") assert(U"atm"== N"atmosphere") assert(U"poise" == N"poise") assert(U"J"== N"joule") assert(U"cal"== N"calorie") assert(U"erg"== N"erg") assert(U"eV"== N"electron_volt") assert(U"W"== N"watt") assert(U"K"== N"kelvin") assert(U"mol"== N"mole") assert(U"A"== N"ampere") -- assert(U"C"== N"coulomb") assert(U"V"== N"volt") assert(U"cd"== N"candela") assert(U"rad"== N"radian") assert(U"degree" == N"degree") assert(U"pi" == N"pi") U"kB" U"Nav" U"c" U"e" assert(U"Em" == U"10¹⁸ m") assert(U"Pm" == U"10¹⁵ m") assert(U"Tm" == U"10¹² m") assert(U"Gm" == U"10⁹ m") assert(U"Mm" == U"10⁶ m") assert(U"km" == U"10³ m") assert(U"hm" == U"10² m") assert(U"dam" == U"10¹ m") assert(U"dm" == U"10⁻¹ m") assert(U"cm" == U"10⁻² m") assert(U"mm" == U"10⁻³ m") assert(U"um" == U"10⁻⁶ m") assert(U"nm" == U"10⁻⁹ m") assert(U"pm" == U"10⁻¹² m") assert(U"fm" == U"10⁻¹⁵ m") assert(U"am" == U"10⁻¹⁸ m") print("h5md.lua done")