source: trunk/src/octave/rpGetUnits.cc @ 122

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

added initial version of octave language bindings.
1) no claiming language bindings work, but will happily take credit if they do.
2) bindings are untested
3) bindings happen to work with mystery example that happens to be located in examples/app-fermi/matlab/fermi_rp.m and happens to be invokable with examples/app-fermi/matlab/tool_rp.xml
4) bindings need octave2.1-headers installed (in debian: apt-get install octave2.1-headers) to get the mkoctfile program
5) binding function names might be changing to be more discriptive and more tightly bound to either the lib or units module.
6) adjusted Makefile to add octave bindings compilation.

File size: 2.4 KB
Line 
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
27DEFUN_DLD (rpGetUnits, args, ,
28"-*- texinfo -*-\n\
29[retVal,err] = rpGetUnits(@var{unitHandle})\n\
30\n\
31Retrieve the units of the Rappture Units object with the handle \n\
32'unitHandle'. Note this does not include the exponent.\n\
33For units and exponent in one string see rpGetUnitsName().\n\
34Return the units as a string.\n\
35Error 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}
Note: See TracBrowser for help on using the repository browser.