source: trunk/src/matlab/rpConvert.cc @ 115

Last change on this file since 115 was 115, checked in by mmc, 19 years ago

Updated all copyright notices.

File size: 1.5 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    (retStr,result) = rpConvert(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
18void mexFunction(int nlhs, mxArray *plhs[],
19                 int nrhs, const mxArray *prhs[])
20{
21    const char* fromVal     = NULL;
22    const char* toUnitsName  = NULL;
23    int         showUnits   = 0;
24    int         result      = 0;
25    std::string retStr      = "";
26
27    /* Check for proper number of arguments. */
28    if (nrhs != 3)
29        mexErrMsgTxt("Two input required.");
30    else if (nlhs > 2)
31        mexErrMsgTxt("Too many output arguments.");
32
33    fromVal      = getStringInput(prhs[0]);
34    toUnitsName  = getStringInput(prhs[1]);
35    showUnits    = getIntInput(prhs[2]);
36
37    /* Call the C subroutine. */
38    if (fromVal && toUnitsName) {
39        retStr = RpUnits::convert(fromVal,toUnitsName,showUnits,&result);
40    }
41
42    /* Set C-style string output_buf to MATLAB mexFunction output*/
43    plhs[0] = mxCreateString(retStr.c_str());
44    plhs[1] = mxCreateDoubleScalar((double)result);
45
46    return;
47}
Note: See TracBrowser for help on using the repository browser.