Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Français - Português - Русский

Please note that the recommended version of Scilab is 6.0.2. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> API Scilab > List manipulation > 要素数 (Scilab ゲートウェイ)

要素数 (Scilab ゲートウェイ)

リスト(list, mlist, tlist)中の要素数を取得する方法.

呼び出し手順

SciErr getListItemNumber(void* _pvCtx, int* _piAddress, int* _piNbItem)

引数

_pvCtx

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

_piAddress

リストのアドレス.

_piNbItem

返される要素数.

SciErr

エラーメッセージの履歴と最初のエラー番号が保存されるエラー構造体.

説明

このヘルプはリスト(list, mlist, tlist)中の要素数を取得する方法を説明します.

ゲートウェイソース

#include "api_scilab.h"
int get_list_info(int* _piAddress);
void insert_indent(void);
static int iLocalTab = 0;
int common_list(char *fname,unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddr = NULL;
    CheckInputArgument(pvApiCtx, 1, 1);
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    get_list_info(piAddr);
    AssignOutputVariable(pvApiCtx, 1) = 0;
    return 0;
}
int get_list_info(int* _piAddress)
{
    SciErr sciErr;
    int i       = 0;
    int iRet    = 0;
    int iItem   = 0;
    //get list item number, failed if variable is not a kind of list
    sciErr = getListItemNumber(pvApiCtx, _piAddress, &iItem);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        sciprint("This variable is not a list");
        return 0;
    }
    sciprint("List (%d items) -> address : 0x%08X) : \n", iItem, _piAddress);
    for(i = 0 ; i < iItem ; i++)
    {
        int iType           = 0;
        int* piAddrChild    = NULL;
        sciErr = getListItemAddress(pvApiCtx, _piAddress, i + 1, &piAddrChild);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
        sciErr = getVarType(pvApiCtx, piAddrChild, &iType);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
        if(iType == sci_list || iType == sci_tlist || iType == sci_mlist)
        {
            insert_indent();
            sciprint("Child %d -> ", i + 1);
            iLocalTab++;
            iRet = get_list_info(piAddrChild);
            iLocalTab--;
            if(iRet)
            {
                return 1;
            }
        }
        else
        {
            insert_indent();
            sciprint("Child %d -> address : 0x%08X\n", i + 1, piAddrChild);
        }
    }
    return 0;
}
void insert_indent(void)
{
    int i = 0;
    for(i = 0 ; i < iLocalTab ; i++)
    {
        sciprint("\t");
    }
}

Scilab テストスクリプト

l1 = [1,2*%i,3;%i,2,3*%i];
l2 = ["may","the";"puffin","be";"with","you"];
l3 = int8([1,2,3]);
l5 = list(l1,l2,l3);
l4 = list(l5, list(l5,l5));
l6 = uint16([1000,2000,3000]);
l = list(l1,l2,l3,l6,l4,l5);
common_list(l)
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 02 13:58:35 CEST 2014