Example #1
0
/*--------------------------------------------------------------------------*/
int get_strf_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** strf)
{
    int first_opt = FirstOpt(_pvCtx), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        char* pstData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);
        if (iType != 10)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, pos);
            return 0;
        }

        getAllocatedSingleString(_pvCtx, piAddr, &pstData);
        if ((int)strlen(pstData) != 3)
        {
            freeAllocatedSingleString(pstData);
            Scierror(999, _("%s: Wrong size for input argument #%d: String of %d characters expected.\n"), fname, pos, 3);
            return 0;
        }
        *strf = pstData;
    }
    else if ((kopt = FindOpt(_pvCtx, "strf", opts)) >= 0)
    {
        char* pstData = NULL;
        int iType = 0;
        getVarType(_pvCtx, opts[kopt].piAddr, &iType);
        if (iType != 10)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, pos);
            return 0;
        }

        getAllocatedSingleString(_pvCtx, opts[kopt].piAddr, &pstData);
        if ((int)strlen(pstData) != 3)
        {
            freeAllocatedSingleString(pstData);
            Scierror(999, _("%s: Wrong size for input argument #%d: String of %d characters expected.\n"), fname, kopt, 3);
            return 0;
        }
        *strf = pstData;
    }
    else
    {
        /* def value can be changed */
        reinitDefStrfN();
        *strf = getDefStrf();
    }
    return 1;
}
int sci_deleteNamedVariable(char *fname, void* pvApiCtx)
{
    SciErr sciErr;
    int iRet = 0;
    int* piAddr = NULL;
    char* pstVarName = NULL;

    CheckRhs(1, 1);
    CheckLhs(1, 1);

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

    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName))
    {
        //error
        return 1;
    }

    if (isNamedVarExist(pvApiCtx, pstVarName))
    {
        iRet = deleteNamedVariable(pvApiCtx, pstVarName);
    }

    freeAllocatedSingleString(pstVarName);
    createScalarBoolean(pvApiCtx, Rhs + 1, iRet);
    AssignOutputVariable(pvApiCtx, 1) = Rhs + 1;
    return 0;
}
Example #3
0
/* ==================================================================== */
static void freeAllocatedStrings(char *url, char *username, char *password)
{
    if (url != NULL)
    {
        freeAllocatedSingleString(url);
    }

    if (username != NULL)
    {
        freeAllocatedSingleString(username);
    }

    if (password != NULL)
    {
        freeAllocatedSingleString(password);
    }
}
Example #4
0
/*--------------------------------------------------------------------------*/
int sci_xinit(char * fname, void *pvApiCtx)
{
    SciErr err;
    int * addr = 0;
    char * path = 0;
    char * realPath = 0;

    CheckInputArgument(pvApiCtx, 1, 1);

    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
    if (err.iErr)
    {
        printError(&err, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 0;
    }

    if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1))
    {
        Scierror(999, gettext("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
        return 0;
    }

    if (getAllocatedSingleString(pvApiCtx, addr, &path) != 0)
    {
        Scierror(999, _("%s: No more memory.\n"), fname);
        return 0;
    }

    realPath = expandPathVariable(path);

    if (realPath)
    {
        org_scilab_modules_graphic_export::Driver::setPath(getScilabJavaVM(), realPath);
        FREE(realPath);
    }
    else
    {
        Scierror(999, _("%s: Invalid path: %s.\n"), fname, path);
        return 0;
    }

    freeAllocatedSingleString(path);

    LhsVar(1) = 0;
    PutLhsVar();

    return 0;
}
Example #5
0
/*--------------------------------------------------------------------------*/
int C2F(sci_getscilabmode)(char *fname, unsigned long fname_len)
{
    int n1 = 0, m1 = 0;
    char *output = NULL ;
    int iRet = 0;
    SciErr sciErr;

    CheckInputArgument(pvApiCtx, 0, 0) ;
    CheckOutputArgument(pvApiCtx, 1, 1) ;

    switch (getScilabMode())
    {
        case SCILAB_API:
        default :
            output = strdup("API");
            break;
        case SCILAB_STD:
            output = strdup("STD");
            break;
        case SCILAB_NW:
            output = strdup("NW");
            break;
        case SCILAB_NWNI:
            output = strdup("NWNI");
            break;
    }

    /* Create the string matrix as return of the function */
    iRet = createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, output);
    free(output); // Data have been copied into Scilab memory
    if (iRet)
    {
        freeAllocatedSingleString(output);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #6
0
/*--------------------------------------------------------------------------*/
int getStackArgumentAsBoolean(void* _pvCtx, int* _piAddr)
{
    if (isScalar(_pvCtx, _piAddr))
    {
        if (isDoubleType(_pvCtx, _piAddr))
        {
            double dbl = 0;
            getScalarDouble(_pvCtx, _piAddr, &dbl);
            return ((int)dbl == 0 ? FALSE : TRUE);
        }
        else if (isBooleanType(_pvCtx, _piAddr))
        {
            int i = 0;
            getScalarBoolean(_pvCtx, _piAddr, &i);
            return (i == 0 ? FALSE : TRUE);
        }
        else if (isStringType(_pvCtx, _piAddr))
        {
            int ret = 0;
            char* pst = NULL;
            if (getAllocatedSingleString(_pvCtx, _piAddr, &pst))
            {
                return -1;
            }

            if (stricmp(pst, "on") == 0)
            {
                ret = TRUE;
            }

            freeAllocatedSingleString(pst);

            return ret;
        }
    }
    return -1;
}
Example #7
0
int ScilabGateway::invoke_lu(char * fname, const int envId, void * pvApiCtx)
{
    SciErr err;
    int typ = 0;
    int * addr = 0;
    int * listaddr = 0;
    int len = 0;
    int * tmpvar = 0;
    int idObj = 0;
    int * args = 0;
    int * child = 0;
    char * methName = 0;
    int * eId;
    int row, col;
    int * ret = 0;
    int nbArgs = 0;
    std::vector<int> torem;

    CheckInputArgument(pvApiCtx, 4, 4);

    err = getVarAddressFromPosition(pvApiCtx, 4, &listaddr);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    err = getVarType(pvApiCtx, listaddr, &typ);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    if (typ != sci_list)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A List expected."), 4);
    }

    err = getListItemNumber(pvApiCtx, listaddr, &len);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    // Get the environment id
    err = getVarAddressFromPosition(pvApiCtx, 2, &addr);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    err = getVarType(pvApiCtx, addr, &typ);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    if (typ != sci_ints)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 2);
    }
    else
    {
        int prec;

        err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec);
        if (err.iErr)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        if (prec != SCI_INT32)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 2);
        }

        err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, &eId);
        if (err.iErr)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }
    }

    ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(*eId);
    ScilabGatewayOptions & options = env.getGatewayOptions();
    OptionsHelper::setCopyOccurred(false);
    ScilabObjects::initialization(env, pvApiCtx);
    options.setIsNew(false);

    // Get the object id
    err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    err = getVarType(pvApiCtx, addr, &typ);
    if (err.iErr)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
    }

    if (typ != sci_ints)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 1);
    }
    else
    {
        int prec;
        int * id;

        err = getMatrixOfIntegerPrecision(pvApiCtx, addr, &prec);
        if (err.iErr)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        if (prec != SCI_INT32)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An Integer32 expected."), 1);
        }

        err = getMatrixOfInteger32(pvApiCtx, addr, &row, &col, &id);
        if (err.iErr)
        {
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        idObj = *id;
    }

    if (idObj == 0)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot invoke on null object."), __FILE__, __LINE__);
    }

    tmpvar = new int[len + 1];
    *tmpvar = 0;

    args = new int[len];
    nbArgs = len;

    for (int i = 0; i < len; i++)
    {
        err = getListItemAddress(pvApiCtx, listaddr, i + 1, &child);
        if (err.iErr)
        {
            delete[] args;
            ScilabObjects::removeTemporaryVars(*eId, tmpvar);
            delete[] tmpvar;
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        try
        {
            args[i] = ScilabObjects::getArgumentId(child, tmpvar, false, false, *eId, pvApiCtx);
        }
        catch (ScilabAbstractEnvironmentException & e)
        {
            delete[] args;
            delete[] tmpvar;
            throw;
        }

        if (args[i] == VOID_OBJECT)
        {
            nbArgs = 0;
        }
    }

    try
    {
        methName = ScilabObjects::getSingleString(3, pvApiCtx);
    }
    catch (ScilabAbstractEnvironmentException & e)
    {
        delete[] args;
        ScilabObjects::removeTemporaryVars(*eId, tmpvar);
        delete[] tmpvar;
        throw;
    }

    try
    {
        ret = env.invoke(idObj, methName, args, nbArgs);
    }
    catch (std::exception & e)
    {
        delete[] args;
        ScilabObjects::removeTemporaryVars(*eId, tmpvar);
        delete[] tmpvar;
        freeAllocatedSingleString(methName);
        throw;
    }

    delete[] args;
    ScilabObjects::removeTemporaryVars(*eId, tmpvar);
    delete[] tmpvar;
    freeAllocatedSingleString(methName);

    if (!ret || *ret <= 0 || (*ret == 1 && ret[1] == VOID_OBJECT))
    {
        if (ret)
        {
            delete[] ret;
        }

        PutLhsVar();

        return 0;
    }

    torem.reserve(*ret);

    for (int i = 1; i <= *ret; i++)
    {
        if (!ScilabObjects::unwrap(ret[i], Rhs + i, *eId, pvApiCtx))
        {
            try
            {
                ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, ret[i], *eId, pvApiCtx);
            }
            catch (ScilabAbstractEnvironmentException & e)
            {
                if (!torem.empty())
                {
                    env.removeobject(&(torem[0]), torem.size());
                }
                env.removeobject(ret + 1, *ret);
                delete[] ret;
                throw;
            }
        }
        else
        {
            torem.push_back(ret[i]);
        }

        LhsVar(i) = Rhs + i;
    }

    if (!torem.empty())
    {
        env.removeobject(&(torem[0]), torem.size());
    }

    delete[] ret;

    PutLhsVar();

    return 0;
}
Example #8
0
/*--------------------------------------------------------------------------*/
int sci_uigetcolor(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    //WARNING ALL NEW DECALRATIONS ARE HERE IF YOUR HAVE MANY FUNCTIONS
    //IN THE FILE YOU HAVE PROBABLY TO MOVE DECLARATIONS IN GOOD FUNCTIONS
    int* piAddrredAdr = NULL;
    double* redAdr = NULL;
    int* piAddrtitleAdr = NULL;
    char* titleAdr = NULL;
    int* piAddrgreenAdr = NULL;
    double* greenAdr = NULL;
    int* piAddrblueAdr = NULL;
    double* blueAdr = NULL;

    int colorChooserID = 0;
    int firstColorIndex = 0;

    int nbRow = 0, nbCol = 0;

    double *selectedRGB = NULL;

    CheckInputArgument(pvApiCtx, 0, 4);

    if ((nbOutputArgument(pvApiCtx) != 1) && (nbOutputArgument(pvApiCtx) != 3)) /* Bad use */
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d or %d expected.\n"), fname, 1, 3);
        return FALSE;
    }

    /* Rhs==1: title or [R, G, B] given */
    if (nbInputArgument(pvApiCtx) == 1)
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrredAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
                return 1;
            }

            if ((nbRow != 1) || (nbCol != 3))
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 1, 3);
                return FALSE;
            }
        }
        else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real or a string expected.\n"), fname, 1);
            return FALSE;
        }
    }

    /* Title and [R, G, B] given */
    if (nbInputArgument(pvApiCtx) == 2)
    {
        /* Title */
        if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
            return FALSE;
        }

        /* [R, G, B] */
        if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrredAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 2.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 3)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 2, 3);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 2, 3);
            return FALSE;
        }
    }

    /* No title given but colors given with separate values */
    if (nbInputArgument(pvApiCtx) == 3)
    {
        firstColorIndex = 1;
    }

    /* Title and colors given with separate values */
    if (nbInputArgument(pvApiCtx) == 4)
    {
        firstColorIndex = 2;

        /* Title */
        if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real or a string expected.\n"), fname, 1);
            return FALSE;
        }
    }

    /* R, G, B given */
    if (nbInputArgument(pvApiCtx) >= 3)
    {
        /* Default red value */
        if ((checkInputArgumentType(pvApiCtx, firstColorIndex, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex, &piAddrredAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position firstColorIndex.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex);
            return FALSE;
        }

        /* Default green value */
        if (checkInputArgumentType(pvApiCtx, firstColorIndex + 1, sci_matrix))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex + 1, &piAddrgreenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position firstColorIndex + 1.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrgreenAdr, &nbRow, &nbCol, &greenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex + 1);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex + 1);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex + 1);
            return FALSE;
        }

        /* Default blue value */
        if (checkInputArgumentType(pvApiCtx, firstColorIndex + 2, sci_matrix))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex + 2, &piAddrblueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position firstColorIndex + 2.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrblueAdr, &nbRow, &nbCol, &blueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex + 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex + 2);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex + 2);
            return FALSE;
        }
    }

    /* Create the Java Object */
    colorChooserID = createColorChooser();

    /* Title */
    if (titleAdr != 0)
    {
        setColorChooserTitle(colorChooserID, titleAdr);
        freeAllocatedSingleString(titleAdr);
    }

    /* Default red value */
    if (redAdr != 0)
    {
        if (greenAdr != 0 ) /* All values given in first input argument */
        {
            setColorChooserDefaultRGBSeparateValues(colorChooserID, (int)redAdr[0], (int)greenAdr[0], (int)blueAdr[0]);
        }
        else
        {
            setColorChooserDefaultRGB(colorChooserID, redAdr);
        }
    }

    /* Display it and wait for a user input */
    colorChooserDisplayAndWait(colorChooserID);

    /* Return the selected color */
    /* Read the user answer */
    selectedRGB = getColorChooserSelectedRGB(colorChooserID);

    if (selectedRGB[0] >= 0) /* The user selected a color */
    {

        nbRow = 1;
        if (nbOutputArgument(pvApiCtx) == 1)
        {
            nbCol = 3;
            sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, selectedRGB);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            nbCol = 1;

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            redAdr[0] = selectedRGB[0];

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &greenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            greenAdr[0] = selectedRGB[1];

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &blueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            blueAdr[0] = selectedRGB[2];

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
            AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
        }
    }
    else /* The user canceled */
    {
        nbRow = 0;
        nbCol = 0;
        if (nbOutputArgument(pvApiCtx) == 1)
        {
            /* Return [] */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }


            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &greenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &blueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }


            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
            AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
        }
    }

    ReturnArguments(pvApiCtx);
    return TRUE;
}
Example #9
0
/*--------------------------------------------------------------------------*/
static int xlfont_n_rhs(char * fname)
{
    SciErr sciErr;
    BOOL isBold = FALSE;
    BOOL isItalic = FALSE;

    if (nbInputArgument(pvApiCtx) == 3)
    {
        int m3 = 0, n3 = 0;
        int* piAddrl3 = NULL;
        int* l3 = NULL;
        if ((!checkInputArgumentType(pvApiCtx, 3, sci_boolean)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
            return 0;
        }

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

        // Retrieve a matrix of boolean at position 3.
        sciErr = getMatrixOfBoolean(pvApiCtx, piAddrl3, &m3, &n3, &l3);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: Boolean matrix expected.\n"), fname, 3);
            return 1;
        }

        isBold = (BOOL) * l3;
    }

    if (nbInputArgument(pvApiCtx) == 4)
    {
        int m4 = 0, n4 = 0;
        int* piAddrl4 = NULL;
        int* l4 = NULL;
        if ((!checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
            return 0;
        }
        sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrl4);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of boolean at position 4.
        sciErr = getMatrixOfBoolean(pvApiCtx, piAddrl4, &m4, &n4, &l4);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: Boolean matrix expected.\n"), fname, 4);
            return 1;
        }

        isItalic = (BOOL) * l4;
    }

    if (((checkInputArgumentType(pvApiCtx, 1, sci_strings))) && ((checkInputArgumentType(pvApiCtx, 2, sci_matrix))))
    {
        int m1 = 0, n1 = 0;
        int m2 = 0, n2 = 0;
        char* strl1 = NULL;
        double* l2 = NULL;
        int* l1 = NULL;

        int* piAddrl1 = NULL;
        int* piAddrl2 = NULL;

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

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &strl1))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

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

        // Retrieve a matrix of double at position 2.
        sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2);
            return 1;
        }

        if ((m2 == 1) && (n2 == 1))
        {
            int fontIndex = (int)l2[0];
            char *fontname = strl1;
            if (fontIndex < 0)
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: Non-negative int expected.\n"), fname, 2);
                return 0;
            }

            if ((nbInputArgument(pvApiCtx) == 2) && FileExist(fontname))
            {
                int Id = changeFontFromFilename(fontIndex, fontname);
                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = Id;

                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
            }
            else if (isAvailableFontsName(fontname))
            {
                int Id = changeFontWithProperty(fontIndex, fontname, isBold, isItalic);
                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = Id;

                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: A valid fontname expected.\n"), fname, 1);
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 2);
        }

        freeAllocatedSingleString(strl1);
    }
    else
    {
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
            return 0;
        }

        if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Non-negative int expected.\n"), fname, 2);
            return 0;
        }
    }
    return 0;
}
Example #10
0
/*--------------------------------------------------------------------------*/
int sci_dnaupd(char *fname, void *pvApiCtx)
{
    SciErr sciErr;

    int* piAddrpIDO     = NULL;
    int* pIDO           = NULL;
    int* piAddrpBMAT    = NULL;
    char* pBMAT         = NULL;
    int* piAddrpN       = NULL;
    int* pN             = NULL;
    int* piAddrpWHICH   = NULL;
    char* pWHICH        = NULL;
    int* piAddrpNEV     = NULL;
    int* pNEV           = NULL;
    int* piAddrpTOL     = NULL;
    double* pTOL        = NULL;
    int* piAddrpRESID   = NULL;
    double* pRESID      = NULL;
    int* piAddrpNCV     = NULL;
    int* pNCV           = NULL;
    int* piAddrpV       = NULL;
    double* pV          = NULL;
    int* piAddrpIPARAM  = NULL;
    int* pIPARAM        = NULL;
    int* piAddrpIPNTR   = NULL;
    int* pIPNTR         = NULL;
    int* piAddrpWORKD   = NULL;
    double* pWORKD      = NULL;
    int* piAddrpWORKL   = NULL;
    double* pWORKL      = NULL;
    int* piAddrpINFO    = NULL;
    int* pINFO          = NULL;

    int IDO,   mIDO,   nIDO;
    int mN,     nN;
    int mNEV,   nNEV;
    int mTOL,   nTOL;
    int RESID, mRESID, nRESID;
    int mNCV,   nNCV;
    int V,     mV,     nV;
    int IPARAM, mIPARAM, nIPARAM;
    int IPNTR, mIPNTR, nIPNTR;
    int WORKD, mWORKD, nWORKD;
    int WORKL, mWORKL, nWORKL;
    int INFO,  mINFO,  nINFO;

    int minlhs = 1, minrhs = 14, maxlhs = 8, maxrhs = 14;
    int LDV, LWORKL;
    int sizeWORKL = 0;

    /* [IDO,RESID,V,IPARAM,IPNTR,WORKD,WORKL,INFO]=dnaupd...
       (ID0,BMAT,N,WHICH,NEV,TOL,RESID,NCV,V,IPARAM,IPNTR,WORKD,WORKL,INFO) */

    CheckInputArgument(pvApiCtx, minrhs, maxrhs);
    CheckOutputArgument(pvApiCtx, minlhs, maxlhs);

    /*                                                  VARIABLE = NUMBER   */
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpIDO);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 1.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIDO, &mIDO, &nIDO, &pIDO);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
        return 1;
    }

    IDO =  1;

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

    // Retrieve a matrix of double at position 3.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpN, &mN, &nN, &pN);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
        return 1;
    }

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

    // Retrieve a matrix of double at position 5.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNEV, &mNEV, &nNEV, &pNEV);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 5);
        return 1;
    }

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

    // Retrieve a matrix of double at position 6.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrpTOL, &mTOL, &nTOL, &pTOL);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 6);
        return 1;
    }

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

    // Retrieve a matrix of double at position 7.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrpRESID, &mRESID, &nRESID, &pRESID);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 7);
        return 1;
    }

    RESID =  7;
    sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddrpNCV);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 8.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNCV, &mNCV, &nNCV, &pNCV);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 8);
        return 1;
    }

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

    // Retrieve a matrix of double at position 9.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrpV, &mV, &nV, &pV);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 9);
        return 1;
    }

    V =  9;
    sciErr = getVarAddressFromPosition(pvApiCtx, 10, &piAddrpIPARAM);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 10.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPARAM, &mIPARAM, &nIPARAM, &pIPARAM);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 10);
        return 1;
    }

    IPARAM = 10;
    sciErr = getVarAddressFromPosition(pvApiCtx, 11, &piAddrpIPNTR);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 11.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPNTR, &mIPNTR, &nIPNTR, &pIPNTR);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 11);
        return 1;
    }

    IPNTR = 11;
    sciErr = getVarAddressFromPosition(pvApiCtx, 12, &piAddrpWORKD);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 12.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrpWORKD, &mWORKD, &nWORKD, &pWORKD);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 12);
        return 1;
    }

    WORKD = 12;
    sciErr = getVarAddressFromPosition(pvApiCtx, 13, &piAddrpWORKL);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 13.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrpWORKL, &mWORKL, &nWORKL, &pWORKL);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 13);
        return 1;
    }

    WORKL = 13;
    sciErr = getVarAddressFromPosition(pvApiCtx, 14, &piAddrpINFO);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 14.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpINFO, &mINFO, &nINFO, &pINFO);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 14);
        return 1;
    }

    INFO = 14;

    LWORKL = mWORKL * nWORKL;
    LDV = Max(1, pN[0]);

    /* Don't call dnaupd if ido == 99 */
    if (pIDO[0] == 99)
    {
        Scierror(999, _("%s: the computation is already terminated\n"), fname);
        return 1;
    }

    /* Check some sizes */
    if (mIPARAM*nIPARAM != 11)
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPARAM", 11);
        return 1;
    }

    if (mIPNTR*nIPNTR != 14)
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPNTR", 14);
        return 1;
    }

    if (mRESID*nRESID != pN[0])
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "RESID", *(int*)(pN));
        return 1;
    }

    if ((mV != pN[0]) || (nV != pNCV[0]))
    {
        Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "V", *(int*)(pN), *(int*)(pNCV));
        return 1;
    }

    if (mWORKD * nWORKD < 3 * pN[0])
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKD", 3 * *(int*)(pN));
        return 1;
    }

    sizeWORKL = 3 * pNCV[0] * pNCV[0] + 6 * pNCV[0];

    if (mWORKL * nWORKL < sizeWORKL)
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKL", sizeWORKL);
        return 1;
    }

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

    // Retrieve a matrix of double at position 2.
    if (getAllocatedSingleString(pvApiCtx, piAddrpBMAT, &pBMAT))
    {
        Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
        return 1;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrpWHICH);
    if (sciErr.iErr)
    {
        freeAllocatedSingleString(pBMAT);
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 4.
    if (getAllocatedSingleString(pvApiCtx, piAddrpWHICH, &pWHICH))
    {
        freeAllocatedSingleString(pBMAT);
        Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 4);
        return 1;
    }

    C2F(dnaupd)(pIDO, pBMAT, pN,
                pWHICH, pNEV, pTOL,
                pRESID, pNCV, pV, &LDV,
                pIPARAM, pIPNTR, pWORKD,
                pWORKL, &LWORKL, pINFO, 1L, 2L);

    freeAllocatedSingleString(pBMAT);
    freeAllocatedSingleString(pWHICH);

    if (*pINFO < 0)
    {
        Scierror(998, _("%s: internal error, info=%d.\n"), fname, *pINFO);
        return 0;
    }

    AssignOutputVariable(pvApiCtx, 1) = IDO;
    AssignOutputVariable(pvApiCtx, 2) = RESID;
    AssignOutputVariable(pvApiCtx, 3) = V;
    AssignOutputVariable(pvApiCtx, 4) = IPARAM;
    AssignOutputVariable(pvApiCtx, 5) = IPNTR;
    AssignOutputVariable(pvApiCtx, 6) = WORKD;
    AssignOutputVariable(pvApiCtx, 7) = WORKL;
    AssignOutputVariable(pvApiCtx, 8) = INFO;

    ReturnArguments(pvApiCtx);

    return 0;
}
Example #11
0
/*------------------------------------------------------------------------*/
int sci_plot2d(char* fname, void *pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    double* lt = NULL;
    int iTypel1 = 0;
    int iTypel2 = 0;
    int lw = 0;

    int m1 = 0, n1 = 0, m2 = 0, n2 = 0;
    int test = 0, i = 0, j = 0, iskip = 0;
    int frame_def = 8;
    int *frame = &frame_def;
    int axes_def = 1;
    int *axes = &axes_def;

    /* F.Leray 18.05.04 : log. case test*/
    int size_x = 0, size_y = 0;
    char dataflag = 0;

    char* logFlags = NULL;
    int* style = NULL;
    double* rect = NULL;
    char* strf = NULL;
    char* legend = NULL;
    int* nax = NULL;
    BOOL flagNax = FALSE;
    char strfl[4];
    BOOL freeStrf = FALSE;

    rhs_opts opts[] =
    {
        { -1, "axesflag", -1, 0, 0, NULL},
        { -1, "frameflag", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "logflag", -1, 0, 0, NULL},
        { -1, "nax", -1, 0, 0, NULL},
        { -1, "rect", -1, 0, 0, NULL},
        { -1, "strf", -1, 0, 0, NULL},
        { -1, "style", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    if (nbInputArgument(pvApiCtx) == 0)
    {
        sci_demo(fname, pvApiCtx);
        return 0;
    }

    CheckInputArgument(pvApiCtx, 1, 9);

    iskip = 0;
    if (getOptionals(pvApiCtx, fname, opts) == 0)
    {
        ReturnArguments(pvApiCtx);
        return 0;
    }

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
    {
        /* logflags */
        GetLogflags(pvApiCtx, fname, 1, opts, &logFlags);
        iskip = 1;
    }

    if (FirstOpt(pvApiCtx) == 2 + iskip)                                /** plot2d([loglags,] y, <opt_args>); **/
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        sciErr = getVarType(pvApiCtx, piAddrl2, &iTypel2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // the argument can be a matrix of doubles or other
        // If it is not a matrix of doubles, call overload
        if (iTypel2 == sci_matrix)
        {

            // Retrieve a matrix of double at position 1 + iskip.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1 + iskip);
                return 1;
            }
        }
        else
        {
            OverLoad(1);
            return 0;
        }

        if (m2 == 1 && n2 > 1)
        {
            m2 = n2;
            n2 = 1;
        }

        m1 = m2;
        n1 = n2;

        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        for (i = 0; i < m2 ; ++i)
        {
            for (j = 0 ; j < n2 ;  ++j)
            {
                *(l1 + i + m2 * j) = (double) i + 1;
            }
        }
    }
    else if (FirstOpt(pvApiCtx) >= 3 + iskip)     /** plot2d([loglags,] x, y[, style [,...]]); **/
    {
        /* x */
        sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        sciErr = getVarType(pvApiCtx, piAddrl1, &iTypel1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // x can be a matrix of doubles or other
        // If x is not a matrix of doubles, call overload
        if (iTypel1 == sci_matrix)
        {

            // Retrieve a matrix of double at position 1 + iskip.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1 + iskip);
                return 1;
            }
        }
        else
        {
            OverLoad(1);
            return 0;
        }

        /* y */
        sciErr = getVarAddressFromPosition(pvApiCtx, 2 + iskip, &piAddrl2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        sciErr = getVarType(pvApiCtx, piAddrl2, &iTypel2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // y can be a matrix of doubles or other
        // If y is not a matrix of doubles, call overload
        if (iTypel2 == sci_matrix)
        {

            // Retrieve a matrix of double at position 1 + iskip.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2 + iskip);
                return 1;
            }
        }
        else
        {
            OverLoad(2);
            return 0;
        }

        test = (m1 * n1 == 0) ||
               ((m1 == 1 || n1 == 1) && (m2 == 1 || n2 == 1) && (m1 * n1 == m2 * n2))  ||
               ((m1 == m2) && (n1 == n2)) ||
               ((m1 == 1 && n1 == m2) || (n1 == 1 && m1 == m2));
        //CheckDimProp
        if (!test)
        {
            Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
            return 1;
        }

        if (m1 * n1 == 0)
        {
            /* default x=1:n */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, &lt);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            if (m2 == 1 && n2 > 1)
            {
                m2 = n2;
                n2 = 1;
            }
            for (i = 0; i < m2 ; ++i)
            {
                for (j = 0 ; j < n2 ;  ++j)
                {
                    *(lt + i + m2 * j) = (double) i + 1;
                }
            }
            m1 = m2;
            n1 = n2;
            l1 = lt;
        }
        else if ((m1 == 1 || n1 == 1) && (m2 != 1 && n2 != 1))
        {
            /* a single x vector for mutiple columns for y */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, &lt);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            for (i = 0; i < m2 ; ++i)
            {
                for (j = 0 ; j < n2 ;  ++j)
                {
                    *(lt + i + m2 * j) = *(l1 + i);
                }
            }
            m1 = m2;
            n1 = n2;
            l1 = lt;
        }
        else if ((m1 == 1 && n1 == 1) && (n2 != 1))
        {
            /* a single y row vector  for a single x */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n2, &lt);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            for (j = 0 ; j < n2 ;  ++j)
            {
                lt[j] = *l1;
            }
            n1 = n2;
            l1 = lt;
        }
        else
        {
            if (m2 == 1 && n2 > 1)
            {
                m2 = n2;
                n2 = 1;
            }
            if (m1 == 1 && n1 > 1)
            {
                m1 = n1;
                n1 = 1;
            }
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong number of mandatory input arguments. At least %d expected.\n"), fname, 1);
        return 0;
    }

    if (n1 == -1 || n2 == -1 || m1 == -1 || m2 == -1)
    {
        Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2); /* @TODO : detail error */
        return 0;
    }

    sciGetStyle(pvApiCtx, fname, 3 + iskip, n1, opts, &style);
    GetStrf(pvApiCtx, fname, 4 + iskip, opts, &strf);
    GetLegend(pvApiCtx, fname, 5 + iskip, opts, &legend);
    GetRect(pvApiCtx, fname, 6 + iskip, opts, &rect);
    GetNax(pvApiCtx, 7 + iskip, opts, &nax, &flagNax);

    if (iskip == 0)
    {
        GetLogflags(pvApiCtx, fname, 8, opts, &logFlags);
    }

    freeStrf = !isDefStrf(strf);

    // Check strf [0-1][0-8][0-5]
    if (!isDefStrf(strf) && (strlen(strf) != 3 || strf[0] < '0' || strf[0] > '1' || strf[1] < '0' || strf[1] > '8' || strf[2] < '0' || strf[2] > '5'))
    {
        Scierror(999, _("%s: Wrong value for strf option: %s.\n"), fname, strf);
        if (freeStrf)
        {
            freeAllocatedSingleString(strf);
        }
        return -1;
    }

    if (isDefStrf(strf))
    {
        strcpy(strfl, DEFSTRFN);

        strf = strfl;
        if (!isDefRect(rect))
        {
            strfl[1] = '7';
        }
        if (!isDefLegend(legend))
        {
            strfl[0] = '1';
        }

        GetOptionalIntArg(pvApiCtx, fname, 9, "frameflag", &frame, 1, opts);
        if (frame != &frame_def)
        {
            if (*frame >= 0 && *frame <= 8)
            {
                strfl[1] = (char)(*frame + 48);
            }
            else
            {
                Scierror(999, _("%s: Wrong value for frameflag option.\n"), fname);
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                return -1;
            }
        }

        GetOptionalIntArg(pvApiCtx, fname, 9, "axesflag", &axes, 1, opts);
        if (axes != &axes_def)
        {
            if ((*axes >= 0 && *axes <= 5) || *axes == 9)
            {
                strfl[2] = (char)(*axes + 48);
            }
            else
            {
                Scierror(999, _("%s: Wrong value for axesflag option.\n"), fname);
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                return -1;
            }
        }
    }

    /* Make a test on log. mode : available or not depending on the bounds set by Rect arg. or xmin/xmax :
       Rect case :
       - if the min bound is strictly posivite, we can use log. mode
       - if not, send error message
       x/y min/max case:
       - we find the first strictly positive min bound in Plo2dn.c ?? */

    switch (strf[1])
    {
        case '0':
            /* no computation, the plot use the previous (or default) scale */
            break;
        case '1' :
        case '3' :
        case '5' :
        case '7':
            /* based on Rect arg */
            if (rect[0] > rect[2] || rect[1] > rect[3])
            {
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                Scierror(999, _("%s: Impossible status min > max in x or y rect data.\n"), fname);
                return -1;
            }

            if (rect[0] <= 0. && logFlags[1] == 'l') /* xmin */
            {
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                Scierror(999, _("%s: Bounds on x axis must be strictly positive to use logarithmic mode.\n"), fname);
                return -1;
            }

            if (rect[1] <= 0. && logFlags[2] == 'l') /* ymin */
            {
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                Scierror(999, _("%s: Bounds on y axis must be strictly positive to use logarithmic mode.\n"), fname);
                return -1;
            }

            break;
        case '2' :
        case '4' :
        case '6' :
        case '8':
        case '9':
            /* computed from the x/y min/max */
            if ((int)strlen(logFlags) < 1)
            {
                dataflag = 'g';
            }
            else
            {
                dataflag = logFlags[0];
            }

            switch (dataflag)
            {
                case 'e' :
                    size_x = (m1 != 0) ? 2 : 0;
                    break;
                case 'o' :
                    size_x = m1;
                    break;
                case 'g' :
                default  :
                    size_x = (n1 * m1);
                    break;
            }

            if (size_x != 0)
            {
                if (logFlags[1] == 'l' && sciFindStPosMin((l1), size_x) <= 0.0)
                {
                    if (freeStrf)
                    {
                        freeAllocatedSingleString(strf);
                    }
                    Scierror(999, _("%s: At least one x data must be strictly positive to compute the bounds and use logarithmic mode.\n"), fname);
                    return -1;
                }
            }

            size_y = (n1 * m1);

            if (size_y != 0)
            {
                if (logFlags[2] == 'l' && sciFindStPosMin((l2), size_y) <= 0.0)
                {
                    if (freeStrf)
                    {
                        freeAllocatedSingleString(strf);
                    }
                    Scierror(999, _("%s: At least one y data must be strictly positive to compute the bounds and use logarithmic mode\n"), fname);
                    return -1;
                }
            }

            break;
    }

    // open a figure if none already exists
    getOrCreateDefaultSubwin();

    Objplot2d (1, logFlags, (l1), (l2), &n1, &m1, style, strf, legend, rect, nax, flagNax);

    // Allocated by sciGetStyle (get_style_arg function in GetCommandArg.c)
    FREE(style);

    if (freeStrf)
    {
        freeAllocatedSingleString(strf);
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
/*--------------------------------------------------------------------------*/
int sci_uigetfont(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrfontNameAdr  = NULL;
    int* piAddrfontSizeAdr  = NULL;
    int* piAddrboldAdr      = NULL;
    int* boldAdr            = NULL;
    int* piAddritalicAdr    = NULL;
    int* italicAdr          = NULL;
    double* fontSizeAdr     = NULL;

    int fontChooserID = 0;
    int nbRow = 0;
    int nbCol = 0;

    char **fontNameAdr = NULL;
    int fontNameSize   = 0;

    char *selectedFontName  = NULL;
    int selectedFontSize    = 0;
    BOOL selectedBold       = FALSE;
    BOOL selectedItalic     = FALSE;

    CheckInputArgument(pvApiCtx, 0, 4);
    CheckOutputArgument(pvApiCtx, 1, 4);

    /* Default font name */
    if (nbInputArgument(pvApiCtx) >= 1)
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfontNameAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 1.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrfontNameAdr, &nbRow, &nbCol, &fontNameAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
                return 1;
            }

            fontNameSize = nbRow * nbCol;
            if (fontNameSize != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
            return FALSE;
        }
    }

    /* Default font size */
    if (nbInputArgument(pvApiCtx) >= 2)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrfontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 2.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrfontSizeAdr, &nbRow, &nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 2);
            return FALSE;
        }
    }

    /* Is the default font bold ? */
    if (nbInputArgument(pvApiCtx) >= 3)
    {
        if ((checkInputArgumentType(pvApiCtx, 3, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrboldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 3.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddrboldAdr, &nbRow, &nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
                return FALSE;
            }

        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
            return FALSE;
        }
    }

    /* Is the default font italic ? */
    if (nbInputArgument(pvApiCtx) >= 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddritalicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 4.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddritalicAdr, &nbRow, &nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 4);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 4);
                return FALSE;
            }

        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 4);
            return FALSE;
        }
    }

    /* Create the Java Object */
    fontChooserID = createFontChooser();

    /* Default font */
    if (fontNameAdr != NULL)
    {
        setFontChooserFontName(fontChooserID, fontNameAdr[0]);
    }

    /* Default size */
    if (fontSizeAdr != 0)
    {
        setFontChooserFontSize(fontChooserID, (int)fontSizeAdr[0]);
    }

    /* Default bold */
    if (boldAdr != 0)
    {
        setFontChooserBold(fontChooserID, booltoBOOL(boldAdr[0]));
    }

    /* Default italic */
    if (italicAdr != 0)
    {
        setFontChooserItalic(fontChooserID, booltoBOOL(italicAdr[0]));
    }

    /* Display it and wait for a user input */
    fontChooserDisplayAndWait(fontChooserID);

    /* Return the selected font */

    /* Read the user answer */
    selectedFontName = getFontChooserFontName(fontChooserID);


    if (strcmp(selectedFontName, "")) /* The user selected a font */
    {
        selectedFontSize = getFontChooserFontSize(fontChooserID);
        selectedBold = getFontChooserBold(fontChooserID);
        selectedItalic = getFontChooserItalic(fontChooserID);

        nbRow = 1;
        nbCol = 1;
        if (nbOutputArgument(pvApiCtx) >= 1)
        {
            sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, (const char * const*) &selectedFontName);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (selectedFontName)
        {
            freeAllocatedSingleString(selectedFontName);
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *fontSizeAdr = selectedFontSize;
        }

        if (nbOutputArgument(pvApiCtx) >= 3)
        {
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *boldAdr = selectedBold;
        }

        if (nbOutputArgument(pvApiCtx) >= 4)
        {
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 4, nbRow, nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *italicAdr = selectedItalic;
        }
    }
    else /* The user canceled */
    {
        if (selectedFontName)
        {
            freeAllocatedSingleString(selectedFontName);
        }
        nbRow = 0;
        nbCol = 0;
        if (nbOutputArgument(pvApiCtx) >= 1)
        {
            /* Return "" as font name */
            char* fontNameEmpty = NULL;
            if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow * nbCol, (const char**) &fontNameEmpty))
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            /* Return [] as font size */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 3)
        {
            /* Return [] as bold value */
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 4)
        {
            /* Return [] as italic value */
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 4, nbRow, nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
    AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
    AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;

    if (fontNameSize)
    {
        freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
    }
    ReturnArguments(pvApiCtx);
    return TRUE;
}
Example #13
0
/*--------------------------------------------------------------------------*/
int sci_mgetl(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;
    int numberOfLinesToRead = -1;

    Rhs = Max(0, Rhs);

    CheckRhs(1, 2);
    CheckLhs(1, 1);

    if (Rhs == 2)
    {
        int *piAddressVarTwo = NULL;

        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
            return 0;
        }

        if ( isDoubleType(pvApiCtx, piAddressVarTwo) )
        {
            double dValue = 0.;
            if (!isScalar(pvApiCtx, piAddressVarTwo))
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: Integer expected.\n"), fname, 2);
                return 0;
            }

            if ( getScalarDouble(pvApiCtx, piAddressVarTwo, &dValue) == 0)
            {
                numberOfLinesToRead = (int)dValue;
            }
            else
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Integer expected.\n"), fname, 2);
            return 0;
        }
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 0;
    }

    if ( isStringType(pvApiCtx, piAddressVarOne) || isDoubleType(pvApiCtx, piAddressVarOne) )
    {
        char **wcReadedStrings = NULL;
        int numberOfLinesReaded = 0;
        int fileDescriptor = -1;
        int iErrorMgetl = 0;
        BOOL bCloseFile = FALSE;

        if (!isScalar(pvApiCtx, piAddressVarOne))
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: String or logical unit expected.\n"), fname, 1);
            return 0;
        }

        if (isStringType(pvApiCtx, piAddressVarOne))
        {
            char *fileName = NULL;
            if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &fileName) == 0)
            {
                char *expandedFileName = expandPathVariable(fileName);
                freeAllocatedSingleString(fileName);
                fileName = NULL;

                if (IsAlreadyOpenedInScilab(expandedFileName))
                {
                    int fd = GetIdFromFilename(expandedFileName);
                    fileDescriptor = fd;
                    if (expandedFileName)
                    {
                        FREE(expandedFileName);
                        expandedFileName = NULL;
                    }
                    bCloseFile = FALSE;
                }
                else
                {
#define READ_ONLY_TEXT_MODE "rt"
                    int fd = 0;
                    int f_swap = 0;
                    double res = 0.0;
                    int ierr = 0;

                    C2F(mopen)(&fd, expandedFileName, READ_ONLY_TEXT_MODE, &f_swap, &res, &ierr);
                    bCloseFile = TRUE;

                    switch (ierr)
                    {
                        case MOPEN_NO_ERROR:
                            fileDescriptor = fd;
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            break;
                        case MOPEN_NO_MORE_LOGICAL_UNIT:
                        {
                            Scierror(66, _("%s: Too many files opened!\n"), fname);
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            return 0;
                        }
                        break;
                        case MOPEN_CAN_NOT_OPEN_FILE:
                        {
                            Scierror(999, _("%s: Cannot open file %s.\n"), fname, expandedFileName);
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            return 0;
                        }
                        break;
                        case MOPEN_NO_MORE_MEMORY:
                        {
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            Scierror(999, _("%s: No more memory.\n"), fname);
                            return 0;
                        }
                        break;
                        case MOPEN_INVALID_FILENAME:
                        {
                            Scierror(999, _("%s: invalid filename %s.\n"), fname, expandedFileName);
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            return 0;
                        }
                        break;
                        case MOPEN_INVALID_STATUS:
                        default:
                        {
                            if (expandedFileName)
                            {
                                FREE(expandedFileName);
                                expandedFileName = NULL;
                            }
                            Scierror(999, _("%s: invalid status.\n"), fname);
                            return 0;
                        }
                        break;
                    }
                }
            }
            else
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
        }
        else /* double */
        {
            double dValue = 0.;

            if ( !getScalarDouble(pvApiCtx, piAddressVarOne, &dValue) )
            {
                FILE *fd = NULL;
                fileDescriptor = (int)dValue;
                if ((fileDescriptor == STDIN_ID) || (fileDescriptor == STDOUT_ID))
                {
                    SciError(244);
                    return 0;
                }

                fd = GetFileOpenedInScilab(fileDescriptor);
                if (fd == NULL)
                {
                    Scierror(245, _("%s: No input file associated to logical unit %d.\n"), fname, fileDescriptor);
                    return 0;
                }
            }
            else
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
        }

        wcReadedStrings = mgetl(fileDescriptor, numberOfLinesToRead, &numberOfLinesReaded, &iErrorMgetl);

        if (bCloseFile)
        {
            double dErrClose = 0.;
            C2F(mclose)(&fileDescriptor, &dErrClose);
        }

        switch (iErrorMgetl)
        {
            case MGETL_NO_ERROR:
            {
                if (numberOfLinesReaded == 0)
                {
                    if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0)
                    {
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }
                else
                {
                    int m = numberOfLinesReaded;
                    int n = 1;

                    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, wcReadedStrings);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(17, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }

                freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                wcReadedStrings = NULL;
            }
            break;

            case MGETL_EOF:
            {
                if (numberOfLinesReaded == 0)
                {
                    if (createEmptyMatrix(pvApiCtx, Rhs + 1) != 0)
                    {
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                }
                else
                {
                    int m = numberOfLinesReaded;
                    int n = 1;

                    sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, wcReadedStrings);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(17, _("%s: Memory allocation error.\n"), fname);
                        return 0;
                    }
                    freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                    wcReadedStrings = NULL;
                }
            }
            break;

            case MGETL_MEMORY_ALLOCATION_ERROR:
            {
                if (wcReadedStrings)
                {
                    freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                    wcReadedStrings = NULL;
                }
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 0;
            }
            break;

            case MGETL_ERROR:
            {
                if (wcReadedStrings)
                {
                    freeArrayOfString(wcReadedStrings, numberOfLinesReaded);
                    wcReadedStrings = NULL;
                }
                Scierror(999, _("%s: error.\n"), fname);
                return 0;
            }
            break;
        }

        LhsVar(1) = Rhs + 1;
        PutLhsVar();
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: String or logical unit expected.\n"), fname, 1);
    }

    return 0;
}
Example #14
0
/*--------------------------------------------------------------------------*/
int sci_save(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int iOldSave    = FALSE;

    int* piAddr1    = NULL;
    int iType1      = 0;

    CheckRhs(1, 100000);
    CheckLhs(0, 1);

    //filename or file descriptor
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    if (iType1 == sci_strings)
    {
        int* piAddrI    = NULL;
        int* piAddrI2   = NULL;
        int iTypeI      = 0;
        int iRowsI      = 0;
        int iColsI      = 0;
        char* pstVarI   = NULL;

        if (Rhs > 1)
        {
            int i = 0;
            for (i = 2 ; i <= Rhs ; i++)
            {
                sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrI);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                sciErr = getVarType(pvApiCtx, piAddrI, &iTypeI);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (iTypeI != sci_strings)
                {
                    iOldSave = TRUE;
                    break;
                }

                sciErr = getVarDimension(pvApiCtx, piAddrI, &iRowsI, &iColsI);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (iRowsI != 1 || iColsI != 1)
                {
                    iOldSave = TRUE;
                    break;
                }

                if (getAllocatedSingleString(pvApiCtx, piAddrI, &pstVarI))
                {
                    return 1;
                }

                if (strcmp(pstVarI, "-append") != 0)
                {
                    //try to get variable by name
                    sciErr = getVarAddressFromName(pvApiCtx, pstVarI, &piAddrI2);
                    if (sciErr.iErr)
                    {
                        // Try old save because here the input variable can be of type "string" but not a variable name
                        // Ex: a=""; save(filename, a);
                        iOldSave = TRUE;
                        break;
                    }

                    if (piAddrI2 == 0)
                    {
                        iOldSave = TRUE;
                        break;
                    }
                }

                freeAllocatedSingleString(pstVarI);
            }
        }
        else
        {
            iOldSave = FALSE;
        }
    }
    else
    {
        iOldSave = TRUE;
    }

    //new save to sod format
    if (iOldSave == FALSE)
    {
        int lw = 0;
        //call "overload" to prepare data to export_to_hdf5 function.
        C2F(overload) (&lw, "save", (unsigned long)strlen("save"));
    }

    //old save

    if (iOldSave)
    {
        //show warning only for variable save, not for environment.
        if (getWarningMode() && Rhs > 1)
        {
            sciprint(_("%s: Scilab 6 will not support the file format used.\n"), _("Warning"));
            sciprint(_("%s: Please quote the variable declaration. Example, save('myData.sod',a) becomes save('myData.sod','a').\n"), _("Warning"));
            sciprint(_("%s: See help('save') for the rational.\n"), _("Warning"));
        }
        C2F(intsave)();
    }

    return 0;
}
Example #15
0
/*--------------------------------------------------------------------------*/
int sci_helpbrowser(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrhelpAdr      = NULL;
    int* piAddrkeywordAdr   = NULL;
    int* piAddrfullTextAdr  = NULL;
    int* fullTextAdr        = NULL;

    int nbRow = 0;
    int nbCol = 0;
    char** keywordAdr = NULL;

    int nbRowHelp       = 0;
    int nbColHelp       = 0;
    char** helpAdr      = NULL;
    char** languageAdr  = NULL;
    int ret = 1;

    CheckInputArgument(pvApiCtx, 2, 4);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* We load SciNotes when calling javahelp because we have no way to know
     * to load it when using Javahelp because it can call SciNotes directly */
    if (!loadedDep)
    {
        loadOnUseClassPath("SciNotes");
        loadedDep = TRUE;
    }

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrhelpAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrhelpAdr, &nbRowHelp, &nbColHelp, &helpAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 1;
        }
    }
    else if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
    {
        helpAdr = NULL; /* No toolboxes installed */
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 1);
        return FALSE;
    }

    if (nbInputArgument(pvApiCtx) == 2)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            int* piAddrlanguageAdr = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrlanguageAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrlanguageAdr, &nbRow, &nbCol, &languageAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }

        ret = launchHelpBrowser(helpAdr, nbRowHelp * nbColHelp, languageAdr[0]);

        if (helpAdr)
        {
            freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
        }
        freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
    }
    else if (nbInputArgument(pvApiCtx) == 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrkeywordAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }

                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrkeywordAdr, &nbRow, &nbCol, &keywordAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }

                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, keywordAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 3, sci_strings)))
        {
            int* piAddrlanguageAdr = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrlanguageAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrlanguageAdr, &nbRow, &nbCol, &languageAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 3);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            freeAllocatedSingleString(*keywordAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrfullTextAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 4.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddrfullTextAdr, &nbRow, &nbCol, &fullTextAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 4);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 4);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            freeAllocatedSingleString(*keywordAdr);
            freeAllocatedSingleString(*languageAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 4);
            return FALSE;
        }

        ret = searchKeyword(helpAdr, nbRowHelp * nbColHelp, keywordAdr[0], languageAdr[0], *fullTextAdr == 1);

        if (helpAdr)
        {
            freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
        }

        freeAllocatedSingleString(*keywordAdr);
        freeAllocatedSingleString(*languageAdr);
    }
    else
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 2, 4);
        return FALSE;
    }

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

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
Example #16
0
/*--------------------------------------------------------------------------*/
int sci_xstringb(char *fname, void *pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    int* piAddrStr = NULL;
    int* piAddrl4 = NULL;
    double* l4 = NULL;
    int* piAddrl5 = NULL;
    double* l5 = NULL;
    int* piAddrl6 = NULL;
    char* l6 = NULL;

    int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0, m5 = 0, n5 = 0, m6 = 0, n6 = 0;
    BOOL autoSize = TRUE ;
    double x = 0., y = 0., w = 0., hx = 0.;
    char **Str = NULL;
    double rect[4], angle = 0.;
    long hdlstr = 0;
    double userSize[2] ;
    int textBoxMode = 1; // 0 : off | 1 : centered | 2 : filled

    if ( nbInputArgument(pvApiCtx) <= 0 )
    {
        /* demo */
        sci_demo(fname, pvApiCtx);
        return 0 ;
    }

    CheckInputArgument(pvApiCtx, 5, 6);

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

    // Retrieve a matrix of double at position 1.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
        return 1;
    }

    //CheckScalar
    if (m1 != 1 || n1 != 1)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, 1);
        return 1;
    }

    x = *l1;
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 2.
    // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int l2".
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
        return 1;
    }

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

    y = *l2;
    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrStr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of string at position 3.
    if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m3, &n3, &Str))
    {
        Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
        return 1;
    }

    if ( m3*n3 == 0 )
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

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

    // Retrieve a matrix of double at position 4.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrl4, &m4, &n4, &l4);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 4);
        return 1;
    }

    //CheckScalar
    if (m4 != 1 || n4 != 1)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, 4);
        return 1;
    }

    w = *l4;
    sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrl5);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 5.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrl5, &m5, &n5, &l5);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 5);
        return 1;
    }

    //CheckScalar
    if (m5 != 1 || n5 != 1)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, 5);
        return 1;
    }

    hx = *l5;

    if (nbInputArgument(pvApiCtx) == 6)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddrl6);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a string at position 6.
        if (isScalar(pvApiCtx, piAddrl6) == 0)
        {
            Scierror(999, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 6);
            return 1;
        }

        if (getAllocatedSingleString(pvApiCtx, piAddrl6, &l6))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 6);
            return 1;
        }

        if (strcmp(l6, "fill") == 0 )
        {
            autoSize = FALSE ;
            textBoxMode = 2;
        }
        else
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 6, "fill");
            return 0;
        }

        freeAllocatedSingleString(l6);
    }

    userSize[0] = w ;
    userSize[1] = hx ;
    Objstring (Str, m3, n3, x, y, &angle, rect, autoSize, userSize, &hdlstr, textBoxMode, NULL, NULL, FALSE, TRUE, FALSE, ALIGN_CENTER);

    freeArrayOfString(Str, m3 * n3);

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    return 0;

}
Example #17
0
/* fftw function.
*
* Scilab Calling sequence :
*   fftw(A [,option])
*   fftw(A,sign [,option])
*   fftw(A,sel,sign [,option])
*   fftw(A,sign,dim,incr [,option])
*
* Input : A : a scilab double complex or real vector, matrix or hypermatrix
*
*         sign : a scilab double or integer scalar (-1 or 1): the sign
*                  in the exponential component
*
*         sel : a scilab double or integer vector, the selection of dimensions

*         dim : a scilab double or integer vector: the dimensions
*                  of the Fast Fourier Transform to perform
*
*         incr : a scilab double or integer vector: the increments
*                  of the Fast Fourier Transform to perform
*
* Output : a scilab double complex or real array with same shape as A that
*          gives the result of the transform.
*
*/
int sci_fftw(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddr = NULL;
    char *option = NULL;
    int iopt = 0; /* automatic r2c or c2r transform use decision */
    int rhs = Rhs;
    int iTypeOne = 0;

    int ndimsA = 0;
    int *dimsA = NULL;
    double *Ar = NULL, *Ai = NULL;

    int isn = FFTW_FORWARD;
    WITHMKL = withMKL();
    /****************************************
    * Basic constraints on rhs arguments  *
    ****************************************/

    /* check min/max lhs/rhs arguments of scilab function */
    CheckInputArgument(pvApiCtx, 1, 5);
    CheckOutputArgument(pvApiCtx, 1, 1);

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddr, &iTypeOne);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 1;
    }

    if ((iTypeOne == sci_list) || (iTypeOne == sci_tlist))
    {
        OverLoad(1);
        return 1;
    }

    if (iTypeOne == sci_mlist)
    {
        /* We allow overload for not hypermatrix type */
        if (!isHyperMatrixMlist(pvApiCtx, piAddr))
        {
            OverLoad(1);
            return 1;
        }
    }

    /* checking if last argument is a potential option argument (character string) */
    sciErr = getVarAddressFromPosition(pvApiCtx, Rhs, &piAddr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, Rhs);
        return 1;
    }

    if (isStringType(pvApiCtx, piAddr))   /*  fftw(...,option); */
    {
        if (isScalar(pvApiCtx, piAddr))
        {
            if (getAllocatedSingleString(pvApiCtx, piAddr, &option) == 0)
            {
                if (strcmp("symmetric", option) == 0)  iopt = 1; /*user assumes symmetry */
                else if (strcmp("nonsymmetric", option) == 0) iopt = 2; /*user claims full transform */
                else
                {
                    Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, Rhs, "\"symmetric\"", "\"nonsymmetric\"");
                    freeAllocatedSingleString(option);
                    option = NULL;
                    return 1;
                }
                freeAllocatedSingleString(option);
                option = NULL;
                rhs = Rhs - 1;
            }
            else
            {
                 Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, Rhs, "\"symmetric\"", "\"nonsymmetric\"");
                return 1;
            }
        }
    }


    /********************  Checking if isn is given  ************************************************/
    if (rhs == 1)  /*only one rhs argument: forward fft*/
    {
        isn = FFTW_FORWARD; /* default value */
    }
    else   /*get isn out of second argument*/
    {
        sciErr = getScalarIntArg(pvApiCtx, 2, fname, &isn);
        if (sciErr.iErr)
        {
            Scierror(sciErr.iErr, getErrorMessage(sciErr));
            return 1;
        }
        /* check value of second rhs argument */
        if ((isn !=  FFTW_FORWARD) && (isn !=  FFTW_BACKWARD))
        {
            Scierror(53, _("%s: Wrong value for input argument #%d: %d or %d expected.\n"), fname, 2, FFTW_FORWARD, FFTW_BACKWARD);
            return 1;
        }
    }

    /********************  getting the array A      ************************************************/
    getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
    if (!getArrayOfDouble(pvApiCtx, piAddr, &ndimsA, &dimsA, &Ar, &Ai))
    {
        Scierror(999, _("%s: Wrong type for argument #%d: Array of floating point numbers expected.\n"), fname, 1);
        return 1;
    }


    /********************  Select proper method     ************************************************/
    if (rhs < 3)
    {
        /* fftw(A ,sign [,option])*/
        sci_fft_2args(pvApiCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
    }
    else if (rhs == 3)
    {
        /* fftw(A ,sign ,sel [,option])*/
        sci_fft_3args(pvApiCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
    }
    else if (rhs == 4)
    {
        /* fftw(A ,sign ,dim,incr [option])*/
        sci_fft_4args(pvApiCtx, fname, ndimsA, dimsA, Ar, Ai, isn, iopt);
    }

    return 0;
}
Example #18
0
int sci_eigs(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int *piAddressVarOne	= NULL;
    int iRowsOne			= 0;
    int iColsOne			= 0;
    double elemt1			= 0;
    double elemt2			= 0;
    double* Areal			= NULL;
    doublecomplex* Acplx	= NULL;
    int Asym				= 1;
    int Acomplex			= 0;
    int N					= 0;

    int *piAddressVarTwo	= NULL;
    int iTypeVarTwo			= 0;
    int iRowsTwo			= 0;
    int iColsTwo			= 0;
    double* Breal			= NULL;
    doublecomplex* Bcplx	= NULL;
    int Bcomplex			= 0;
    int matB				= 0;

    int *piAddressVarThree	= NULL;
    double dblNEV			= 0;
    int iNEV				= 0;

    int *piAddressVarFour	= NULL;
    int iTypeVarFour		= 0;
    int iRowsFour			= 0;
    int iColsFour			= 0;
    char* pstData			= NULL;
    doublecomplex SIGMA;

    int *piAddressVarFive	= NULL;
    double dblMAXITER		= 0;

    int *piAddressVarSix	= NULL;
    double dblTOL			= 0;

    int *piAddressVarSeven	= NULL;
    int TypeVarSeven		= 0;
    int RowsSeven			= 0;
    int ColsSeven			= 0;
    double* dblNCV			= NULL;

    int *piAddressVarEight	= NULL;
    int iTypeVarEight       = 0;
    double dblCHOLB			= 0;
    int iCHOLB              = 0;

    int *piAddressVarNine	= NULL;
    int iTypeVarNine		= 0;
    int iRowsNine			= 0;
    int iColsNine			= 0;
    double* RESID			= NULL;
    doublecomplex* RESIDC	= NULL;

    int *piAddressVarTen	= NULL;
    int iINFO				= 0;
    int RVEC                = 0;
    // Output arguments
    double* eigenvalue      = NULL;
    double* eigenvector     = NULL;
    doublecomplex* eigenvalueC  = NULL;
    doublecomplex* eigenvectorC	= NULL;

    double* mat_eigenvalue	= NULL;
    doublecomplex* mat_eigenvalueC  = NULL;
    int INFO_EUPD					= 0;
    int error						= 0;

    int iErr				= 0;
    int i					= 0;
    int j					= 0;

    CheckInputArgument(pvApiCtx, 1, 10);
    CheckOutputArgument(pvApiCtx, 0, 2);

    /****************************************
    *    	First variable : A    		*
    *****************************************/

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 1;
    }

    sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &iRowsOne, &iColsOne);
    //check if A is a square matrix
    if (iRowsOne * iColsOne == 1 || iRowsOne != iColsOne)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A square matrix expected.\n"), "eigs", 1);
        return 1;
    }

    N = iRowsOne;

    //check if A is complex
    if (isVarComplex(pvApiCtx, piAddressVarOne))
    {
        sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddressVarOne, &iRowsOne, &iColsOne, &Acplx);
        Acomplex = 1;
    }
    else
    {
        sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &iRowsOne, &iColsOne, &Areal);

        for (i = 0; i < iColsOne; i++)
        {
            for (j = 0; j < i; j++)
            {
                elemt1 = Areal[j + i * iColsOne];
                elemt2 = Areal[j * iColsOne + i];
                if (fabs(elemt1 - elemt2) > 0)
                {
                    Asym = 0;
                    break;
                }
            }
            if (Asym == 0)
            {
                break;
            }
        }
    }

    /****************************************
    *    	Second variable : B    		*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iTypeVarTwo);
    if (sciErr.iErr || iTypeVarTwo != sci_matrix)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Wrong type for input argument #%d: An empty matrix or full or sparse square matrix expected.\n"), "eigs", 2);
        return 1;
    }

    sciErr = getVarDimension(pvApiCtx, piAddressVarTwo, &iRowsTwo, &iColsTwo);
    matB = iRowsTwo * iColsTwo;
    if (matB && (iRowsTwo != iRowsOne || iColsTwo != iColsOne))
    {
        Scierror(999, _("%s: Wrong dimension for input argument #%d: B must have the same size as A.\n"), "eigs", 2);
        return 1;
    }

    if (isVarComplex(pvApiCtx, piAddressVarTwo))
    {
        sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddressVarTwo, &iRowsTwo, &iColsTwo, &Bcplx);
        Bcomplex = 1;
    }
    else
    {
        sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &iRowsTwo, &iColsTwo, &Breal);
    }

    if (matB != 0)
    {
        if (Acomplex && !Bcomplex)
        {
            Bcplx = (doublecomplex*)MALLOC(N * N * sizeof(doublecomplex));
            memset(Bcplx, 0, N * N * sizeof(doublecomplex));
            Bcomplex = 1;
            for (i = 0 ; i < N * N ;  i++)
            {
                Bcplx[i].r = Breal[i];
            }
        }
        if (!Acomplex && Bcomplex)
        {
            Acplx = (doublecomplex*)MALLOC(N * N * sizeof(doublecomplex));
            memset(Acplx, 0, N * N * sizeof(doublecomplex));
            Acomplex = 1;
            for (i = 0 ; i < N * N ;  i++)
            {
                Acplx[i].r = Areal[i];
            }
        }
    }


    /****************************************
    *    			NEV   					*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
        FREE_AB;
        return 1;
    }

    iErr = getScalarDouble(pvApiCtx, piAddressVarThree, &dblNEV);
    if (iErr)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "eigs", 3);
        FREE_AB;
        return 1;
    }

    if (isVarComplex(pvApiCtx, piAddressVarThree))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "eigs", 3);
        FREE_AB;
        return 1;
    }

    if (dblNEV != floor(dblNEV) || (dblNEV <= 0))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: k must be a positive integer.\n"), "eigs", 3);
        FREE_AB;
        return 1;
    }

    if (!finite(dblNEV))
    {
        Scierror(999, _("%s: Wrong value for input argument #%d: k must be in the range 1 to N.\n"), "eigs", 3);
        FREE_AB;
        return 1;
    }


    iNEV = (int)dblNEV;

    /****************************************
    *    		SIGMA AND WHICH    			*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddressVarFour);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
        FREE_AB;
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddressVarFour, &iTypeVarFour);
    if (sciErr.iErr || (iTypeVarFour != sci_matrix && iTypeVarFour != sci_strings))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "eigs", 4);
        FREE_AB;
        return 1;
    }

    if (iTypeVarFour == sci_strings)
    {
        int iErr = getAllocatedSingleString(pvApiCtx, piAddressVarFour, &pstData);
        if (iErr)
        {
            FREE_AB;
            return 1;
        }

        if (strcmp(pstData, "LM") != 0 && strcmp(pstData, "SM") != 0  && strcmp(pstData, "LR") != 0 && strcmp(pstData, "SR") != 0 && strcmp(pstData, "LI") != 0
                && strcmp(pstData, "SI") != 0 && strcmp(pstData, "LA") != 0 && strcmp(pstData, "SA") != 0 && strcmp(pstData, "BE") != 0)
        {
            if (!Acomplex && Asym)
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: Unrecognized sigma value.\n Sigma must be one of '%s', '%s', '%s', '%s' or '%s'.\n" ),
                         "eigs", 4, "LM", "SM", "LA", "SA", "BE");
                freeAllocatedSingleString(pstData);
                return 1;
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: Unrecognized sigma value.\n Sigma must be one of '%s', '%s', '%s', '%s', '%s' or '%s'.\n " ),
                         "eigs", 4, "LM", "SM", "LR", "SR", "LI", "SI");
                FREE_AB;
                freeAllocatedSingleString(pstData);
                return 1;
            }
        }

        if ((Acomplex || !Asym) && (strcmp(pstData, "LA") == 0 || strcmp(pstData, "SA") == 0 || strcmp(pstData, "BE") == 0))
        {
            Scierror(999, _("%s: Invalid sigma value for complex or non symmetric problem.\n"), "eigs", 4);
            FREE_AB;
            freeAllocatedSingleString(pstData);
            return 1;
        }

        if (!Acomplex && Asym && (strcmp(pstData, "LR") == 0 || strcmp(pstData, "SR") == 0 || strcmp(pstData, "LI") == 0 || strcmp(pstData, "SI") == 0))
        {
            Scierror(999, _("%s: Invalid sigma value for real symmetric problem.\n"), "eigs", 4);
            freeAllocatedSingleString(pstData);
            return 1;
        }

        SIGMA.r = 0;
        SIGMA.i = 0;
    }

    if (iTypeVarFour == sci_matrix)
    {
        sciErr = getVarDimension(pvApiCtx, piAddressVarFour, &iRowsFour, &iColsFour);
        if (iRowsFour * iColsFour != 1)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), "eigs", 4);
            FREE_AB;
            return 1;
        }

        if (getScalarComplexDouble(pvApiCtx, piAddressVarFour, &SIGMA.r, &SIGMA.i))
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 4);
            FREE_AB;
            return 1;
        }

        if (C2F(isanan)(&SIGMA.r) || C2F(isanan)(&SIGMA.i))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: sigma must be a real.\n"), "eigs", 4);
            FREE_AB;
            return 1;
        }

        pstData = "LM";
    }

    /****************************************
    *    			MAXITER    				*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddressVarFive);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 5);
        FREE_AB;
        FREE_PSTDATA;
        return 0;
    }

    iErr = getScalarDouble(pvApiCtx, piAddressVarFive, &dblMAXITER);
    if (iErr)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: %s must be a scalar.\n"), "eigs", 5, "opts.maxiter");
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    if ((dblMAXITER != floor(dblMAXITER)) || (dblMAXITER <= 0))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer positive value.\n"), "eigs", 5, "opts.maxiter");
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    /****************************************
    *    				TOL	    			*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddressVarSix);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 6);
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    iErr = getScalarDouble(pvApiCtx, piAddressVarSix, &dblTOL);
    if (iErr)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: %s must be a real scalar.\n"), "eigs", 6, "opts.tol");
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    if (C2F(isanan)(&dblTOL))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: %s must be a real scalar.\n"), "eigs", 6, "opts.tol");
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    /****************************************
    *    				NCV	    			*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddressVarSeven);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 7);
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddressVarSeven, &TypeVarSeven);
    if (sciErr.iErr || TypeVarSeven != sci_matrix)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer scalar.\n"), "eigs", 7, "opts.ncv");
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }
    else
    {
        if (isVarComplex(pvApiCtx, piAddressVarSeven))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer scalar.\n"), "eigs", 7, "opts.ncv");
        }
        else
        {
            sciErr = getVarDimension(pvApiCtx, piAddressVarSeven, &RowsSeven, &ColsSeven);
            if (RowsSeven * ColsSeven > 1)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer scalar.\n"), "eigs", 7, "opts.ncv");
                FREE_AB;
                FREE_PSTDATA;
                return 1;
            }

            if (RowsSeven * ColsSeven == 1)
            {
                sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarSeven, &RowsSeven, &ColsSeven, &dblNCV);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 7);
                    FREE_AB;
                    FREE_PSTDATA;
                    return 1;
                }

                if (dblNCV[0] != floor(dblNCV[0]))
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer scalar.\n"), "eigs", 7, "opts.ncv");
                    FREE_AB;
                    FREE_PSTDATA;
                    return 1;
                }
            }
        }
    }

    /****************************************
    *    			CHOLB    			*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddressVarEight);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 8);
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddressVarEight, &iTypeVarEight);
    if (sciErr.iErr || (iTypeVarEight != sci_matrix && iTypeVarEight != sci_boolean))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer scalar or a boolean.\n"), "eigs", 8, "opts.cholB");
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    if (iTypeVarEight == sci_boolean)
    {
        iErr = getScalarBoolean(pvApiCtx, piAddressVarEight, &iCHOLB);
        if (iErr)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer scalar or a boolean.\n"), "eigs", 8, "opts.cholB");
            FREE_AB;
            FREE_PSTDATA;
            return 1;
        }

        if (iCHOLB != 1 && iCHOLB != 0)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: %s must be %s or %s.\n"), "eigs", 8, "opts.cholB", "%f", "%t");
            FREE_AB;
            FREE_PSTDATA;
            return 1;
        }
        dblCHOLB = (double) iCHOLB;
    }

    if (iTypeVarEight == sci_matrix)
    {
        iErr = getScalarDouble(pvApiCtx, piAddressVarEight, &dblCHOLB);
        if (iErr)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: %s must be an integer scalar or a boolean.\n"), "eigs", 8, "opts.cholB");
            FREE_AB;
            FREE_PSTDATA;
            return 1;
        }

        if (dblCHOLB != 1 && dblCHOLB != 0)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: %s must be %s or %s.\n"), "eigs", 8, "opts.cholB", "%f", "%t");
            FREE_AB;
            FREE_PSTDATA;
            return 1;
        }
    }

    if ( dblCHOLB ) // check that B is upper triangular with non zero element on the diagonal
    {
        if (!Bcomplex)
        {
            for (i = 0; i < N; i++)
            {
                for (j = 0; j <= i; j++)
                {
                    if (i == j && Breal[i + j * N] == 0)
                    {
                        Scierror(999, _("%s: B is not positive definite. Try with sigma='SM' or sigma=scalar.\n"), "eigs");
                        FREE_PSTDATA;
                        return 0;
                    }
                    else
                    {
                        if ( j < i && Breal[i + j * N] != 0 )
                        {
                            Scierror(999, _("%s: If opts.cholB is true, B should be upper triangular.\n"), "eigs");
                            FREE_PSTDATA;
                            return 0;
                        }
                    }
                }
            }
        }
        else
        {
            for (i = 0; i < N; i++)
            {
                for (j = 0; j <= i; j++)
                {
                    if (i == j && Bcplx[i + i * N].r == 0 && Bcplx[i + i * N].i == 0)
                    {
                        Scierror(999, _("%s: B is not positive definite. Try with sigma='SM' or sigma=scalar.\n"), "eigs");
                        FREE_AB;
                        FREE_PSTDATA;
                        return 0;
                    }
                    else
                    {
                        if ( j < i && (Bcplx[i + j * N].r != 0 || Bcplx[i + j * N].i != 0) )
                        {
                            Scierror(999, _("%s: If opts.cholB is true, B should be upper triangular.\n"), "eigs");
                            FREE_AB;
                            FREE_PSTDATA;
                            return 0;
                        }
                    }
                }
            }
        }
    }

    /****************************************
    *    			RESID    			*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 9, &piAddressVarNine);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 9);
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddressVarNine, &iTypeVarNine);
    if (sciErr.iErr || iTypeVarNine != sci_matrix)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Wrong type for input argument #%d: A real or complex matrix expected.\n"), "eigs", 9);
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }
    else
    {
        sciErr = getVarDimension(pvApiCtx, piAddressVarNine, &iRowsNine, &iColsNine);
        if (iRowsNine * iColsNine == 1 || iRowsNine * iColsNine != N)
        {
            Scierror(999, _("%s: Wrong dimension for input argument #%d: Start vector %s must be N by 1.\n"), "eigs", 9, "opts.resid");
            FREE_AB;
            FREE_PSTDATA;
            return 1;
        }
    }

    if (!Acomplex && !Bcomplex)
    {
        if (isVarComplex(pvApiCtx, piAddressVarNine))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Start vector %s must be real for real problems.\n"), "eigs", 9, "opts.resid");
            FREE_PSTDATA;
            return 1;
        }
        else
        {
            sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarNine, &iRowsNine, &iColsNine, &RESID);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Can not read input argument #%d.\n"), "eigs", 9);
                FREE_PSTDATA;
                return 1;
            }
        }
    }
    else
    {
        sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddressVarNine, &iRowsNine, &iColsNine, &RESIDC);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Can not read input argument #%d.\n"), "eigs", 9);
            FREE_AB;
            FREE_PSTDATA;
            return 1;
        }
    }

    /****************************************
    *    			INFO    			*
    *****************************************/
    sciErr = getVarAddressFromPosition(pvApiCtx, 10, &piAddressVarTen);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), "eigs", 9);
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    iErr = getScalarInteger32(pvApiCtx, piAddressVarTen, &iINFO);
    if (iErr)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: An integer expected.\n"), "eigs", 1);
        FREE_AB;
        FREE_PSTDATA;
        return 1;
    }

    // Initialization output arguments
    if (nbOutputArgument(pvApiCtx) > 1)
    {
        RVEC = 1;
    }

    if (Acomplex || Bcomplex || !Asym)
    {
        eigenvalueC = (doublecomplex*)CALLOC((iNEV + 1), sizeof(doublecomplex));
        if (RVEC)
        {
            eigenvectorC = (doublecomplex*)CALLOC(N * (iNEV + 1), sizeof(doublecomplex));
        }
    }
    else
    {
        eigenvalue = (double*)CALLOC(iNEV, sizeof(double));
        /* we should allocate eigenvector only if RVEC is true, but dseupd segfaults
         if Z is not allocated even when RVEC is false, contrary to the docs.*/
        eigenvector = (double*)CALLOC(iNEV * N, sizeof(double));
    }

    error = eigs(Areal, Acplx, N, Acomplex, Asym, Breal, Bcplx, Bcomplex, matB, iNEV, SIGMA, pstData, &dblMAXITER,
                 &dblTOL, dblNCV, RESID, RESIDC, &iINFO, &dblCHOLB, INFO_EUPD, eigenvalue, eigenvector, eigenvalueC, eigenvectorC, RVEC);

    FREE_AB;
    FREE_PSTDATA;

    switch (error)
    {
    case -1 :
        if (Asym && !Acomplex && !Bcomplex)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: For real symmetric problems, NCV must be k < NCV <= N.\n"), "eigs", 7);
        }
        else
        {
            if (!Asym && !Acomplex && !Bcomplex)
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: For real non symmetric problems, NCV must be k + 2 < NCV <= N.\n"), "eigs", 7);
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: For complex problems, NCV must be k + 1 < NCV <= N.\n"), "eigs", 7);
            }
        }
        ReturnArguments(pvApiCtx);
        return 1;

    case -2 :
        if (Asym && !Acomplex && !Bcomplex)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: For real symmetric problems, k must be an integer in the range 1 to N - 1.\n"), "eigs", 3);
        }
        else
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: For real non symmetric or complex problems, k must be an integer in the range 1 to N - 2.\n"), "eigs", 3);
        }
        ReturnArguments(pvApiCtx);
        return 1;

    case -3 :
        Scierror(999, _("%s: Error with input argument #%d: B is not positive definite. Try with sigma='SM' or sigma=scalar.\n"), "eigs", 2);
        ReturnArguments(pvApiCtx);
        return 0;

    case -4 :
        if (!Acomplex && !Bcomplex)
        {
            if (Asym)
            {
                Scierror(999, _("%s: Error with %s: info = %d \n"), "eigs", "DSAUPD", iINFO);
            }
            else
            {
                Scierror(999, _("%s: Error with %s: info = %d \n"), "eigs", "DNAUPD", iINFO);
            }
        }
        else
        {
            Scierror(999, _("%s: Error with %s: info = %d \n"), "eigs", "ZNAUPD", iINFO);
        }
        ReturnArguments(pvApiCtx);
        return 1;

    case -5 :
        if (!Acomplex && !Bcomplex)
        {
            if (Asym)
            {
                Scierror(999, _("%s: Error with %s: unknown mode returned.\n"), "eigs", "DSAUPD");
            }
            else
            {
                Scierror(999, _("%s: Error with %s: unknown mode returned.\n"), "eigs", "DNAUPD");
            }
        }
        else
        {
            Scierror(999, _("%s: Error with %s: unknown mode returned.\n"), "eigs", "ZNAUPD");
        }
        ReturnArguments(pvApiCtx);
        return 1;

    case -6 :
        if (!Acomplex && !Bcomplex)
        {
            if (Asym)
            {
                Scierror(999, _("%s: Error with %s: info = %d \n"), "eigs", "DSEUPD", INFO_EUPD);
            }
            else
            {
                Scierror(999, _("%s: Error with %s: info = %d \n"), "eigs", "DNEUPD", INFO_EUPD);
            }
        }
        else
        {
            Scierror(999,  _("%s: Error with %s: info = %d \n"), "eigs", "ZNEUPD", INFO_EUPD);
        }
        ReturnArguments(pvApiCtx);
        FREE(mat_eigenvalue);
        return 1;
    }

    if (nbOutputArgument(pvApiCtx) <= 1)
    {
        if (eigenvalue)
        {
            sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNEV, 1, eigenvalue);
            FREE(eigenvalue);
            FREE(eigenvector);
        }
        else if (eigenvalueC)
        {
            sciErr = createComplexZMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNEV, 1, eigenvalueC);
            FREE(eigenvalueC);
        }

        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    }
    else
    {
        // create a matrix which contains the eigenvalues
        if (eigenvalue)
        {
            mat_eigenvalue = (double*)CALLOC(iNEV * iNEV, sizeof(double));
            for (i = 0; i < iNEV; i++)
            {
                mat_eigenvalue[i * iNEV + i] = eigenvalue[i];
            }
            sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNEV, iNEV, mat_eigenvalue);
            FREE(eigenvalue);
            FREE(mat_eigenvalue);
        }
        else if (eigenvalueC)
        {
            mat_eigenvalueC = (doublecomplex*)CALLOC(iNEV * iNEV, sizeof(doublecomplex));
            for (i = 0; i < iNEV; i++)
            {
                mat_eigenvalueC[i * iNEV + i] = eigenvalueC[i];
            }
            sciErr = createComplexZMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNEV, iNEV, mat_eigenvalueC);
            FREE(eigenvalueC);
            FREE(mat_eigenvalueC);
        }

        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        if (eigenvector)
        {
            sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, N, iNEV, eigenvector);
            FREE(eigenvector);
        }
        else if (eigenvectorC)
        {
            sciErr = createComplexZMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, N, iNEV, eigenvectorC);
            FREE(eigenvectorC);
        }

        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
    }

    ReturnArguments(pvApiCtx);
    return 0;
}
Example #19
0
/*--------------------------------------------------------------------------*/
static int xlfont_one_rhs(char * fname)
{
    SciErr sciErr;
    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        int* piAddrl1 = NULL;
        int* l1 = NULL;
        char* strl1 = NULL;
        int m1 = 0, n1 = 0;

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

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &strl1))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        if (strcmp(strl1, "AVAILABLE_FONTS") == 0)
        {
            int nbElements = 0;
            char **fontsname = getAvailableFontsName(&nbElements);

            m1 = nbElements;
            n1 = 1;

            sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, (const char * const*)fontsname);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            freeArrayOfString(fontsname, nbElements);
            freeAllocatedSingleString(strl1);
            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            ReturnArguments(pvApiCtx);
            return 0;
        }
        else if (strcmp(strl1, "reset") == 0)
        {
            resetFontManager();
            freeAllocatedSingleString(strl1);
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }
        else
        {
            if (isAvailableFontsName(strl1))
            {
                int fontID = addFont(strl1);

                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = fontID;

                freeAllocatedSingleString(strl1);
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }
            else if (FileExist(strl1))
            {
                int fontID = addFontFromFilename(strl1);

                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = fontID;

                freeAllocatedSingleString(strl1);
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: A valid fontname expected.\n"), fname, 1);
            }
        }

        freeAllocatedSingleString(strl1);
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
        return 0;
    }

    return 0;
}
Example #20
0
int ScilabGateway::array(char * fname, const int envId, void * pvApiCtx)
{
    SciErr err;
    int ret = 0;
    int * addr = 0;
    char * className = 0;
    int * args = 0;
    char * errmsg = 0;

    ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);

    if (Rhs < 2)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong number of arguments : more than %d expected."), 2);
    }

    OptionsHelper::setCopyOccured(false);
    ScilabObjects::initialization(env, pvApiCtx);
    env.getGatewayOptions().setIsNew(false);

    className = ScilabObjects::getSingleString(1, pvApiCtx);

    args = new int[Rhs - 1];

    for (int i = 0; i < Rhs - 1; i++)
    {
        err = getVarAddressFromPosition(pvApiCtx, i + 2, &addr);
        if (err.iErr)
        {
            delete[] args;
            freeAllocatedSingleString(className);
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        args[i] = ScilabObjects::isPositiveIntegerAtAddress(addr, pvApiCtx);

        if (args[i] == -1 || args[i] == 0)
        {
            delete[] args;
            freeAllocatedSingleString(className);
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("A strictly positive integer is expected at position %d."), i + 2);
        }
    }

    try
    {
        ret = env.createarray(className, args, Rhs - 1);
    }
    catch (std::exception & e)
    {
        delete[] args;
        freeAllocatedSingleString(className);
        throw;
    }

    delete[] args;
    freeAllocatedSingleString(className);

    try
    {
        ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + 1, ret, envId, pvApiCtx);
    }
    catch (ScilabAbstractEnvironmentException & e)
    {
        env.removeobject(ret);
        throw;
    }

    LhsVar(1) = Rhs + 1;
    PutLhsVar();

    return 0;
}
Example #21
0
/*--------------------------------------------------------------------------*/
int sci_libraryinfo(char *fname,unsigned long fname_len)
{
    SciErr sciErr;
    int *piAddressVarOne = NULL;

    CheckRhs(1,1);
    CheckLhs(1,2);

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
        return 0;
    }

    if (isStringType(pvApiCtx, piAddressVarOne))
    {
        char *libraryname = NULL;

        if (!isScalar(pvApiCtx, piAddressVarOne))
        {
            Scierror(999,_("%s: Wrong size for input argument #%d: String expected.\n"), fname, 1);
            return 0;
        }

        if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &libraryname) == 0)
        {
            if (libraryname)
            {
                char *pathlibrary = getlibrarypath(libraryname);
                if (pathlibrary)
                {
                    int sizemacrosarray = 0;
                    char **macros = getlistmacrosfromlibrary(libraryname, &sizemacrosarray);
                    if (macros)
                    {
                        int m = sizemacrosarray;
                        int n = 1;

                        sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, macros);
                        if(sciErr.iErr)
                        {
                            freeArrayOfString(macros, sizemacrosarray);
                            if (pathlibrary) 
                            {
                                FREE(pathlibrary); 
                                pathlibrary = NULL;
                            }

                            if (libraryname) 
                            {
                                freeAllocatedSingleString(libraryname);
                                libraryname = NULL;
                            }
                            printError(&sciErr, 0);
                            Scierror(999,_("%s: Memory allocation error.\n"), fname);
                            return 0;
                        }
                    }
                    else
                    {
                        createEmptyMatrix(pvApiCtx, Rhs + 1);
                    }
                    LhsVar(1) = Rhs+1;

                    freeArrayOfString(macros, sizemacrosarray);

                    if (Lhs == 2)
                    {
                        createSingleString(pvApiCtx, Rhs + 2, pathlibrary);
                        LhsVar(2) = Rhs+2;
                    }

                    if (pathlibrary) {FREE(pathlibrary);pathlibrary=NULL;}

                    PutLhsVar();
                }
                else
                {
                    Scierror(999,_("%s: Invalid library %s.\n"),fname, libraryname);
                }

                if (libraryname) 
                {
                    freeAllocatedSingleString(libraryname);
                    libraryname = NULL;
                }
            }
            else
            {
                Scierror(999,_("%s: Memory allocation error.\n"), fname);
            }
        }
        else
        {
            Scierror(999,_("%s: Memory allocation error.\n"), fname);
        }
    }
    else
    {
        Scierror(999,_("%s: Wrong type of input argument #%d: String expected.\n"),fname,1);
    }

    return 0;
}
Example #22
0
// fann_set_error_log   Change where errors are logged to.
int sci_fann_set_error_log(char * fname)
{
  int * pi_name_addr = NULL;
  int res;
  char * Name     = NULL;
  FILE * log_file = NULL;
  struct fann_error * result_error = (struct fann_error *)MALLOC(1*sizeof(struct fann_error));
  SciErr _sciErr;

  // Initialisation of the structure
  result_error->errstr    = NULL;
  result_error->errno_f   = FANN_E_NO_ERROR;
  result_error->error_log = fann_default_error_log;
  
  if (Rhs==0)
    {
      fann_set_error_log(result_error,NULL);
      
      fann_reset_errno(result_error);
      fann_reset_errstr(result_error);

      res = createScilabFannErrorStructFromCFannErrorStruct(result_error,NULL,Rhs + 1);
      
      LhsVar(1) = Rhs + 1;
    }
  else
    {
      if ((Rhs!=1)&&(Lhs!=1))
	{
	  Scierror(999,"%s: usage log_out = %(filename).\n", fname, fname);
	  return 0;
	}

      _sciErr = getVarAddressFromPosition(pvApiCtx, 1, &pi_name_addr);
      if (_sciErr.iErr)
	{
	  printError(&_sciErr, 0);
	  return 0;
	}
      
      getAllocatedSingleString(pvApiCtx,  pi_name_addr, &Name);

      log_file = fopen(Name,"w+");
      if (log_file == NULL)
	{
	  Scierror(999,"%s: unable to open the file %s for writing.\n",fname,Name);
	  freeAllocatedSingleString(Name);
	  return 0;
	}
      freeAllocatedSingleString(Name);

      fann_set_error_log(result_error,log_file);
      fann_reset_errno(result_error);
      fann_reset_errstr(result_error);

      res = createScilabFannErrorStructFromCFannErrorStruct(result_error, log_file, Rhs + 1);
      
      LhsVar(1) = Rhs + 1;
    }

  if (result_error==NULL)
    {
      Scierror(999,"%s: unable to create a fann_error structure\n",fname);
      return 0;
    }

  return 0;
}
Example #23
0
/*******************************************************************************
   Interface for MATIO function called Mat_Open
   Scilab function name : matfile_open
*******************************************************************************/
int sci_matfile_open(char *fname, void* pvApiCtx)
{
    int nbRow = 0, nbCol = 0;
    mat_t *matfile;
    int fileIndex = 0;
    char * filename  = NULL;
    char * optionStr = NULL;
    int option = 0, var_type;
    int * filename_addr = NULL, * option_addr = NULL, * version_addr = NULL;
    char * versionStr = NULL;
    int version = MAT_FT_MAT5; // By default, use MAtlab 5 files
    SciErr sciErr;

    CheckRhs(1, 3);
    CheckLhs(1, 1);

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &filename_addr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    sciErr = getVarType(pvApiCtx, filename_addr, &var_type);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }

    if (var_type == sci_strings)
    {
        getAllocatedSingleString(pvApiCtx, filename_addr, &filename);
        sciErr = getVarDimension(pvApiCtx, filename_addr, &nbRow, &nbCol);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        if (nbCol != 1)
        {
            Scierror(999, _("%s: Wrong size for first input argument: string expected.\n"), fname);
            freeAllocatedSingleString(filename);
            return FALSE;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for first input argument: string expected.\n"), fname);
        freeAllocatedSingleString(filename);
        return FALSE;
    }

    if (Rhs >= 2)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &option_addr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        sciErr = getVarType(pvApiCtx, option_addr, &var_type);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        if (var_type == sci_strings)
        {
            getAllocatedSingleString(pvApiCtx, option_addr, &optionStr);
            sciErr = getVarDimension(pvApiCtx, option_addr, &nbRow, &nbCol);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }

            if (nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for second input argument: string expected.\n"), fname);
                freeAllocatedSingleString(filename);
                freeAllocatedSingleString(optionStr);

                return FALSE;
            }

            if (strcmp(optionStr, "r") == 0)
            {
                option = MAT_ACC_RDONLY;
            }
            else if (strcmp(optionStr, "w") == 0)
            {
                option = MAT_ACC_RDWR;
            }
            else
            {
                Scierror(999, _("%s: Wrong value for second input argument: 'r' or 'w' expected.\n"), fname);
                freeAllocatedSingleString(filename);
                freeAllocatedSingleString(optionStr);

                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for second input argument: string expected.\n"), fname);
            freeAllocatedSingleString(filename);
            freeAllocatedSingleString(optionStr);

            return FALSE;
        }
    }
    else
    {
        /* Default option value */
        option = MAT_ACC_RDONLY;
    }

    if (Rhs >= 3)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &version_addr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }

        sciErr = getVarType(pvApiCtx, version_addr, &var_type);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 0;
        }
        printf("sci_strings %d %d\n", var_type, sci_strings);
        if (var_type == sci_strings)
        {
            getAllocatedSingleString(pvApiCtx, version_addr, &versionStr);
            sciErr = getVarDimension(pvApiCtx, version_addr, &nbRow, &nbCol);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 0;
            }
            if (nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 3);
                freeAllocatedSingleString(filename);
                freeAllocatedSingleString(optionStr);
                freeAllocatedSingleString(versionStr);

                return FALSE;
            }

            if (strcmp(versionStr, "7.3") == 0)
            {
                version = MAT_FT_MAT73; // Matlab 7.3 file
            }
            else
            {
                version = MAT_FT_MAT5; // Default, Matlab 5 file
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3);
            return 0;
        }
    }

    if (option == MAT_ACC_RDWR) // Write, option = "w"
    {
        /* create a Matlab 5 or 7.3 file */
        matfile = Mat_CreateVer(filename, NULL, version);
    }
    else // Read, option = "r"
    {
        /* Try to open the file (as a Matlab 5 file) */
        matfile = Mat_Open(filename, option);
    }

    if (matfile == NULL) /* Opening failed */
    {
        /* Function returns -1 */
        fileIndex = -1;
    }

    if (matfile != NULL) /* Opening succeed */
    {
        /* Add the file to the manager */
        matfile_manager(MATFILEMANAGER_ADDFILE, &fileIndex, &matfile);
    }

    /* Return the index */
    createScalarDouble(pvApiCtx, Rhs + 1, (double)fileIndex);

    freeAllocatedSingleString(filename);
    freeAllocatedSingleString(optionStr);
    freeAllocatedSingleString(versionStr);

    LhsVar(1) = Rhs + 1;
    PutLhsVar();

    return TRUE;
}
Example #24
0
/*--------------------------------------------------------------------------*/
int sci_uimenu(char *fname, void *pvApiCtx)
{
    SciErr sciErr;
    int nbRow = 0, nbCol = 0;
    int setStatus = SET_PROPERTY_SUCCEED;
    int inputIndex = 0, beginIndex = 0;
    char *propertyName = NULL;
    int iParentUID = 0;
    unsigned long GraphicHandle = 0;
    int parentDefined = FALSE;
    int iCurrentFigure = 0;
    int iParentType = -1;
    int *piParentType = &iParentType;

    /* Create a new menu */
    GraphicHandle = getHandle(CreateUimenu());

    /* If no nbInputArgument(pvApiCtx) -> current figure is the parent (Ascendant compatibility) */
    if (nbInputArgument(pvApiCtx) == 0)
    {
        // Set the parent property
        iCurrentFigure = getCurrentFigure();
        if (iCurrentFigure == 0)
        {
            iCurrentFigure = createNewFigureWithAxes();
        }
        setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle));
    }

    /**
    * Odd number of input arguments
    * First input is the parent ID
    * All event inputs are property names
    * All odd (except first) inputs are property values
    */
    if (nbInputArgument(pvApiCtx) % 2 == 1)
    {
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle expected.\n"), fname, 1);
            return FALSE;
        }
        else                    /* Get parent ID */
        {
            int *piAddr = NULL;
            long long hParent = 0;
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of handle at position 1.
            // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr".
            if (getScalarHandle(pvApiCtx, piAddr, &hParent))
            {
                Scierror(202, _("%s: Wrong type for input argument #%d: Handle expected.\n"), fname, 1);
                return 1;
            }

            iParentUID = getObjectFromHandle((long)hParent);
            if (iParentUID != 0)
            {
                getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
                if (iParentType != __GO_FIGURE__ && iParentType != __GO_UIMENU__)
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu");
                    return FALSE;
                }

                // Set the parent property
                callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), &hParent, sci_handles, 1, 1, "parent");

                // Set the flag to avoid setting the parent two times
                parentDefined = TRUE;
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu");
                return FALSE;
            }

            // First input parameter which is a property name
            beginIndex = 2;
        }
    }
    /**
    * Even number of input arguments
    * All odd inputs are property names
    * All even inputs are property values
    */
    else
    {
        // First input parameter which is a property name
        beginIndex = 1;
    }

    /* Read and set all properties */
    for (inputIndex = beginIndex; inputIndex < nbInputArgument(pvApiCtx); inputIndex = inputIndex + 2)
    {
        int* piAddrValue = NULL;
        int* piAddrProperty = NULL;

        int isUserDataProperty = 0;
        int iPropertyValuePositionIndex = inputIndex + 1;
        size_t posStackOrAdr = 0;

        /* Read property name */
        if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex);
            return FALSE;
        }
        else
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddrProperty);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            if (getAllocatedSingleString(pvApiCtx, piAddrProperty, &propertyName))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex);
                return 1;
            }

            if (stricmp(propertyName, "parent") == 0)
            {
                parentDefined = TRUE;
            }

            isUserDataProperty = (stricmp(propertyName, "user_data") == 0) || (stricmp(propertyName, "userdata") == 0);
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, iPropertyValuePositionIndex, &piAddrValue);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            freeAllocatedSingleString(propertyName);
            return 1;
        }

        if (isUserDataProperty)
        {
            nbRow = -1;
            nbCol = -1;
            setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, 0, 0, 0, propertyName);
        }
        else
        {
            /* Read property value */
            switch (getInputArgumentType(pvApiCtx, iPropertyValuePositionIndex))
            {
                case sci_matrix:
                {
                    double* pdblValue = NULL;
                    sciErr = getMatrixOfDouble(pvApiCtx, piAddrValue, &nbRow, &nbCol, &pdblValue);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, iPropertyValuePositionIndex);
                        freeAllocatedSingleString(propertyName);
                        return 1;
                    }

                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pdblValue, sci_matrix, nbRow, nbCol, propertyName);
                    break;
                }
                case sci_strings:
                {
                    char* pstValue = NULL;
                    if (getAllocatedSingleString(pvApiCtx, piAddrValue, &pstValue))
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, iPropertyValuePositionIndex);
                        freeAllocatedSingleString(propertyName);
                        return 1;
                    }

                    nbRow = (int)strlen(pstValue);
                    nbCol = 1;
                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pstValue, sci_strings, nbRow, nbCol, propertyName);
                    freeAllocatedSingleString(pstValue);
                    break;
                }
                case sci_handles:
                {
                    long long* phValues = NULL;
                    sciErr = getMatrixOfHandle(pvApiCtx, piAddrValue, &nbRow, &nbCol, &phValues);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, iPropertyValuePositionIndex);
                        freeAllocatedSingleString(propertyName);
                        return 1;
                    }
                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), phValues, sci_handles, nbRow, nbCol, propertyName);
                    break;
                }
                case sci_list:
                {
                    getListItemNumber(pvApiCtx, piAddrValue, &nbRow);
                    nbCol = 1;
                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, sci_list, nbRow, nbCol, propertyName);
                    break;
                }
                default:
                {
                    setStatus = SET_PROPERTY_ERROR;
                    break;
                }
            }
        }

        if (setStatus == SET_PROPERTY_ERROR)
        {
            Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName);
            freeAllocatedSingleString(propertyName);
            return FALSE;
        }

        freeAllocatedSingleString(propertyName);
    }

    /* If the parent is not given, the current figure is set as parent */
    if (!parentDefined && (nbInputArgument(pvApiCtx) != 0))
    {
        // Set the parent property
        iCurrentFigure = getCurrentFigure();
        if (iCurrentFigure == 0)
        {
            iCurrentFigure = createNewFigureWithAxes();
        }
        setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle));
    }

    /* Create return variable */
    nbRow = 1;
    nbCol = 1;
    // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr".
    if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
Example #25
0
/*--------------------------------------------------------------------------*/
int sci_uicontrol(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int nbRow = 0, nbCol = 0, k = 0;
    int setStatus = SET_PROPERTY_SUCCEED;
    int PARENT_NOT_FOUND = -2;
    int NOT_FOUND = -1;
    int inputIndex = 0, beginIndex = 0;
    char *propertyName = NULL;
    char *styleProperty = NULL;

    int iPropertiesCount = sizeof(propertiesNames) / sizeof(char**);
    unsigned long GraphicHandle = 0;

    int found = 0;              /* Does the property exists ? */

    int *propertiesValuesIndices = NULL;

    int iParentType = -1;
    int *piParentType = &iParentType;
    int iParentStyle = -1;
    int *piParentStyle = &iParentStyle;

    int iParentUID      = 0;
    int iUicontrol      = 0;
    int iCurrentFigure  = 0;

    CheckOutputArgument(pvApiCtx, 0, 1);

    //init properties index
    init_property_index();

    if (nbInputArgument(pvApiCtx) == 0)
    {
        /* Create a pushbutton in current figure */

        /* Create a new pushbutton */
        GraphicHandle = getHandle(CreateUIControl(NULL));

        /* Set current figure as parent */
        iCurrentFigure = getCurrentFigure();
        if (iCurrentFigure == 0)
        {
            iCurrentFigure = createNewFigureWithAxes();
        }

        iUicontrol = getObjectFromHandle(GraphicHandle);
        setGraphicObjectRelationship(iCurrentFigure, iUicontrol);
    }
    else if (nbInputArgument(pvApiCtx) == 1)
    {
        /* Create a pushbutton in figure given as parameter */
        /* Or give focus to the uicontrol given as parameter */
        int* piAddr = NULL;
        int iType = 0;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
        if (sciErr.iErr)
        {
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

        if (isHandleType(pvApiCtx, piAddr) == FALSE && isStringType(pvApiCtx, piAddr) == FALSE)
        {
            OverLoad(1);
            return FALSE;
        }
#if 0 // Allow XML loading
        else if (isStringType(pvApiCtx, piAddr))
        {
            char* pstXmlfile = NULL;
            char* pstExpandedPath = NULL;

            if (isScalar(pvApiCtx, piAddr) == 0)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
                return FALSE;
            }

            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstXmlfile))
            {
                freeAllocatedSingleString(pstXmlfile);
                Scierror(999, _("%s: No more memory.\n"), fname);
                return FALSE;
            }

            pstExpandedPath = expandPathVariable(pstXmlfile);
            freeAllocatedSingleString(pstXmlfile);
            iUicontrol = xmlload(pstExpandedPath);
            if (iUicontrol < 1)
            {
                Scierror(999, _("%s: can not read file %s.\n"), fname, pstExpandedPath);
                FREE(pstExpandedPath);
                return 0;
            }
            FREE(pstExpandedPath);
            GraphicHandle = getHandle(iUicontrol);

            /* Create return variable */
            if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            ReturnArguments(pvApiCtx);
            return TRUE;
        }
