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 getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
SciErr getComplexMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal, double** _pdblImg)

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

SciErr readNamedMatrixOfDouble(void* _pvCtx, const char* _pstName, int* _piRows, int* _piCols, double* _pdblReal)
SciErr readNamedComplexMatrixOfDouble(void* _pvCtx, const char* _pstName, int* _piRows, int* _piCols, double* _pdblReal, double* _pdblImg)

引数

_pvCtx

Scilab環境ポインタ, api_scilab.hで定義される "pvApiCtx" を指定

_piAddress

Scilab変数のアドレス.

_pstName

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

_piRows

返される行数.

_piCols

返される列数.

_pdblReal

返される実数データ配列のアドレス (大きさ: _iCols * _iRows). "名前指定" 関数の場合, _pdblReal は関数コール前にメモリを確保しておく必要があります.

_pdblImg
Return address of imaginary data array (size: _iCols * _iRows). For "Named" function, _pdblImg must be allocated before calling function.
SciErr

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

説明

このヘルプはdoubleの行列をScilab APIにより処理する方法を示します.

ゲートウェイのソース

#include "api_scilab.h"
int read_double(char *fname,void* pvApiCtx)
{
	SciErr sciErr;
	int i;
        // 最初の変数の情報 : doubleの実数行列
	int iType			= 0;
	int iRows			= 0;
	int iCols			= 0;
	int iComplex		= 0;
	int *piAddr			= NULL;
	double* pdblReal	= NULL;
	double* pdblImg		= NULL;
	// 入力/出力引数を確認
    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);
    /************************
	*    最初の変数    *
	************************/
	// 最初の引数の変数アドレスを取得
	sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}
	// 型を確認
	sciErr = getVarType(pvApiCtx, piAddr, &iType);
	if(sciErr.iErr || iType != sci_matrix)
	{
		printError(&sciErr, 0);
		return 0;
	}
	// 複素数かどうかを取得
	iComplex	= isVarComplex(pvApiCtx, piAddr);
	// 複素数かどうかを確認
	if(iComplex)
	{
		// Scilabメモリから大きさとデータを取得
		sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal, &pdblImg);
	}
	else
	{
		// Scilabメモリから大きさとデータを取得
		sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
	}
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}
	// データを用いて処理を行う
	// 変数が複素数の場合,実部と虚部を交換し,それ以外は-1を乗じる
	if(iComplex)
	{
		sciErr = createComplexMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pdblImg, pdblReal);
	}
	else
	{
		for(i = 0 ; i < iRows * iCols ; i++)
		{
			pdblReal[i] = pdblReal[i] * -1;
		}
		sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pdblReal);
	}
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
	return 0;
}

Scilab テストスクリプト

a = [   0 1 2 3; ..
        4 5 6 7; ..
        8 9 10 11];
b = [   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];
a2 = read_double(a);
b2 = read_double(b);
if or(a2 <> a * -1) then error("failed"), end
if or(b2 <> (imag(b) + real(b) * %i)) then error("failed"), end
Report an issue
<< deleteNamedVariable Low level functions doubleの書き込み (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