source: trunk/lang/matlab/rpUnitsGetUnits.cc @ 1082

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

modified matlab bindings and tests.
includes all popular functions available in RpLibrary? and RpUnits
compile and run, but not all tests work as they should
some of these functions will be removed soon because the id field is
no longer a valid argument. path ids should be incorporated in paths from now on.

File size: 2.0 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retStr,err] = rpUnitsGetUnits(unitsHandle)
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2004-2005  Purdue Research Foundation
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15
16#include "RpMatlabInterface.h"
17
18/**********************************************************************/
19// METHOD: [retStr,err] = rpUnitsGetUnits(unitHandle)
20/// Return the units of the Rappture Unit represented by unitHandle.
21/**
22 * Retrieve the units of the Rappture Units object with the handle`
23 * 'unitHandle'. Note this does not include the exponent.
24 * For units and exponent in one string see rpUnitsGetUnitsName().
25 * Return the units as a string.
26 * Error code, err=0 on success, anything else is failure.
27 */
28
29void mexFunction(int nlhs, mxArray *plhs[],
30                 int nrhs, const mxArray *prhs[])
31{
32    int            unitsHandle = 0;
33    int            err         = 1;
34    const RpUnits* unitsObj    = NULL;
35    const char*    retString   = NULL;
36
37    /* Check for proper number of arguments. */
38    if (nrhs != 1)
39        mexErrMsgTxt("Two input required.");
40    else if (nlhs > 2)
41        mexErrMsgTxt("Too many output arguments.");
42
43    unitsHandle = getIntInput(prhs[0]);
44
45    /* Call the C subroutine. */
46    if (unitsHandle > 0) {
47        unitsObj = getObject_UnitsStr(unitsHandle);
48        if (unitsObj) {
49            retString = unitsObj->getUnits().c_str();
50            if (retString) {
51                err = 0;
52            }
53        }
54    }
55
56    /* Set C-style string output_buf to MATLAB mexFunction output*/
57    plhs[0] = mxCreateString(retString);
58    plhs[1] = mxCreateDoubleScalar(err);
59
60    return;
61}
Note: See TracBrowser for help on using the repository browser.