diff options
author | Rupak Rokade | 2021-07-04 18:18:49 +0530 |
---|---|---|
committer | GitHub | 2021-07-04 18:18:49 +0530 |
commit | 0dde2f4241572e7ab07b6e6f9095b071449f6c0f (patch) | |
tree | 243b8841f0b787f2096ccc6c0a0a8a95cd99a331 /sci_gateway | |
parent | 66ab875f7a0de3acaa0c9e2b1a8eb4ebee5f2481 (diff) | |
parent | 0b968ae5124a37916f9ab901e91a11cd90ff81a4 (diff) | |
download | fossee-scilab-octave-toolbox-0dde2f4241572e7ab07b6e6f9095b071449f6c0f.tar.gz fossee-scilab-octave-toolbox-0dde2f4241572e7ab07b6e6f9095b071449f6c0f.tar.bz2 fossee-scilab-octave-toolbox-0dde2f4241572e7ab07b6e6f9095b071449f6c0f.zip |
Added Support for Windows OS
Diffstat (limited to 'sci_gateway')
-rw-r--r-- | sci_gateway/cpp/builder_gateway_cpp.sce | 24 | ||||
-rw-r--r-- | sci_gateway/cpp/sci_octave.cpp | 80 |
2 files changed, 69 insertions, 35 deletions
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 177a6b9..391c932 100644 --- a/sci_gateway/cpp/sci_octave.cpp +++ b/sci_gateway/cpp/sci_octave.cpp @@ -29,28 +29,39 @@ extern "C" #include <stdlib.h> 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. - */ + + /** + * @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) { - //printf("nin: %d\n", nin); + //DEBUG//printf("nin: %d\n", nin); + // Check number of inputs if (nin < 1) { Scierror(999, _("%s: Wrong number of input arguments. Atleast %d expected.\n"), fname, 2); return STATUS_ERROR; } + // Declare and initialize the API variables 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; @@ -67,14 +78,20 @@ extern "C" double *in_real; double *in_img; + + + // Check the data type of input variables and format them into the FUNNCALL for (i = 0; i < nin; i++) { + // Check if [in] of type Sci:matrix if (scilab_getType(env, in[i]) == 1) { ins[i].type = TYPE_DOUBLE; + + // Check if [in] is of type Sci:complex if (scilab_isComplex(env, in[i]) == 1) { - //printf("input %d is complex \n", i); + //DEBUG//printf("input %d is complex \n", i); ins[i].is_in_cmplx = 1; size = scilab_getDim2d(env, in[i], &row, &col); ins[i].n_in_rows = row; @@ -100,9 +117,10 @@ extern "C" } } } + // [in] is not of type Sci:complex else { - //printf("input %d is NOT complex \n", i); + //DEBUG//printf("input %d is NOT complex \n", i); ins[i].is_in_cmplx = 0; size = scilab_getDim2d(env, in[i], &row, &col); ins[i].n_in_rows = row; @@ -112,7 +130,7 @@ extern "C" ins[i].in_data_real = malloc(sizeof(double) * size); d = (double *)ins[i].in_data_real; - ////This code snippet is to flatten matrix row wise and then store it + //DEBUG//This code snippet is to flatten matrix row wise and then store it int p, q, k = 0; for (p = 0; p < row; p++) { @@ -126,6 +144,7 @@ extern "C" } ///////////////////////////////////////// } + // Check if [in] of type SCI:Matrix of strings else if (scilab_getType(env, in[i]) == 10) { ins[i].is_in_cmplx = 0; @@ -174,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 @@ -247,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 @@ -279,7 +298,7 @@ extern "C" if (!err.empty() && status_fun == 0) sciprint("Warning from Octave\n%s", err.c_str()); buffer_err.str(""); - + //printf("in scilab status_fun is: %d\n", status_fun); //printf("in scilab funcall.n_out_arguments is: %d\n", funcall.n_out_arguments); //printf("in scilab funcall.n_out_user is: %d\n", funcall.n_out_user); @@ -292,10 +311,12 @@ extern "C" Scierror(999, "Error from Octave\n%s", err.c_str()); return 1; } + // Format output variable for SciLab else if (funcall.n_out_user <= funcall.n_out_arguments) { for (i = 0; i < nout; i++) { + // Format Complex data type if (ins[i].is_out_cmplx == 1) { //printf("output %d is complex\n", i); @@ -317,20 +338,24 @@ extern "C" out_img[j] = ocd[j]; } } - else if (ins[i].is_out_struct == 1){ + // Format Struct data type + else if (ins[i].is_out_struct == 1) + { // creating scilab struct out[i] = scilab_createStruct(env); int structLen = ins[i].n_out_struct_len; - - FUNCSTRUCT* outStruct = ins[i].out_struct; - for (int j = 0; j < structLen; j++){ + FUNCSTRUCT *outStruct = ins[i].out_struct; + + for (int j = 0; j < structLen; j++) + { // std::printf("currKey in sciOctave.cpp OP: %ls\n", outStruct[j].key); - scilab_addField(env, out[i], (const wchar_t*) outStruct[j].key); + scilab_addField(env, out[i], (const wchar_t *)outStruct[j].key); scilabVar currValue = NULL; - if (outStruct[j].type == TYPE_COMPLEX){ + if (outStruct[j].type == TYPE_COMPLEX) + { currValue = scilab_createDoubleMatrix2d(env, outStruct[j].rows, outStruct[j].cols, 1); - + double *outReal = NULL; double *outImg = NULL; scilab_getDoubleComplexArray(env, currValue, &outReal, &outImg); @@ -398,11 +423,16 @@ extern "C" Scierror(77, _("%s: Wrong number of output arguments: This function can return a maximum of %d output(s).\n"), fname, funcall.n_out_arguments); return 1; } + + // Free the mem allocated for out variables for (i = 0; i < nout; i++) { - if (ins[i].is_out_struct == 1){ - FUNCSTRUCT* tempStruct = ins[i].out_struct; - for (int j = 0; j < ins[i].n_out_struct_len; j++){ + // + if (ins[i].is_out_struct == 1) + { + FUNCSTRUCT *tempStruct = ins[i].out_struct; + for (int j = 0; j < ins[i].n_out_struct_len; j++) + { // std::wstring tempWStr((wchar_t *) tempStruct[j].key); // std::string(tempWStr.begin(), tempWStr.end()); // std::cout << "freeing key: " << std::string(tempWStr.begin(), tempWStr.end()) << std::endl; |