From e714c776ac9f5637d1dc4f9eb23c242f83a4e2f9 Mon Sep 17 00:00:00 2001 From: rupak Date: Wed, 13 Nov 2019 15:00:02 +0530 Subject: added src folder for cpp source --- jar/scilab_en_US_help.jar | Bin 16530 -> 16530 bytes macros/octave_fun.bin | Bin 4411 -> 4411 bytes sci_gateway/cpp/libscilab_octave.so | Bin 17160 -> 17160 bytes src/Makefile | 20 ++++ src/fun.cpp | 180 ++++++++++++++++++++++++++++++++++++ src/fun.h | 38 ++++++++ src/fun.o | Bin 0 -> 4617248 bytes src/libfun.so | Bin 0 -> 2887768 bytes src/main.cpp | 112 ++++++++++++++++++++++ src/testfun | Bin 0 -> 41008 bytes thirdparty/linux/lib/x64/libfun.so | Bin 2856176 -> 2887768 bytes 11 files changed, 350 insertions(+) create mode 100755 src/Makefile create mode 100644 src/fun.cpp create mode 100644 src/fun.h create mode 100644 src/fun.o create mode 100755 src/libfun.so create mode 100644 src/main.cpp create mode 100755 src/testfun diff --git a/jar/scilab_en_US_help.jar b/jar/scilab_en_US_help.jar index d876a5c..c7db7b5 100644 Binary files a/jar/scilab_en_US_help.jar and b/jar/scilab_en_US_help.jar differ diff --git a/macros/octave_fun.bin b/macros/octave_fun.bin index 2e1076e..f063b32 100644 Binary files a/macros/octave_fun.bin and b/macros/octave_fun.bin differ diff --git a/sci_gateway/cpp/libscilab_octave.so b/sci_gateway/cpp/libscilab_octave.so index 3a2f181..e8bea75 100755 Binary files a/sci_gateway/cpp/libscilab_octave.so and b/sci_gateway/cpp/libscilab_octave.so differ diff --git a/src/Makefile b/src/Makefile new file mode 100755 index 0000000..ad535f0 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,20 @@ +LIBNAME = fun + +all: lib$(LIBNAME).so test$(LIBNAME) + +$(LIBNAME).o: $(LIBNAME).h $(LIBNAME).cpp + mkoctfile -c -fPIC $(LIBNAME).cpp + +lib$(LIBNAME).so: $(LIBNAME).o + g++ -loctave -loctinterp -shared -o lib$(LIBNAME).so $(LIBNAME).o + +test$(LIBNAME): lib$(LIBNAME).so main.cpp fun.h + g++ -Wall -L$(PWD) -Wl,-rpath=$(PWD) -o $@ main.cpp -l$(LIBNAME) -g -loctave -loctinterp + +install: + cp fun.h ../thirdparty/linux/include/ + cp libfun.so ../thirdparty/linux/lib/x64/ + +.PHONY: clean +clean: + $(RM) -f *.out *.so *.o *.oct diff --git a/src/fun.cpp b/src/fun.cpp new file mode 100644 index 0000000..31d5dc1 --- /dev/null +++ b/src/fun.cpp @@ -0,0 +1,180 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "fun.h" + +extern "C" +{ + int fun(FUNCARGS *inp, FUNCCALL *funcall) + { + + static octave::interpreter interpreter; + bool status = interpreter.initialized(); + + if(status==false) + { + interpreter.initialize (); + int status_exec = interpreter.execute (); + + if (status_exec != 0) + { + std::cerr << "creating embedded Octave interpreter failed!" + << std::endl; + } + } + + try + { + octave_value_list in; + unsigned int k; + int l; + int str_count = 0; + char str_fun[20]; + char str_pkg[20]; + int pkg=0; + int nouts; + for(l=0;ln_in_arguments;l++) + { + if(inp[l].type==TYPE_DOUBLE) + { + if(inp[l].is_in_cmplx==1) + { + ComplexMatrix matr = ComplexMatrix (inp[l].n_in_rows,inp[l].n_in_cols); + double* id_real = (double *)inp[l].in_data_real; + double* id_img = (double *)inp[l].in_data_img; + k=0; + for (int r=0;rn_out_user); + + + int row; + int col; + nouts = out.length(); + funcall->n_out_arguments = nouts; +//std::cout << "funcall->n_out_arguments is: " << funcall->n_out_arguments << '\n'; + + for( unsigned int ii = 0; ii < nouts; ii++ ) + { + if(out(ii).iscomplex()==1) + { + inp[ii].is_out_cmplx=1; + //std::cout << "out "<< ii<< " is complex" << '\n'; + ComplexMatrix cmOut(out(ii).complex_matrix_value()); + //std::cout << "cmOut "<< cmOut << '\n'; + //std::cout << "Out(ii) "<< out(ii).complex_matrix_value() << '\n'; + //std::cout << "out(ii) "<< out(ii) << '\n'; + row = cmOut.rows(); + col = cmOut.columns(); + inp[ii].n_out_rows = row; + inp[ii].n_out_cols = col; + k=0; + inp[ii].out_data_real = malloc(sizeof(double)*(row*col)); + inp[ii].out_data_img = malloc(sizeof(double)*(row*col)); + double* rd = (double *)inp[ii].out_data_real; + double* cd = (double *)inp[ii].out_data_img; + for(unsigned int i=0;i +#include +#include +#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; a2) + //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