The method to use Scilab function in C++ code


1. Introduction

Scilab© is a free and open source software for numerical computation. Many advanced data structures and numerical methods in scientific computation have been built in Scilab. It also includes a high level programming language similar to the Matlab© language. For Matlab users, this software can be used as a free alternative.
For C++ (and other high level general purpose programming languages) programmers, Scilab provides a quick and easy access to many necessary numerical methods, such as matrix operation, solution to equations, simulation, control, optimization, and signal processing. This document will describes one applicable configuration.
Depends on purposes, it may be necessary to trust only on someone’s own codes sometimes. So use the method in this document with caution. If the compiler and the operation system are different, this document may be useful as a reference.
The material is based on http://help.scilab.org/docs/5.3.3/en_US/call_scilab.html. This experience was gained during my 2012 spring visit to Hokkaido University, Japan.

2. Procedure

Software
• Windows 7 Enterprise 64-bit (English version)
• Visual Studio 2010 Premium 32-bit (English version)
• Scilab 5.3.3 32-bit (English version)
Installation directory: C:\Program Files (x86)\scilab-5.3.3
Remark: Visual studio and Scilab need to be both 32-bit versions or both 64-bit versions.

Tell C++ code to use Scilab

Add #include files and commands to initial call_scilab
These three lines will provide necessary information about scilab related functions for visual studio. They can be added after the other #include” commands.

 

#include     “call_scilab.h”
#include     “api_scilab.h”
#include     “stack-c.h”

 

Call_scilab functions should be placed between the initialization and termination of Scilab engine.

// Initialization
if ( StartScilab(NULL, NULL, 0) == FALSE )
{
printf(“Error : StartScilab\n”);
return 0;
}
// Termination
if ( TerminateScilab(NULL) == FALSE )
{ printf(“Error : TerminateScilab\n”);
cout<}}

 

These two parts of codes can be placed in the beginning and ending of the “main” function.

Change the property to let visual studio and windows find Scilab

The property setting of the “project/solution” in visual studio can be found in the right-click menu (Illustration 1).

screenshoot1.png

 

Illustration 1: property menu

Add “additional include directories” (Illustration 2). In the author’s case, the added content is C:\Program Files (x86)\scilab-5.3.3\modules\core\includes;C:\Program Files (x86)\scilab-5.3.3\modules\call_scilab\includes;C:\Program Files (x86)\scilab-5.3.3\modules\api_scilab\includes;

screenshoot2.png

 

Illustration 2: additional include directories

Add “additional library directories” (Illustration 3). In the author’s case, the added content is C:\Program Files (x86)\scilab-5.3.3\bin

screenshoot2_half.png

 

Illustration 3: additional library directories

Add new dependencies to “additional dependencies” (Illustration 4). In the author’s case, the added content is C:\Program Files (x86)\scilab-5.3.3\bin\api_scilab.lib;C:\Program Files (x86)\scilab-5.3.3\bin\call_scilab.lib;

screenshoot3.png

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

 

Illustration 4: additional dependencies

Add “import library” (Illustration 5). In the author’s case, the content is C:\Program Files (x86)\scilab-5.3.3\bin

screenshoot4.png

 

Illustration 5: import library

Add the installation path of Scilab to the system environment (Illustration 6). In the author’s case, the added content is C:\Program Files (x86)\scilab-5.3.3\bin;

screenshoot5.png

 

Illustration 6: environment variable

 

C++ programming procedure

  • Add the #include files, initialization codes and termination codes, as mentioned in the previous section.
  • Transport data between C++’s memory and Scilab’s memory.
    To use functions in Scilab, the variables necessary must be already in the Scilab’s memory. The results are also stored in Scilab’s memory, so they need to be exported to the C++ part after running the functions. To create simple variables in the Scilab section, the value can be used to form a string in the format of Scilab command. For example, the command SendScilabJob(“d=2.0;”);  creates a variable with the name “d” and the value “2.0”. Note the default type of numeric value in Scilab is double. To create matrices, it is more convenient to create them firstly in C++, and then use certain functions provided by Scilab to transfer them to the Scilab part. Note that in Scilab, the matrices are filled in the column firstly, i.e. the storage of a matrix [1 2;3 4] would look like [1 3 2 4].

These functions related to double-management include:

 

SciErr getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
Remark: _pvCtx is Scilab environment pointer, simply pass in “pvApiCtx” pro-vided by api_scilab.h;
SciErr getComplexMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal, double** _pdblImg)
SciErr readNamedMatrixOfDouble(void* _pvCtx, char* _pstName, int* _piRows, int* _piCols, double* _pdblReal)
SciErr readNamedComplexMatrixOfDouble(void* _pvCtx, char* _pstName, int* _piRows, int* _piCols, double* _pdblReal, double* _pdblImg)

 

  • Send commands in Scilab format to Scilab engine.
    Two functions are provided to do the job. They are “SendScilabJob” and “SendScilabJobs”. The former one sends one command, and the other one can send multiple commands.

3. Where to find help?

a. Scilab help browser
This can be activated by the command “help” in Scilab console. Related topics are listed under the title of “call_scilab API” and “API Scilab”.
b. Example codes
They are located in a sub-directory in the Scilab installation directory. For example, the directory can be “C:\Program Files (x86)\scilab-5.3.3\modules\call_scilab\examples”

 

[출처] http://weihuang.blogs.rice.edu/tips-on-computing-tools/the-method-to-use-scilab-function-in-c-code/

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
24 [scientific computing] SageMath에서 사용하는 숫자 file 졸리운_곰 2021.08.14 35
23 [sagemath] sagemath 설치와 세팅, scientific computig file 졸리운_곰 2021.08.14 59
22 [도스 (MS-DOS) 시절 엔지니어링 프로그램과 호환을 위한] OpenBGI library file 졸리운_곰 2020.10.18 77
21 Octave — Scientific Programming Language Crash Course file 졸리운_곰 2020.09.19 85
20 gnuplot 기초 사용법 졸리운_곰 2020.07.09 202
19 gnuplot 사용법 file 졸리운_곰 2020.07.09 90
18 GNUPLOT 사용법, 함수 그래프 그리기, 두 함수 사이의 영역 색칠하기 file 졸리운_곰 2020.07.09 648
17 Windows 환경의 C++ 언어에서 gnuplot을 사용한 그래프 출력 2  file 졸리운_곰 2020.07.07 400
16 Windows 환경의 C++언어에서 gnuplot을 사용한 그래프 출력 file 졸리운_곰 2020.07.07 337
15 가장 간단한 수치해석, essential example programs for physics [python] file 졸리운_곰 2020.06.17 84
14 2018 수치해석 실습자료 file 졸리운_곰 2020.06.17 144
13 [Fortran] Numerical Recipes in Fortran 졸리운_곰 2020.03.26 35
12 희소행렬 file 졸리운_곰 2020.02.12 83
» The method to use Scilab function in C++ code file 졸리운_곰 2016.08.10 97
10 Visual Basic for Electronics Engineering Applications (2nd ed.) file 졸리운_곰 2016.04.25 83
9 log함수의 도시 semilogx file 가을의 곰을... 2013.02.04 732
8 log함수의 도시 semilogy file 가을의 곰을... 2013.02.04 1254
7 로그함수의 도시 loglog file 가을의 곰을... 2013.02.04 809
6 극좌표계의 Plot file 가을의 곰을... 2013.02.03 869
5 표시 부호 (mark) 만으로 도시 file 가을의 곰을... 2013.02.03 615
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED