示例#1
0
Function::ReturnValue sci_spones(typed_list &in, int _piRetCount, typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), "spones", 1);
        return Function::Error;
    }

    if (in[0]->isSparse() == false && in[0]->isSparseBool() == false)
    {
        Scierror(999, _("%s: Wrong type for argument %d: Sparse matrix expected.\n"), "spones", 1);
        return Function::Error;
    }

    if (in[0]->isSparse())
    {
        out.push_back(in[0]->getAs<Sparse>()->newOnes());
    }
    else
    {
        out.push_back(in[0]->getAs<SparseBool>()->newOnes());
    }

    return Function::OK;
}
示例#2
0
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_deletefile(typed_list &in, int _iRetCount, typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "deletefile", 1);
        return Function::Error;
    }

    if (in[0]->isString() == false || in[0]->getAs<types::String>()->getSize() != 1)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), "deletefile", 1);
        return Function::Error;
    }


    Bool *pOut = NULL;
    if (deleteafileW(in[0]->getAs<types::String>()->get(0)))
    {
        pOut = new Bool(1);
    }
    else
    {
        pOut = new Bool(0);
    }

    out.push_back(pOut);
    return Function::OK;
    //CheckRhs(1,1);
    //CheckLhs(1,1);

    //if (GetType(1) == sci_strings)
    //{
    //	int m1,n1,l1;
    //	char *VarName=NULL;

    //	GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
    //	/* Bug 3089 */
    //	VarName = cstk(l1);

    //	n1=1;
    //	if ( deleteafile(VarName) )
    //	{
    //		CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
    //		*istk(l1)=(int)(TRUE);
    //	}
    //	else
    //	{
    //		CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
    //		*istk(l1)=(int)(FALSE);
    //	}

    //	LhsVar(1)=Rhs+1;
    //	C2F(putlhsvar)();
    //}
    //else
    //{
    //	Scierror(999,_("%s: Wrong type for input argument: A string expected.\n"),fname);
    //}
    //return 0;
}
示例#3
0
Function::ReturnValue sci_system_getproperty(typed_list &in, int _piRetCount, typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "system_getproperty", 1);
        return Function::Error;
    }

    if (_piRetCount != 1)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "system_getproperty", 1);
        return Function::Error;
    }

    if (in[0]->isString() == false || in[0]->getAs<types::String>()->getSize() != 1)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), "system_getproperty" , 1);
        return Function::Error;
    }

    char* pstProperty   = wide_string_to_UTF8(in[0]->getAs<types::String>()->get(0));
    char* pstValue      = system_getproperty(pstProperty, "unknown");
    String* pS          = new String(pstValue);
    out.push_back(pS);

    FREE(pstProperty);
    FREE(pstValue);

    return Function::OK;
}
Function::ReturnValue sci_inspectorGetUnreferencedItem(typed_list &in, int _iRetCount, typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "inspectorGetItem", 1);
        return Function::Error;
    }

    if (in[0]->isDouble() == false)
    {

        Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "inspectorGetItem", 1);
        return Function::Error;
    }

    Double *pD = in[0]->getAs<Double>();
    if (pD->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), "inspectorGetItem", 1);
        Function::Error;
    }

    int iPos = (int)pD->get(0) - 1;

    out.push_back(Inspector::getUnreferencedItem(iPos));
    return Function::OK;
}
示例#5
0
Function::ReturnValue WrapMexFunction::call(typed_list &in, optional_list &/*opt*/, int _iRetCount, typed_list &out)
{
    int ret = 1;
    if (m_pLoadDeps != NULL)
    {
        ret = m_pLoadDeps(m_wstName);
    }

    if (ret == 0)
    {
        return Error;
    }

    ReturnValue retVal = Callable::OK;

    char* name = wide_string_to_UTF8(getName().c_str());
    ConfigVariable::setMexFunctionName(name);
    FREE(name);

    int nlhs = _iRetCount;
    int** plhs = new int*[nlhs];
    memset(plhs, 0x00, sizeof(int*) * nlhs);

    int nrhs = (int)in.size();
    int** prhs = new int*[nrhs];
    for (int i = 0; i < nrhs; i++)
    {
        prhs[i] = (int*)(in[i]);
    }

    try
    {
        m_pOldFunc(nlhs, plhs, nrhs, prhs);
    }
    catch (const ast::InternalError& ie)
    {
        delete[] plhs;
        delete[] prhs;
        throw ie;
    }

    if (_iRetCount == 1 && plhs[0] == NULL)
    {
        //dont copy empty values, juste return "no value"
        return retVal;
    }

    for (int i = 0; i < nlhs; i++)
    {
        out.push_back((types::InternalType*)plhs[i]);
    }

    delete[] plhs;
    delete[] prhs;
    return retVal;
}
bool ImplicitList::invoke(typed_list & in, optional_list & /*opt*/, int /*_iRetCount*/, typed_list & out, const ast::Exp & e)
{
    if (in.size() == 0)
    {
        out.push_back(this);
    }
    else
    {
        InternalType * _out = extract(&in);
        if (!_out)
        {
            std::wostringstream os;
            os << _W("Invalid index.\n");
            throw ast::InternalError(os.str(), 999, e.getLocation());
        }
        out.push_back(_out);
    }

    return true;
}
Function::ReturnValue sci_inspectorGetFunctionList(typed_list &in, int _iRetCount, typed_list &out)
{
    if (in.size() != 0)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "inspectorGetFunctionList", 0);
        return Function::Error;
    }

    symbol::Context* pC = symbol::Context::getInstance();

    std::list<symbol::Symbol> funcName;
    int size = pC->getFunctionList(funcName, L"");

    String* pOut = new String(size, 4);

    int i = 0;
    for (auto it : funcName)
    {
        types::Callable* pCall = pC->get(it)->getAs<types::Callable>();
        //Function name
        pOut->set(i, 0, pCall->getName().c_str());
        pOut->set(i, 1, pCall->getModule().c_str());
        pOut->set(i, 2, pCall->getTypeStr().c_str());

        if (pCall->isMacroFile())
        {
            pOut->set(i, 3, pCall->getAs<types::MacroFile>()->getMacro() == NULL ? L"false" : L"true");
        }
        else
        {
            pOut->set(i, 3, L"");
        }

        ++i;
    }

    out.push_back(pOut);
    return Function::OK;
}
示例#8
0
Function::ReturnValue WrapCFunction::call(typed_list& in, optional_list& opt, int _iRetCount, typed_list& out)
{
    if (m_pLoadDeps != NULL)
    {
        if (m_pLoadDeps(m_wstName) == 0)
        {
            return Error;
        }
    }

    ReturnValue retVal = OK;

    try
    {
        GatewayCStruct gcs;
        gcs.name = m_stName;
        out.resize(_iRetCount, NULL);
        if (m_pCFunc((void*)&gcs, (int)in.size(), (scilabVar*)(in.data()), (int)opt.size(), (scilabOpt)&opt, _iRetCount, (scilabVar*)(out.data())))
        {
            retVal = Error;
        }
    }
    catch (const ast::InternalError& ie)
    {
        throw ie;
    }

    if (retVal == OK)
    {
        if (_iRetCount == 1 && out[0] == NULL)
        {
            //dont copy empty values, juste return "no value"
            out.clear();
            return retVal;
        }
    }

    return retVal;
}
示例#9
0
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mgetl(typed_list &in, int _iRetCount, typed_list &out)
{
    int iFileID                 = 0;
    int iErr                    = 0;
    bool bCloseFile             = false;
    int iLinesExcepted          = -1;
    int iLinesRead              = -1;
    wchar_t** wcReadedStrings   = NULL;

    if (in.size() < 1 || in.size() > 2)
    {
        Scierror(77, _("%s: Wrong number of input arguments: %d to %d expected.\n"), "mgetl" , 1, 2);
        return Function::OK;
    }

    if (in.size() == 2)
    {
        //number of lines
        if (in[1]->isDouble() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: An integer value expected.\n"), "mgetl", 2);
            return Function::Error;
        }

        if (in[1]->getAs<Double>()->isScalar() == false)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: An integer value expected.\n"), "mgetl", 2);
            return Function::Error;
        }

        if (in[1]->getAs<Double>()->get(0) != (int)in[1]->getAs<Double>()->get(0))
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: An integer value expected.\n"), "mgetl", 2);
            return Function::Error;
        }

        iLinesExcepted = static_cast<int>(in[1]->getAs<Double>()->get(0));
    }

    if (in[0]->isDouble() && in[0]->getAs<Double>()->getSize() == 1)
    {
        iFileID = static_cast<int>(in[0]->getAs<Double>()->get(0));
    }
    else if (in[0]->isString() && in[0]->getAs<types::String>()->getSize() == 1)
    {
        wchar_t *expandedFileName = expandPathVariableW(in[0]->getAs<types::String>()->get(0));

        iErr = mopen(expandedFileName, L"rt", 0, &iFileID);

        if (iErr)
        {
            char* pst = wide_string_to_UTF8(expandedFileName);
            switch (iErr)
            {
                case MOPEN_NO_MORE_LOGICAL_UNIT:
                    Scierror(66, _("%s: Too many files opened!\n"), "mgetl");
                    break;
                case MOPEN_CAN_NOT_OPEN_FILE:
                    Scierror(999, _("%s: Cannot open file %s.\n"), "mgetl", pst);
                    break;
                case MOPEN_NO_MORE_MEMORY:
                    Scierror(999, _("%s: No more memory.\n"), "mgetl");
                    break;
                case MOPEN_INVALID_FILENAME:
                    Scierror(999, _("%s: invalid filename %s.\n"), "mgetl", pst);
                    break;
                default: //MOPEN_INVALID_STATUS
                    Scierror(999, _("%s: invalid status.\n"), "mgetl");
                    break;
            }

            FREE(pst);
            return Function::Error;
        }
        FREE(expandedFileName);
        bCloseFile = true;
    }
    else
    {
        //Error
        Scierror(999, _("%s: Wrong type for input argument #%d: a String or Integer expected.\n"), "mgetl", 1);
        return Function::Error;
    }

    switch (iFileID)
    {
        case 0: // stderr
        case 6: // stdout
            Scierror(999, _("%s: Wrong file descriptor: %d.\n"), "mgetl", iFileID);
            return types::Function::Error;
        default :
        {
            types::File* pFile = FileManager::getFile(iFileID);
            // file opened with fortran open function
            if (pFile == NULL || pFile->getFileType() == 1)
            {
                Scierror(999, _("%s: Wrong file descriptor: %d.\n"), "mgetl", iFileID);
                return types::Function::Error;
            }

            wcReadedStrings = mgetl(iFileID, iLinesExcepted, &iLinesRead, &iErr);

            switch (iErr)
            {
                case MGETL_MEMORY_ALLOCATION_ERROR :
                    break;

            }
        }
    }

    if (wcReadedStrings && iLinesRead > 0)
    {
        String *pS = new String(iLinesRead, 1);
        pS->set(wcReadedStrings);
        out.push_back(pS);
        freeArrayOfWideString(wcReadedStrings, iLinesRead);
    }
    else
    {
        out.push_back(types::Double::Empty());
        if (wcReadedStrings)
        {
            FREE(wcReadedStrings);
        }
    }

    if (bCloseFile)
    {
        mclose(iFileID);
    }

    return Function::OK;
}
示例#10
0
Function::ReturnValue sci_setdefaultlanguage(typed_list &in, int _piRetCount, typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), "setdefaultlanguage", 1);
        return Function::Error;
    }

    if (_piRetCount != 1)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "setdefaultlanguage", 1);
        return Function::Error;
    }

