source: trunk/lang/octave/rpUnitsGetUnits.cc @ 1044

Last change on this file since 1044 was 135, checked in by dkearney, 18 years ago

1) fixed children function in c++'s library module so users can now
search for children by type.
2) adjusted bindings dictionary module for storing lib's to allow caller
to set the key of the value being stored.
3) removed old targets for rappture_interface.o and rappture_fortran.o
from makefile
4) renamed matlab and octave binding functions names to match the module
they came from.
5) adjusted matlab/octave example in examples/app_fermi/matlab
6) added matlab and octave search paths environment variables to
gui/apps/rappture

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