source: trunk/lang/matlab/rpUnitsConvertDbl.cc @ 4346

Last change on this file since 4346 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 2.1 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retVal,result] = rpUnitsConvertDbl(fromVal, toUnitsName)
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] = rpUnitsConvertDbl(fromVal,toUnitsName)
20/// Convert between RpUnits return a double value without units
21/**
22 * Convert the value and units in the string @var{fromVal} to units specified
23 * in string @var{toUnitsName}. Units will not be shown in @var{retVal}.
24 * The second return value @var{err} specifies whether there was an error
25 * during conversion.
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    const char* fromVal     = NULL;
33    const char* toUnitsName  = NULL;
34    int         showUnits   = 0;
35    int         result      = 0;
36    std::string retStr      = "";
37    double      retVal      = 0;
38
39    /* Check for proper number of arguments. */
40    if (nrhs != 2)
41        mexErrMsgTxt("Two input required.");
42    else if (nlhs > 2)
43        mexErrMsgTxt("Too many output arguments.");
44
45    fromVal      = getStringInput(prhs[0]);
46    toUnitsName  = getStringInput(prhs[1]);
47
48    /* Call the C subroutine. */
49    if (fromVal && toUnitsName) {
50        retStr = RpUnits::convert(fromVal,toUnitsName,showUnits,&result);
51
52        if ( !retStr.empty() ) {
53            retVal = atof(retStr.c_str());
54        }
55    }
56
57    /* Set C-style string output_buf to MATLAB mexFunction output*/
58    plhs[0] = mxCreateDoubleScalar(retVal);
59    plhs[1] = mxCreateDoubleScalar((double)result);
60
61    return;
62}
Note: See TracBrowser for help on using the repository browser.