source: trunk/src/matlab/rpUnitsDefineUnit.cc @ 962

Last change on this file since 962 was 154, checked in by dkearney, 18 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.7 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [unitsHandle,err] = rpUnitsDefineUnit(unitSymbol, basisHandle)
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: [unitsHandle,err] = rpUnitsDefineUnit(unitSymbol, basisHandle)
20/// Define a new Rappture Units type.
21/**
22 * Define a new Rappture Units type which can be searched for using
23 * @var{unitSymbol} and has a basis of @var{basisHandle}. Because of
24 * the way the Rappture Units module parses unit names, complex units must
25 * be defined as multiple basic units. See the RpUnits Howto for more
26 * information on this topic. A @var{basisHandle} equal to 0 means that
27 * the unit being defined should be considered as a basis. Unit names must
28 * not be empty strings.
29 *
30 * The first return value, @var{unitsHandle} represents the handle of the
31 * instance of the RpUnits object inside the internal dictionary. On
32 * success this value will be greater than zero (0), any other value is
33 * represents failure within the function. The second return value
34 * @var{err} represents the error code returned from the function.
35 *
36 * Error code, err=0 on success, anything else is failure.
37 */
38
39void mexFunction(int nlhs, mxArray *plhs[],
40                 int nrhs, const mxArray *prhs[])
41{
42    char *unitSymbol = NULL;
43    const RpUnits* basis = NULL;
44    RpUnits* myUnit = NULL;
45    int retHandle = 0;
46    int basisHandle = 0;
47    int retIndex = 0;
48    int err = 1;
49
50    /* Check for proper number of arguments. */
51    if (nrhs != 2)
52        mexErrMsgTxt("Two input required.");
53    else if (nlhs > 2)
54        mexErrMsgTxt("Too many output arguments.");
55
56    unitSymbol = getStringInput(prhs[0]);
57    basisHandle = getIntInput(prhs[1]);
58
59    /* Call the C subroutine. */
60    if (basisHandle > 0) {
61        basis = getObject_UnitsStr(basisHandle);
62    }
63
64    if (unitSymbol) {
65        myUnit = RpUnits::define(unitSymbol,basis);
66
67        if (myUnit) {
68            retHandle = storeObject_UnitsStr(myUnit->getUnitsName());
69            if (retHandle) {
70                err = 0;
71            }
72        }
73    }
74
75    /* Set C-style string output_buf to MATLAB mexFunction output*/
76    plhs[0] = mxCreateDoubleScalar(retHandle);
77    plhs[1] = mxCreateDoubleScalar(err);
78
79    return;
80}
Note: See TracBrowser for help on using the repository browser.