source: trunk/src/octave/rpConvertDbl.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 *    [retVal,err] = rpConvertDbl(fromVal, toUnitsName)
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] = rpConvertDbl(fromVal,toUnitsName)
18/// Convert between RpUnits return a double value without units
19/**
20 * Convert the value and units in the string @var{fromVal} to units specified
21 * in string @var{toUnitsName}. Units will not be shown in @var{retVal}.
22 * The second return value @var{err} specifies whether there was an error
23 * during conversion.
24 * Error code, err=0 on success, anything else is failure.
25 */
26
27DEFUN_DLD (rpConvertDbl, args, ,
28"-*- texinfo -*-\n\
29[retVal,err] = rpConvertDbl(@var{fromVal},@var{toUnitsName})\n\
30\n\
31Convert the value and units in the string @var{fromVal} to units specified\n\
32in string @var{toUnitsName}. Units will not be shown in @var{retVal}.\n\
33The second return value @var{err} specifies whether there was an error\n\
34during conversion. \n\
35Error code, err=0 on success, anything else is failure.")
36{
37    static std::string who = "rpConvertDbl";
38
39    // The list of values to return.
40    octave_value_list retval;
41    int err = 1;
42    int nargin = args.length ();
43    std::string fromVal = "";
44    std::string toUnitsName = "";
45    int showUnits = 0;
46    std::string retStr = "";
47    double retVal = 0;
48
49    if (nargin == 2) {
50
51        if (    args(0).is_string      () &&
52                args(1).is_string      ()   ) {
53
54            fromVal = args(0).string_value ();
55            toUnitsName = args(1).string_value ();
56
57            // Call the C++ subroutine.
58            // we allow toUnitsName to be an empty string
59            // to let the user not change the units of fromVal
60            // but still remove the units from being shown.
61            if ( !fromVal.empty() ) {
62
63                retStr = RpUnits::convert(fromVal,toUnitsName,showUnits,&err);
64                if ( !err && !retStr.empty() ) {
65                    retVal = atof(retStr.c_str());
66                }
67            }
68            else {
69                print_usage ("rpConvertDbl");
70            }
71        }
72        else {
73            print_usage ("rpConvertDbl");
74        }
75    }
76    else {
77        print_usage ("rpConvertDbl");
78    }
79
80    retval(0) = retVal;
81    retval(1) = err;
82    return retval;
83}
Note: See TracBrowser for help on using the repository browser.