From d5d77fe4d8f3cd14dc3083ae0e5687b4f56976e4 Mon Sep 17 00:00:00 2001 From: KRIXUS-alpha Date: Wed, 12 May 2021 14:04:10 +0530 Subject: documentation struct --- src/fun.cpp | 309 +++++++++++++++++++++++++++++++++++++++++++++--------------- src/fun.h | 96 +++++++++++++------ 2 files changed, 302 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/fun.cpp b/src/fun.cpp index 4eeb24c..71b7d45 100644 --- a/src/fun.cpp +++ b/src/fun.cpp @@ -17,116 +17,183 @@ #include #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