source: trunk/lang/matlab/rpUnitsConvertStr.cc @ 1018

Last change on this file since 1018 was 154, checked in by dkearney, 19 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.1 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retStr,result] = rpUnitsConvertStr(fromVal, toUnitsName, showUnits)
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: [retStr,err] = rpUnitsConvertStr(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("Three 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.