1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * INTERFACE: Matlab Rappture Library Source |
---|
4 | * |
---|
5 | * [retStr,err] = rpConvertObjStr(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] = rpConvertObjStr(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 (rpConvertObjStr, args, , |
---|
31 | "-*- texinfo -*-\n\ |
---|
32 | [retStr,err] = rpConvertObjStr(@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 = "rpConvertObjStr"; |
---|
44 | |
---|
45 | // The list of values to return. |
---|
46 | octave_value_list retval; |
---|
47 | |
---|
48 | int err = 1; |
---|
49 | int nargin = args.length (); |
---|
50 | int fromObjHandle = 0; |
---|
51 | int toObjHandle = 0; |
---|
52 | int showUnits = 0; |
---|
53 | double inVal = 0; |
---|
54 | std::string outVal = ""; |
---|
55 | |
---|
56 | const RpUnits* fromObj = NULL; |
---|
57 | const RpUnits* toObj = NULL; |
---|
58 | |
---|
59 | if (nargin == 4) { |
---|
60 | |
---|
61 | if ( args(0).is_real_scalar () && |
---|
62 | args(1).is_real_scalar () && |
---|
63 | args(2).is_real_scalar () && |
---|
64 | args(3).is_real_scalar () ) { |
---|
65 | |
---|
66 | fromObjHandle = args(0).int_value (); |
---|
67 | toObjHandle = args(1).int_value (); |
---|
68 | inVal = args(2).double_value (); |
---|
69 | showUnits = args(3).int_value (); |
---|
70 | |
---|
71 | /* Call the C subroutine. */ |
---|
72 | if ( (fromObjHandle != 0) && |
---|
73 | (toObjHandle != 0) ) { |
---|
74 | |
---|
75 | fromObj = getObject_UnitsStr(fromObjHandle); |
---|
76 | toObj = getObject_UnitsStr(toObjHandle); |
---|
77 | |
---|
78 | if ( fromObj && toObj) { |
---|
79 | outVal = fromObj->convert(toObj,inVal,showUnits,&err); |
---|
80 | } |
---|
81 | |
---|
82 | } |
---|
83 | else { |
---|
84 | print_usage (who.c_str()); |
---|
85 | } |
---|
86 | } |
---|
87 | else { |
---|
88 | print_usage (who.c_str()); |
---|
89 | } |
---|
90 | } |
---|
91 | else { |
---|
92 | print_usage (who.c_str()); |
---|
93 | } |
---|
94 | |
---|
95 | retval(0) = outVal; |
---|
96 | retval(1) = err; |
---|
97 | return retval; |
---|
98 | } |
---|
99 | |
---|