source: trunk/src/cee/RpUnitsCInterface.h @ 568

Last change on this file since 568 was 568, checked in by dkearney, 18 years ago

reworking of the Rappture Units code.
Rappture Units no longer creates an object for each metric extension of every
metric unit. Now the metric prefixes are kept in the dictionary as unit objects,
and when a unit is parsed out of the string received from the user, the unit
is checked to see if it acccepts metric prefixes, if so, a search is done for
the prefix. This allows Rappture Units code to more easily tackle case insensitive
unit name searches. Eventually the prefixes will be removed as direct Rappture Units objects and be turned into (possibly a derived object) rappture units prefix objects.

The find function of the core Rappture Units code now accepts
a "hints" function pointer. The function pointer is executed by the dictionary when
the dictionary thinks it found a matching object. This allows the user of the
dictionary to insert different objects with the same key. For Rappture Units,
multiple units objects with the same key can be inserted into the dictionary.
This is important for units like "A" which could stand for angstroms or amperes.

Additionally, the "make metric" functions were removed because the idea of being a
metric unit has been reduced to a flag inside the Rappture Units object and some
newly added logic. The role of setting the metric flag has been added to the define()
function as an additional function input. The fortran and c code has been updated to
reflect the removal of the function. No updates were made to the define function in
the fortran and c code.

The units.test file was also updated with new tests. Old tests were updated, removing
derived units from the list of compatible units. When searching for micro-meters (um),
compatible units of (A,in,m) will be provided instead of (A,in,m,um).

File size: 2.6 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: C Rappture Units Header
4 *
5 * ======================================================================
6 *  AUTHOR:  Derrick Kearney, Purdue University
7 *  Copyright (c) 2004-2005  Purdue Research Foundation
8 *
9 *  See the file "license.terms" for information on usage and
10 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 * ======================================================================
12 */
13
14#ifndef _RpUNITS_C_H
15#define _RpUNITS_C_H
16
17#ifdef __cplusplus
18    extern "C" {
19#endif // ifdef __cplusplus
20
21    typedef struct RpUnits RpUnits;
22
23    // unit definition functions
24    const RpUnits* rpDefineUnit  ( const char* unitSymbol,
25                                   const RpUnits* basis );
26
27    // conversion definition functions
28    const RpUnits* rpDefineConv  ( const RpUnits* fromUnit,
29                                   const RpUnits* toUnit,
30                                   double (*convForwFxnPtr)(double),
31                                   double (*convBackFxnPtr)(double)    );
32
33    // unit attribute access functions
34    const char* rpGetUnits       ( const RpUnits* unit );
35
36    const char* rpGetUnitsName   ( const RpUnits* unit );
37
38    double rpGetExponent         ( const RpUnits* unit );
39
40    const RpUnits* rpGetBasis    ( const RpUnits* unit);
41
42    const RpUnits* rpFind        ( const char* unitSymbol);
43
44    // convert functions
45
46    const char* rpConvert        ( const char* fromVal,
47                                   const char* toUnitsName,
48                                   int showUnits,
49                                   int* result );
50
51    const char* rpConvertStr     ( const char* fromVal,
52                                   const char* toUnitsName,
53                                   int showUnits,
54                                   int* result );
55
56    const char* rpConvert_ObjStr ( const RpUnits* fromUnits,
57                                   const RpUnits* toUnits,
58                                   double val,
59                                   int showUnits,
60                                   int* result );
61
62    double rpConvertDbl          ( const char* fromVal,
63                                   const char* toUnitsName,
64                                   int* result );
65
66    double rpConvert_ObjDbl      ( const RpUnits* fromUnits,
67                                   const RpUnits* toUnits,
68                                   double val,
69                                   int* result );
70
71    int rpAddPresets ( const char* presetName );
72
73#ifdef __cplusplus
74    }
75#endif // ifdef __cplusplus
76
77#endif // ifndef _RpUNITS_C_H
Note: See TracBrowser for help on using the repository browser.