source: branches/1.4/lang/matlab/rpUnitsConvertObjDbl.cc @ 5874

Last change on this file since 5874 was 5679, checked in by ldelgass, 9 years ago

Full merge 1.3 branch to uq branch to sync. Fixed partial subdirectory merge
by removing mergeinfo from lang/python/Rappture directory.

  • Property svn:eol-style set to native
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-2012  HUBzero Foundation, LLC
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.