#endif // Allow XML loading
        else /* Get parent ID */
        {
            int* piAddr = NULL;
            long long hParent = 0;
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            if (isScalar(pvApiCtx, piAddr) == 0)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
                return FALSE;
            }

            if (getScalarHandle(pvApiCtx, piAddr, &hParent))
            {
                Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                return 1;
            }

            iParentUID = getObjectFromHandle((long)hParent);
            if (iParentUID != 0)
            {
                getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
                if (iParentType == __GO_UICONTROL__)  /* Focus management */
                {
                    GraphicHandle = (unsigned long)hParent;
                    requestFocus(iParentUID);
                }
                else if (iParentType == __GO_FIGURE__ || iParentType == __GO_UIMENU__)  /* PushButton creation */
                {
                    /* Create a new pushbutton */
                    GraphicHandle = getHandle(CreateUIControl(NULL));
                    iUicontrol = getObjectFromHandle(GraphicHandle);

                    /* First parameter is the parent */
                    setGraphicObjectRelationship(iParentUID, iUicontrol);
                    setStatus = callSetProperty(pvApiCtx, iUicontrol, &hParent, sci_handles, 1, 1, (char*)propertiesNames[parent_property]);
                    if (setStatus == SET_PROPERTY_ERROR)
                    {
                        Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName);
                        return FALSE;
                    }
                }
                else
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol",
                             "Figure", "Uimenu");
                    return FALSE;
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure",
                         "Uimenu");
                return FALSE;
            }
        }
    }
    else
    {
        if (!checkInputArgumentType(pvApiCtx, 1, sci_handles) && !checkInputArgumentType(pvApiCtx, 1, sci_strings))
        {
            OverLoad(1);
            return FALSE;
        }

        /* Allocate memory to store the position of properties in uicontrol call */
        if ((propertiesValuesIndices = (int*)MALLOC(sizeof(int) * iPropertiesCount)) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            return FALSE;
        }

        /* Init all positions to NOT_FOUND */
        for (inputIndex = 0; inputIndex < iPropertiesCount; inputIndex++)
        {
            propertiesValuesIndices[inputIndex] = NOT_FOUND;    /* Property initialized as not found */
        }

        /**
         * Odd number of input arguments
         * First input is the parent ID
         * All event inputs are property names
         * All odd (except first) inputs are property values
         */
        if (nbInputArgument(pvApiCtx) % 2 == 1)
        {
            if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
            {
                if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
                {
                    int* piAddr = NULL;
                    double dblValue = 0;

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

                    if (isScalar(pvApiCtx, piAddr) == 0)
                    {
                        Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
                        return FALSE;
                    }

                    if (getScalarDouble(pvApiCtx, piAddr, &dblValue))
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
                        return 1;
                    }

                    iParentUID = getFigureFromIndex((int)dblValue);
                }
                else
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                             "Frame uicontrol");
                    return FALSE;
                }
            }
            else /* Get parent ID */
            {
                int* piAddr = NULL;
                long long hParent = 0;
                sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (isScalar(pvApiCtx, piAddr) == 0)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                             "Frame uicontrol");
                    return FALSE;
                }

                if (getScalarHandle(pvApiCtx, piAddr, &hParent))
                {
                    Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                    return 1;
                }

                iParentUID = getObjectFromHandle((long)hParent);
            }

            if (iParentUID == 0)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                         "Frame uicontrol");
                return FALSE;
            }

            getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
            if (iParentType != __GO_FIGURE__)
            {
                getGraphicObjectProperty(iParentUID, __GO_STYLE__, jni_int, (void **)&piParentStyle);
                if (iParentType != __GO_UICONTROL__ ||
                        (iParentStyle != __GO_UI_FRAME__ && iParentStyle != __GO_UI_TAB__ && iParentStyle != __GO_UI_LAYER__))
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                             "Frame uicontrol");
                    return FALSE;
                }
            }
            /* First parameter is the parent */
            propertiesValuesIndices[parent_property] = 1;
            // First input parameter which is a property name
            beginIndex = 2;
        }
        /**
         * Even number of input arguments
         * All odd inputs are property names
         * All even inputs are property values
         */
        else
        {
            // First input parameter which is a property name
            beginIndex = 1;
        }

        /* Get all properties positions */
        for (inputIndex = beginIndex; inputIndex < Rhs; inputIndex = inputIndex + 2)
        {
            /* Read property name */
            if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings)))
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex);
                return FALSE;
            }
            else
            {
                int* piAddr = NULL;
                sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (getAllocatedSingleString(pvApiCtx, piAddr, &propertyName))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex);
                    return 1;
                }


                /* Bug 3031 */
                /* We only want to compare propertyName along its length */
                /* 'posi' must be matched to 'position' */
                found = 0;
                for (k = 0; k < iPropertiesCount ; k++)
                {
                    if (strlen(propertyName) <= strlen(propertiesNames[k]))
                    {
                        if (strnicmp(propertyName, propertiesNames[k], strlen(propertyName)) == 0)
                        {
                            propertiesValuesIndices[k] = inputIndex + 1;    /* Position of value for property */
                            found = 1;
                            break;
                        }
                    }
                }

                freeAllocatedSingleString(propertyName);

                if (found == 0)
                {
                    Scierror(999, _("%s: Unknown property: %s for '%s' handles.\n"), fname, propertyName, "Uicontrol");
                    return FALSE;
                }
            }
        }

        if (propertiesValuesIndices[style_property] != NOT_FOUND)    /* Style found */
        {
            if ((checkInputArgumentType(pvApiCtx, propertiesValuesIndices[style_property], sci_strings)))
            {
                int* piAddr = NULL;
                sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[style_property], &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (getAllocatedSingleString(pvApiCtx, piAddr, &styleProperty))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]);
                    return 1;
                }

                if (strcmp(styleProperty, "frame") == 0)
                {
                    //check scrollable property to create a scroll frame instead of normal frame
                    if (propertiesValuesIndices[scrollable_property] != NOT_FOUND)
                    {
                        char* pstScroll = NULL;
                        int iScroll = 0;
                        sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[scrollable_property], &piAddr);
                        if (sciErr.iErr)
                        {
                            printError(&sciErr, 0);
                            return 1;
                        }

                        if (isStringType(pvApiCtx, piAddr) == 0 && isBooleanType(pvApiCtx, piAddr) == 0 && isScalar(pvApiCtx, piAddr) == 0)
                        {
                            Scierror(202, _("%s: Wrong type for argument #%d: string or boolean expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
                            return 1;
                        }

                        if (isStringType(pvApiCtx, piAddr))
                        {
                            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstScroll))
                            {
                                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
                                return 1;
                            }

                            if (strcmp(pstScroll, "on") == 0)
                            {
                                iScroll = 1;
                            }

                            freeAllocatedSingleString(pstScroll);
                        }
                        else
                        {
                            if (getScalarBoolean(pvApiCtx, piAddr, &iScroll))
                            {
                                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
                                return 1;
                            }
                        }

                        if (iScroll)
                        {
                            freeAllocatedSingleString(styleProperty);
                            styleProperty = os_strdup("framescrollable");
                        }

                        propertiesValuesIndices[scrollable_property] = NOT_FOUND;
                    }
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]);
                return FALSE;
            }
        }

        /* Create a new uicontrol */
        iUicontrol = CreateUIControl(styleProperty);
        freeAllocatedSingleString(styleProperty);
        if (iUicontrol == 0) /* Error in creation */
        {
            Scierror(999, _("%s: Could not create 'Uicontrol' handle.\n"), fname);
            return FALSE;
        }
        GraphicHandle = getHandle(iUicontrol);

        /* If no parent given then the current figure is the parent */
        if (propertiesValuesIndices[parent_property] == NOT_FOUND)
        {
            /* Set the parent */
            iCurrentFigure = getCurrentFigure();

            if (iCurrentFigure == 0)
            {
                iCurrentFigure = createNewFigureWithAxes();
            }

            propertiesValuesIndices[parent_property] = PARENT_NOT_FOUND;
        }

        /* Read and set all properties */
        for (inputIndex = 1; inputIndex < iPropertiesCount; inputIndex++)   /* Style has already been set */
        {
            if (propertiesValuesIndices[inputIndex] == PARENT_NOT_FOUND)
            {
                //special case for not specified parent
                //but set relationship at the good moment.
                setGraphicObjectRelationship(iCurrentFigure, iUicontrol);
            }
            else if (propertiesValuesIndices[inputIndex] != NOT_FOUND)
            {
                int* piAddr = NULL;
                sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[inputIndex], &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (inputIndex == user_data_property || inputIndex == userdata_property)   /* User data settings */
                {
                    nbRow = -1;
                    nbCol = -1;
                    setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, 0, 0, 0, (char*)propertiesNames[inputIndex]);
                }
                else            /* All other properties */
                {
                    /* Read property value */
                    switch (getInputArgumentType(pvApiCtx, propertiesValuesIndices[inputIndex]))
                    {
                        case sci_matrix:
                        {
                            double* pdblValue = NULL;
                            sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &pdblValue);
                            if (sciErr.iErr)
                            {
                                printError(&sciErr, 0);
                                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                return 1;
                            }

                            setStatus = callSetProperty(pvApiCtx, iUicontrol, pdblValue, sci_matrix, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                            break;
                        }
                        case sci_strings:
                            /* Index for String & TooltipString properties: Can be more than one character string */
                            if ((inputIndex == string_property) || (inputIndex == tooltipstring_property))
                            {
                                char** pstValue = NULL;
                                if (getAllocatedMatrixOfString(pvApiCtx, piAddr, &nbRow, &nbCol, &pstValue))
                                {
                                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                    return 1;
                                }

                                setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                                freeAllocatedMatrixOfString(nbRow, nbCol, pstValue);
                            }
                            else
                            {
                                char* pstValue = NULL;
                                if (getAllocatedSingleString(pvApiCtx, piAddr, &pstValue))
                                {
                                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                    return 1;
                                }

                                nbRow = (int)strlen(pstValue);
                                nbCol = 1;
                                setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                                freeAllocatedSingleString(pstValue);
                            }
                            break;
                        case sci_handles:
                        {
                            long long* pHandles = NULL;
                            sciErr = getMatrixOfHandle(pvApiCtx, piAddr, &nbRow, &nbCol, &pHandles);
                            if (sciErr.iErr)
                            {
                                printError(&sciErr, 0);
                                Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                return 1;
                            }

                            setStatus = callSetProperty(pvApiCtx, iUicontrol, pHandles, sci_handles, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                            break;
                        }
                        case sci_tlist: //constraints and border
                        {
                            setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, sci_tlist, 1, 1, (char*)propertiesNames[inputIndex]);
                            break;
                        }
                        default:
                            setStatus = SET_PROPERTY_ERROR;
                            break;
                    }
                }
                if (setStatus == SET_PROPERTY_ERROR)
                {
                    Scierror(999, _("%s: Could not set property '%s'.\n"), fname, (char*)propertiesNames[inputIndex]);
                    return FALSE;
                }
            }
        }
    }

    if (propertiesValuesIndices != NULL
            && (propertiesValuesIndices[sliderstep_property] == NOT_FOUND &&
                (propertiesValuesIndices[min_property] != NOT_FOUND || propertiesValuesIndices[max_property] != NOT_FOUND)))    /* SliderStep property not set */
    {
        /* Set SliderStep property to [1/100*(Max-Min) 1/10*(Max-Min)] */
        double maxValue = 0;
        double* pdblMaxValue = &maxValue;
        double minValue = 0;
        double* pdblMinValue = &minValue;
        double pdblStep[2];

        getGraphicObjectProperty(iUicontrol, __GO_UI_MIN__, jni_double, (void**) &pdblMinValue);
        getGraphicObjectProperty(iUicontrol, __GO_UI_MAX__, jni_double, (void**) &pdblMaxValue);

        pdblStep[0] = 0.01 * (maxValue - minValue);
        pdblStep[1] = 0.1 * (maxValue - minValue);

        setGraphicObjectProperty(iUicontrol, __GO_UI_SLIDERSTEP__, pdblStep, jni_double_vector, 2);
    }

    if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[position_property] == NOT_FOUND))    /* Position property not set */
    {
        double* pdblPosition = NULL;

        getGraphicObjectProperty(iUicontrol, __GO_POSITION__, jni_double_vector, (void**) &pdblPosition);
        setGraphicObjectProperty(iUicontrol, __GO_POSITION__, pdblPosition, jni_double_vector, 4);
        releaseGraphicObjectProperty(__GO_POSITION__, pdblPosition, jni_double_vector, 4);
    }

    if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[visible_property] == NOT_FOUND))    /* Visible property not set */
    {
        /* Force the uicontrol to be visible because is invisible by default in the model (See bug #10346) */
        int b = (int)TRUE;
        setGraphicObjectProperty(iUicontrol, __GO_VISIBLE__, &b, jni_bool, 1);
    }

    FREE(propertiesValuesIndices);

    /* Create return variable */
    if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
