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 | |
---|
28 | DEFUN_DLD (rpUnitsConvertObjDbl, args, , |
---|
29 | "-*- texinfo -*-\n\ |
---|
30 | [retVal,err] = rpUnitsConvertObjDbl(@var{fromObjHandle},@var{toObjHandle},@var{value})\n\ |
---|
31 | \n\ |
---|
32 | Convert @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\ |
---|
36 | there was an error during conversion.\n\ |
---|
37 | Error 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 | } |
---|