source: trunk/lang/matlab/rpUnitsConvertObjDbl.cc @ 1095

Last change on this file since 1095 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.4 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retVal,result] = rpUnitsConvertObjDbl(fromObjHandle, toObjHandle, value)
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: [retVal,err] = rpUnitsConvertObjDbl(fromObjHandle,toObjHandle,value)
20/// Convert between RpUnits return a double value without units
21/**
22 * Convert @var{value} from the units represented by the RpUnits object
23 * @var{fromObjHandle} to the units represented by the RpUnits object
24 * @var{toObjHandle}. On success, the converted value is returned through
25 * @var{retVal}. The second return value, @var{err}, specifies whether`
26 * there was an error during conversion.
27 * Error code, err=0 on success, anything else is failure.
28 */
29
30void mexFunction(int nlhs, mxArray *plhs[],
31                 int nrhs, const mxArray *prhs[])
32{
33    int               result        = 0;
34    double            retVal        = 0;
35    int               fromObjHandle = 0;
36    int               toObjHandle   = 0;
37    const RpUnits*    fromObj       = NULL;
38    const RpUnits*    toObj         = NULL;
39    double            value         = 0;
40
41    /* Check for proper number of arguments. */
42    if (nrhs != 3)
43        mexErrMsgTxt("Two input required.");
44    else if (nlhs > 2)
45        mexErrMsgTxt("Too many output arguments.");
46
47    fromObjHandle = getIntInput(prhs[0]);
48    toObjHandle   = getIntInput(prhs[1]);
49    value         = getDoubleInput(prhs[2]);
50
51    // grab the RpUnits objects from the dictionary
52    if ( (fromObjHandle > 0) && (toObjHandle > 0) ){
53        fromObj       = getObject_UnitsStr(fromObjHandle);
54        toObj         = getObject_UnitsStr(toObjHandle);
55
56        /* Call the C subroutine. */
57        if (fromObj && toObj) {
58            retVal = fromObj->convert(toObj,value,&result);
59        }
60    }
61
62    /* Set C-style string output_buf to MATLAB mexFunction output*/
63    plhs[0] = mxCreateDoubleScalar(retVal);
64    plhs[1] = mxCreateDoubleScalar((double)result);
65
66    return;
67}
Note: See TracBrowser for help on using the repository browser.