source: trunk/src/octave/rpUnitsGetBasis.cc @ 138

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

1) addition of octave/matlab test scripts, some still need work
2) the rpLibPutDoubleId and rpLibPutStringId functions are not quite working.
3) minor fixes to src/octave/rpLibPutDouble.cc and src/octave/rpUnitsGetBasis.cc

File size: 3.0 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                        // store the basis
63                        retHandle =
64                            storeObject_UnitsStr(myBasis->getUnitsName());
65                    }
66
67                    // adjust error code
68                    // if there is a basis retHandle will be a positive value
69                    // if storing was successful. retHandle will be zero if
70                    // storing failed.
71                    // if there is no basis, myBasis will be null and
72                    // retHandle will not change from its original negative
73                    // value
74                    if (retHandle != 0) {
75                        err = 0;
76                    }
77                }
78            }
79            else {
80                // invalid unitHandle
81                print_usage (who.c_str());
82            }
83        }
84        else {
85            print_usage (who.c_str());
86        }
87    }
88    else {
89        print_usage (who.c_str());
90    }
91
92    retval(0) = retHandle;
93    retval(1) = err;
94    return retval;
95}
Note: See TracBrowser for help on using the repository browser.