source: tags/20100403/lang/octave/rpUnitsFind.cc @ 1687

Last change on this file since 1687 was 1262, checked in by dkearney, 15 years ago

attempting to fix compiler warning for octave's print_usage function
this seems to work for octave3.0
also adding checks to configure for more header files

File size: 2.8 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [unitHandle,err] = rpUnitsFind(unitSymbol)
6 *
7 * ======================================================================
8 *  AUTHOR:  Derrick Kearney, Purdue University
9 *  Copyright (c) 2005
10 *  Purdue Research Foundation, West Lafayette, IN
11 * ======================================================================
12 */
13
14#include "RpOctaveInterface.h"
15
16/**********************************************************************/
17// METHOD: [unitHandle,err] = rpUnitsFind(unitSymbol)
18/// Search the dictionary of Rappture Units for an instance named 'unitSymbol'
19/**
20 * This method searches the Rappture Units Dictionary for the
21 * RpUnit named 'unitSymbol'. If it is found, its handle is
22 * returned, as a non-negative integer, to the caller for further use,
23 * else a negative integer is returned signifying no unit of that
24 * name was found.
25 * If unitSymbol is an empty string, unitHandle will be set to zero and err
26 * will be set to a positive value.
27 * Error code, err=0 on success, anything else is failure.
28 */
29
30DEFUN_DLD (rpUnitsFind, args, ,
31"-*- texinfo -*-\n\
32[unitHandle,err] = rpUnitsFind(@var{unitSymbol})\n\
33\n\
34This method searches the Rappture Units Dictionary for the\n\
35RpUnit named @var{unitSymbol}. If it is found, its handle is \n\
36returned, as a non-negative integer, to the caller for further use,\n\
37else a negative integer is returned signifying no unit of that \n\
38name was found.\n\
39If @var{unitSymbol} is an empty string, @var{unitHandle} will be set to\n\
40zero and @var{err} will be set to a positive value.\n\
41Error code, err=0 on success, anything else is failure.")
42{
43    static std::string who = "rpUnitsFind";
44
45    // The list of values to return.
46    octave_value_list retval;
47    int err = 1;
48    int nargin = args.length ();
49    std::string unitSymbol = "";
50    int retHandle = -1;
51    const RpUnits* retUnit = NULL;
52
53    if (nargin == 1) {
54
55        if ( args(0).is_string() ) {
56
57            unitSymbol = args(0).string_value ();
58
59            /* Call the C subroutine. */
60            if ( !unitSymbol.empty() ) {
61
62                retUnit = RpUnits::find(unitSymbol);
63                // store the returned unit
64                if (retUnit) {
65                    // store the unit
66                    retHandle = storeObject_UnitsStr(retUnit->getUnitsName());
67                    // adjust error code
68                    if (retHandle >= 0) {
69                        err = 0;
70                    }
71                }
72            }
73            else {
74                _PRINT_USAGE (who.c_str());
75            }
76        }
77        else {
78            _PRINT_USAGE (who.c_str());
79        }
80    }
81    else {
82        _PRINT_USAGE (who.c_str());
83    }
84
85    retval(0) = retHandle;
86    retval(1) = err;
87    return retval;
88}
Note: See TracBrowser for help on using the repository browser.