summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fun.cpp19
-rw-r--r--src/fun.h104
-rw-r--r--src/windows_compile.txt2
3 files changed, 82 insertions, 43 deletions
diff --git a/src/fun.cpp b/src/fun.cpp
index 8929d83..18c3395 100644
--- a/src/fun.cpp
+++ b/src/fun.cpp
@@ -30,9 +30,9 @@ extern "C"
int fun(FUNCARGS *inp, FUNCCALL *funcall)
{
- static octave::interpreter interpreter;
+ static octave::interpreter interpreter;
bool status = interpreter.initialized();
-
+ // Check octave interpreter loaded
if (status == false)
{
interpreter.initialize();
@@ -55,8 +55,10 @@ extern "C"
char str_pkg[20];
int pkg = 0;
int nouts;
+ // Format the input data values into data type acceptable by Octave
for (l = 0; l < funcall->n_in_arguments; l++)
{
+ //check if Input type is Double
if (inp[l].type == TYPE_DOUBLE)
{
if (inp[l].is_in_cmplx == 1)
@@ -92,6 +94,7 @@ extern "C"
in(l - str_count) = inMatrix_x;
}
}
+ //check if Input type is string
else if (inp[l].type == TYPE_STRING)
{
//std::cout << "In fun string. l is : " << l << '\n';
@@ -113,6 +116,7 @@ extern "C"
//std::cout << "String is: " << c << '\n';
}
+ //check if Input type is struct
else if (inp[l].type == TYPE_STRUCT){
FUNCSTRUCT* inStruct = inp[l].in_struct;
@@ -177,17 +181,18 @@ extern "C"
//std::cout << "loading package " << str_pkg << '\n';
octave::feval("pkg", ovl("load", str_pkg), 0);
}
-
+ // Use feval to compute the required values
octave_value_list out = octave::feval(str_fun, in, funcall->n_out_user);
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';
-
+ // 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++)
{
+ //Format complex data
if (out(ii).iscomplex() == 1)
{
inp[ii].is_out_cmplx = 1;
@@ -216,6 +221,7 @@ extern "C"
}
}
}
+ //Format Struct data
else if(out(ii).isstruct()){
inp[ii].is_out_struct = 1;
@@ -335,6 +341,7 @@ extern "C"
}
}
}
+ // Exception handling Octave
catch (const octave::exit_exception &ex)
{
std::cerr << "Octave interpreter exited with status = "
@@ -343,7 +350,7 @@ extern "C"
}
catch (const octave::execution_exception &)
{
- //std::cerr << "error encountered in Octave evaluator!" << std::endl;
+ //DEBUG//std::cerr << "error encountered in Octave evaluator!" << std::endl;
return 1;
}
return 0;
diff --git a/src/fun.h b/src/fun.h
index f79fbf4..cbc8800 100644
--- a/src/fun.h
+++ b/src/fun.h
@@ -13,53 +13,83 @@
//extern "C" int fun (double* answ, double* in1, int in1_row, std::string name, std::string opt);
extern "C"
-{
+{
+ /**
+ * @brief Enumeration for the data types suported
+ *
+ */
typedef enum {
- TYPE_DOUBLE,
- TYPE_COMPLEX,
- TYPE_STRING,
- TYPE_STRUCT,
+ TYPE_DOUBLE, /**<similar to scilab double*/
+ TYPE_COMPLEX, /**<similar to scilab complex*/
+ TYPE_STRING, /**<similar to scilab string*/
+ TYPE_STRUCT, /**<similar to scilab struct*/
}FUNCTYPE;
+ /**
+ * @struct FUNCSTRUCT
+ * @brief Struct used to pass structs to Octave from the fun library
+ *
+ */
+
typedef struct {
- FUNCTYPE type; // type of value in struct's field
- void* key; // key of struct field
- int rows; // rows dimension of struct field's value
- int cols; // cols dimension of struct fields' value
- void* dataReal; // Real data if struct field's value is real
- void* dataImg; // Img data if struct field's value is complex
- void* str; // string data if struct field's value is string
+ FUNCTYPE type; /**< Type of value in struct's field*/
+ void* key; /**< key of struct field*/
+ int rows; /**< rows dimension of struct field's value*/
+ int cols; /**< cols dimension of struct fields' value*/
+ void* dataReal; /**< Real data if struct field's value is real*/
+ void* dataImg; /**< Img data if struct field's value is complex*/
+ void* str; /**< String data if struct field's value is string*/
+
} FUNCSTRUCT;
+ /**
+ * @brief Struct used to send/receive Scilab data to/from the gateway to fun.cpp API
+ *
+ */
+
typedef struct {
- FUNCTYPE type;
- int n_in_rows;
- int n_in_cols;
- int n_in_struct_len; // ip struct length
- int n_out_rows;
- int n_out_cols;
- int n_out_struct_len; // op struct length
- int is_in_cmplx;
- int is_out_cmplx;
- int is_out_string;
- int is_out_struct;
- void* in_data_real;
- void* in_data_img;
- void* out_data_real;
- void* out_data_img;
- FUNCSTRUCT* in_struct;
- FUNCSTRUCT* out_struct;
+ /*@{*/
+ FUNCTYPE type; /**< Type of data */
+ int n_in_rows; /**< Input rows dimension of data*/
+ int n_in_cols; /**< Input cols dimension of data*/
+ int n_in_struct_len; /**< input struct length*/
+ int n_out_rows; /**< Ouput rows dimension of data*/
+ int n_out_cols; /**< Output cols dimension of data*/
+ int n_out_struct_len; /**< Output struct length*/
+ int is_in_cmplx; /**< Input is a Complex data type*/
+ int is_out_cmplx; /**< Output is a Complex data type*/
+ int is_out_struct; /**< Output is a Struct data type*/
+ int is_out_string; /**< Output is a String data type*/
+ void* in_data_real; /**< Input real part (complex) array*/
+ void* in_data_img; /**< Input imaginary part (complex) array*/
+ void* out_data_real; /**< Output real part (complex) array*/
+ void* out_data_img; /**< Output imaginary part (complex) array*/
+ FUNCSTRUCT* in_struct; /**< Input struct */
+ FUNCSTRUCT* out_struct; /**< Output struct*/
+ /*@}*/
} FUNCARGS;
-
+ /**
+ * @brief Struct used to call and pass the data to fun.cpp API
+ *
+ */
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 *err; // Name
- //char *package; //Name of octave package to be loaded
- FUNCARGS *argument;
+ /*@{*/
+ int n_in_arguments; /**< Number of input arguments*/
+ int n_out_arguments; /**< Number of output arguements in Scilab*/
+ int n_out_user; /**< Number of output arguements expected to be returned from Octave */
+ char *err; /**< Return errors*/
+ //char *package; //Name of octave package to be loaded*/
+ FUNCARGS *argument; /**< Struct defining and containing the data*/
+ /*@}*/
} FUNCCALL;
-
+ /**
+ * @brief API Function to call/receive and pass the data to fun API
+ *
+ *
+ * @param arr Input data FUNCARGS
+ * @param call Input Arguments FUNCCALL
+ * @return int Status Code
+ */
int fun(FUNCARGS *arr, FUNCCALL *call);
}
diff --git a/src/windows_compile.txt b/src/windows_compile.txt
new file mode 100644
index 0000000..afc3a87
--- /dev/null
+++ b/src/windows_compile.txt
@@ -0,0 +1,2 @@
+mkoctfile -c -fPIC fun.cpp
+g++ -L C:\Octave\Octave-4.4.1\bin -loctave-6 -loctinterp-6 -shared -o libfun.dll fun.o -Wl,--out-implib,libfun.a \ No newline at end of file