1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: Matlab Rappture Library Source |
---|
4 | * |
---|
5 | * [retStr,err] = rpUnitsConvertObjStr(fromObjHandle,toObjHandle,value,showUnits) |
---|
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: [retStr,err] = rpUnitsConvertObjStr(fromObjHandle,toObjHandle,value,showUnits) |
---|
18 | /// Convert between RpUnits return a string value with or 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}. If @var{showUnits} is set to 0, no units will be |
---|
23 | * displayed in @var{retStr}, else units are displayed. |
---|
24 | * On success, the converted value is returned through |
---|
25 | * @var{retStr}. The second return value, @var{err}, specifies whether |
---|
26 | * there was an error during conversion. |
---|
27 | * Error code, err=0 on success, anything else is failure. |
---|
28 | */ |
---|
29 | |
---|
30 | DEFUN_DLD (rpUnitsConvertObjStr, args, , |
---|
31 | "-*- texinfo -*-\n\ |
---|
32 | [retStr,err] = rpUnitsConvertObjStr(@var{fromObjHandle},@var{toObjHandle},@var{value},@var{showUnits})\n\ |
---|
33 | \n\ |
---|
34 | Convert @var{value} from the units represented by the RpUnits object\n\ |
---|
35 | @var{fromObjHandle} to the units represented by the RpUnits object\n\ |
---|
36 | @var{toObjHandle}. If @var{showUnits} is set to 0, no units will be\n\ |
---|
37 | displayed in @var{retStr}, else units are displayed.\n\ |
---|
38 | On success, the converted value is returned through\n\ |
---|
39 | @var{retStr}. The second return value, @var{err}, specifies whether \n\ |
---|
40 | there was an error during conversion.\n\ |
---|
41 | Error code, err=0 on success, anything else is failure.") |
---|
42 | { |
---|
43 | static std::string who = "rpUnitsConvertObjStr"; |
---|
44 | |
---|
45 | // The list of values to return. |
---|
46 | octave_value_list retval; |
---|
47 | int err = 1; |
---|
48 | std::string outVal = ""; |
---|
49 | if (args.length() == 4) { |
---|
50 | if ((args(0).is_real_scalar()) && (args(1).is_real_scalar()) && |
---|
51 | (args(2).is_real_scalar()) && (args(3).is_real_scalar())) { |
---|
52 | int fromObjHandle; |
---|
53 | int toObjHandle; |
---|
54 | int showUnits; |
---|
55 | double inVal; |
---|
56 | |
---|
57 | fromObjHandle = args(0).int_value(); |
---|
58 | toObjHandle = args(1).int_value(); |
---|
59 | inVal = args(2).double_value(); |
---|
60 | showUnits = args(3).int_value(); |
---|
61 | |
---|
62 | /* Call the C subroutine. */ |
---|
63 | if ((fromObjHandle != 0) && (toObjHandle != 0)) { |
---|
64 | const RpUnits* fromObj; |
---|
65 | const RpUnits* toObj; |
---|
66 | |
---|
67 | fromObj = getObject_UnitsStr(fromObjHandle); |
---|
68 | toObj = getObject_UnitsStr(toObjHandle); |
---|
69 | if (fromObj && toObj) { |
---|
70 | outVal = fromObj->convert(toObj, inVal, showUnits, &err); |
---|
71 | } |
---|
72 | } else { |
---|
73 | _PRINT_USAGE(who.c_str()); |
---|
74 | } |
---|
75 | } else { |
---|
76 | _PRINT_USAGE(who.c_str()); |
---|
77 | } |
---|
78 | } else { |
---|
79 | _PRINT_USAGE(who.c_str()); |
---|
80 | } |
---|
81 | retval(0) = outVal; |
---|
82 | retval(1) = err; |
---|
83 | return retval; |
---|
84 | } |
---|
85 | |
---|