antha: github.com/antha-lang/antha/antha/anthalib/wunit Index | Files

package wunit

import "github.com/antha-lang/antha/antha/anthalib/wunit"

Package wunit is a core Antha package for dealing with units in Antha

Core Antha package for dealing with units in Antha

Index

Package Files

axis.go conversion.go parse.go serialize.go siprefix.go sort.go systemunits.go unit.go unitfromstring.go unitregistry.go wdimension.go wunit.go

Variables

var (
    Yocto = newPrefix("y", "yocto", 1e-24)
    Zepto = newPrefix("z", "zepto", 1e-21)
    Atto  = newPrefix("a", "atto", 1e-18)
    Femto = newPrefix("f", "femto", 1e-15)
    Pico  = newPrefix("p", "pico", 1e-12)
    Nano  = newPrefix("n", "nano", 1e-9)
    Micro = newPrefix("u", "micro", 1e-6)
    Milli = newPrefix("m", "milli", 1e-3)
    Centi = newPrefix("c", "centi", 1e-2)
    Deci  = newPrefix("d", "deci", 1e-1)
    Deca  = newPrefix("da", "deca", 1e1)
    Hecto = newPrefix("h", "hecto", 1e2)
    Kilo  = newPrefix("k", "kilo", 1e3)
    Mega  = newPrefix("M", "mega", 1e6)
    Giga  = newPrefix("G", "giga", 1e9)
    Tera  = newPrefix("T", "tera", 1e12)
    Peta  = newPrefix("P", "peta", 1e15)
    Exa   = newPrefix("E", "exa", 1e18)
    Zetta = newPrefix("Z", "zetta", 1e21)
    Yotta = newPrefix("Y", "yotta", 1e24)
    None  = SIPrefix{Symbol: "", Name: "", Value: 1.0} // not a valid SIPrefix, hence not in SIPrefixes, but used for non-prefixed units
)
var SIPrefixes []SIPrefix

SIPrefixes a list containing all valid SI prefixes

func DivideConcentrations Uses

func DivideConcentrations(num, den Concentration) (float64, error)

DivideConcentrations divides the SI Value of conc1 by conc2 to return a factor. An error is returned if the concentration unit is not dividable or the number generated is infinity.

func DivideVolumes Uses

func DivideVolumes(vol1, vol2 Volume) (float64, error)

DivideVolumes divides the SI Value of vol1 by vol2 to return a factor. An error is returned if the volume is infinity or not a number.

func SIPrefixSymbols Uses

func SIPrefixSymbols() []string

SIPrefixSymbols returns a list of all supported SI prefixes

func SplitValueAndUnit Uses

func SplitValueAndUnit(str string) (float64, string)

SplitValueAndUnit splits a joined value and unit in string format into seperate typed value and unit fields. If the string input is not in the valid format of value followed by unit it will not be parsed correctly. If a value on its own is given the unit will be returned blank, if the unit is given alone the value will be 0.0 valid: 10s, 10 s, 10.5s, 2.16e+04 s, 10, s invalid: s 10 s10

type Angle Uses

type Angle struct {
    *ConcreteMeasurement
}

angle

func NewAngle Uses

func NewAngle(v float64, unit string) Angle

generate a new angle unit

func (Angle) MarshalJSON Uses

func (m Angle) MarshalJSON() ([]byte, error)

func (*Angle) UnmarshalJSON Uses

func (m *Angle) UnmarshalJSON(b []byte) error

type AngularVelocity Uses

type AngularVelocity struct {
    *ConcreteMeasurement
}

func NewAngularVelocity Uses

func NewAngularVelocity(v float64, unit string) AngularVelocity

type Area Uses

type Area struct {
    *ConcreteMeasurement
}

area

func NewArea Uses

func NewArea(v float64, unit string) Area

make an area unit

func ZeroArea Uses

func ZeroArea() Area

func (Area) MarshalJSON Uses

func (m Area) MarshalJSON() ([]byte, error)

func (*Area) UnmarshalJSON Uses

func (m *Area) UnmarshalJSON(b []byte) error

type Axis Uses

type Axis int

Axis represent a particular direction

