source: trunk/lang/octave/src/rpUnitsGetBasis.cc @ 4346

Last change on this file since 4346 was 1844, checked in by gah, 14 years ago

allow both octave2 and octave3 builds simultaneously

File size: 3.3 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [basisHandle,err] = rpUnitsGetBasis(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] = rpUnitsGetBasis(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 (rpUnitsGetBasis, args, ,
27"-*- texinfo -*-\n\
28[basisHandle,err] = rpUnitsGetBasis(@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 = "rpUnitsGetBasis";
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                        // this unit has a basis
63                        // store the basis
64                        retHandle =
65                            storeObject_UnitsStr(myBasis->getUnitsName());
66                    }
67                    else {
68                        // this unit does not have a basis
69                        // this unit is a basis
70                        // set handle to -1
71                        retHandle = -1;
72                    }
73
74                    // adjust error code
75                    // if there is a basis retHandle will be a positive value
76                    // if storing was successful. retHandle will be zero if
77                    // storing failed.
78                    // if there is no basis, myBasis will be null and
79                    // retHandle will not change from its original negative
80                    // value
81                    if (retHandle != 0) {
82                        err = 0;
83                    }
84                }
85            }
86            else {
87                // invalid unitHandle
88                _PRINT_USAGE (who.c_str());
89            }
90        }
91        else {
92            _PRINT_USAGE (who.c_str());
93        }
94    }
95    else {
96        _PRINT_USAGE (who.c_str());
97    }
98
99    retval(0) = retHandle;
100    retval(1) = err;
101    return retval;
102}
Note: See TracBrowser for help on using the repository browser.