source: trunk/lang/octave/rpUnitsDefineUnit.cc @ 1095

Last change on this file since 1095 was 135, checked in by dkearney, 18 years ago

1) fixed children function in c++'s library module so users can now
search for children by type.
2) adjusted bindings dictionary module for storing lib's to allow caller
to set the key of the value being stored.
3) removed old targets for rappture_interface.o and rappture_fortran.o
from makefile
4) renamed matlab and octave binding functions names to match the module
they came from.
5) adjusted matlab/octave example in examples/app_fermi/matlab
6) added matlab and octave search paths environment variables to
gui/apps/rappture

File size: 3.7 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Octave Rappture Library Source
4 *
5 *    [unitsHandle,err] = rpUnitsDefineUnit(unitSymbol, basisHandle)
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: [unitsHandle,err] = rpUnitsDefineUnit(unitSymbol, basisHandle)
18/// Define a new Rappture Units type.
19/**
20 * Define a new Rappture Units type which can be searched for using
21 * @var{unitSymbol} and has a basis of @var{basisHandle}. Because of
22 * the way the Rappture Units module parses unit names, complex units must
23 * be defined as multiple basic units. See the RpUnits Howto for more
24 * information on this topic. A @var{basisHandle} equal to 0 means that
25 * the unit being defined should be considered as a basis. Unit names must
26 * not be empty strings.
27 *
28 * The first return value, @var{unitsHandle} represents the handle of the
29 * instance of the RpUnits object inside the internal dictionary. On
30 * success this value will be greater than zero (0), any other value is
31 * represents failure within the function. The second return value
32 * @var{err} represents the error code returned from the function.
33 *
34 * Error code, err=0 on success, anything else is failure.
35 */
36
37DEFUN_DLD (rpUnitsDefineUnit, args, ,
38"-*- texinfo -*-\n\
39[unitsHandle,err] = rpUnitsDefineUnit(@var{unitSymbol},@var{basisHandle})\n\
40\n\
41Define a new Rappture Units type which can be searched for using\n\
42@var{unitSymbol} and has a basis of @var{basisHandle}. Because of\n\
43the way the Rappture Units module parses unit names, complex units must\n\
44be defined as multiple basic units. See the RpUnits Howto for more\n\
45information on this topic. A @var{basisHandle} equal to 0 means that\n\
46the unit being defined should be considered as a basis. Unit names must\n\
47not be empty strings.\n\
48\n\
49The first return value, @var{unitsHandle} represents the handle of the\n\
50instance of the RpUnits object inside the internal dictionary. On\n\
51success this value will be greater than zero (0), any other value is\n\
52represents failure within the function. The second return value\n\
53@var{err} represents the error code returned from the function.\n\
54\n\
55Error code, err=0 on success, anything else is failure.")
56{
57    static std::string who = "rpUnitsDefineUnit";
58
59    // The list of values to return.
60    octave_value_list retval;
61    int err                  = 1;
62    int nargin               = args.length ();
63    std::string unitSymbol   = "";
64    int basisHandle          = 0;
65    RpUnits* newUnit         = NULL;
66    const RpUnits* basisUnit = NULL;
67
68    if (nargin == 2) {
69
70        if (    args(0).is_string      () &&
71                args(1).is_real_scalar ()    ) {
72
73            unitSymbol  = args(0).string_value ();
74            basisHandle = args(1).int_value ();
75
76            // Call the C++ subroutine.
77            if ( !unitSymbol.empty() ) {
78
79                basisUnit = getObject_UnitsStr(basisHandle);
80                newUnit = RpUnits::define(unitSymbol,basisUnit);
81                if (newUnit) {
82                    err = 0;
83                }
84            }
85            else {
86                print_usage (who.c_str());
87            }
88        }
89        else {
90            print_usage (who.c_str());
91        }
92    }
93    else {
94        print_usage (who.c_str());
95    }
96
97    retval(0) = storeObject_UnitsStr(newUnit->getUnitsName());
98    retval(1) = err;
99    return retval;
100}
Note: See TracBrowser for help on using the repository browser.