source: trunk/lang/matlab/rpUnitsConvert.cc @ 3482

Last change on this file since 3482 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 *    [retStr,result] = rpUnitsConvert(fromVal, toUnitsName, showUnits)
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: [retStr,err] = rpUnitsConvert(fromVal,toUnitsName,showUnits)
20/// Convert between RpUnits return a string value with or without units
21/**
22 * Convert the value and units in the string @var{fromVal} to units specified
23 * in string @var{toUnitsName}. If @var{showUnits} is set to 1, then show the
24 * units in the returned string @var{retStr}, else leave the units off.
25 * The second return value @var{err} specifies whether there was an error
26 * 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    const char* fromVal     = NULL;
34    const char* toUnitsName  = NULL;
35    int         showUnits   = 0;
36    int         result      = 0;
37    std::string retStr      = "";
38
39    /* Check for proper number of arguments. */
40    if (nrhs != 3)
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    showUnits    = getIntInput(prhs[2]);
48
49    /* Call the C subroutine. */
50    if (fromVal && toUnitsName) {
51        retStr = RpUnits::convert(fromVal,toUnitsName,showUnits,&result);
52    }
53
54    /* Set C-style string output_buf to MATLAB mexFunction output*/
55    plhs[0] = mxCreateString(retStr.c_str());
56    plhs[1] = mxCreateDoubleScalar((double)result);
57
58    return;
59}
Note: See TracBrowser for help on using the repository browser.