source: trunk/src/octave/rpFind.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.8 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [unitHandle,err] = rpFind(unitSymbol)
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: [unitHandle,err] = rpFind(unitSymbol)
18/// Search the dictionary of Rappture Units for an instance named 'unitSymbol'
19/**
20 * This method searches the Rappture Units Dictionary for the
21 * RpUnit named 'unitSymbol'. If it is found, its handle is
22 * returned, as a non-negative integer, to the caller for further use,
23 * else a negative integer is returned signifying no unit of that
24 * name was found.
25 * If unitSymbol is an empty string, unitHandle will be set to zero and err
26 * will be set to a positive value.
27 * Error code, err=0 on success, anything else is failure.
28 */
29
30DEFUN_DLD (rpFind, args, ,
31"-*- texinfo -*-\n\
32[unitHandle,err] = rpFind(@var{unitSymbol})\n\
33\n\
34This method searches the Rappture Units Dictionary for the\n\
35RpUnit named @var{unitSymbol}. If it is found, its handle is \n\
36returned, as a non-negative integer, to the caller for further use,\n\
37else a negative integer is returned signifying no unit of that \n\
38name was found.\n\
39If @var{unitSymbol} is an empty string, @var{unitHandle} will be set to\n\
40zero and @var{err} will be set to a positive value.\n\
41Error code, err=0 on success, anything else is failure.")
42{
43    static std::string who = "rpFind";
44
45    // The list of values to return.
46    octave_value_list retval;
47    int err = 1;
48    int nargin = args.length ();
49    std::string unitSymbol = "";
50    int retHandle = -1;
51    const RpUnits* retUnit = NULL;
52
53    if (nargin == 1) {
54
55        if ( args(0).is_string() ) {
56
57            unitSymbol = args(0).string_value ();
58
59            /* Call the C subroutine. */
60            if ( !unitSymbol.empty() ) {
61
62                retUnit = RpUnits::find(unitSymbol);
63                // store the returned unit
64                if (retUnit) {
65                    // store the unit
66                    retHandle = storeObject_UnitsStr(retUnit->getUnitsName());
67                    // adjust error code
68                    if (retHandle >= 0) {
69                        err = 0;
70                    }
71                }
72            }
73            else {
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.