#ifndef _MSC_VER
    /*
    ** No need to set default language except under Windows.
    ** Will return FALSE
    */
    if (getWarningMode())
    {
        sciprint(_("%ls: This feature is only used on Windows.\n"), L"setdefaultlanguage");
    }
    Bool* pbOut = new Bool(FALSE);

    out.push_back(pbOut);

    return Function::OK;
#else
    if (in[0]->isString() == false || in[0]->getAs<types::String>()->getSize() != 1)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), "setdefaultlanguage" , 1);
        return Function::Error;
    }
    wchar_t *newlang = getLanguageFromAlias(in[0]->getAs<types::String>()->get(0));

    if ( !isValidLanguage(newlang) )
    {
        if ( getWarningMode() )
        {
            sciprint(_("Unsupported language '%ls'.\n"), newlang);
        }
        out.push_back(new Bool(FALSE));

        return Function::OK;
    }
    else
    {
        wchar_t *savedLanguage = getLanguagePreferences();
        if ( wcscmp(newlang, savedLanguage) == 0 )
        {
            /* do nothing */
            out.push_back(new Bool(TRUE));

            return Function::OK;
        }
        else
        {
            // ??                if (savedLanguage) { FREE(savedLanguage); savedLanguage = NULL; }
            if ( !setlanguage(newlang) ) /* */
            {
                out.push_back(new Bool(FALSE));
                return Function::OK;
            }
            else
            {
                if ( getWarningMode() )
                {
                    sciprint("\n");
                    sciprint(_("The language for menus cannot be changed on a running console.\n"));
                    sciprint(_("Restart Scilab to apply to menus.\n"));
                }
                if ( setLanguagePreferences() )
                {
                    out.push_back(new Bool(TRUE));
                }
                else
                {
                    out.push_back(new Bool(FALSE));
                }
                return Function::OK;
            }
        }
    }

#endif
}
示例#11
0
Function::ReturnValue WrapFunction::call(typed_list &in, optional_list &opt, int _iRetCount, typed_list &out)
{
    int ret = 1;
    int inSize = (int)in.size();
    int optSize = (int)opt.size();
    int isRef = checkReferenceModule(m_wstModule.c_str());

    if (m_pLoadDeps != NULL)
    {
        ret = m_pLoadDeps(m_wstName);
    }

    if (ret == 0)
    {
        return Error;
    }

    ReturnValue retVal = Callable::OK;
    GatewayStruct gStr;
    _iRetCount = std::max(1, _iRetCount);
    gStr.m_iIn = inSize + optSize;
    gStr.m_iOut = _iRetCount;

    //copy input parameter to prevent calling gateway modifies input data
    typed_list inCopy;

    if (isRef == 0)
    {
        for (int i = 0; i < inSize; i++)
        {
            inCopy.push_back(in[i]->clone());
        }
    }
    else
    {
        for (int i = 0; i < inSize; i++)
        {
            inCopy.push_back(in[i]);
        }
    }
    gStr.m_pIn = &inCopy;
    gStr.m_pOpt = &opt;
    typed_list::value_type tmpOut[MAX_OUTPUT_VARIABLE];
    std::fill_n(tmpOut, MAX_OUTPUT_VARIABLE, static_cast<typed_list::value_type>(0));
    gStr.m_pOut = tmpOut;
    gStr.m_piRetCount = &_iRetCount;
    gStr.m_pstName = m_stName.data();
    // we should use a stack array of the max size to avoid dynamic alloc.
    std::vector<int> outOrder(_iRetCount < 1 ? 1 : _iRetCount, -1);
    gStr.m_pOutOrder = outOrder.data();

    //call gateway
    m_pOldFunc(const_cast<char*>(m_stName.data()), reinterpret_cast<int*>(&gStr));
    if (ConfigVariable::isError())
    {
        retVal = Callable::Error;
        ConfigVariable::resetError();
    }
    else
    {
        for (std::size_t i(0); i != (size_t)_iRetCount && outOrder[i] != -1 && outOrder[i] != 0; ++i)
        {
            if (outOrder[i] - 1 < gStr.m_iIn)
            {
                std::size_t const iPos(outOrder[i] - 1);
                //protect variable to deletion
                inCopy[iPos]->IncreaseRef();
                if (inCopy[iPos]->isDouble() && ((types::Double*)inCopy[iPos])->isViewAsInteger())
                {
                    types::Double* pD = inCopy[iPos]->getAs<types::Double>();
                    pD->convertFromInteger();
                }

                if (inCopy[iPos]->isDouble() && ((types::Double*)inCopy[iPos])->isViewAsZComplex())
                {
                    types::Double* pD = inCopy[iPos]->getAs<types::Double>();
                    pD->convertFromZComplex();
                }

                out.push_back(inCopy[iPos]);
            }
            else
            {
                std::size_t const iPos(outOrder[i] - gStr.m_iIn - 1);
                if (tmpOut[iPos]->isDouble() && ((types::Double*)tmpOut[iPos])->isViewAsInteger())
                {
                    types::Double* pD = tmpOut[iPos]->getAs<types::Double>();
                    pD->convertFromInteger();
                }

                if (tmpOut[iPos]->isDouble() && ((types::Double*)tmpOut[iPos])->isViewAsZComplex())
                {
                    types::Double* pD = tmpOut[iPos]->getAs<types::Double>();
                    pD->convertFromZComplex();
                }

                out.push_back(tmpOut[iPos]);
                tmpOut[iPos] = 0;
            }
        }
    }

    for (std::size_t i(0); i != MAX_OUTPUT_VARIABLE; ++i)
    {
        if (tmpOut[i])
        {
            tmpOut[i]->killMe();
        }
    }

    //clean input copy
    if (isRef == 0)
    {
        //protect outputs
        int size = (int)out.size();
        for (int i = 0; i < size; i++)
        {
            out[i]->IncreaseRef();
        }

        for (int i = 0; i < inSize; i++)
        {
            inCopy[i]->killMe();
        }

        //unprotect outputs
        for (int i = 0; i < size; i++)
        {
            out[i]->DecreaseRef();
        }
    }

    return retVal;
}
示例#12
0
Function::ReturnValue sci_inpnv(typed_list &in, int _iRetCount, typed_list &out)
{
    if (in.size() != 13)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), "inpnv", 7);
        return Function::Error;
    }

    if (_iRetCount != 1)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "inpnv", 2);
        return Function::Error;
    }


    //get argument #1
    if (in[0]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 1);
        return Function::Error;
    }

    Double* pdbl1 = in[0]->getAs<Double>();
    pdbl1->convertToInteger();
    int* neqns = (int*)pdbl1->get();

    //get argument #2
    if (in[1]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 2);
        return Function::Error;
    }

    Double* pdbl2 = in[1]->getAs<Double>();
    pdbl2->convertToInteger();
    int* xadhf = (int*)pdbl2->get();

    //get argument #3
    if (in[2]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 3);
        return Function::Error;
    }

    Double* pdbl3 = in[2]->getAs<Double>();
    pdbl3->convertToInteger();
    int* adjf = (int*)pdbl3->get();

    //get argument #4
    if (in[3]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 4);
        return Function::Error;
    }

    Double* pdbl4 = in[3]->getAs<Double>();
    double* anzf = pdbl4->get();

    //get argument #5
    if (in[4]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 5);
        return Function::Error;
    }

    Double* pdbl5 = in[4]->getAs<Double>();
    pdbl5->convertToInteger();
    int* perm = (int*)pdbl5->get();

    //get argument #6
    if (in[5]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 6);
        return Function::Error;
    }

    Double* pdbl6 = in[5]->getAs<Double>();
    pdbl6->convertToInteger();
    int* invp = (int*)pdbl6->get();

    //get argument #7
    if (in[6]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 7);
        return Function::Error;
    }

    Double* pdbl7 = in[6]->getAs<Double>();
    pdbl7->convertToInteger();
    int* nsuper = (int*)pdbl7->get();

    //get argument #8
    if (in[7]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 8);
        return Function::Error;
    }

    Double* pdbl8 = in[7]->getAs<Double>();
    pdbl8->convertToInteger();
    int* xsuper = (int*)pdbl8->get();

    //get argument #9
    if (in[8]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 9);
        return Function::Error;
    }

    Double* pdbl9 = in[8]->getAs<Double>();
    pdbl9->convertToInteger();
    int* xlindx = (int*)pdbl9->get();

    //get argument #10
    if (in[9]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 10);
        return Function::Error;
    }

    Double* pdbl10 = in[9]->getAs<Double>();
    pdbl10->convertToInteger();
    int* lindx = (int*)pdbl10->get();

    //get argument #11
    if (in[10]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 11);
        return Function::Error;
    }

    Double* pdbl11 = in[10]->getAs<Double>();
    pdbl11->convertToInteger();
    int* xlnz = (int*)pdbl11->get();

    //get argument #12
    if (in[11]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 12);
        return Function::Error;
    }

    Double* pdbl12 = in[11]->getAs<Double>();
    double* lnz = pdbl12->get();

    //get argument #13
    if (in[12]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "inpnv", 13);
        return Function::Error;
    }

    Double* pdbl13 = in[12]->getAs<Double>();
    pdbl13->convertToInteger();
    int* offset = (int*)pdbl13->get();


    C2F(inpnv)(neqns, xadhf, adjf, anzf, perm, invp,
               nsuper, xsuper, xlindx, lindx,
               xlnz, lnz, offset);

    pdbl1->convertFromInteger();
    pdbl2->convertFromInteger();
    pdbl3->convertFromInteger();
    pdbl5->convertFromInteger();
    pdbl6->convertFromInteger();
    pdbl7->convertFromInteger();
    pdbl8->convertFromInteger();
    pdbl9->convertFromInteger();
    pdbl10->convertFromInteger();
    pdbl11->convertFromInteger();
    pdbl13->convertFromInteger();

    out.push_back(pdbl12);

    return Function::OK;
}
示例#13
0
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_basename(typed_list &in, int _iRetCount, typed_list &out)
{
    int iExpand     = 1;
    int iConvert    = 1;

    if (in.size() < 1 || in.size() > 3)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "basename", 1, 3);
        return Function::Error;
    }

    if (_iRetCount != 1)
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "basename", 1);
        return Function::Error;
    }

    if (in.size() > 2)
    {
        if (in[2]->isBool() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 3);
            return Function::Error;
        }

        if (in[2]->getAs<types::Bool>()->getSize() != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 3);
            return Function::Error;
        }

        iExpand = in[2]->getAs<types::Bool>()->get()[0];
    }

    if (in.size() > 1)
    {
        if (in[1]->isBool() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 2);
            return Function::Error;
        }

        if (in[1]->getAs<types::Bool>()->getSize() != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 2);
            return Function::Error;
        }

        iConvert = in[1]->getAs<types::Bool>()->get()[0];
    }

    if (in[0]->isDouble() && in[0]->getAs<Double>()->isEmpty())
    {
        out.push_back(Double::Empty());
        return Function::OK;
    }
    if (in[0]->isString() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string matrix expected.\n"), "basename", 1);
        return Function::Error;
    }

    String* pS      = in[0]->getAs<types::String>();
    String* pOut    = new String(pS->getRows(), pS->getCols());
    for (int i = 0 ; i < pS->getSize() ; i++)
    {
        wchar_t* base = basenameW(pS->get(i), (BOOL)iExpand);
        pOut->set(i, base);
        FREE(base);
    }


    out.push_back(pOut);
    return Function::OK;
    //SciErr sciErr;
    //BOOL flag = TRUE; /* default */
    //BOOL flagexpand = TRUE; /* default */

    //int *piAddressVarOne = NULL;
    //wchar_t **pStVarOne = NULL;
    //int *lenStVarOne = NULL;
    //int iType1					= 0;
    //int m1 = 0, n1 = 0;

    //wchar_t **pStResult = NULL;

    //int i = 0;

    ///* Check Input & Output parameters */
    //CheckRhs(1,3);
    //CheckLhs(1,1);

    //if (Rhs > 2)
    //{
    //	int *piAddressVarThree = NULL;
    //	int *piData = NULL;
    //	int iType3	= 0;
    //	int m3 = 0, n3 = 0;

    //	sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	sciErr = getVarType(pvApiCtx, piAddressVarThree, &iType3);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if (iType3 != sci_boolean)
    //	{
    //		Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
    //		return 0;
    //	}

    //	sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarThree, &m3, &n3,  &piData);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	sciErr = getVarDimension(pvApiCtx, piAddressVarThree, &m3, &n3);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if ( (m3 != n3) && (n3 != 1) )
    //	{
    //		Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
    //		return 0;
    //	}

    //	flagexpand = piData[0];
    //}

    //if (Rhs > 1)
    //{
    //	int *piAddressVarTwo = NULL;
    //	int *piData = NULL;
    //	int iType2	= 0;
    //	int m2 = 0, n2 = 0;

    //	sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if (iType2 != sci_boolean)
    //	{
    //		Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
    //		return 0;
    //	}

    //	sciErr = getVarDimension(pvApiCtx, piAddressVarTwo, &m2, &n2);

    //	if ( (m2 != n2) && (n2 != 1) )
    //	{
    //		Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2);
    //		return 0;
    //	}

    //	sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarTwo, &m2, &n2,  &piData);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	flag = piData[0];
    //}

    //sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
    //if(sciErr.iErr)
    //{
    //	printError(&sciErr, 0);
    //	return 0;
    //}

    //sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
    //if(sciErr.iErr)
    //{
    //	printError(&sciErr, 0);
    //	return 0;
    //}

    //if (iType1 == sci_matrix)
    //{
    //	sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if ( (m1 == n1) && (m1 == 0) )
    //	{
    //		sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, NULL);
    //		if(sciErr.iErr)
    //		{
    //			printError(&sciErr, 0);
    //			return 0;
    //		}

    //		LhsVar(1) = Rhs + 1;
    //		C2F(putlhsvar)();
    //	}
    //	else
    //	{
    //		Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
    //	}
    //}
    //else if (iType1 == sci_strings)
    //{
    //	int i = 0;

    //	sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
    //	if (lenStVarOne == NULL)
    //	{
    //		Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //		return 0;
    //	}

    //	// get lenStVarOne value
    //	sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
    //	if(sciErr.iErr)
    //	{
    //		freeArrayOfWideString(pStVarOne, m1 * n1);
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
    //	if (pStVarOne == NULL)
    //	{
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //		return 0;
    //	}

    //	for (i = 0; i < (m1 * n1); i++)
    //	{
    //		pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
    //		if (pStVarOne[i] == NULL)
    //		{
    //			freeArrayOfWideString(pStVarOne, m1 * n1);
    //			if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //			Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //			return 0;
    //		}
    //	}

    //	// get pStVarOne
    //	sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
    //	if(sciErr.iErr)
    //	{
    //		freeArrayOfWideString(pStVarOne, m1 * n1);
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	pStResult = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));

    //	if (pStResult == NULL)
    //	{
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //		return 0;
    //	}

    //	for (i=0;i< m1 * n1; i++)
    //	{
    //		pStResult[i] = basenameW(pStVarOne[i], flagexpand);
    //	}

    //	sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 1, m1, n1, pStResult);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	LhsVar(1) = Rhs + 1;
    //	C2F(putlhsvar)();

    //	if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //	freeArrayOfWideString(pStResult, m1 * n1);
    //	freeArrayOfWideString(pStVarOne, m1 * n1);
    //}
    //else
    //{
    //	Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
    //}
    //return 0;
}
示例#14
0
Function::ReturnValue sci_blkfc1i(typed_list &in, int _iRetCount, typed_list &out)
{
    if (in.size() != 15)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), "blkfc1", 15);
        return Function::Error;
    }

    if (_iRetCount != 2)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), "blkfc1", 2);
        return Function::Error;
    }


    //get argument #1
    if (in[0]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 1);
        return Function::Error;
    }

    Double* pdbl1 = in[0]->getAs<Double>();
    pdbl1->convertToInteger();
    int* neqns = (int*)pdbl1->get();

    //get argument #2
    if (in[1]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 2);
        return Function::Error;
    }

    Double* pdbl2 = in[1]->getAs<Double>();
    pdbl2->convertToInteger();
    int* nsuper = (int*)pdbl2->get();

    //get argument #3
    if (in[2]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 3);
        return Function::Error;
    }

    Double* pdbl3 = in[2]->getAs<Double>();
    pdbl3->convertToInteger();
    int* xsuper = (int*)pdbl3->get();

    //get argument #4
    if (in[3]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 4);
        return Function::Error;
    }

    Double* pdbl4 = in[3]->getAs<Double>();
    pdbl4->convertToInteger();
    int* snode = (int*)pdbl4->get();

    //get argument #5
    if (in[4]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 5);
        return Function::Error;
    }

    Double* pdbl5 = in[4]->getAs<Double>();
    pdbl5->convertToInteger();
    int* split = (int*)pdbl5->get();

    //get argument #6
    if (in[5]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 6);
        return Function::Error;
    }

    Double* pdbl6 = in[5]->getAs<Double>();
    pdbl6->convertToInteger();
    int* xlindx = (int*)pdbl6->get();

    //get argument #7
    if (in[6]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 7);
        return Function::Error;
    }

    Double* pdbl7 = in[6]->getAs<Double>();
    pdbl7->convertToInteger();
    int* lindx = (int*)pdbl7->get();

    //get argument #8
    if (in[7]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 8);
        return Function::Error;
    }

    Double* pdbl8 = in[7]->getAs<Double>();
    pdbl8->convertToInteger();
    int* xlnz = (int*)pdbl8->get();

    //get argument #9
    if (in[8]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 9);
        return Function::Error;
    }

    Double* pdbl9 = in[8]->getAs<Double>();
    double* lnz = pdbl9->get();

    //get argument #10
    if (in[9]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 10);
        return Function::Error;
    }

    Double* pdbl10 = in[9]->getAs<Double>();
    pdbl10->convertToInteger();
    int* iwsiz = (int*)pdbl10->get();

    //get argument #11
    if (in[10]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 11);
        return Function::Error;
    }

    Double* pdbl11 = in[10]->getAs<Double>();
    pdbl11->convertToInteger();
    int* iwork = (int*)pdbl11->get();

    //get argument #12
    if (in[11]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 12);
        return Function::Error;
    }

    Double* pdbl12 = in[11]->getAs<Double>();
    pdbl12->convertToInteger();
    int* tmpsiz = (int*)pdbl12->get();

    //get argument #13
    if (in[12]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 13);
        return Function::Error;
    }

    Double* pdbl13 = in[12]->getAs<Double>();
    double* tmpvec = pdbl13->get();

    //get argument #14
    if (in[13]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 14);
        return Function::Error;
    }

    Double* pdbl14 = in[13]->getAs<Double>();
    pdbl14->convertToInteger();
    int* iflag = (int*)pdbl14->get();

    //get argument #15
    if (in[14]->isDouble() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix of integer value expected.\n"), "blkfc1", 15);
        return Function::Error;
    }

    Double* pdbl15 = in[14]->getAs<Double>();
    pdbl15->convertToInteger();
    int* lelvel = (int*)pdbl15->get();



    C2F(blkfc1)(neqns, nsuper, xsuper, snode, split,
                xlindx, lindx, xlnz, lnz, iwsiz,
                iwork, tmpsiz, tmpvec, iflag, lelvel);

    if (iflag[0])
    {

        Scierror(999, _("%s: insufficient working storage"), "blkfc1");
        return Function::Error;
    }

    pdbl1->convertFromInteger();
    pdbl2->convertFromInteger();
    pdbl3->convertFromInteger();
    pdbl4->convertFromInteger();
    pdbl5->convertFromInteger();
    pdbl6->convertFromInteger();
    pdbl7->convertFromInteger();
    pdbl8->convertFromInteger();
    pdbl10->convertFromInteger();
    pdbl11->convertFromInteger();
    pdbl12->convertFromInteger();
    pdbl14->convertFromInteger();
    pdbl15->convertFromInteger();

    out.push_back(pdbl9);
    out.push_back(pdbl14);

    return Function::OK;
}