source: trunk/lang/matlab/rpUnitsFind.cc @ 5119

Last change on this file since 5119 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 *    [unitsHandle,err] = rpUnitsFind(unitSymbol)
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: [unitHandle,err] = rpUnitsFind(unitSymbol)
20/// Search the dictionary of Rappture Units for an instance named 'unitSymbol'
21/**
22 * This method searches the Rappture Units Dictionary for the
23 * RpUnit named 'unitSymbol'. If it is found, its handle is`
24 * returned, as a non-negative integer, to the caller for further use,
25 * else a negative integer is returned signifying no unit of that`
26 * name was found.
27 * If unitSymbol is an empty string, unitHandle will be set to zero and err
28 * will be set to a positive value.
29 * Error code, err=0 on success, anything else is failure.
30 */
31
32void mexFunction(int nlhs, mxArray *plhs[],
33                 int nrhs, const mxArray *prhs[])
34{
35    char *unitSymbol = NULL;
36    const RpUnits* myUnit = NULL;
37    int retHandle = 0;
38    int err = 1;
39
40    /* Check for proper number of arguments. */
41    if (nrhs != 1)
42        mexErrMsgTxt("Two input required.");
43    else if (nlhs > 2)
44        mexErrMsgTxt("Too many output arguments.");
45
46    unitSymbol = getStringInput(prhs[0]);
47
48    /* Call the C subroutine. */
49    if (unitSymbol) {
50        myUnit = RpUnits::find(unitSymbol);
51
52        if (myUnit) {
53            retHandle = storeObject_UnitsStr(myUnit->getUnitsName());
54            if (retHandle) {
55                err = 0;
56            }
57        }
58    }
59
60    /* Set C-style string output_buf to MATLAB mexFunction output*/
61    plhs[0] = mxCreateDoubleScalar(retHandle);
62    plhs[1] = mxCreateDoubleScalar(err);
63
64    return;
65}
Note: See TracBrowser for help on using the repository browser.