const (
    XAxis Axis = iota
    YAxis
    ZAxis
)

func AxisFromString Uses

func AxisFromString(a string) (Axis, error)

AxisFromString return the relevant axis from the string which should be "X", "Y", or "Z" (or lowercase), otherwise returns an invalid axis and an error

func (Axis) String Uses

func (a Axis) String() string

String return the name of the axis

type Concentration Uses

type Concentration struct {
    *ConcreteMeasurement
}

defines a concentration unit

func AddConcentrations Uses

func AddConcentrations(concs ...Concentration) (Concentration, error)

AddConcentrations adds a variable number of concentrations from an original concentration. An error is returned if the concentration units are incompatible.

func CopyConcentration Uses

func CopyConcentration(v Concentration) Concentration

func DivideConcentration Uses

func DivideConcentration(v Concentration, factor float64) (newconc Concentration)

DivideConcentration divides a concentration by a factor.

func MaxConcentration Uses

func MaxConcentration(concs []Concentration) (max Concentration, err error)

MaxConcentration returns the highest concentration value from a set of concentration values. An error will be returned if no values are specified or the base units of any of the concentrations are incompatible, e.g. units of X and g/l would not be compatible.

func MinConcentration Uses

func MinConcentration(concs []Concentration) (min Concentration, err error)

MinConcentration returns the lowest concentration value from a set of concentration values. An error will be returned if no values are specified or the base units of any of the concentrations are incompatible, e.g. units of X and g/l would not be compatible.

func MultiplyConcentration Uses

func MultiplyConcentration(v Concentration, factor float64) (newconc Concentration)

MultiplyConcentration multiplies a concentration by a factor.

func NewConcentration Uses

func NewConcentration(v float64, unit string) Concentration

NewConcentration makes a new concentration in SI units... either M/l or kg/l

func ParseConcentration Uses

func ParseConcentration(s string) (bool, Concentration, string)

ParseConcentration utility to extract concentration and component name from a string. Valid inputs include

- "6M Glucose", "6 M Glucose"
- "Glucose 6 M", "Glucose 6M"
- "Glucose (M)", "Glucose M", "Glucose (6 M)"
- "Glucose"

returns three values - a boolean which is true if the value of the concentration was set, the parsed concentration, and the remaining component name. if removing the concentration would leave the empty string, the component name is set as the input string

func SortConcentrations Uses

func SortConcentrations(concs []Concentration) (sorted []Concentration, err error)

SortConcentrations sorts a set of Concentration values. An error will be returned if no values are specified or the base units of any of the concentrations are incompatible, e.g. units of X and g/l would not be compatible.

func SubtractConcentrations Uses

func SubtractConcentrations(originalConc Concentration, subtractConcs ...Concentration) (Concentration, error)

SubtractConcentrations substracts a variable number of concentrations from an original concentration. An error is returned if the concentration units are incompatible.

func (Concentration) Dup Uses

func (c Concentration) Dup() Concentration

Dup deprecated, please use CopyConcentration

func (Concentration) GramPerL Uses

func (conc Concentration) GramPerL(molecularWeight float64) Concentration

GramPerL deprecated, please use GramsPerLitre

func (Concentration) GramsPerLitre Uses

func (conc Concentration) GramsPerLitre(molecularweight float64) (Concentration, error)

GramsPerLitre return a new concentration equal to the current one in grams per litre, using molecularweight given in grams per mole to convert if necessary. Returns an error if the units of conc are not compatible with grams per litre or grams per mole (such as "X" or "v/v")

func (Concentration) MarshalJSON Uses

func (m Concentration) MarshalJSON() ([]byte, error)

func (Concentration) MolPerL Uses

func (conc Concentration) MolPerL(molecularWeight float64) Concentration

MolPerL deprecated, please use MolesPerLitre

func (Concentration) MolesPerLitre Uses

func (conc Concentration) MolesPerLitre(molecularweight float64) (Concentration, error)

MolesPerLitre return a new concentration equal to the current one in mols per litre, using molecularweight given in grams per mole to convert if necessary. Returns an error if the units of conc are not compatible with grams per litre or grams per mole (such as "X" or "v/v")

