source: branches/1.3/lang/matlab/rpUnitsConvertObjStr.cc @ 5900

Last change on this file since 5900 was 5675, checked in by ldelgass, 9 years ago

merge r5673 from trunk (eol-style)

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retStr,result] =
6 *          rpUnitsConvertObjStr(fromObjHandle, toObjHandle, value, showUnits)
7 *
8 * ======================================================================
9 *  AUTHOR:  Derrick Kearney, Purdue University
10 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16
17#include "RpMatlabInterface.h"
18
19/**********************************************************************/
20// METHOD: [retStr,err] = rpUnitsConvertObjStr(fromObjHandle,toObjHandle,value,showUnits)
21/// Convert between RpUnits return a string value with or without units
22/**
23 * Convert @var{value} from the units represented by the RpUnits object
24 * @var{fromObjHandle} to the units represented by the RpUnits object
25 * @var{toObjHandle}. If @var{showUnits} is set to 0, no units will be
26 * displayed in @var{retStr}, else units are displayed.`
27 * On success, the converted value is returned through
28 * @var{retStr}. The second return value, @var{err}, specifies whether`
29 * there was an error during conversion.
30 * Error code, err=0 on success, anything else is failure.
31 */
32
33void mexFunction(int nlhs, mxArray *plhs[],
34                 int nrhs, const mxArray *prhs[])
35{
36    int            result        = 0;
37    std::string    retStr        = "";
38    int            fromObjHandle = 0;
39    int            toObjHandle   = 0;
40    const RpUnits* fromObj       = NULL;
41    const RpUnits* toObj         = NULL;
42    double         value         = 0;
43    int            showUnits     = 0;
44
45    /* Check for proper number of arguments. */
46    if (nrhs != 4)
47        mexErrMsgTxt("Two input required.");
48    else if (nlhs > 2)
49        mexErrMsgTxt("Too many output arguments.");
50
51    fromObjHandle = getIntInput(prhs[0]);
52    toObjHandle   = getIntInput(prhs[1]);
53    value         = getDoubleInput(prhs[2]);
54    showUnits     = getIntInput(prhs[3]);
55
56    // grab the RpUnits objects from the dictionary
57    fromObj       = getObject_UnitsStr(fromObjHandle);
58    toObj         = getObject_UnitsStr(toObjHandle);
59
60    /* Call the C subroutine. */
61    if (fromObj && toObj) {
62        retStr = fromObj->convert(toObj,value,showUnits,&result);
63    }
64
65    /* Set C-style string output_buf to MATLAB mexFunction output*/
66    plhs[0] = mxCreateString(retStr.c_str());
67    plhs[1] = mxCreateDoubleScalar((double)result);
68
69    return;
70}
Note: See TracBrowser for help on using the repository browser.