Next: , Previous: Setting up the structures, Up: Units


10.2 units_parse

parse a string composed of a floating point number and a units specification.

Synopsis

     #include <suplib/units.h>
     
     
     
int units_parse( const char *spec, UnitVal *uv, const UnitsList *list );

Parameters

const char *spec
the specification to parse
UnitVal *uv
the resultant number and unit id
const UnitsList *list
the list of units

Description

This routine parses a string composed of a floating point number and a units specification (e.g. ‘1mm’, ‘23 arcsec’). White space between the number and the unit is ignored. The caller must ensure that there is no white space following the unit specification.

Returns

The parsed number and the unit id are written into the passed UnitVal structure. The unit element is only changed if a valid unit was found. units_parse returns a UNITS_ParseErr consistent with the results of the parse:

UNITS_OK
no errors were encountered
UNITS_BADNUM
there was an error while parsing the number
UNITS_NOSPEC
no units specification was present
UNITS_BADSPEC
the units specification wasn't recognized

Author

Diab Jerius