func (*Concentration) UnmarshalJSON Uses

func (m *Concentration) UnmarshalJSON(b []byte) error

type ConcreteMeasurement Uses

type ConcreteMeasurement struct {
    // the raw value
    Mvalue float64
    // the relevant units
    Munit *Unit
}

structure implementing the Measurement interface

func NewMeasurement Uses

func NewMeasurement(v float64, pu string) *ConcreteMeasurement

func NewTypedMeasurement Uses

func NewTypedMeasurement(measurementType string, value float64, unit string) *ConcreteMeasurement

NewTypedMeasurement create a new measurement from the global registry asserting that the supplied units match the given type, and calling panic() if not

func (*ConcreteMeasurement) Add Uses

func (cm *ConcreteMeasurement) Add(m Measurement)

Add deprecated, please use IncrBy

func (*ConcreteMeasurement) ConvertToString Uses

func (cm *ConcreteMeasurement) ConvertToString(s string) float64

ConvertToString deprecated, please use InStringUnit

func (*ConcreteMeasurement) DecrBy Uses

func (cm *ConcreteMeasurement) DecrBy(m Measurement) error

DecrBy subtract m from the receiver

func (*ConcreteMeasurement) DivideBy Uses

func (cm *ConcreteMeasurement) DivideBy(factor float64)

func (*ConcreteMeasurement) EqualTo Uses

func (cm *ConcreteMeasurement) EqualTo(m Measurement) bool

XXX This should be made more literal and rounded behaviour explicitly called for by user

func (*ConcreteMeasurement) EqualToRounded Uses

func (cm *ConcreteMeasurement) EqualToRounded(m Measurement, p int) bool

func (*ConcreteMeasurement) EqualToTolerance Uses

func (cm *ConcreteMeasurement) EqualToTolerance(m Measurement, tol float64) bool

EqualToTolerance return true if the two measurements are within a small tolerace, tol, of each other where tol is expressed in the same units as the receiver

func (*ConcreteMeasurement) GreaterThan Uses

func (cm *ConcreteMeasurement) GreaterThan(m Measurement) bool

func (*ConcreteMeasurement) GreaterThanRounded Uses

func (cm *ConcreteMeasurement) GreaterThanRounded(m Measurement, p int) bool

func (*ConcreteMeasurement) InStringUnit Uses

func (cm *ConcreteMeasurement) InStringUnit(symbol string) (Measurement, error)

InStringUnit return a new measurement in the new units

func (*ConcreteMeasurement) InUnit Uses

func (cm *ConcreteMeasurement) InUnit(p PrefixedUnit) (Measurement, error)

ConvertTo return a new measurement in the new units

func (*ConcreteMeasurement) IncrBy Uses

func (cm *ConcreteMeasurement) IncrBy(m Measurement) error

IncrBy add the measurement m to the receiver

func (*ConcreteMeasurement) IsNegative Uses

func (cm *ConcreteMeasurement) IsNegative() bool

IsNegative true if the measurement is negative by more than a very small delta

func (*ConcreteMeasurement) IsNil Uses

func (cm *ConcreteMeasurement) IsNil() bool

func (*ConcreteMeasurement) IsPositive Uses

func (cm *ConcreteMeasurement) IsPositive() bool

IsPositive true if the measurement is positive by more than a very small delta

func (*ConcreteMeasurement) IsZero Uses

func (cm *ConcreteMeasurement) IsZero() bool

func (*ConcreteMeasurement) LessThan Uses

func (cm *ConcreteMeasurement) LessThan(m Measurement) bool

func (*ConcreteMeasurement) LessThanRounded Uses

func (cm *ConcreteMeasurement) LessThanRounded(m Measurement, p int) bool

func (*ConcreteMeasurement) MultiplyBy Uses

func (cm *ConcreteMeasurement) MultiplyBy(factor float64)

multiply

func (*ConcreteMeasurement) MustInStringUnit Uses

func (cm *ConcreteMeasurement) MustInStringUnit(symbol string) Measurement

MustInStringUnit return a new measurement in the new units

func (*ConcreteMeasurement) MustInUnit Uses

func (cm *ConcreteMeasurement) MustInUnit(p PrefixedUnit) Measurement

MustInUnit convert to the given unit, calls panic() if the units are not compatible

func (*ConcreteMeasurement) RawValue Uses

func (cm *ConcreteMeasurement) RawValue() float64

value without conversion

func (*ConcreteMeasurement) SIValue Uses

func (cm *ConcreteMeasurement) SIValue() float64

value when converted to SI units

func (*ConcreteMeasurement) SetValue Uses

func (cm *ConcreteMeasurement) SetValue(v float64) float64

set the value of this measurement

func (*ConcreteMeasurement) String Uses

func (cm *ConcreteMeasurement) String() string

String will return a summary of the ConcreteMeasurement Value and prefixed unit as a string. The value will be formatted in scientific notation for large exponents and the value unbounded. The Summary() method should be used to return a rounded string.

func (*ConcreteMeasurement) Subtract Uses

func (cm *ConcreteMeasurement) Subtract(m Measurement)

Subtract deprecated, please use DecrBy

func (*ConcreteMeasurement) ToString Uses

func (cm *ConcreteMeasurement) ToString() string

ToString will return a summary of the ConcreteMeasurement Value and prefixed unit as a string. The value will be formatted in scientific notation for large exponents and will be bounded to 3 decimal places. The String() method should be used to use the unbounded value.

func (*ConcreteMeasurement) Unit Uses

func (cm *ConcreteMeasurement) Unit() PrefixedUnit

get unit with prefix

type Density Uses

type Density struct {
    *ConcreteMeasurement
}

a structure which defines a density

func NewDensity Uses

func NewDensity(v float64, unit string) Density

make a new density structure in SI units

func (Density) MarshalJSON Uses

func (m Density) MarshalJSON() ([]byte, error)

func (*Density) UnmarshalJSON Uses

func (m *Density) UnmarshalJSON(b []byte) error

type Energy Uses

type Energy struct {
    *ConcreteMeasurement
}

this is really Mass Length/Time^2

func NewEnergy Uses

func NewEnergy(v float64, unit string) Energy

make a new energy unit

func (Energy) MarshalJSON Uses

func (m Energy) MarshalJSON() ([]byte, error)

func (*Energy) UnmarshalJSON Uses

func (m *Energy) UnmarshalJSON(b []byte) error

type FlowRate Uses

type FlowRate struct {
    *ConcreteMeasurement
}

func NewFlowRate Uses

func NewFlowRate(v float64, unit string) FlowRate

func (FlowRate) MarshalJSON Uses

func (m FlowRate) MarshalJSON() ([]byte, error)

func (*FlowRate) UnmarshalJSON Uses

func (m *FlowRate) UnmarshalJSON(b []byte) error

type Force Uses

type Force struct {
    *ConcreteMeasurement
}

a Force

func NewForce Uses

func NewForce(v float64, unit string) Force

a new force in Newtons

func (Force) MarshalJSON Uses

func (m Force) MarshalJSON() ([]byte, error)

func (*Force) UnmarshalJSON Uses

func (m *Force) UnmarshalJSON(b []byte) error

type Length Uses

type Length struct {
    *ConcreteMeasurement
}

length

func NewLength Uses

func NewLength(v float64, unit string) Length

make a length

func ZeroLength Uses

func ZeroLength() Length

func (Length) MarshalJSON Uses

func (m Length) MarshalJSON() ([]byte, error)

func (*Length) UnmarshalJSON Uses

func (m *Length) UnmarshalJSON(b []byte) error

type Mass Uses

type Mass struct {
    *ConcreteMeasurement
}

mass

func MassForTargetConcentration Uses

func MassForTargetConcentration(targetConc Concentration, totalVol Volume) (Mass, error)

MassForTargetConcentration multiplies a concentration (in g/l) by a volume (in l) to return the mass (in g). if a concentration is not in a form convertable to g/l an error is returned.

func NewMass Uses

func NewMass(v float64, unit string) Mass

func VolumeToMass Uses

func VolumeToMass(v Volume, d Density) (Mass, error)

VolumeToMass multiplies a volume (in L) by a density (in kg/m^3) and returns the mass (in kg).

func VolumetoMass Uses

func VolumetoMass(v Volume, d Density) Mass

VolumetoMass deprecated, pelase use VolumeToMass

func (Mass) MarshalJSON Uses

func (m Mass) MarshalJSON() ([]byte, error)

func (*Mass) Quantity Uses

func (m *Mass) Quantity() Measurement

defines mass to be a SubstanceQuantity

func (*Mass) UnmarshalJSON Uses

func (m *Mass) UnmarshalJSON(b []byte) error

type Measurement Uses

type Measurement interface {
    // the value in base SI units
    SIValue() float64
    // the value in the current units
    RawValue() float64
    // unit plus prefix
    Unit() PrefixedUnit
    // set the value, this must be thread-safe
    // returns old value
    SetValue(v float64) float64
    // InUnit get a new Measurement with the new units, returns error if units are not compatible
    InUnit(p PrefixedUnit) (Measurement, error)
    // InStringUnit wrapper for InUnit which fetches the unit from the global UnitRegistry
    InStringUnit(symbol string) (Measurement, error)
    // MustInUnit get a new Measurement with the new units, equivalent to InUnit except calls panic() if units are not compatible
    MustInUnit(p PrefixedUnit) Measurement
    // MustInStringUnit wrapper for InUnit which fetches the unit from the global UnitRegistry,
    // equivalent to InStringUnit but calls panic() if units are incompatible
    MustInStringUnit(symbol string) Measurement
    // ConvertToString deprecated, please use ConvertTo or InStringUnit
    ConvertToString(s string) float64
    // IncrBy add to this measurement
    IncrBy(m Measurement) error
    // DecrBy subtract from this measurement
    DecrBy(m Measurement) error
    // Add deprecated, please use IncrBy
    Add(m Measurement)
    // Subtract deprecated, please use DecrBy
    Subtract(m Measurement)
    // multiply measurement by a factor
    MultiplyBy(factor float64)
    // divide measurement by a factor
    DivideBy(factor float64)
    // comparison operators
    LessThan(m Measurement) bool
    GreaterThan(m Measurement) bool
    EqualTo(m Measurement) bool

    // A nice string representation
    ToString() string
}

fundamental representation of a value in the system

type Moles Uses

type Moles struct {
    *ConcreteMeasurement
}

mole

func NewAmount Uses

func NewAmount(v float64, unit string) Moles

generate a new Amount in moles

func NewMoles Uses

func NewMoles(v float64, unit string) Moles

generate a new Amount in moles

func (Moles) MarshalJSON Uses

func (m Moles) MarshalJSON() ([]byte, error)

func (*Moles) Quantity Uses

func (a *Moles) Quantity() Measurement

defines Moles to be a SubstanceQuantity

func (*Moles) UnmarshalJSON Uses

func (m *Moles) UnmarshalJSON(b []byte) error

type PrefixedUnit Uses

type PrefixedUnit interface {
    // Name get the full name of the unit
    Name() string
    // String return a string including the long name of the unit, its prefix, and symbol, e.g. "miligrams[mg]"
    String() string
    // Prefix get the SI prefix associated with the unit, or None if none, e.g. Mili
    Prefix() SIPrefix
    // PrefixedSymbol get the symbol including any prefix, e.g. "mg"
    PrefixedSymbol() string
    // RawSymbol the unit symbol excluding any prefix, e.g. "g"
    RawSymbol() string
    // BaseSISymbol returns the symbol of the appropriate unit if we ask for SI values, e.g. "kg"
    BaseSISymbol() string
}

PrefixedUnit a unit with an SI prefix

type Pressure Uses

type Pressure struct {
    *ConcreteMeasurement
}

a Pressure structure

func NewPressure Uses

func NewPressure(v float64, unit string) Pressure

make a new pressure in Pascals

func (Pressure) MarshalJSON Uses

func (m Pressure) MarshalJSON() ([]byte, error)

func (*Pressure) UnmarshalJSON Uses

func (m *Pressure) UnmarshalJSON(b []byte) error

type Rate Uses

type Rate struct {
    *ConcreteMeasurement
}

func NewRate Uses

func NewRate(v float64, unit string) (r Rate, err error)

func (Rate) MarshalJSON Uses

func (m Rate) MarshalJSON() ([]byte, error)

func (*Rate) UnmarshalJSON Uses

func (m *Rate) UnmarshalJSON(b []byte) error

type SIPrefix Uses

type SIPrefix struct {
    Symbol string  // short version of the prefix
    Name   string  // long name of the prefix
    Value  float64 // multiplier that the exponent applies to the value
}

SIPrefix

type SpecificHeatCapacity Uses

type SpecificHeatCapacity struct {
    *ConcreteMeasurement
}

a structure which defines a specific heat capacity

func NewSpecificHeatCapacity Uses

func NewSpecificHeatCapacity(v float64, unit string) SpecificHeatCapacity

make a new specific heat capacity structure in SI units

type SubstanceQuantity Uses

type SubstanceQuantity interface {
    Quantity() Measurement
}

mass or mole

type Temperature Uses

type Temperature struct {
    *ConcreteMeasurement
}

temperature

func NewTemperature Uses

func NewTemperature(v float64, unit string) Temperature

make a temperature

func (Temperature) MarshalJSON Uses

func (m Temperature) MarshalJSON() ([]byte, error)

func (*Temperature) UnmarshalJSON Uses

func (m *Temperature) UnmarshalJSON(b []byte) error

type Time Uses

type Time struct {
    *ConcreteMeasurement
}

time

func AddTimes Uses

func AddTimes(timesToAdd ...Time) (sum Time)

AddTimes sums a variable number of Time arguments. If the dimension of the times are different the product will be returned in the SI value of Time (seconds).

func CopyTime Uses

func CopyTime(time Time) Time

CopyTime creates a safe duplicate of a time value.

func DivideTime Uses

func DivideTime(v Time, factor float64) Time

DivideTime divides a Time by a factor.

func FromDuration Uses

func FromDuration(t time.Duration) Time

func MultiplyTime Uses

func MultiplyTime(v Time, factor float64) Time

MultiplyTime multiplies a Time by a factor.

func NewTime Uses

func NewTime(v float64, unit string) (t Time)

NewTime creates a time unit.

func SubtractTimes Uses

func SubtractTimes(timeToSubtractFrom Time, timesToSubtract ...Time) (newTime Time)

SubtractTimes subtracts a variable number of Time arguments from timeToSubtractFrom.

func (Time) AsDuration Uses

func (t Time) AsDuration() time.Duration

func (Time) MarshalJSON Uses

func (m Time) MarshalJSON() ([]byte, error)

func (Time) Seconds Uses

func (t Time) Seconds() float64

func (*Time) UnmarshalJSON Uses

func (m *Time) UnmarshalJSON(b []byte) error

type Unit Uses

type Unit struct {
    // contains filtered or unexported fields
}

Unit everything we need to know about a unit to support it

func (*Unit) BaseSISymbol Uses

func (self *Unit) BaseSISymbol() string

BaseSISymbol Base SI or derived unit for this property, equivalent to BaseSISymbol

func (*Unit) Copy Uses

func (self *Unit) Copy() *Unit

Copy return a pointer to a new Unit identical to this one

func (*Unit) GobDecode Uses

func (self *Unit) GobDecode(b []byte) error

GobDecode deserialise gob

func (*Unit) GobEncode Uses

func (self *Unit) GobEncode() ([]byte, error)

GobEncode encode the unit as gob

func (*Unit) MarshalJSON Uses

func (self *Unit) MarshalJSON() ([]byte, error)

MarshalJSON marshal the unit as a JSON string

func (*Unit) Name Uses

func (self *Unit) Name() string

Name get the full name of the unit

func (*Unit) Prefix Uses

func (self *Unit) Prefix() SIPrefix

Prefix get the SI prefix of this unit, or " " if none

func (*Unit) PrefixedSymbol Uses

func (self *Unit) PrefixedSymbol() string

PrefixedSymbol the symbol including any prefix

func (*Unit) RawSymbol Uses

func (self *Unit) RawSymbol() string

RawSymbol symbol without prefex, equivalent to Symbol()

func (*Unit) String Uses

func (self *Unit) String() string

String a string representation of the unit name and symbol

func (*Unit) UnmarshalJSON Uses

func (self *Unit) UnmarshalJSON(data []byte) error

UnmarshalJSON marshal the unit as a JSON string

type UnitRegistry Uses

type UnitRegistry struct {
    // contains filtered or unexported fields
}

UnitRegistry store all the valid units in the library

func GetGlobalUnitRegistry Uses

func GetGlobalUnitRegistry() *UnitRegistry

GetGlobalUnitRegistry gets the shared unit registry which contains system types

func NewUnitRegistry Uses

func NewUnitRegistry() *UnitRegistry

NewUnitRegistry build a new empty unit registry

func (*UnitRegistry) AssertValidUnitForType Uses

func (self *UnitRegistry) AssertValidUnitForType(measurementType, symbol string) error

AssertValidForType assert that the symbol refers to a valid unit for the given type the same as ValidUnitForType, except this function returns a useful

func (*UnitRegistry) DeclareAlias Uses

func (self *UnitRegistry) DeclareAlias(measurementType, baseSymbol, baseTarget string, validPrefixes []SIPrefix) error

DeclareAlias declare an alias for a target symbol such that units with the alias are converted to the target. This is expected to be used when there are multiple convensions for writing a unit, for example

reg.DeclareAlias("volume", "L", "l", SIPrefixes)

will lead to all units with "L" (e.g. "uL", "mL") being converted to "l" (e.g. "ul", "ml", etc). If validPrefixes is zero length, only the base symbol will be added Note there is no value scaling, for that see DeclareDerivedUnit

func (*UnitRegistry) DeclareDerivedUnit Uses

func (self *UnitRegistry) DeclareDerivedUnit(measurementType string, name, symbol string, validPrefixes []SIPrefix, exponent int, target string, symbolInTargets float64) error

DeclareDerivedUnit such that references to "symbol" are converted to "target" using the conversion factor symbolInTargets, for each valid prefix. The target should already exist in the Registry. If validPrefixes is nil or zero length, only the base unit will be added e.g. DeclareDerivedUnit("pint", nil, "l", 0.568) will cause the unit "1 pint" to be understood as "0.568 l"

func (*UnitRegistry) DeclareUnit Uses

func (self *UnitRegistry) DeclareUnit(measurementType, name, baseSymbol, SISymbol string, validPrefixes []SIPrefix, exponent int) error

DeclareUnit add a unit to the registry, as well as corresponding entries for valid prefixes If validPrefixes is zero length, only the base symbol will be added

func (*UnitRegistry) GetUnit Uses

func (self *UnitRegistry) GetUnit(symbol string) (*Unit, error)

GetUnit return the unit referred to by symbol

func (*UnitRegistry) ListValidUnitsForType Uses

func (self *UnitRegistry) ListValidUnitsForType(measurementType string) []string

ListValidUnitsForType returns a sorted list of all valid unit symbols for a given measurement type

func (*UnitRegistry) NewMeasurement Uses

func (self *UnitRegistry) NewMeasurement(value float64, unitSymbol string) (*ConcreteMeasurement, error)

NewMeasurement return a new typed measurement

func (*UnitRegistry) ValidUnitForType Uses

func (self *UnitRegistry) ValidUnitForType(measurementType, symbol string) bool

ValidUnitForType return true if the given symbol represents a unit that is valid for the given measurement type e.g. ValidUnitForType("Length", "m") -> true and ValidUnitForType("Area", "l") -> false

type Velocity Uses

type Velocity struct {
    *ConcreteMeasurement
}

func NewVelocity Uses

func NewVelocity(v float64, unit string) Velocity

func (Velocity) MarshalJSON Uses

func (m Velocity) MarshalJSON() ([]byte, error)

func (*Velocity) UnmarshalJSON Uses

func (m *Velocity) UnmarshalJSON(b []byte) error

type Velocity3D Uses

type Velocity3D struct {
    X, Y, Z Velocity
}

