diff options
-rw-r--r-- | README.md | 73 | ||||
-rw-r--r-- | sci_gateway/cpp/builder_gateway_cpp.sce | 24 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_octave.cpp | 4 | ||||
-rw-r--r-- | src/windows_compile.txt | 2 | ||||
-rw-r--r-- | thirdparty/windows/include/fun.h | 95 | ||||
-rw-r--r-- | thirdparty/windows/lib/libfun.a | bin | 0 -> 102020 bytes | |||
-rw-r--r-- | thirdparty/windows/lib/libfun.dll | bin | 0 -> 18330032 bytes |
7 files changed, 179 insertions, 19 deletions
@@ -3,29 +3,54 @@ This is a scilab toolbox to call octave functions. It requires octave to be installed on the system. ## This toolbox has been built and tested using -1. `OS - Linux Debian 10, Ubuntu 18.10 and 19.10 (64-bit)` +1. `OS - Linux Debian 10, Ubuntu 18.10 and 19.10 (64-bit), Windows 10 (64-bit)` 2. `Octave - Version 4.4.1, 5.1.0` 3. `Scilab - Version 6.0.x` -## Software prerequisites: +--- + +## Software prerequisites +## Linux Run the following commands in the linux terminal 1. `sudo apt-get install build-essential (~117 MB download)` 2. `sudo apt-get install liboctave-dev (~103 MB download)` 3. `sudo apt-get install octave` 4. `sudo apt-get install scilab` -## Install the required octave packages using the below command in linux terminal -1. `sudo apt-get install octave-<pkg name>` -For example, to install signal package in octave, do -1. `sudo apt-get install octave-signal` +Install the required octave packages using the below command in linux terminal +1. `sudo apt-get install octave-<pkg name>` For example, to install signal package in octave, do `sudo apt-get install octave-signal` + + +## Windows +1. Download and Install Scilab 6.0.1 x64 from [Scilab.org](https://www.scilab.org/) +2. Download and Install Octave 4.4.1 x64. (If you use a custom installation path different from the default see troubleshooting section below.) +3. Install Mingw Tollbox for Scilab (https://atoms.scilab.org/toolboxes/mingw/0.10.5). +4. Create an user variable called `'OCTAVE_HOME'` with value equal to the installation directory of Octave (default being: `"C:\Octave\Octave-4.4.1\"`). + +--- + +## Running the Toolbox -## Launch Scilab and run the following commands inside the scilab console +## Linux +Launch Scilab and run the following commands inside the scilab console 1. `cd <path to fossee-scilab-octave-toolbox directory>` 2. `exec builder.sce` 3. `exec loader.sce` 4. `help octave_fun` (then execute the examples appearing on the help page to test the toolbox) +## Windows +Launch Scilab and run the following commands inside the scilab console +1. `cd <path to fossee-scilab-octave-toolbox directory>` +2. `exec builder.sce` (If you see erros executing this step, see troubleshooting section.) +3. Add "C:\Octave\Octave-4.4.1\bin" or wherever you installaed Octave to Environment PATH. (You need to follow this step only when you are building the toolbox for the first time). +4. `exec loader.sce` +5. `help octave_fun` (then execute the examples appearing on the help page to test the toolbox) + +--- + ## Building the source + +## Linux In case if executing the builder and loader files in scilab throw an error regarding .so files, you probably need to build the toolbox from source. Do the following on the linux terminal 1. Download the fossee-scilab-octave-toolbox source from [`atoms.scilab.org`](https://atoms.scilab.org) 2. Close scilab, if running @@ -34,4 +59,38 @@ In case if executing the builder and loader files in scilab throw an error regar 5. `make` 6. `make install` +## Windows +1. `cd <path to fossee-scilab-octave-toolbox/src/ directory>` +2. Run the commands in `src/window_compile.txt` in a cmd prompt. +3. Copy `fun.h` to `thirdparty/windows/include`. +4. Copy and Overwrite `libfun.a` & `libfun.dll` to `thirdparty/windows/lib` + +--- + +## Troubleshooting +## Windows +**1. Custom Octave install path** + +If you have a custom Octave installtion path then change the path in `tollbox_root/sci_gateway/cpp/builder_gateway_cpp.sce` for `octave_lib_dir` at Line 43. + +**2. library_name.a not found error on running "exec builder.sce".** + +This usually happens when you build the toolbox on Windows for the first time or from scratch. Simply comment the commands +> octave_lib_dir + "liboctave-6"; +> +> octave_lib_dir + "liboctinterp-6"; + +in `tollbox_root/sci_gateway/cpp/builder_gateway_cpp.sce`. Run `exec builder.sce` to get a sucessful build. Uncomment the commands you just commented and run the builder command once again. This time the toolbox will build sucessfully. + +**3. Mingw gcc file not found/ path errors when running "exec builder.sce".** + +This usually happens when you build the toolbox on Windows for the first time or from scratch and have the octave/bin folder in your PATH, causing conflicts with the gcc version required by Mingw Toolbox. + +Remove "C:\Octave\Octave-4.4.1\bin" (or your Octave installation equivalent) from Environment Variable PATH, build the toolbox and add octave/bin back to your PATH as it is required by loader.sce. + +**4. Some Octave Functions Not Found** + +You are missing the OCTAVE_HOME user variable. See Windows software prerequisites section. + + diff --git a/sci_gateway/cpp/builder_gateway_cpp.sce b/sci_gateway/cpp/builder_gateway_cpp.sce index b83ab7a..0b5f9cb 100644 --- a/sci_gateway/cpp/builder_gateway_cpp.sce +++ b/sci_gateway/cpp/builder_gateway_cpp.sce @@ -37,13 +37,17 @@ Version = opt(2); //Build_64Bits = %f; if getos()=="Windows" then - - third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; - lib_base_dir = third_dir + filesep() + 'windows' + filesep() + 'lib' + filesep() + Version + filesep(); - inc_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include'; - threads_dir=third_dir + filesep() + 'linux' + filesep() + 'include' + filesep() + 'pthreads-win32'; - C_Flags=['-D__USE_DEPRECATED_STACK_FUNCTIONS__ -I -w '+path_builder+' '+ '-I '+inc_base_dir+' '+'-I '+threads_dir+' '] - Linker_Flag = [lib_base_dir+"liblibraryname.lib"] + third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; + lib_base_dir = third_dir + filesep() + 'windows' + filesep() + 'lib' + filesep(); + inc_base_dir = third_dir + filesep() + 'windows' + filesep() + 'include'+ filesep(); + octave_lib_dir = "C:\Octave\Octave-4.4.1\bin\"; + C_Flags=[' -D__USE_DEPRECATED_STACK_FUNCTIONS__ -I -w '+ path_builder + ' '+ ' -I ' + inc_base_dir + ' ']; + libs = [ + lib_base_dir + "libfun"; + octave_lib_dir + "liboctave-6"; + octave_lib_dir + "liboctinterp-6"; + ]; + Linker_Flag = ""; elseif getos()=="Darwin" then third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; @@ -51,7 +55,7 @@ elseif getos()=="Darwin" then inc_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include'; C_Flags=["-D__USE_DEPRECATED_STACK_FUNCTIONS__ -w -fpermissive -I"+path_builder+" -I"+inc_base_dir+" -Wl,-rpath "+lib_base_dir+" "] Linker_Flag = ["-L"+lib_base_dir+"liblibraryname"]; - + libs = []; else//LINUX third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; @@ -61,12 +65,12 @@ else//LINUX C_Flags = ["-I"+inc_base_dir]; Linker_Flag = ["-L" + lib_base_dir + " -lfun -Wl,-rpath="+lib_base_dir+" -loctave -loctinterp"] - + libs = []; //disp(C_Flags); //disp(Linker_Flag); end -tbx_build_gateway(toolbox_title,Function_Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags,[]); +tbx_build_gateway(toolbox_title,Function_Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), libs, Linker_Flag, C_Flags); clear toolbox_title Function_Names Files Linker_Flag C_Flags; diff --git a/sci_gateway/cpp/sci_octave.cpp b/sci_gateway/cpp/sci_octave.cpp index 156178b..391c932 100644 --- a/sci_gateway/cpp/sci_octave.cpp +++ b/sci_gateway/cpp/sci_octave.cpp @@ -193,7 +193,7 @@ extern "C" { // storing the key inStruct[j].key = malloc(sizeof(wchar_t) * (wcslen(keys[j]) + 1)); - wcpcpy((wchar_t*) inStruct[j].key, keys[j]); + wcscpy((wchar_t*) inStruct[j].key, keys[j]); struct_out = scilab_getStructMatrix2dData(env, in[i], keys[j], 0, 0); // Retrieving Curr Value @@ -266,7 +266,7 @@ extern "C" //printf("%S\n", in1); inStruct[j].str = malloc(sizeof(wchar_t) * (wcslen(in1) + 1)); - wcpcpy((wchar_t*) inStruct[j].str, in1); + wcscpy((wchar_t*) inStruct[j].str, in1); // printf("%s\n", str); } else 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 diff --git a/thirdparty/windows/include/fun.h b/thirdparty/windows/include/fun.h new file mode 100644 index 0000000..cbc8800 --- /dev/null +++ b/thirdparty/windows/include/fun.h @@ -0,0 +1,95 @@ +// Copyright (C) 2019 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Author: Rupak Rokade +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +#define fun_h__ +//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, /**<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*/ + + } FUNCSTRUCT; + + /** + * @brief Struct used to send/receive Scilab data to/from the gateway to fun.cpp API + * + */ + + typedef 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 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/thirdparty/windows/lib/libfun.a b/thirdparty/windows/lib/libfun.a Binary files differnew file mode 100644 index 0000000..26517c5 --- /dev/null +++ b/thirdparty/windows/lib/libfun.a diff --git a/thirdparty/windows/lib/libfun.dll b/thirdparty/windows/lib/libfun.dll Binary files differnew file mode 100644 index 0000000..dcaf9b4 --- /dev/null +++ b/thirdparty/windows/lib/libfun.dll |