Unverified Commit c2a182e9 authored by Miroslav Kratochvil's avatar Miroslav Kratochvil Committed by GitHub
Browse files

Merge pull request #145 from giordano/mg/fix-units

Fix definition of units
parents 8f87883a 04b8ef81
...@@ -239,17 +239,22 @@ const UNIT_KIND_STRINGS_TO_UNIT = Dict( ...@@ -239,17 +239,22 @@ const UNIT_KIND_STRINGS_TO_UNIT = Dict(
) )
# Get a `Unitful` quantity out of a `Unit_t`. # Get a `Unitful` quantity out of a `Unit_t`.
get_unit(u::VPtr) = function get_unit(u::VPtr)
UNIT_KIND_STRINGS_TO_UNIT[unsafe_string( multiplier = ccall(sbml(:Unit_getMultiplier), Cdouble, (VPtr,), u)
unit = UNIT_KIND_STRINGS_TO_UNIT[unsafe_string(
ccall( ccall(
sbml(:UnitKind_toString), sbml(:UnitKind_toString),
Cstring, Cstring,
(Cint,), (Cint,),
ccall(sbml(:Unit_getKind), Cint, (VPtr,), u), ccall(sbml(:Unit_getKind), Cint, (VPtr,), u),
), ),
)]^ccall(sbml(:Unit_getExponent), Cint, (VPtr,), u) * )]
exp10(ccall(sbml(:Unit_getScale), Cint, (VPtr,), u)) * scale = ccall(sbml(:Unit_getScale), Cint, (VPtr,), u)
ccall(sbml(:Unit_getMultiplier), Cdouble, (VPtr,), u) exponent = ccall(sbml(:Unit_getExponent), Cint, (VPtr,), u)
# See page 44 of
# http://sbml.org/Special/specifications/sbml-level-3/version-2/core/release-2/sbml-level-3-version-2-release-2-core.pdf
return (multiplier * unit * exp10(scale)) ^ exponent
end
# Get `Unitful` quantity out of a `UnitDefinition_t`. # Get `Unitful` quantity out of a `UnitDefinition_t`.
get_units(ud::VPtr) = prod( get_units(ud::VPtr) = prod(
......
...@@ -22,7 +22,7 @@ end ...@@ -22,7 +22,7 @@ end
sbmlfile * ".does.not.really.exist", sbmlfile * ".does.not.really.exist",
) )
@test mdl.units["mmol_per_gDW_per_hr"] == 2.7777e-7 * u"mol * g^-1 * s^-1" @test mdl.units["mmol_per_gDW_per_hr"] 3.6001008028224795 * u"mol * g^-1 * s^-1"
@test length(mdl.compartments) == 2 @test length(mdl.compartments) == 2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment