Citrus C API Reference

Name

Citrus C API Reference -- A library for performing dimensional analysis. This is the C API Reference Manual.

Synopsis



#define     CITRUS_UNIT_PLURAL_S
#define     CITRUS_UNIT_PLURAL_ES
#define     CITRUS_UNIT_PLURAL_SPECIAL
int         citrus_initialize               (const char *configFile);
void*       citrus_quantity_from_string     (const char *src);
xmlNodePtr  citrus_quantity_export_mathml   (const void *quantity);
int         citrus_convert_quantities       (void *from,
                                             void *to,
                                             double *result);
int         citrus_convert_string           (const char *from,
                                             const char *to,
                                             double *result);
int         citrus_convert_array            (double *value,
                                             int len,
                                             const char *from,
                                             const char *to,
                                             double *result);
int         citrus_convert                  (double value,
                                             const char *from,
                                             const char *to,
                                             double *result);
const void* citrus_dimension_group_get_next (const void *pDgrp);
const void* citrus_dimension_group_get_next_unit
                                            (const void *pDgrp,
                                             const void *pUnit);
const gchar* citrus_dimension_group_get_name
                                            (const void *pDgrp);
double      citrus_unit_get_scale           (const void *pUnit);
gboolean    citrus_unit_has_offset          (const void *pUnit);
double      citrus_unit_get_offset          (const void *pUnit);
const gchar* citrus_unit_get_name           (const void *pUnit);
const gchar* citrus_unit_get_abbr           (const void *pUnit);
gint        citrus_unit_get_plural_policy   (const void *pUnit);
gchar*      citrus_unit_get_plural_form     (const void *pUnit);

Description

Citrus is a library for performing dimensional analysis. This is the reference manual for the C API.

Details

CITRUS_UNIT_PLURAL_S

#define CITRUS_UNIT_PLURAL_S		0

This flag indicates that a unit's plural form is obtained by adding 's' to the end of the unit's name. An example would be "meter", for which the plural is "meters".


CITRUS_UNIT_PLURAL_ES

#define CITRUS_UNIT_PLURAL_ES		1

This flag indicates that a unit's plural form is obtained by adding 'es' to the end of the unit's name. An example would be "inch", for which the plural is "inches".


CITRUS_UNIT_PLURAL_SPECIAL

#define CITRUS_UNIT_PLURAL_SPECIAL	2

This flag indicates that a unit's plural form name is significantly different from the unit's singular form name. An example would be "foot", for which the plural is "feet".


citrus_initialize ()

int         citrus_initialize               (const char *configFile);

Initialize the Citrus library. At the moment, all this does is read the configuration file. The configuration file contains all of the dimensions, dimensional groups, and units. Without them, the library is relatively useless.

configFile : The absolute path and name of the configuration file. This may be NULL, in which case several compiled in defaults are checked: ${prefix}/share/citrus/units.xml and ~/.citrus/units.xml.
Returns : 0 if unable to find any configuration file, non-zero for success.


citrus_quantity_from_string ()

void*       citrus_quantity_from_string     (const char *src);

This creates an internal representation of a number with units that can be used to convert units, find the dimensional group of a given number, or find a canonical representation (in the unit system of your choice).

src : A string containing a number and a unit expression. The number may be in exponential notation. The unit expression must be created from elements of the form {[prefix]unit_abbrev^exp} joined together by spaces or asteriks (multiplication) or slashes (division).
Returns : NULL on error or a pointer to a quantity on success.


citrus_quantity_export_mathml ()

xmlNodePtr  citrus_quantity_export_mathml   (const void *quantity);

Return an XML tree containing MathML nodes describing the quantity.

These nodes have no parent document. This function will change in the near future. There are also plans to add citrus_unit_expr_export_mathml and citrus_unit_powers_export_mathml. These routines will be more flexible but won't add the value of the quantity to the left of the units.

quantity : A pointer to a quantity.
Returns : An XML node (possibly with children).


citrus_convert_quantities ()

int         citrus_convert_quantities       (void *from,
                                             void *to,
                                             double *result);

Convert one quantity into the units of another.

from : A pointer to a quantity containing the number to be converted along with its native units.
to : A pointer to a quantity containing the desired units. The number associated with this quantity will be overwritten assuming the conversion can occur.
result : Either NULL or a pointer to a double where the result of the conversion can be stored.
Returns : 0 on success. Non-zero indicates that the original and desired units did not match.


citrus_convert_string ()

int         citrus_convert_string           (const char *from,
                                             const char *to,
                                             double *result);

Convert a string containing a number and units into a number with the units of a second string.

from : A pointer to a string containing the number to be converted along with its native units.
to : A pointer to a string containing the desired units.
result : A pointer to a double where the result of the conversion can be stored.
Returns : 0 on success. Non-zero indicates that the original and desired units did not match. A value of 2 indicates that there was an error parsing one of the strings.


citrus_convert_array ()

int         citrus_convert_array            (double *value,
                                             int len,
                                             const char *from,
                                             const char *to,
                                             double *result);

Convert a number and a string containing its units into a number with the units of a second string.

value : A pointer to an array of numbers to be converted.
len : The number of elements in the value array.
from : A pointer to a string containing the units of the input array.
to : A pointer to a string containing the desired units.
result : A pointer to an array of doubles where the result of the conversions can be stored.
Returns : 0 on success. Non-zero indicates that the original and desired units did not match. A value of 2 indicates that there was an error parsing one of the strings.


citrus_convert ()

int         citrus_convert                  (double value,
                                             const char *from,
                                             const char *to,
                                             double *result);

Convert a number and a string containing its units into a number with the units of a second string.

value : The number of interest.
from : A pointer to a string containing the native units of the number.
to : A pointer to a string containing the desired units.
result : A pointer to a double where the result of the conversion can be stored.
Returns : 0 on success. Non-zero indicates that the original and desired units did not match. A value of 2 indicates that there was an error parsing one of the strings.


citrus_dimension_group_get_next ()

const void* citrus_dimension_group_get_next (const void *pDgrp);

This function can be used to enumerate all of the recognized dimensional groups. Handy for displaying the capabilities of the converter.

pDgrp : A pointer to a dimension group ("velocity","length",...). If NULL, it returns the first dimension group in the list of all dimension groups.
Returns : A pointer to the next dimension group in the list of all dimension groups, or NULL if the end of the list has been reached.


citrus_dimension_group_get_next_unit ()

const void* citrus_dimension_group_get_next_unit
                                            (const void *pDgrp,
                                             const void *pUnit);

pDgrp : 
pUnit : 


citrus_dimension_group_get_name ()

const gchar* citrus_dimension_group_get_name
                                            (const void *pDgrp);

Return the name of a dimension group given a pointer to a dimension group. Use this with citrus_dimension_group_get_next().

pDgrp : A pointer to a dimension group ("velocity","length",...).
Returns : A string containing the name of the dimension group. You may not change or free this string. Copy it first if you want to fiddle with it.


citrus_unit_get_scale ()

double      citrus_unit_get_scale           (const void *pUnit);

Get how a unit scales a dimensional axis (length, mass, time) compared to an arbitary (but fixed) reference unit. Our reference units are SI kgs units.

pUnit : A pointer to a single unit (something that assigns a scale to a single dimension). So, "furlong" would be a unit, but "m^2" would not be.
Returns : The scale of the unit compared to a standard reference unit which just always happens to coincide with SI kgs units.


citrus_unit_has_offset ()

gboolean    citrus_unit_has_offset          (const void *pUnit);

Get whether a unit's zero point is at an offset compared to an arbitary (but fixed) reference unit. Our reference units are SI kgs units.

pUnit : A pointer to a single unit (something that assigns a scale to a single dimension). So, "furlong" would be a unit, but "m^2" would not be.
Returns : Whether, in addition to being scaled, the unit is measured at an offset to the reference axis. Currently, this is only true for the temperature units degF and degC.


citrus_unit_get_offset ()

double      citrus_unit_get_offset          (const void *pUnit);

Get the distance unit's zero point is at an offset compared to an arbitary (but fixed) reference unit. Our reference units are SI kgs units. The result is measured in the reference units.

pUnit : A pointer to a single unit (something that assigns a scale to a single dimension). So, "furlong" would be a unit, but "m^2" would not be.
Returns : The difference between a reference unit's zero point and pUnit 's zero point, measured using the reference units.


citrus_unit_get_name ()

const gchar* citrus_unit_get_name           (const void *pUnit);

The full name of a unit, in singular form.

pUnit : A pointer to a single unit (something that assigns a scale to a single dimension). So, "furlong" would be a unit, but "m^2" would not be.
Returns : A string containing the name of the unit. You may not alter or free the string.


citrus_unit_get_abbr ()

const gchar* citrus_unit_get_abbr           (const void *pUnit);

The abbreviation of a unit. Unit abbreviations are what's used to specify the units associated with numbers (see citrus_quantity_from_string(), for instance).

pUnit : A pointer to a single unit (something that assigns a scale to a single dimension). So, "furlong" would be a unit, but "m^2" would not be.
Returns : A string containing the abbreviation of the unit. You may not alter or free the string.


citrus_unit_get_plural_policy ()

gint        citrus_unit_get_plural_policy   (const void *pUnit);

Return an integer representing how the name of a unit is pluralized.

pUnit : A pointer to a single unit (something that assigns a scale to a single dimension). So, "furlong" would be a unit, but "m^2" would not be.
Returns : CITRUS_PLURAL_NONE, CITRUS_PLURAL_NORMAL, or CITRUS_PLURAL_SPECIAL.


citrus_unit_get_plural_form ()

gchar*      citrus_unit_get_plural_form     (const void *pUnit);

You are responsible for calling g_free on the result.

pUnit : A pointer to a single unit (something that assigns a scale to a single dimension). So, "furlong" would be a unit, but "m^2" would not be.
Returns : A string containing the plural of the name of a unit.

See Also

In addition to this manual, there are several other sources of documentation.

  1. The Citrus Developer's Guide , which is an overview of how to use the library, from installation to the intended use of routines. However, it does not contain a detailed description of each function or C++ class.

  2. The Citrus User's Guide , which describes how to use the demo applications that come with the Citrus library.

  3. The Citrus C++ Reference Manual which doesn't exist yet. It will be an automatically generated description of the C++ interface to Citrus.