source: trunk/src/octave/rpGetBasis.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.6 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [basisHandle,err] = rpGetBasis(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: [basisHandle,err] = rpGetBasis(unitHandle)
18/// Return a handle to the basis of the provided instance of a Rappture Unit.
19/**
20 * Retrieve the basis of the Rappture Units object with the handle
21 * 'unitHandle'. Return the handle of the basis if it exists. If there
22 * is no basis, then return a negative integer.
23 * Error code, err=0 on success, anything else is failure.
24 */
25
26DEFUN_DLD (rpGetBasis, args, ,
27"-*- texinfo -*-\n\
28[basisHandle,err] = rpGetBasis(@var{unitHandle})\n\
29\n\
30Retrieve the basis of the Rappture Units object with the handle \n\
31'unitHandle'. Return the handle of the basis if it exists. If there \n\
32is no basis, then return a negative integer.\n\
33Error code, err=0 on success, anything else is failure.")
34{
35    static std::string who = "rpGetBasis";
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* myBasis = NULL;
43    const RpUnits* myUnit = NULL;
44    int retHandle = -1;
45    int unitHandle = 0;
46
47    if (nargin == 1) {
48
49        if ( args(0).is_real_scalar() ) {
50
51            unitHandle = args(0).int_value ();
52
53            /* Call the C subroutine. */
54            if ( unitHandle >= 0 ) {
55
56                // get the original unit
57                myUnit = getObject_UnitsStr(unitHandle);
58                if (myUnit) {
59                    // get the basis
60                    myBasis = myUnit->getBasis();
61                    if (myBasis) {
62                        // store the basis
63                        retHandle =
64                            storeObject_UnitsStr(myBasis->getUnitsName());
65                        // adjust error code
66                        if (retHandle >= 0) {
67                            err = 0;
68                        }
69                    }
70                }
71            }
72            else {
73                // invalid unitHandle
74                print_usage (who.c_str());
75            }
76        }
77        else {
78            print_usage (who.c_str());
79        }
80    }
81    else {
82        print_usage (who.c_str());
83    }
84
85    retval(0) = retHandle;
86    retval(1) = err;
87    return retval;
88}
Note: See TracBrowser for help on using the repository browser.