source: trunk/src/octave/rpDefineUnit.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: 3.7 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [unitsHandle,err] = rpDefineUnit(unitSymbol, basisHandle)
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: [unitsHandle,err] = rpDefineUnit(unitSymbol, basisHandle)
18/// Define a new Rappture Units type.
19/**
20 * Define a new Rappture Units type which can be searched for using
21 * @var{unitSymbol} and has a basis of @var{basisHandle}. Because of
22 * the way the Rappture Units module parses unit names, complex units must
23 * be defined as multiple basic units. See the RpUnits Howto for more
24 * information on this topic. A @var{basisHandle} equal to 0 means that
25 * the unit being defined should be considered as a basis. Unit names must
26 * not be empty strings.
27 *
28 * The first return value, @var{unitsHandle} represents the handle of the
29 * instance of the RpUnits object inside the internal dictionary. On
30 * success this value will be greater than zero (0), any other value is
31 * represents failure within the function. The second return value
32 * @var{err} represents the error code returned from the function.
33 *
34 * Error code, err=0 on success, anything else is failure.
35 */
36
37DEFUN_DLD (rpDefineUnit, args, ,
38"-*- texinfo -*-\n\
39[unitsHandle,err] = rpDefineUnit(@var{unitSymbol},@var{basisHandle})\n\
40\n\
41Define a new Rappture Units type which can be searched for using\n\
42@var{unitSymbol} and has a basis of @var{basisHandle}. Because of\n\
43the way the Rappture Units module parses unit names, complex units must\n\
44be defined as multiple basic units. See the RpUnits Howto for more\n\
45information on this topic. A @var{basisHandle} equal to 0 means that\n\
46the unit being defined should be considered as a basis. Unit names must\n\
47not be empty strings.\n\
48\n\
49The first return value, @var{unitsHandle} represents the handle of the\n\
50instance of the RpUnits object inside the internal dictionary. On\n\
51success this value will be greater than zero (0), any other value is\n\
52represents failure within the function. The second return value\n\
53@var{err} represents the error code returned from the function.\n\
54\n\
55Error code, err=0 on success, anything else is failure.")
56{
57    static std::string who = "rpDefineUnit";
58
59    // The list of values to return.
60    octave_value_list retval;
61    int err                  = 1;
62    int nargin               = args.length ();
63    std::string unitSymbol   = "";
64    int basisHandle          = 0;
65    RpUnits* newUnit         = NULL;
66    const RpUnits* basisUnit = NULL;
67
68    if (nargin == 2) {
69
70        if (    args(0).is_string      () &&
71                args(2).is_real_scalar ()    ) {
72
73            unitSymbol  = args(0).string_value ();
74            basisHandle = args(2).int_value ();
75
76            // Call the C++ subroutine.
77            if ( !unitSymbol.empty() ) {
78
79                basisUnit = getObject_UnitsStr(basisHandle);
80
81                if (basisUnit) {
82                    newUnit = RpUnits::define(unitSymbol,basisUnit);
83                    if (newUnit) {
84                        err = 0;
85                    }
86                }
87            }
88            else {
89                print_usage (who.c_str());
90            }
91        }
92        else {
93            print_usage (who.c_str());
94        }
95    }
96    else {
97        print_usage (who.c_str());
98    }
99
100    retval(0) = storeObject_UnitsStr(newUnit->getUnitsName());
101    retval(1) = err;
102    return retval;
103}
Note: See TracBrowser for help on using the repository browser.