summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--macros/scilab_error.binbin1951 -> 1951 bytes
-rw-r--r--macros/scilab_sum.binbin913 -> 913 bytes
-rwxr-xr-xsci_gateway/cpp/libscilab_toolbox.sobin17144 -> 17024 bytes
-rw-r--r--sci_gateway/cpp/sci_matrix.cpp219
-rw-r--r--test.sce206
-rw-r--r--thirdparty/linux/include/fun.h37
-rwxr-xr-xthirdparty/linux/lib/x64/libfun.sobin2728112 -> 2753112 bytes
7 files changed, 332 insertions, 130 deletions
diff --git a/macros/scilab_error.bin b/macros/scilab_error.bin
index fa6a4de..42580e8 100644
--- a/macros/scilab_error.bin
+++ b/macros/scilab_error.bin
Binary files differ
diff --git a/macros/scilab_sum.bin b/macros/scilab_sum.bin
index e809335..6d27d24 100644
--- a/macros/scilab_sum.bin
+++ b/macros/scilab_sum.bin
Binary files differ
diff --git a/sci_gateway/cpp/libscilab_toolbox.so b/sci_gateway/cpp/libscilab_toolbox.so
index 9fcddc9..9e0c225 100755
--- a/sci_gateway/cpp/libscilab_toolbox.so
+++ b/sci_gateway/cpp/libscilab_toolbox.so
Binary files differ
diff --git a/sci_gateway/cpp/sci_matrix.cpp b/sci_gateway/cpp/sci_matrix.cpp
index b41026c..26fd7dd 100644
--- a/sci_gateway/cpp/sci_matrix.cpp
+++ b/sci_gateway/cpp/sci_matrix.cpp
@@ -1,7 +1,7 @@
#include <string>
#include "wchar.h"
#include <cstdlib>
-//#include <ctype.h>
+
extern "C"
{
#include<Scierror.h>
@@ -13,160 +13,139 @@ extern "C"
#include <math.h>
#include <stdio.h>
#include "os_string.h"
+#include <stdlib.h>
static const char fname[] = "octave_fun";
-///////#####call octave_fun([2],"hamming") ########////////////
+///////#####call octave_fun("hamming",[5],"periodic") ########////////////
int sci_octave_fun(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt* opt, int nout, scilabVar* out)
{
- if (nin < 2)
+//printf("nin: %d\n", nin);
+ if (nin < 1)
{
- Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
+ Scierror(999, _("%s: Wrong number of input arguments. Atleast %d expected.\n"), fname, 1);
return STATUS_ERROR;
}
-/*
-int typ=0;
- for(int i=1;i<nin+1;i++)
- {
- typ = scilab_getType(env, in[i-1]);
- printf("Type of input %d is: %d\n",i,typ);
- }
-printf("%s\n","1 - sci_matrix: a matrix of doubles");
-printf("%s\n","10 - sci_strings: a matrix of strings");
-printf("%s\n", "=================================");
-*/
+ FUNCCALL funcall;
+ FUNCCALL *funptr = &funcall;
+ funcall.n_in_arguments = nin;
+ funcall.n_out_user = nout;
-/*
- printf("%d\n", nin);
- int row = 0;
- int col = 0;
- int size = 0;
- size = scilab_getDim2d(env, in[0], &row, &col);
- printf("%d\n", row);
- printf("%d\n", col);
- int i=3;
-*/
-
- octf ins;
+ FUNCARGS ins[funcall.n_in_arguments*nout];
+ FUNCARGS *argptr = ins;
- octf *inptr = &ins;
-///////////////////First Input/////////////////////
+ int i,j;
+ double* d;
+ int size;
+ char str[20];
+ char* c;
double* n = NULL;
int row = 0;
int col = 0;
- int size = 0;
- size = scilab_getDim2d(env, in[0], &row, &col);
- scilab_getDoubleArray(env, in[0], &n);
-// double ar[(int)n[0]];//output size can be defined here
-
-// if((int)n[0]!=NULL)
-// if(in[i]!=NULL)
-// printf("\nInput %d is not null\n",i);
-
-//double inp[col];
-ins.input1 = new double[col];
-ins.size_input1[2]=col;
- for(int i=0; i<col; i++)
- {
- ins.input1[i] = n[i];//.float_value();
+ for(i=0;i<nin;i++)
+ {
+ if(scilab_getType(env, in[i])==1)
+ {
+ ins[i].type = TYPE_DOUBLE;
+ size = scilab_getDim2d(env, in[i], &row, &col);
+ ins[i].n_in_rows = row;
+ ins[i].n_in_cols = col;
+ scilab_getDoubleArray(env, in[i], &n);
+
+ ins[i].in_data = malloc(sizeof(double)*size);
+ d = (double *)ins[i].in_data;
+
+ for(j=0;j<size;j++)
+ {
+ d[j] = n[j];
+ //printf("%f\n",d[j]);
+ }
}
-
-////////////////Second Input/////////////////////
- wchar_t* in1 = 0;
-
- char str[20];
- if (scilab_isString(env, in[1]) == 0)
- {
- Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), fname, 2);
- return STATUS_ERROR;
- }
- else
+ else if(scilab_getType(env, in[i])==10)
{
- scilab_getString(env, in[1], &in1);
+ wchar_t* in1 = 0;
+
+ scilab_getString(env, in[i], &in1);
//printf("%S\n", in1);
- wcstombs(str, in1, sizeof(str));
+ wcstombs(str, in1, sizeof(str));
//printf("%s\n", str);
if(str)
- ins.name1 = str;
+ {
+ //printf("lenght of string input: %d\n", strlen(str));
+ ins[i].type = TYPE_STRING;
+ ins[i].n_in_rows = 1;
+ ins[i].n_in_cols = strlen(str);
+ size = (ins[i].n_in_rows)*(ins[i].n_in_cols);
+ ins[i].in_data = malloc(sizeof(char)*size+1);
+ c = (char *)ins[i].in_data;
+ int ci;
+
+ strcpy(c,str);
+ ins[i].n_in_cols = strlen(c);
+ //printf("in scilab strin is: %s\n", c);
+
+ }
}
-////////////////Third Input/////////////////////
-if(nin<3)
-{
- ins.name2 = NULL;
-}
-else
-{
-
-
-
- wchar_t* in4 = 0;
+ }
- char str2[20];
+ int status_fun = fun(argptr, funptr);
+ //printf("in scilab status_fun is: %d\n", status_fun);
+ //printf("in scilab funcall.n_out_arguments is: %d\n", funcall.n_out_arguments);
+ //printf("in scilab funcall.n_out_user is: %d\n", funcall.n_out_user);
+//printf("in scilab ins[0].n_out_rows is: %d\n", ins[0].n_out_rows);
+//printf("in scilab ins[0].n_out_cols is: %d\n", ins[0].n_out_cols);
- if (scilab_isString(env, in[2]) == 0)
- {
- printf("Here----------------");
- ins.name2 = NULL;
- Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), fname, 3);
- return STATUS_ERROR;
- }
- else
+//printf("in scilab ouput args are: %d\n", funcall.n_out_arguments);
+ if(status_fun==1)
+ {
+ return 1;
+ }
+ else if(funcall.n_out_user <= funcall.n_out_arguments)
+ {
+ for(i=0;i<nout;i++)
+ {
+ out[i] = scilab_createDoubleMatrix2d(env, ins[i].n_out_rows, ins[i].n_out_cols, 0);
+
+ double* out1 = NULL;
+ scilab_getDoubleArray(env, out[i], &out1);
+ int len = ins[i].n_out_rows*ins[i].n_out_cols;
+ double* dd = (double *)ins[i].out_data;
+ //printf("output length is: %d\n", len);
+ for(j=0; j<len; j++)
{
- scilab_getString(env, in[2], &in4);
- //printf("%S\n", in1);
-
- wcstombs(str2, in4, sizeof(str2));
- //printf("%s\n", str);
- if(!*str2)
- ins.name2 = str2;
- else
- ins.name2 = NULL;
+ out1[j] = dd[j];//.float_value();
}
+ }
+ }
+ else
+ {
+ Scierror(77, _("%s: Wrong number of output argument(s): This function can return a maximum of %d output(s).\n"), fname, funcall.n_out_arguments);
+ return 1;
+ }
-}
-
-//if (nin != 0)
-// {
-// Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), fname, 1);
-// return 1;
-// }
-
-if (nout != 1)
- {
- Scierror(77, _("%s: Wrong number of output argument(s): %d expected.\n"), fname, 1);
- return 1;
- }
-
- //fun(ar, inp, col, str, str2);
- int status_fun = fun(inptr);
- if(status_fun==1)
+ for(i=0;i<nout;i++)
{
- return 1;
+ //printf("%ld : ",&ins[i].in_data);
+ // printf("%f\n",(*(double *)ins[i].in_data));
+
+ free(ins[i].out_data);
}
- else
- {
- out[0] = scilab_createDoubleMatrix2d(env, ins.size_output1[1], 1, 0);
-
- double* out1 = NULL;
- scilab_getDoubleArray(env, out[0], &out1);
-
- for(int i=0; i<ins.size_output1[1]; i++)
- {
- out1[i] = ins.output1[i];//.float_value();
- }
- free(ins.output1);
- free(ins.input1);
+ for(i=0;i<nin;i++)
+ {
+ //printf("%ld : ",&ins[i].in_data);
+ // printf("%f\n",(*(double *)ins[i].in_data));
+
+ free(ins[i].in_data);
}
-
- return 0;
+ return 0;
}
}
diff --git a/test.sce b/test.sce
new file mode 100644
index 0000000..7a6f906
--- /dev/null
+++ b/test.sce
@@ -0,0 +1,206 @@
+test_pass=[]
+res=[]
+
+test1=0
+exec loader.sce
+/////////Test case for 2) arburg //////////
+
+a = octave_fun("arburg","signal", [1,2,3,4,5],2);
+a = round(a*10000)/10000;
+
+if(a == [1. -1.8639 0.9571])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("arburg test failed")
+end
+
+/////////Test case for 4) aryule //////////
+
+a = octave_fun("aryule","signal", [1,2,3,4,5],2);
+a = round(a*10000)/10000;
+
+if(a == [1. -0.814 0.1193])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("aryule test failed")
+end
+
+/////////Test case for 38)levinson //////////
+
+a = [1 0.1 -0.8];
+v = 0.4;
+rand("seed", 0);
+w = sqrt(v)*rand(15000,1);
+x=octave_fun("filter","signal",1,a,w);
+
+r=octave_fun("xcorr","signal",x);
+
+ar=octave_fun("levinson","signal",r,length(a)-1);
+
+ar = round(ar*10000)/10000;
+
+if(ar == [1 0.0984 -0.793])
+ test_pass=[test_pass,1]
+ else
+ test_pass=[test_pass,0]
+ disp("levinson Test failed")
+end
+
+/////////Test case for **)sigmoid_train //////////
+
+s = octave_fun("sigmoid_train",0.1,[1:3],[4]);
+s = round(s*10000)/10000
+
+if(s == 0.2737)
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("sigmoid_train Test failed")
+end
+
+/////////Test case for **)circshift /////////
+
+ M = [1 2 3 4];
+ R = octave_fun("circshift",M,[0 1]);
+
+if(R == [4 1 2 3])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("circshift failed")
+end
+
+/////////////////////////////////////////////
+/////////Test case for **)kaiser //////////
+
+win = octave_fun("kaiser",6,[0.2]) ;
+win = round(win*10000)/10000;
+
+if(win == [ 0.9901; 0.9964; 0.9996; 0.9996; 0.9964; 0.9901 ])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("kaiser Test failed")
+end
+
+/////////////////////////////////////////////
+
+/////////////////////////////////////////////
+
+
+/////////Test case for autoreg_matrix //////////
+m = octave_fun("autoreg_matrix",[1 2 3],[2]);
+
+if(m == [1 0 0; 1 1 0; 1 2 1])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("autoreg_matrix test failed")
+end
+
+/////////////////////////////////////////////
+/////////Test case for arch_rnd //////////
+
+a = [1 2 3 4 5];
+b = [7 8 9 10];
+t = 5 ;
+rand("seed", 0)
+m = octave_fun("arch_rnd",a,b,t);
+m = round(m*1000)/1000
+
+if(m == [ 7.211
+ 65.48
+ 654.008
+ 7194.657
+ 78364.905 ])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("arch_rnd Test failed")
+end
+
+/////////////////////////////////////////////
+
+/////////Test case for postpad //////////
+
+y = octave_fun("postpad",[1 2 3],6);
+
+if(y == [1 2 3 0 0 0 ] )
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("postpad Test failed")
+end
+
+
+/////////Test case for wconv //////////
+a = [1 2 3 4 5];
+b = [7 8 9 10];
+y = octave_fun("wconv",[1],a,b);
+
+if(y == [7. 22. 46. 80. 114. 106. 85. 50.])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("wconv Test failed")
+end
+/////////Test case for dctmtx //////////
+T = octave_fun("dctmtx",[3]);
+T = round(T*10000)/10000;
+if(T == [0.5774 0.5774 0.5774; 0.7071 0 -0.7071; 0.4082 -0.8165 0.4082])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("dctmtx Test failed")
+end
+
+/////////Test case for 40) medfilt1 //////////
+
+
+fs = 100;
+t = 0:1/fs:1;
+x = sin(2*%pi*t*3)+0.25*sin(2*%pi*t*40);
+
+y = octave_fun("medfilt1","signal",x,10);
+y = round(y*10000)/10000 ;
+y = y'
+
+if(y == fscanfMat("macros/medfilt1op.txt"))
+ test_pass=[test_pass,1]
+ else
+ test_pass=[test_pass,0]
+ disp("medfilt1 Test failed")
+end
+
+/////////////////////////////////////////////
+/////////Test case for arma_rnd //////////
+
+a = [1 2 3 4 5];
+b = [7; 8; 9; 10; 11];
+t = 5 ;
+v = 10 ;
+n = 100 ;
+rand("seed", 0)
+m = octave_fun("arma_rnd","signal",a, b, v, t, n);
+m = round(m) ;
+
+if(m == [ 61401.
+ 158177.
+ 407440.
+ 1049604.
+ 2703841. ])
+ test_pass=[test_pass,1]
+else
+ test_pass=[test_pass,0]
+ disp("arma_rnd Test failed")
+end
+/////////////////////////////////////////////
+res=find(test_pass==0)
+
+if(res~=[])
+ disp("One or more tests failed in test1")
+ disp(length(test_pass),"Total functions tested in test1:")
+ test1=1;
+end
diff --git a/thirdparty/linux/include/fun.h b/thirdparty/linux/include/fun.h
index 9b59492..45f5a7d 100644
--- a/thirdparty/linux/include/fun.h
+++ b/thirdparty/linux/include/fun.h
@@ -3,15 +3,32 @@
extern "C"
{
-typedef struct octave_fun
-{
- char* name1 = "";
- char* name2 = "";
- double* input1;
- int size_input1[2];
- double* output1;
- int size_output1[2];
-}octf;
-int fun(octf *inp);
+ typedef enum
+ {
+ TYPE_DOUBLE,
+ TYPE_STRING,
+ }FUNCTYPE;
+
+ typedef struct
+ {
+ FUNCTYPE type;
+ int n_in_rows;
+ int n_in_cols;
+ int n_out_rows;
+ int n_out_cols;
+ void* in_data;
+ void* out_data;
+ }FUNCARGS;
+
+ typedef struct {
+ int n_in_arguments; // number of input arguments
+ int n_out_arguments; // number of output arguments
+ int n_out_user; // number of output arguments
+ //char *name; // Name
+ //char *package; //Name of octave package to be loaded
+ FUNCARGS *argument;
+} FUNCCALL;
+
+ int fun(FUNCARGS *arr, FUNCCALL *call);
}
diff --git a/thirdparty/linux/lib/x64/libfun.so b/thirdparty/linux/lib/x64/libfun.so
index dba701d..191f3a6 100755
--- a/thirdparty/linux/lib/x64/libfun.so
+++ b/thirdparty/linux/lib/x64/libfun.so
Binary files differ