From d5d77fe4d8f3cd14dc3083ae0e5687b4f56976e4 Mon Sep 17 00:00:00 2001 From: KRIXUS-alpha Date: Wed, 12 May 2021 14:04:10 +0530 Subject: documentation struct --- sci_gateway/cpp/sci_octave.cpp | 618 ++++++++++++++++++++++++++++------------- src/fun.cpp | 309 ++++++++++++++++----- src/fun.h | 96 +++++-- 3 files changed, 734 insertions(+), 289 deletions(-) diff --git a/sci_gateway/cpp/sci_octave.cpp b/sci_gateway/cpp/sci_octave.cpp index 5f1f685..f106be3 100644 --- a/sci_gateway/cpp/sci_octave.cpp +++ b/sci_gateway/cpp/sci_octave.cpp @@ -17,9 +17,9 @@ extern "C" { -#include -#include -#include +#include +#include +#include #include "localization.h" #include "fun.h" #include @@ -28,226 +28,472 @@ extern "C" #include "os_string.h" #include + static const char fname[] = "octave_fun"; + + /** + * @brief Function to connect to Scilab's API. + * + * This function will get Data from Scilab, proccess the data + * in Octave then return the output back to Scilab using the + * API. + * + * @param env Scialb env + * @param nin[in] Number of input arguments + * @param in[in] Input Parameters + * @param nopt[in] Number of optional parameters + * @param opt[in] Optional parameters + * @param nout[out] Number of expected output parametets + * @param out[out] Array for output data + * @return int + */ + int sci_octave_fun(scilabEnv env, int nin, scilabVar *in, int nopt, scilabOpt *opt, int nout, scilabVar *out) - -static const char fname[] = "octave_fun"; -int sci_octave_fun(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt* opt, int nout, scilabVar* out) - -{ -//printf("nin: %d\n", nin); - if (nin < 2) - { - Scierror(999, _("%s: Wrong number of input arguments. Atleast %d expected.\n"), fname, 2); - return STATUS_ERROR; - } - - FUNCCALL funcall; - FUNCCALL *funptr = &funcall; - funcall.n_in_arguments = nin; - funcall.n_out_user = nout; - - FUNCARGS ins[funcall.n_in_arguments*nout]; - FUNCARGS *argptr = ins; - - int i,j; - double* d; - double* rd = NULL;; - double* cd = NULL;; - int size; - char str[20]; - char* c; - double* n = NULL; - int row = 0; - int col = 0; - double* in_real; - double* in_img; - - for(i=0;i #include #include +#include #include "fun.h" extern "C" { + /*! + * \brief Function to Interact with Octave's API. + * + * This Function will be communicating with Octave to access it's function. + */ int fun(FUNCARGS *inp, FUNCCALL *funcall) { - static octave::interpreter interpreter; + static octave::interpreter interpreter; bool status = interpreter.initialized(); - - if(status==false) + // Check octave interpreter loaded + if (status == false) { - interpreter.initialize (); - int status_exec = interpreter.execute (); + interpreter.initialize(); + int status_exec = interpreter.execute(); if (status_exec != 0) { std::cerr << "creating embedded Octave interpreter failed!" - << std::endl; + << 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 pkg = 0; int nouts; - for(l=0;ln_in_arguments;l++) + // Format the input data values into data type acceptable by Octave + for (l = 0; l < funcall->n_in_arguments; l++) { - if(inp[l].type==TYPE_DOUBLE) + //check if Input type is Double + if (inp[l].type == TYPE_DOUBLE) { - if(inp[l].is_in_cmplx==1) + 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); - octave_value_list out = octave::feval (str_fun, in, funcall->n_out_user); - - - int row; - int col; + int row = 0; + int col = 0; 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++ ) + // DEBUG // std::cout << "funcall->n_out_arguments is: " << funcall->n_out_arguments << '\n'; + // Format and set the output data values from Octave into the FUNCARGS + for (unsigned int ii = 0; ii < nouts; ii++) { - if(out(ii).iscomplex()==1) + //Format complex data + if (out(ii).iscomplex() == 1) { - inp[ii].is_out_cmplx=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'; @@ -136,54 +203,144 @@ extern "C" 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