-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvecdiv.cpp
More file actions
85 lines (70 loc) · 1.83 KB
/
Copy pathvecdiv.cpp
File metadata and controls
85 lines (70 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* VecDivCmd
* The idea is a wrapper to speed up list divition
* See if it works!
*/
#include <iostream>
#include <math.h>
#include "/Censere/pkgs/tk-8.6.8-hbc83047_0/include/tcl.h"
#include <vector>
extern "C" {
int VecDivCmd( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
Tcl_Obj *resultptr;
Tcl_Obj **listv;
int listc1;
int listc2;
if (objc != 3)
{
Tcl_WrongNumArgs(interp,2,objv,
"Usage : vecdiv list1 list2");
return TCL_ERROR;
}
if (Tcl_ListObjGetElements(interp, objv[objc-2],
&listc1, &listv) !=TCL_OK )
{
Tcl_SetResult(interp, (char *) "error parsing argument",
TCL_STATIC);
return -1;
}
std::vector<double> Arr1(listc1, 0);
std::vector<double> Arr2(listc1, 0);
for (int i=0; i<listc1; i++) {
if (Tcl_GetDoubleFromObj(interp, listv[i], &Arr1[i]) != TCL_OK)
{
Tcl_SetResult(interp,
(char *) "error parsing elements from list ", TCL_STATIC);
return -1;
}
}
if (Tcl_ListObjGetElements(interp, objv[objc-1],
&listc2, &listv) !=TCL_OK )
{
Tcl_SetResult(interp,
(char *) "error parsin element ", TCL_STATIC);
return -1;
}
if (listc1 != listc2) {
std::cout << "Lists are different Lenght" << std::endl;
}
for (int i=0; i<listc1; i++) {
if (Tcl_GetDoubleFromObj(interp, listv[i], &Arr2[i]) != TCL_OK)
{
Tcl_SetResult(interp,
(char *) "error parsing elements from list ", TCL_STATIC);
return -1;
}
}
for (int i=0; i<listc1; i++) {
Tcl_SetDoubleObj(listv[i],Arr1[i] / Arr2[i]);
}
resultptr = Tcl_GetObjResult(interp);
Tcl_SetListObj(resultptr, listc1, listv);
return TCL_OK;
}
int Vecdiv_Init( Tcl_Interp *interp )
{
Tcl_CreateObjCommand(interp, "vecdiv", VecDivCmd,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
return TCL_OK;
}
}