Example #26
0
/*--------------------------------------------------------------------------*/
int sci_TCL_UnsetVar(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    int* piAddrl2 = NULL;
    char* l2 = NULL;

    static int n1, m1;
    static int n2, m2;

    Tcl_Interp *TCLinterpreter = NULL;

    CheckInputArgument(pvApiCtx, 1, 2);
    CheckOutputArgument(pvApiCtx, 1, 1);

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
    {
        int paramoutINT = 0;
        char *VarName = NULL;

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

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &VarName))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        if (!existsGlobalInterp())
        {
            freeAllocatedSingleString(VarName);
            Scierror(999, _("%s: Error main TCL interpreter not initialized.\n"), fname);
            return 0;
        }

        if (nbInputArgument(pvApiCtx) == 2)
        {
            // two arguments given - get a pointer on the slave interpreter
            if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
            {
                sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
                if (sciErr.iErr)
                {
                    freeAllocatedSingleString(VarName);
                    printError(&sciErr, 0);
                    return 1;
                }

                // Retrieve a matrix of double at position 2.
                if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
                {
                    freeAllocatedSingleString(VarName);
                    Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
                    return 1;
                }

                TCLinterpreter = Tcl_GetSlave(getTclInterp(), (l2));
                freeAllocatedSingleString(l2);
                releaseTclInterp();
                if (TCLinterpreter == NULL)
                {
                    freeAllocatedSingleString(VarName);
                    Scierror(999, _("%s: No such slave interpreter.\n"), fname);
                    return 0;
                }
            }
            else
            {
                freeAllocatedSingleString(VarName);
                Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 2);
                return 0;
            }
        }
        else
        {
            // only one argument given - use the main interpreter
            TCLinterpreter = getTclInterp();
        }

        paramoutINT = (int)(Tcl_UnsetVar(TCLinterpreter, VarName, TCL_GLOBAL_ONLY) != TCL_ERROR);
        freeAllocatedSingleString(VarName);

        if (createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, paramoutINT))
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else
    {
        releaseTclInterp();
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
        return 0;
    }
    releaseTclInterp();

    return 0;
}
Example #27
0
/*--------------------------------------------------------------------------*/
int sci_zneupd(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrpRVEC    = NULL;
    int* pRVEC          = NULL;
    int* piAddrpHOWMANY = NULL;
    char* pHOWMANY      = NULL;
    int* piAddrpSELECT  = NULL;
    int* pSELECT        = NULL;
    int* piAddrpBMAT    = NULL;
    char* pBMAT         = NULL;
    int* piAddrpN       = NULL;
    int* pN             = NULL;
    int* piAddrpWHICH   = NULL;
    char* pWHICH        = NULL;
    int* piAddrpNEV     = NULL;
    int* pNEV           = NULL;
    int* piAddrpTOL     = NULL;
    double* pTOL        = NULL;
    int* piAddrpNCV     = NULL;
    int* pNCV           = NULL;
    int* piAddrpIPARAM  = NULL;
    int* pIPARAM        = NULL;
    int* piAddrpIPNTR   = NULL;
    int* pIPNTR         = NULL;
    int* piAddrpRWORK   = NULL;
    double* pRWORK      = NULL;
    int* piAddrpINFO    = NULL;
    int* pINFO          = NULL;

    int* piAddrpD           = NULL;
    doublecomplex* pD       = NULL;
    int* piAddrpZ           = NULL;
    doublecomplex* pZ       = NULL;
    int* piAddrpSIGMA       = NULL;
    doublecomplex* pSIGMA   = NULL;
    int* piAddrpWORKev      = NULL;
    doublecomplex* pWORKev  = NULL;
    int* piAddrpRESID       = NULL;
    doublecomplex* pRESID   = NULL;
    int* piAddrpWORKD       = NULL;
    doublecomplex* pV       = NULL;
    int* piAddrpV           = NULL;
    doublecomplex* pWORKD   = NULL;
    int* piAddrpWORKL       = NULL;
    doublecomplex* pWORKL   = NULL;

    int mRVEC,     nRVEC;
    int mHOWMANY,  nHOWMANY;
    int mSELECT,   nSELECT;
    int D,        mD,        nD;
    int Z,        mZ,        nZ;
    int mSIGMA,    nSIGMA;
    int mWORKev,   nWORKev;
    int mBMAT,     nBMAT;
    int mN,        nN;
    int mWHICH,    nWHICH;
    int mNEV,      nNEV;
    int mTOL,      nTOL;
    int RESID,    mRESID,    nRESID;
    int mNCV,      nNCV;
    int mV,        nV;
    int IPARAM,   mIPARAM,   nIPARAM;
    int IPNTR,    mIPNTR,    nIPNTR;
    int WORKD,    mWORKD,    nWORKD;
    int WORKL,    mWORKL,    nWORKL;
    int RWORK,    mRWORK,    nRWORK;
    int INFO,     mINFO,     nINFO;

    int minlhs = 1, minrhs = 21, maxlhs = 9, maxrhs = 21;
    int LDZ, LDV, LWORKL;
    int sizeWORKL = 0;

    CheckInputArgument(pvApiCtx, minrhs, maxrhs);
    CheckOutputArgument(pvApiCtx, minlhs, maxlhs);

    /*                                                  VARIABLE = NUMBER   */
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpRVEC);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 1.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpRVEC, &mRVEC, &nRVEC, &pRVEC);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1);
        return 1;
    }

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

    // Retrieve a matrix of double at position 3.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpSELECT, &mSELECT, &nSELECT, &pSELECT);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
        return 1;
    }

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

    // Retrieve a matrix of double at position 4.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpD, &mD, &nD, &pD);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 4);
        return 1;
    }
    D =  4;

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

    // Retrieve a matrix of double at position 5.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpZ, &mZ, &nZ, &pZ);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 5);
        return 1;
    }
    Z =  5;

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

    // Retrieve a matrix of double at position 6.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpSIGMA, &mSIGMA, &nSIGMA, &pSIGMA);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 6);
        return 1;
    }

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

    // Retrieve a matrix of double at position 7.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpWORKev, &mWORKev, &nWORKev, &pWORKev);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 7);
        return 1;
    }

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

    // Retrieve a matrix of double at position 9.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpN, &mN, &nN, &pN);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 9);
        return 1;
    }

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

    // Retrieve a matrix of double at position 11.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNEV, &mNEV, &nNEV, &pNEV);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 11);
        return 1;
    }

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

    // Retrieve a matrix of double at position 12.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrpTOL, &mTOL, &nTOL, &pTOL);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 12);
        return 1;
    }

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

    // Retrieve a matrix of double at position 13.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpRESID, &mRESID, &nRESID, &pRESID);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 13);
        return 1;
    }
    RESID = 13;

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

    // Retrieve a matrix of double at position 14.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpNCV, &mNCV, &nNCV, &pNCV);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 14);
        return 1;
    }

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

    // Retrieve a matrix of double at position 15.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpV, &mV, &nV, &pV);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 15);
        return 1;
    }

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

    // Retrieve a matrix of double at position 16.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPARAM, &mIPARAM, &nIPARAM, &pIPARAM);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 16);
        return 1;
    }

    IPARAM = 16;
    sciErr = getVarAddressFromPosition(pvApiCtx, 17, &piAddrpIPNTR);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 17.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpIPNTR, &mIPNTR, &nIPNTR, &pIPNTR);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 17);
        return 1;
    }

    IPNTR = 17;

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

    // Retrieve a matrix of double at position 18.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpWORKD, &mWORKD, &nWORKD, &pWORKD);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 18);
        return 1;
    }
    WORKD = 18;

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

    // Retrieve a matrix of double at position 19.
    sciErr = getComplexZMatrixOfDouble(pvApiCtx, piAddrpWORKL, &mWORKL, &nWORKL, &pWORKL);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 19);
        return 1;
    }
    WORKL = 19;

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

    // Retrieve a matrix of double at position 20.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrpRWORK, &mRWORK, &nRWORK, &pRWORK);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 20);
        return 1;
    }

    RWORK = 20;
    sciErr = getVarAddressFromPosition(pvApiCtx, 21, &piAddrpINFO);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 21.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrpINFO, &mINFO, &nINFO, &pINFO);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 21);
        return 1;
    }

    INFO = 21;

    LWORKL = mWORKL * nWORKL;
    LDV = Max(1, pN[0]);
    LDZ = LDV;

    /* Check some sizes */
    if (mIPARAM*nIPARAM != 11)
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPARAM", 11);
        return 1;
    }

    if (mIPNTR*nIPNTR != 14)
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "IPNTR", 14);
        return 1;
    }

    if (mRESID*nRESID != pN[0])
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "RESID", pN[0]);
        return 1;
    }

    if (mWORKD * nWORKD < 3 * pN[0])
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKD", 3 * pN[0]);
        return 1;
    }

    if (mSELECT*nSELECT != pNCV[0])
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "SELECT", pNCV[0]);
        return 1;
    }

    if (mD*nD != (pNEV[0] + 1))
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "D", pNEV[0] + 1);
        return 1;
    }

    if ((mZ != pN[0]) || (nZ != pNEV[0]))
    {
        Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "Z", pN[0], pNEV[0]);
        return 1;
    }

    if (mWORKev*nWORKev != 2 * pNCV[0])
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKev", 2 * pNCV[0]);
        return 1;
    }

    if ((mV != pN[0]) || (nV != pNCV[0]))
    {
        Scierror(999, _("%s: Wrong size for input argument %s: A matrix of size %dx%d expected.\n"), fname, "V", pN[0], pNCV[0]);
        return 1;
    }

    sizeWORKL = 3 * pNCV[0] * pNCV[0] + 5 * pNCV[0];

    if ((mWORKL * nWORKL < sizeWORKL))
    {
        Scierror(999, _("%s: Wrong size for input argument %s: An array of size %d expected.\n"), fname, "WORKL", sizeWORKL);
        return 1;
    }

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

    // Retrieve a matrix of double at position 2.
    if (getAllocatedSingleString(pvApiCtx, piAddrpHOWMANY, &pHOWMANY))
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
        return 1;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddrpBMAT);
    if (sciErr.iErr)
    {
        freeAllocatedSingleString(pHOWMANY);
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 8.
    if (getAllocatedSingleString(pvApiCtx, piAddrpBMAT, &pBMAT))
    {
        freeAllocatedSingleString(pHOWMANY);
        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 8);
        return 1;
    }

    sciErr = getVarAddressFromPosition(pvApiCtx, 10, &piAddrpWHICH);
    if (sciErr.iErr)
    {
        freeAllocatedSingleString(pHOWMANY);
        freeAllocatedSingleString(pBMAT);
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 10.
    if (getAllocatedSingleString(pvApiCtx, piAddrpWHICH, &pWHICH))
    {
        freeAllocatedSingleString(pHOWMANY);
        freeAllocatedSingleString(pBMAT);
        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 10);
        return 1;
    }

    C2F(zneupd)(pRVEC, pHOWMANY, pSELECT, pD,
                pZ, &LDZ, pSIGMA, pWORKev,
                pBMAT, pN, pWHICH, pNEV,
                pTOL, pRESID, pNCV, pV,
                &LDV, pIPARAM, pIPNTR, pWORKD,
                pWORKL, &LWORKL, pRWORK, pINFO);

    freeAllocatedSingleString(pHOWMANY);
    freeAllocatedSingleString(pBMAT);
    freeAllocatedSingleString(pWHICH);

    if (pINFO[0] < 0)
    {
        C2F(errorinfo)("zneupd", pINFO, 6L);
        return 0;
    }

    AssignOutputVariable(pvApiCtx, 1) = D;
    AssignOutputVariable(pvApiCtx, 2) = Z;
    AssignOutputVariable(pvApiCtx, 3) = RESID;
    AssignOutputVariable(pvApiCtx, 4) = IPARAM;
    AssignOutputVariable(pvApiCtx, 5) = IPNTR;
    AssignOutputVariable(pvApiCtx, 6) = WORKD;
    AssignOutputVariable(pvApiCtx, 7) = WORKL;
    AssignOutputVariable(pvApiCtx, 8) = RWORK;
    AssignOutputVariable(pvApiCtx, 9) = INFO;

    ReturnArguments(pvApiCtx);

    return 0;
}
Example #28
0
int ScilabGateway::wrapAsRef(char * fname, const int envId, void * pvApiCtx)
{
    SciErr err;
    int * tmpvar = 0;
    int * addr = 0;
    char * varName = 0;
    int idObj;

    if (Rhs == 0)
    {
        throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong number of arguments : more than 1 argument expected."));
    }

    ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId);
    ScilabGatewayOptions & options = env.getGatewayOptions();
    OptionsHelper::setCopyOccurred(false);
    ScilabObjects::initialization(env, pvApiCtx);
    options.setIsNew(false);

    CheckOutputArgument(pvApiCtx, Rhs, Rhs);

    tmpvar = new int[Rhs + 1];
    *tmpvar = 0;

    for (int i = 1; i < Rhs + 1; i++)
    {
        err = getVarAddressFromPosition(pvApiCtx, i, &addr);
        if (err.iErr)
        {
            ScilabObjects::removeTemporaryVars(envId, tmpvar);
            delete[] tmpvar;
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        if (!isScalar(pvApiCtx, addr) || !isStringType(pvApiCtx, addr))
        {
            ScilabObjects::removeTemporaryVars(envId, tmpvar);
            delete[] tmpvar;
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Can only wrap as a reference to a named variable"));
        }

        if (getAllocatedSingleString(pvApiCtx, addr, &varName))
        {
            ScilabObjects::removeTemporaryVars(envId, tmpvar);
            delete[] tmpvar;
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        err = getVarAddressFromName(pvApiCtx, varName, &addr);
        freeAllocatedSingleString(varName);
        if (err.iErr)
        {
            ScilabObjects::removeTemporaryVars(envId, tmpvar);
            delete[] tmpvar;
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
        }

        try
        {
            idObj = ScilabObjects::getArgumentId(addr, tmpvar, true, false, envId, pvApiCtx);
        }
        catch (ScilabAbstractEnvironmentException & /*e*/)
        {
            delete[] tmpvar;
            throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Cannot wrap argument %d."), i);
        }

        try
        {
            ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, idObj, envId, pvApiCtx);
        }
        catch (ScilabAbstractEnvironmentException & /*e*/)
        {
            ScilabObjects::removeTemporaryVars(envId, tmpvar);
            delete[] tmpvar;
            throw;
        }

        LhsVar(i) = Rhs + i;
    }

    // We don't remove tmpvar since it contains id which are put on rhs
    delete[] tmpvar;

    PutLhsVar();

    return 0;
}
Example #29
0
/*--------------------------------------------------------------------------*/
int sci_delete(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    long long* l1 = NULL;
    int* piAddrl2 = NULL;
    char* l2 = NULL;

    int m1 = 0, n1 = 0, lw = 0;
    unsigned long hdl = 0;
    int nb_handles = 0, i = 0, dont_overload = 0;
    int iObjUID = 0;
    int iFigureUID = 0;
    int* piChildrenUID = NULL;
    int iChildrenCount = 0;
    int* childrencount = &iChildrenCount;
    int iHidden = 0;
    int *piHidden = &iHidden;

    int iParentUID = 0;
    int* piParentUID = &iParentUID;
    int iParentType = -1;
    int *piParentType = &iParentType;
    int iObjType = -1;
    int *piObjType = &iObjType;

    CheckInputArgument(pvApiCtx, 0, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if (nbInputArgument(pvApiCtx) == 0)               /* Delete current object */
    {
        iObjUID = getCurrentObject();
        if (iObjUID == 0)
        {
            //No current object, we can leave
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }

        hdl = (unsigned long)getHandle(iObjUID);
        dont_overload = 1;
        nb_handles = 1;
    }
    else
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        switch (getInputArgumentType(pvApiCtx, 1))
        {
            case sci_matrix:
            {
                if (isEmptyMatrix(pvApiCtx, piAddrl1))
                {
                    AssignOutputVariable(pvApiCtx, 1) = 0;
                    ReturnArguments(pvApiCtx);
                    return 1;
                }
                else
                {
                    Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                    return 1;
                }
                break;
            }
            case sci_handles:      /* delete Entity given by a handle */

                // Retrieve a matrix of handle at position 1.
                sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &m1, &n1, &l1); /* Gets the Handle passed as argument */
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                    return 1;
                }

                nb_handles = m1 * n1;

                if (nbInputArgument(pvApiCtx) == 2)
                {
                    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        return 1;
                    }

                    // Retrieve a matrix of double at position 2.
                    if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))   /* Gets the command name */
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
                        return 1;
                    }
                }
                hdl = (unsigned long) * (l1); /* Puts the value of the Handle to hdl */
                break;
            case sci_strings:      /* delete("all") */
                CheckInputArgument(pvApiCtx, 1, 1);
                sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl2);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                // Retrieve a matrix of double at position 1.
                if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                    return 1;
                }

                if (strcmp((l2), "all") == 0)
                {
                    int i = 0;
                    int iFigureNumber = sciGetNbFigure();

                    if (iFigureNumber == 0)
                    {
                        //no graphic windows, we can leave
                        AssignOutputVariable(pvApiCtx, 1) = 0;
                        ReturnArguments(pvApiCtx);
                        return 0;
                    }

                    iFigureUID = getCurrentFigure();

                    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&childrencount);

                    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);

                    for (i = 0; i < childrencount[0]; ++i)
                    {
                        getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
                        if (iHidden == 0)
                        {
                            deleteGraphicObject(piChildrenUID[i]);
                        }
                    }
                    /*
                     * Clone a new Axes object using the Axes model which is then
                     * attached to the 'cleaned' Figure.
                     */
                    cloneAxesModel(iFigureUID);

                    AssignOutputVariable(pvApiCtx, 1) = 0;
                    ReturnArguments(pvApiCtx);

                    return 0;
                }
                else
                {
                    Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 1, "all");
                    return 0;
                }
                break;
            default:
                // Overload
                lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
                C2F(overload) (&lw, "delete", 6);
                return 0;
        }
    }

    for (i = 0; i < nb_handles; i++)
    {
        int iTemp = 0;
        if (nbInputArgument(pvApiCtx) != 0)
        {
            hdl = (unsigned long) * (l1 + i); /* Puts the value of the Handle to hdl */
        }

        iObjUID = getObjectFromHandle(hdl);

        if (iObjUID == 0)
        {
            Scierror(999, _("%s: The handle is not valid.\n"), fname);
            return 0;
        }

        if (isFigureModel(iObjUID) || isAxesModel(iObjUID))
        {
            Scierror(999, _("This object cannot be deleted.\n"));
            return 0;
        }

        /* Object type */
        getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **)&piObjType);
        if (iObjType == __GO_AXES__)
        {
            /* Parent object */
            iParentUID = getParentObject(iObjUID);
            /* Parent type */
            getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
        }

        if (iObjType == __GO_LABEL__)
        {
            Scierror(999, _("A Label object cannot be deleted.\n"));
            return 0;
        }

        //bug #11485 : duplicate pobjUID before delete it.
        iTemp = iObjUID;
        deleteGraphicObject(iObjUID);

        /*
         ** All figure must have at least one axe child.
         ** If the last one is removed, add a new default one.
         */
        if (iObjType == __GO_AXES__ && iParentType == __GO_FIGURE__)
        {
            int iChild = 0;
            int iChildCount = 0;
            int *piChildCount = &iChildCount;
            char **pstChildren = NULL;
            int iChildType = -1;
            int *piChildType = &iChildType;
            int iAxesFound = 0;
            int iDefaultAxes = -1;
            int *piDefaultAxes = &iDefaultAxes;

            getGraphicObjectProperty(iParentUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&piChildCount);
            getGraphicObjectProperty(iParentUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);
            getGraphicObjectProperty(iParentUID, __GO_DEFAULT_AXES__, jni_bool, (void **)&piDefaultAxes);

            for (iChild = 0; iChild < iChildCount; iChild++)
            {
                getGraphicObjectProperty(piChildrenUID[iChild], __GO_TYPE__, jni_int, (void **)&piChildType);
                if (iChildType == __GO_AXES__)
                {
                    if (getCurrentSubWin() == iTemp) // Current axes has been deleted
                    {
                        setCurrentSubWin(piChildrenUID[iChild]);
                    }
                    iAxesFound = 1;
                    break;
                }
            }
            if (!iAxesFound && iDefaultAxes != 0)
            {

                /*
                 * Clone a new Axes object using the Axes model which is then
                 * attached to the newly created Figure.
                 */
                cloneAxesModel(iParentUID);
            }
        }
    }

    if (!dont_overload)
    {
        // Overload
        lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
        C2F(overload) (&lw, "delete", 6);
    }
    else
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
    }

    if (l2)
    {
        freeAllocatedSingleString(l2);
    }

    return 0;
}
int sci_hdf5_load_v2(char *fn, int* pvApiCtx)
{
    SciErr sciErr;

    int* piAddr = NULL;
    char* pstFilename = NULL;
    char* pstExpandedFilename = NULL;
    bool bImport = true;
    const int nbIn = nbInputArgument(pvApiCtx);
    int iSelectedVar = nbIn - 1;

    CheckInputArgumentAtLeast(pvApiCtx , 1);
    CheckOutputArgument(pvApiCtx, 1, 1);

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

    if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFilename))
    {
        if (pstFilename)
        {
            freeAllocatedSingleString(pstFilename);
        }

        Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname.data(), 2);
        return 1;
    }

    //open hdf5 file
    pstExpandedFilename = expandPathVariable(pstFilename);
    int iFile = openHDF5File(pstExpandedFilename, 0);
    if (iFile < 0)
    {
        Scierror(999, _("%s: Unable to open file: %s\n"), fname.data(), pstFilename);
        FREE(pstExpandedFilename);
        FREE(pstFilename);
        return 1;
    }

    FREE(pstExpandedFilename);
    FREE(pstFilename);

    //manage version information
    int iVersion = getSODFormatAttribute(iFile);
    if (iVersion != SOD_FILE_VERSION)
    {
        if (iVersion > SOD_FILE_VERSION)
        {
            //can't read file with version newer that me !
            Scierror(999, _("%s: Wrong SOD file format version. Max Expected: %d Found: %d\n"), fname.data(), SOD_FILE_VERSION, iVersion);
            return 1;
        }
        else
        {
            //call older import functions and exit or ... EXIT !
            if (iVersion == 1 || iVersion == -1)
            {
                return sci_hdf5_load_v1(fn, pvApiCtx);
            }
        }
    }

    std::vector<wchar_t*> varList;
    if (iSelectedVar)
    {
        //selected variable
        char* pstVarName = NULL;
        for (int i = 0 ; i < iSelectedVar ; i++)
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, i + 2, &piAddr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName))
            {
                if (pstVarName)
                {
                    freeAllocatedSingleString(pstVarName);
                }

                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname.data(), i + 1);
                return 1;
            }

            if (import_variable(pvApiCtx, iFile, pstVarName) == false)
            {
                FREE(pstVarName);
                bImport = false;
                break;
            }

            varList.push_back(to_wide_string(pstVarName));
            FREE(pstVarName);
            pstVarName = NULL;
        }
    }
    else
    {
        //all variables
        int iNbItem = 0;
        iNbItem = getVariableNames(iFile, NULL);
        if (iNbItem != 0)
        {
            char **pstVarNameList = (char **)MALLOC(sizeof(char *) * iNbItem);

            iNbItem = getVariableNames(iFile, pstVarNameList);

            //import all data
            for (int i = 0; i < iNbItem; i++)
            {
                if (import_variable(pvApiCtx, iFile, pstVarNameList[i]) == false)
                {
                    bImport = false;
                    break;
                }

                varList.push_back(to_wide_string(pstVarNameList[i]));
            }

            freeArrayOfString(pstVarNameList, iNbItem);
        }
    }
    //close the file
    closeHDF5File(iFile);

    if (bImport == true && varList.size() != 0)
    {
        createMatrixOfWideString(pvApiCtx, nbIn + 1, 1, static_cast<int>(varList.size()), varList.data());
    }
    else
    {
        createEmptyMatrix(pvApiCtx, nbIn + 1);
    }

    for (auto & i : varList)
    {
        FREE(i);
    }

    AssignOutputVariable(pvApiCtx, 1) = nbIn + 1;
    ReturnArguments(pvApiCtx);

    //  printf("End gateway !!!\n");
    return 0;
}