1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: Octave Rappture Library Source |
---|
4 | * |
---|
5 | * [unitsHandle,err] = rpUnitsDefineUnit(unitSymbol, basisHandle) |
---|
6 | * |
---|
7 | * ====================================================================== |
---|
8 | * AUTHOR: Derrick Kearney, Purdue University |
---|
9 | * Copyright (c) 2005 |
---|
10 | * Purdue Research Foundation, West Lafayette, IN |
---|
11 | * ====================================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | #include "RpOctaveInterface.h" |
---|
15 | |
---|
16 | /**********************************************************************/ |
---|
17 | // METHOD: [unitsHandle,err] = rpUnitsDefineUnit(unitSymbol, basisHandle) |
---|
18 | /// Define a new Rappture Units type. |
---|
19 | /** |
---|
20 | * Define a new Rappture Units type which can be searched for using |
---|
21 | * @var{unitSymbol} and has a basis of @var{basisHandle}. Because of |
---|
22 | * the way the Rappture Units module parses unit names, complex units must |
---|
23 | * be defined as multiple basic units. See the RpUnits Howto for more |
---|
24 | * information on this topic. A @var{basisHandle} equal to 0 means that |
---|
25 | * the unit being defined should be considered as a basis. Unit names must |
---|
26 | * not be empty strings. |
---|
27 | * |
---|
28 | * The first return value, @var{unitsHandle} represents the handle of the |
---|
29 | * instance of the RpUnits object inside the internal dictionary. On |
---|
30 | * success this value will be greater than zero (0), any other value is |
---|
31 | * represents failure within the function. The second return value |
---|
32 | * @var{err} represents the error code returned from the function. |
---|
33 | * |
---|
34 | * Error code, err=0 on success, anything else is failure. |
---|
35 | */ |
---|
36 | |
---|
37 | DEFUN_DLD (rpUnitsDefineUnit, args, , |
---|
38 | "-*- texinfo -*-\n\ |
---|
39 | [unitsHandle,err] = rpUnitsDefineUnit(@var{unitSymbol},@var{basisHandle})\n\ |
---|
40 | \n\ |
---|
41 | Define a new Rappture Units type which can be searched for using\n\ |
---|
42 | @var{unitSymbol} and has a basis of @var{basisHandle}. Because of\n\ |
---|
43 | the way the Rappture Units module parses unit names, complex units must\n\ |
---|
44 | be defined as multiple basic units. See the RpUnits Howto for more\n\ |
---|
45 | information on this topic. A @var{basisHandle} equal to 0 means that\n\ |
---|
46 | the unit being defined should be considered as a basis. Unit names must\n\ |
---|
47 | not be empty strings.\n\ |
---|
48 | \n\ |
---|
49 | The first return value, @var{unitsHandle} represents the handle of the\n\ |
---|
50 | instance of the RpUnits object inside the internal dictionary. On\n\ |
---|
51 | success this value will be greater than zero (0), any other value is\n\ |
---|
52 | represents failure within the function. The second return value\n\ |
---|
53 | @var{err} represents the error code returned from the function.\n\ |
---|
54 | \n\ |
---|
55 | Error code, err=0 on success, anything else is failure.") |
---|
56 | { |
---|
57 | static std::string who = "rpUnitsDefineUnit"; |
---|
58 | |
---|
59 | // The list of values to return. |
---|
60 | octave_value_list retval; |
---|
61 | int err = 1; |
---|
62 | int nargin = args.length (); |
---|
63 | std::string unitSymbol = ""; |
---|
64 | int basisHandle = 0; |
---|
65 | RpUnits* newUnit = NULL; |
---|
66 | const RpUnits* basisUnit = NULL; |
---|
67 | |
---|
68 | if (nargin == 2) { |
---|
69 | |
---|
70 | if ( args(0).is_string () && |
---|
71 | args(1).is_real_scalar () ) { |
---|
72 | |
---|
73 | unitSymbol = args(0).string_value (); |
---|
74 | basisHandle = args(1).int_value (); |
---|
75 | |
---|
76 | // Call the C++ subroutine. |
---|
77 | if ( !unitSymbol.empty() ) { |
---|
78 | |
---|
79 | basisUnit = getObject_UnitsStr(basisHandle); |
---|
80 | newUnit = RpUnits::define(unitSymbol,basisUnit); |
---|
81 | if (newUnit) { |
---|
82 | err = 0; |
---|
83 | } |
---|
84 | } |
---|
85 | else { |
---|
86 | print_usage (who.c_str()); |
---|
87 | } |
---|
88 | } |
---|
89 | else { |
---|
90 | print_usage (who.c_str()); |
---|
91 | } |
---|
92 | } |
---|
93 | else { |
---|
94 | print_usage (who.c_str()); |
---|
95 | } |
---|
96 | |
---|
97 | retval(0) = storeObject_UnitsStr(newUnit->getUnitsName()); |
---|
98 | retval(1) = err; |
---|
99 | return retval; |
---|
100 | } |
---|