source: trunk/src/octave/rpUnitsConvertObjDbl.cc @ 135

Last change on this file since 135 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: 2.9 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  INTERFACE: Matlab Rappture Library Source
4 *
5 *    [retVal,err] = rpUnitsConvertObjDbl(fromObjHandle, toObjHandle, value)
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: [retVal,err] = rpUnitsConvertObjDbl(fromObjHandle,toObjHandle,value)
18/// Convert between RpUnits return a double value without units
19/**
20 * Convert @var{value} from the units represented by the RpUnits object
21 * @var{fromObjHandle} to the units represented by the RpUnits object
22 * @var{toObjHandle}. On success, the converted value is returned through
23 * @var{retVal}. The second return value, @var{err}, specifies whether
24 * there was an error during conversion.
25 * Error code, err=0 on success, anything else is failure.
26 */
27
28DEFUN_DLD (rpUnitsConvertObjDbl, args, ,
29"-*- texinfo -*-\n\
30[retVal,err] = rpUnitsConvertObjDbl(@var{fromObjHandle},@var{toObjHandle},@var{value})\n\
31\n\
32Convert @var{value} from the units represented by the RpUnits object\n\
33@var{fromObjHandle} to the units represented by the RpUnits object\n\
34@var{toObjHandle}. On success, the converted value is returned through\n\
35@var{retVal}. The second return value, @var{err}, specifies whether \n\
36there was an error during conversion.\n\
37Error code, err=0 on success, anything else is failure.")
38{
39    static std::string who = "rpUnitsConvertObjDbl";
40
41    // The list of values to return.
42    octave_value_list retval;
43
44    int err            = 1;
45    int nargin         = args.length ();
46    int fromObjHandle  = 0;
47    int toObjHandle    = 0;
48    double value       = 0;
49
50    const RpUnits* fromObj = NULL;
51    const RpUnits* toObj   = NULL;
52
53    if (nargin == 3) {
54
55        if (    args(0).is_real_scalar () &&
56                args(1).is_real_scalar () &&
57                args(2).is_real_scalar ()   ) {
58
59            fromObjHandle = args(0).int_value ();
60            toObjHandle   = args(1).int_value ();
61            value         = args(2).double_value ();
62
63            /* Call the C subroutine. */
64            if (    (fromObjHandle != 0) &&
65                    (toObjHandle != 0)    ) {
66
67                fromObj = getObject_UnitsStr(fromObjHandle);
68                toObj   = getObject_UnitsStr(toObjHandle);
69
70                if ( fromObj && toObj) {
71                    value = fromObj->convert(toObj,value,&err);
72                }
73
74            }
75            else {
76                print_usage (who.c_str());
77            }
78        }
79        else {
80            print_usage (who.c_str());
81        }
82    }
83    else {
84        print_usage (who.c_str());
85    }
86
87    retval(0) = value;
88    retval(1) = err;
89    return retval;
90}
Note: See TracBrowser for help on using the repository browser.