Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - 日本語

Scilab 6.1.0
Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
However, this page did not exist in the previous stable version.

Scilabヘルプ >> API Scilab > legacy > Low level functions > doubleの書き込み (Scilabゲートウェイ)

doubleの書き込み (Scilabゲートウェイ)

ゲートウェイでdoubleの行列を書き込む方法.

既存のデータから作成.

呼び出し手順

入力引数プロファイル:

SciErr createMatrixOfDouble(void* _pvCtx, int _iVar, int _iRows, int _iCols, const double* _pdblReal)
SciErr createComplexMatrixOfDouble(void* _pvCtx, int _iVar, int _iRows, int _iCols, const double* _pdblReal, double* _pdblImg)

名前指定変数プロファイル:

SciErr createNamedMatrixOfDouble(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const double* _pdblReal)
SciErr createNamedComplexMatrixOfDouble(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const double* _pdblReal, const double* _pdblImg)

引数

_pvCtx

Scilab環境ポインタ, api_scilab.h により定義された "pvApiCtx"で指定.

_iVar

変数を保存するScilabメモリの位置.

_pstName

"名前指定" 関数の場合の変数名.

_iRows

新規変数の行数.

_iCols

新規変数の列数.

_pdblReal

実数データ配列のアドレス (大きさ: _iCols * _iRows).

_pdblImg

虚部データ配列のアドレス (大きさ: _iCols * _iRows). この引数は createMatrixOfDouble および createNamedMatrixOfDouble では 存在しません.

SciErr

エラー構造体で, エラーメッセージ履歴と最初のエラー番号を 格納します.

Scilabメモリに直接書き込む.

呼び出し手順

入力引数プロファイル:

SciErr allocMatrixOfDouble(void* _pvCtx, int _iVar, int _iRows, int _iCols, double** _pdblReal)
SciErr allocComplexMatrixOfDouble(void* _pvCtx, int _iVar, int _iRows, int _iCols, double** _pdblReal, double** _pdblImg)
SciErr allocComplexZMatrixOfDouble(void* _pvCtx, int _iVar, int _iRows, int _iCols, double** _pdblReal, doublecomplex** _pdblData)

引数

_pvCtx

Scilab環境ポインタ, api_scilab.h により定義された "pvApiCtx"で指定.

_iVar

変数を保存するScilabメモリの位置.

_iRows

新規変数の行数.

_iCols

新規変数の列数.

_pdblReal

実部データ配列のアドレスを返す (大きさ: _iCols * _iRows).

_pdblImg

虚部データ配列のアドレスを返す (大きさ: _iCols * _iRows). この引数は allocMatrixOfDoubleには存在しません.

_pdblData

doublecomplexデータ配列のアドレスを返します (大きさ: _iCols * _iRows). この引数は allocComplexZMatrixOfDoubleにのみ存在します.

SciErr

エラー構造体で,エラーメッセージ履歴と最初のエラー番号を格納します.

ゲートウェイのソース

#include "api_scilab.h"
int write_double(char *fname,void* pvApiCtx)
{
	SciErr sciErr;
	int i,j;
	// 最初の変数の情報 : 3 x 4 doubleの実数行列
	int iRows1			= 3;
	int iCols1			= 4;
	double* pdblReal1	= NULL;
	// 2番目の変数の情報 : double 4 x 6 doubleの複素数行列
	int iRows2			= 4;
	int iCols2			= 6;
	double* pdblReal2	= NULL;
	double* pdblImg2	= NULL;
	/************************
	*    最初の変数    *
	************************/
	// OSメモリにデータ配列を確保
	pdblReal1 = (double*)malloc(sizeof(double) * iRows1 * iCols1);
	// 増加する値を配列に代入
	//[ 0   1   2   3
	//  4   5   6   7
	//  8   9   10  11]
	for(i = 0 ; i < iRows1 ; i++)
	{
		for(j = 0 ; j < iCols1 ; j++)
		{
			pdblReal1[i + iRows1 * j] = i * iCols1 + j;
		}
	}
	// 1回のループで書くことも可能
	//for(i = 0 ; i < iRows1 * iCols1; i++)
	//{
	//  pdblReal1[i] = i;
	//}
	// 既存のデータ配列から変数を作成
	sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows1, iCols1, pdblReal1);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}
	// 作成後, メモリを解放できます.
	free(pdblReal1);
    /*************************
	*    2番目の変数    *
	*************************/
	// scilabメモリの空間を予約し,代入
	sciErr = allocComplexMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, iRows2, iCols2, &pdblReal2, &pdblImg2);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}
	// 増加する値を実部, 減少する値を虚部に代入
	//[ 23i     1+22i       2+21i       3+20i       4+19i       5+18i
	//  6+17i   7+16i       8+15i       9+14i       10+13i      11+12i
	//  12+11i  13+10i      14+9i       15+8i       16+7i       17+6i
	//  18+5i   19+4i       20+3i       21+2i       22+1i       23  ]
	for(i = 0 ; i < iRows2 ; i++)
	{
		for(j = 0 ; j < iCols2 ; j++)
		{
			pdblReal2[i + iRows2 * j] = i * iCols2 + j;
			pdblImg2 [i + iRows2 * j]	= (iRows2 * iCols2 - 1) - (i * iCols2 + j);
		}
	}
	// 1回のループで書き込むことも可能
	//for(i = 0 ; i < iRows2 * iCols2; i++)
	//{
	//  pdblReal2[i] = i;
	//  pdblImg2 [i] = (iRows2 * iCols2 - 1) - i;
	//}
	// /!\ この場合はScilabメモリなのでメモリを解放しないこと
	// 確保された変数を左辺に代入
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
    return 0;
}

Scilabテストスクリプト

a_ref = [   0 1 2 3; ..
            4 5 6 7; ..
            8 9 10 11];
b_ref = [   23*%i,      1+22*%i,    2+21*%i,    3+20*%i,    4+19*%i,    5+18*%i; ..
            6+17*%i,    7+16*%i,    8+15*%i,    9+14*%i,     10+13*%i,  11+12*%i; ..
            12+11*%i,   13+10*%i,   14+9*%i,    15+8*%i,    16+7*%i,    17+6*%i; ..
            18+5*%i,    19+4*%i,    20+3*%i,    21+2*%i,    22+1*%i,    23];
[a,b] = write_double();
if or(a <> a_ref) then error("failed");end
if or(b <> b_ref) then error("failed");end
Report an issue
<< doubleの読み込み (Scilabゲートウェイ) Low level functions getNbInputArgument (Scilabゲートウェイ) >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:53:30 CET 2020