1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: Octave Rappture Library Source |
---|
4 | * |
---|
5 | * [retStr,err] = rpGetUnits(unitHandle) |
---|
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: [retStr,err] = rpGetUnits(unitHandle) |
---|
18 | /// Return the units of the Rappture Unit represented by unitHandle. |
---|
19 | /** |
---|
20 | * Retrieve the units of the Rappture Units object with the handle |
---|
21 | * 'unitHandle'. Note this does not include the exponent. |
---|
22 | * For units and exponent in one string see rpGetUnitsName(). |
---|
23 | * Return the units as a string. |
---|
24 | * Error code, err=0 on success, anything else is failure. |
---|
25 | */ |
---|
26 | |
---|
27 | DEFUN_DLD (rpGetUnits, args, , |
---|
28 | "-*- texinfo -*-\n\ |
---|
29 | [retVal,err] = rpGetUnits(@var{unitHandle})\n\ |
---|
30 | \n\ |
---|
31 | Retrieve the units of the Rappture Units object with the handle \n\ |
---|
32 | 'unitHandle'. Note this does not include the exponent.\n\ |
---|
33 | For units and exponent in one string see rpGetUnitsName().\n\ |
---|
34 | Return the units as a string.\n\ |
---|
35 | Error code, err=0 on success, anything else is failure.") |
---|
36 | { |
---|
37 | static std::string who = "rpGetUnits"; |
---|
38 | |
---|
39 | // The list of values to return. |
---|
40 | octave_value_list retval; |
---|
41 | int err = 1; |
---|
42 | int nargin = args.length (); |
---|
43 | |
---|
44 | const RpUnits* myUnit = NULL; |
---|
45 | int unitHandle = 0; |
---|
46 | std::string retStr = ""; |
---|
47 | |
---|
48 | if (nargin == 1) { |
---|
49 | |
---|
50 | if ( args(0).is_real_scalar() ) { |
---|
51 | |
---|
52 | unitHandle = args(0).int_value (); |
---|
53 | |
---|
54 | /* Call the C subroutine. */ |
---|
55 | if ( unitHandle >= 0 ) { |
---|
56 | |
---|
57 | // get the original unit |
---|
58 | myUnit = getObject_UnitsStr(unitHandle); |
---|
59 | if (myUnit) { |
---|
60 | // get the basis |
---|
61 | retStr = myUnit->getUnits(); |
---|
62 | // adjust error code |
---|
63 | err = 0; |
---|
64 | } |
---|
65 | } |
---|
66 | else { |
---|
67 | // invalid unitHandle |
---|
68 | print_usage (who.c_str()); |
---|
69 | } |
---|
70 | } |
---|
71 | else { |
---|
72 | print_usage (who.c_str()); |
---|
73 | } |
---|
74 | } |
---|
75 | else { |
---|
76 | print_usage (who.c_str()); |
---|
77 | } |
---|
78 | |
---|
79 | retval(0) = retStr; |
---|
80 | retval(1) = err; |
---|
81 | return retval; |
---|
82 | } |
---|