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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright (C) 2019 - IIT Bombay - FOSSEE
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
// Author: Rupak Rokade
// Organization: FOSSEE, IIT Bombay
// Email: toolbox@scilab.in
#include<iostream>
#include <stdlib.h>
#include <string.h>
#include"fun.h"
//octave_fun("arburg","signal", [1,2,3,4,5],2)
int main(void)
{
FUNCCALL funcall;
FUNCCALL *funptr = &funcall;
funcall.n_in_arguments = 2;
funcall.n_out_user = 1;
FUNCARGS ins[funcall.n_in_arguments*funcall.n_out_user];
FUNCARGS *argptr = ins;
int a;
int in_type[4] = {10,1};
char str[3][20] = {"hamming","signal"};
int si;
double* d;
int size_double;
for(a = 0; a<funcall.n_in_arguments;a++)
{
if(in_type[a]==1)
{
ins[a].is_in_cmplx = 0;
ins[a].n_in_rows = 1;
ins[a].n_in_cols = 1;
//if(a>2)
//ins[a].n_in_cols = 1;
size_double = ins[a].n_in_rows*ins[a].n_in_cols;
ins[a].type = TYPE_DOUBLE;
ins[a].in_data_real = malloc(sizeof(double)*size_double);
d = (double *)ins[a].in_data_real;
for(int i=0;i<size_double;i++)
d[i] = (i+4);
}
else if(in_type[a]==10)
{
if(a==0)
si=0;// "hamming";
else if(a==1)
si=1;// "pkg";
else
si=2;// "symmetric";
ins[a].type = TYPE_STRING;
int len = strlen(str[si]);
ins[a].n_in_rows = 1;
ins[a].n_in_cols = len;
ins[a].in_data_real = malloc(sizeof(char)*len+1);
char* c = (char *)ins[a].in_data_real;
strcpy(c,str[si]);
std::cout << "func string in main is: " << c << '\n';
}
}
for(int j=0;j<funcall.n_in_arguments;j++)
{
if(in_type[j]==1)
{
d = (double *)ins[j].in_data_real;
size_double = ins[j].n_in_rows*ins[j].n_in_cols;
for(int i=0;i<size_double;i++)
std::cout << "input data" << j<< " is: " << d[i] << '\n';
}
}
fun(argptr, funptr);
for(int j=0;j<funcall.n_out_user;j++)
{
double* rd = (double *)ins[j].out_data_real;
for(int i=0;i<(ins[j].n_out_rows*ins[j].n_out_cols);i++)
std::cout << "output data real: " << j<< " is: " << rd[i] << '\n';
if(ins[j].is_out_cmplx==1)
{
double* cd = (double *)ins[j].out_data_img;
for(int i=0;i<(ins[j].n_out_rows*ins[j].n_out_cols);i++)
std::cout << "output data img: " << j<< " is: " << cd[i] << '\n';
}
}
std::cout << "ins[0].n_in_rows is: " << ins[0].n_in_rows << '\n';
std::cout << "ins[0].n_in_cols is: " << ins[0].n_in_cols << '\n';
for(int i=0;i<funcall.n_in_arguments;i++)
{
free(ins[i].in_data_real);
if(ins[i].is_in_cmplx==1)
free(ins[i].in_data_img);
}
for(int i=0;i<funcall.n_out_user;i++)
{
free(ins[i].out_data_real);
if(ins[i].is_out_cmplx==1)
free(ins[i].out_data_img);
}
//free(ins[1].in_data);
//free(ins[2].in_data);
//free(ins[0].out_data);
return 0;
}
|