Velocity3D struct composed of velocities in three axes

func (*Velocity3D) Dup Uses

func (self *Velocity3D) Dup() *Velocity3D

Dup return a copy of the velocities

func (*Velocity3D) GetAxis Uses

func (self *Velocity3D) GetAxis(a Axis) Velocity

GetAxis return the velocity in the axis specified

func (*Velocity3D) SetAxis Uses

func (self *Velocity3D) SetAxis(a Axis, v Velocity)

SetAxis return the velocity in the axis specified

type Voltage Uses

type Voltage struct {
    *ConcreteMeasurement
}

func NewVoltage Uses

func NewVoltage(value float64, unit string) (Voltage, error)

type Volume Uses

type Volume struct {
    *ConcreteMeasurement
}

volume -- strictly speaking of course this is length^3

func AddVolumes Uses

func AddVolumes(vols ...Volume) (newvolume Volume)

AddVolumes adds a set of volumes.

func CopyVolume Uses

func CopyVolume(v Volume) Volume

func DivideVolume Uses

func DivideVolume(v Volume, factor float64) (newvolume Volume)

DivideVolume divides a volume by a factor.

func MassToVolume Uses

func MassToVolume(m Mass, d Density) (Volume, error)

MassToVolume divides a mass (in kg) by a density (in kg/m^3) and returns the volume (in L).

func MasstoVolume Uses

func MasstoVolume(m Mass, d Density) Volume

MasstoVolume deprecated, please use MassToVolume instead

func MaxVolume Uses

func MaxVolume(volumes []Volume) (max Volume, err error)

MaxVolume returns the highest Volume value from a set of volume values. An error will be returned if no values are specified or the base units of any of the volumes are incompatible,

func MinVolume Uses

func MinVolume(volumes []Volume) (min Volume, err error)

MinVolume returns the lowest Volume value from a set of volume values. An error will be returned if no values are specified or the base units of any of the volumes are incompatible,

func MultiplyVolume Uses

func MultiplyVolume(v Volume, factor float64) (newvolume Volume)

MultiplyVolume multiplies a volume by a factor.

func NewVolume Uses

func NewVolume(v float64, unit string) Volume

make a volume

func ParseVolume Uses

func ParseVolume(volstring string) (volume Volume, err error)

ParseVolume parses a volume and valid unit (nl, ul, ml, l) in string format; handles cases where the volume is split with a space.

func SortVolumes Uses

func SortVolumes(volumes []Volume) (sorted []Volume, err error)

SortVolumes sorts a set of Volume values. An error will be returned if no values are specified or the base units of any of the volumes are incompatible,

func SubtractVolumes Uses

func SubtractVolumes(OriginalVol Volume, subtractvols ...Volume) (newvolume Volume)

SubtractVolumes substracts a variable number of volumes from an original volume.

func VolumeForTargetConcentration Uses

func VolumeForTargetConcentration(targetConc Concentration, stockConc Concentration, totalVol Volume) (Volume, error)

VolumeForTargetConcentration returns the volume required to convert a starting stock concentration to a target concentration of volume total volume returns an error if the concentration units are incompatible (M/l and g/L) or if the target concentration is higher than the stock concentration unless the total volume is zero

func VolumeForTargetMass Uses

func VolumeForTargetMass(targetMass Mass, stockConc Concentration) (Volume, error)

VolumeForTargetMass returns the volume required to convert a starting stock concentration to a solution containing a target mass. returns an error if the concentration units are not based on g/l. If the stock concentration is zero a volume of 0ul will be returned with an error. if the target mass is zero a volume of 0ul will be returned with no error.

func ZeroVolume Uses

func ZeroVolume() Volume

func (Volume) Dup Uses

func (v Volume) Dup() Volume

Dup deprecated, please use CopyVolume(Volume)

func (Volume) MarshalJSON Uses

func (m Volume) MarshalJSON() ([]byte, error)

func (*Volume) UnmarshalJSON Uses

func (m *Volume) UnmarshalJSON(b []byte) error

Package wunit imports 12 packages (graph) and is imported by 27 packages. Updated 2018-10-19. Refresh now. Tools for package owners.