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