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

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