Exemplo n.º 1
0
// =============================================================================
static int getNumbersOfColumnsInLines(const char **lines, int sizelines,
                                      const char *separator)
{
    int previousNbColumns = 0;
    int NbColumns = 0;
    BOOL firstLine = TRUE;
    if (lines)
    {
        int i = 0;
        for (i = 0; i < sizelines; i++)
        {
            NbColumns = getNumbersOfColumnsInLine(lines[i], separator);
            if (firstLine)
            {
                previousNbColumns = NbColumns;
                firstLine = FALSE;
            }
            else
            {
                if (previousNbColumns != NbColumns)
                {
                    Sciwarning(_("%s: Inconsistency found in the columns. At line %d, found %d columns while the previous had %d.\n"), _("Warning"), i + 1, NbColumns, previousNbColumns);
                    return 0;
                }
            }
        }
    }
    return NbColumns;
}
/*------------------------------------------------------------------------*/
int set_color_range_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    int values[2];
    int nbColors = 0;

    if (valueType != sci_matrix)
    {
        Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "color_range");
        return SET_PROPERTY_ERROR;
    }

    if (nbRow * nbCol != 2)
    {
        Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "color_range", 2);
        return SET_PROPERTY_ERROR;
    }

    copyDoubleVectorToIntFromStack(_pvData, values, 2);
    /* Returns the number of colors of pobj's parent Figure */
    nbColors = sciGetNumColors(iObjUID);

    if (  values[0] > nbColors || values[0] < 0
            || values[1] > nbColors || values[1] < 0)
    {
        /* It is possible to set color_range outside the colormap, however it won't be used.*/
        Sciwarning(_("WARNING: Wrong value for '%s' property: indices outside the colormap will be clamped.\n"), "color_range");
    }

    status = setGraphicObjectProperty(iObjUID, __GO_COLOR_RANGE__, values, jni_int_vector, 2);

    if (status == TRUE)
    {
        return SET_PROPERTY_SUCCEED;
    }
    else
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "color_range");
        return SET_PROPERTY_ERROR;
    }
}
Exemplo n.º 3
0
int sci_umf_lufact(char* fname, void* pvApiCtx)
{
    SciErr sciErr;
    int stat = 0;
    SciSparse AA;
    CcsSparse A;

    int mA              = 0; // rows
    int nA              = 0; // cols
    int iNbItem         = 0;
    int* piNbItemRow    = NULL;
    int* piColPos       = NULL;
    double* pdblSpReal  = NULL;
    double* pdblSpImg   = NULL;

    /* umfpack stuff */
    double* Control = NULL;
    double* Info    = NULL;
    void* Symbolic  = NULL;
    void* Numeric   = NULL;

    int* piAddr1 = NULL;
    int iComplex = 0;
    int iType1   = 0;

    /* Check numbers of input/output arguments */
    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 1, 1);

    /* get A the sparse matrix to factorize */
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    /* check if the first argument is a sparse matrix */
    sciErr = getVarType(pvApiCtx, piAddr1, &iType1);
    if (sciErr.iErr || iType1 != sci_sparse)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Wrong type for input argument #%d: A sparse matrix expected.\n"), fname, 1);
        return 1;
    }

    if (isVarComplex(pvApiCtx, piAddr1))
    {
        iComplex = 1;
        sciErr = getComplexSparseMatrix(pvApiCtx, piAddr1, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal, &pdblSpImg);
    }
    else
    {
        sciErr = getSparseMatrix(pvApiCtx, piAddr1, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal);
    }

    if (sciErr.iErr)
    {
        FREE(piNbItemRow);
        FREE(piColPos);
        FREE(pdblSpReal);
        if (pdblSpImg)
        {
            FREE(pdblSpImg);
        }
        printError(&sciErr, 0);
        return 1;
    }

    // fill struct sparse
    AA.m     = mA;
    AA.n     = nA;
    AA.it    = iComplex;
    AA.nel   = iNbItem;
    AA.mnel  = piNbItemRow;
    AA.icol  = piColPos;
    AA.R     = pdblSpReal;
    AA.I     = pdblSpImg;

    if (nA <= 0 || mA <= 0)
    {
        FREE(piNbItemRow);
        FREE(piColPos);
        FREE(pdblSpReal);
        if (pdblSpImg)
        {
            FREE(pdblSpImg);
        }
        Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, 1);
        return 1;
    }

    SciSparseToCcsSparse(&AA, &A);

    FREE(piNbItemRow);
    FREE(piColPos);
    FREE(pdblSpReal);
    if (pdblSpImg)
    {
        FREE(pdblSpImg);
    }

    /* symbolic factorization */
    if (A.it == 1)
    {
        stat = umfpack_zi_symbolic(nA, mA, A.p, A.irow, A.R, A.I, &Symbolic, Control, Info);
    }
    else
    {
        stat = umfpack_di_symbolic(nA, mA, A.p, A.irow, A.R, &Symbolic, Control, Info);
    }

    if (stat != UMFPACK_OK)
    {
        freeCcsSparse(A);
        Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("symbolic factorization"), UmfErrorMes(stat));
        return 1;
    }

    /* numeric factorization */
    if (A.it == 1)
    {
        stat = umfpack_zi_numeric(A.p, A.irow, A.R, A.I, Symbolic, &Numeric, Control, Info);
    }
    else
    {
        stat = umfpack_di_numeric(A.p, A.irow, A.R, Symbolic, &Numeric, Control, Info);
    }

    if (A.it == 1)
    {
        umfpack_zi_free_symbolic(&Symbolic);
    }
    else
    {
        umfpack_di_free_symbolic(&Symbolic);
    }

    if ( stat != UMFPACK_OK  &&  stat != UMFPACK_WARNING_singular_matrix )
    {
        freeCcsSparse(A);
        Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("symbolic factorization"), UmfErrorMes(stat));
        return 1;
    }

    if ( stat == UMFPACK_WARNING_singular_matrix  &&  mA == nA )
    {
        if (getWarningMode())
        {
            Sciwarning("\n%s:%s\n", _("Warning"), _("The (square) matrix appears to be singular."));
        }
    }

    /*  add the pointer in the list ListNumeric  */
    if (! AddAdrToList(Numeric, A.it, &ListNumeric))
    {
        /* AddAdrToList return 0 if malloc have failed : as it is just
        for storing 2 pointers this is unlikely to occurs but ... */
        if (A.it == 1)
        {
            umfpack_zi_free_numeric(&Numeric);
        }
        else
        {
            umfpack_di_free_numeric(&Numeric);
        }

        freeCcsSparse(A);
        Scierror(999, _("%s: An error occurred: %s\n"), fname, _("no place to store the LU pointer in ListNumeric."));
        return 1;
    }

    freeCcsSparse(A);

    /* create the scilab object to store the pointer onto the LU factors */
    sciErr = createPointer(pvApiCtx, 2, Numeric);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    /* return the pointer */
    AssignOutputVariable(pvApiCtx, 1) = 2;
    ReturnArguments(pvApiCtx);
    return 0;
}
Exemplo n.º 4
0
/**
 * Older generic interface to DCDLIB's cdf functions.
 * @param fname scilab caller's function name
 * @param inarg number of inputs to the scilab call
 * @param oarg number of outputs begged by the scilab call
 * @param shift tells how much arglist has to be shifted in DCDFLIB funcall
 * @param which of the arguments is to be deduced from the others
 * @param fun actual computation function
 * @return error code
 */
int CdfBase(char const * const fname, void* pvApiCtx, int inarg, int oarg, int shift, int which, int (*fun)(int*, ...))
{
#define MAXARG 6
    double *data[MAXARG];
    int rows[MAXARG], cols[MAXARG];
#undef MAXARG

    double bound = 0;
    int errlevel = 0;
    int i = 0;
    int *p = NULL;
    int siz = strlen(fname);
    int *df;
    int row, col;
    double *datas;
    int resc;
    int pos = 0;
    int pos1 = 0;

    char *option = create_string(pvApiCtx, 1);

    if ( Rhs != inarg + 1 )
    {
        Scierror(999, _("%s: Wrong number of input argument(s): %d expected.\n"), fname, inarg + 1);
        return 1;
    }

    for (i = 0; i < inarg; ++i)
    {
        int j = 0;
        getVarAddressFromPosition(pvApiCtx, i + 2, &p);
        getMatrixOfDouble(pvApiCtx, p, &rows[i], &cols[i], &data[i]);
    }

    for (i = 1; i < inarg ; ++i)
    {
        if (rows[i] != rows[i - 1] || cols[i] != cols[i - 1])
        {
            Scierror(999, _("%s: Incompatible input arguments #%d and #%d': Same sizes expected.\n"), fname, i + 1, i + 2);
            return 1;
        }
    }

    for (i = 0; i < oarg; ++i)
    {
        allocMatrixOfDouble(pvApiCtx, Rhs + i + 1, rows[0], cols[0], &data[i + inarg]);
    }

    //check which scilab function is called
    switch (siz)
    {
    case 4:
        //cdff
        if (fname[3] == 'f')
        {
            if (strcmp(option, "PQ") == 0)
            {
                pos = 3;
                pos1 = 4;
            }
            else if (strcmp(option, "F") == 0)
            {
                pos = 2;
                pos1 = 3;
            }
            else if (strcmp(option, "Dfn") == 0)
            {
                pos = 2;
            }
            else if (strcmp(option, "Dfd") == 0)
            {
                pos = 5;
            }
        }
        //cdft
        else
        {
            if (strcmp(option, "PQ") == 0)
            {
                pos = 3;
            }
            else if (strcmp(option, "T") == 0)
            {
                pos = 2;
            }
        }
        break;
    case 6 :
        //cdfbet
        if (fname[4] == 'e')
        {

        }
        //cdfbin
        else if (fname[4] == 'i')
        {

        }
        //cdffnc
        else if (fname[4] == 'n')
        {
            if (strcmp(option, "PQ") == 0)
            {
                pos = 3;
                pos1 = 4;
            }
            else if (strcmp(option, "F") == 0)
            {
                pos = 2;
                pos1 = 3;
            }
            else if (strcmp(option, "Dfn") == 0)
            {
                pos = 2;
            }
            else if (strcmp(option, "Dfd") == 0)
            {
                pos = 6;
            }
            else if (strcmp(option, "Pnonc") == 0)
            {
                pos = 5;
                pos1 = 6;
            }
        }
        //cdfgam
        else if (fname[4] == 'a')
        {

        }
        //cdfnbn
        else if (fname[4] == 'b')
        {

        }
        else if (fname[4] == 'h')
        {
            //cdfchi
            if (fname[5] == 'i')
            {
                if (strcmp(option, "PQ") == 0)
                {
                    pos = 3;
                }
                else if (strcmp(option, "X") == 0)
                {
                    pos = 2;
                }
            }
            //cdfchn
            else
            {
                if (strcmp(option, "PQ") == 0)
                {
                    pos = 3;
                }
                else if (strcmp(option, "X") == 0)
                {
                    pos = 2;
                }
                else if (strcmp(option, "Pnonc") == 0)
                {
                    pos = 5;
                }
            }
        }
        else
        {
            //cdfnor
            if (fname[5] == 'r')
            {

            }
            //cdfpoi
            else
            {

            }
        }
        break;
    }

    if (pos != 0)
    {
        getVarAddressFromPosition(pvApiCtx, pos, &df);
        getMatrixOfDouble(pvApiCtx, df, &row, &col, &datas);
        resc = checkInteger(row, col, datas, pos, fname);
        if (resc == 1)
        {
            Sciwarning(_("%s: Warning: using non integer values for argument #%d may lead to incorrect results.\n"), fname, pos);
        }
    }
    if (pos1 != 0)
    {
        getVarAddressFromPosition(pvApiCtx, pos1, &df);
        getMatrixOfDouble(pvApiCtx, df, &row, &col, &datas);
        resc = checkInteger(row, col, datas, pos1, fname);
        if (resc == 1)
        {
            Sciwarning(_("%s: Warning: using non integer values for argument #%d may lead to incorrect results.\n"), fname, pos1);
        }
    }
#define callpos(i) rotate(i, shift, inarg + oarg)
    for (i = 0; i < rows[0] * cols[0]; ++i)
    {
        switch (inarg + oarg)
        {
        case 4: /* cdfchi, cdfpoi, cdft */
            (*fun)(&which, &(data[callpos(0)][i]), &(data[callpos(1)][i]), &(data[callpos(2)][i]), &(data[callpos(3)][i]), &errlevel, &bound);
            break;
        case 5: /* cdfchn, cdff, cdfgam, cdfnor */
            (*fun)(&which, &(data[callpos(0)][i]), &(data[callpos(1)][i]), &(data[callpos(2)][i]), &(data[callpos(3)][i]), &(data[callpos(4)][i]), &errlevel, &bound);
            break;
        case 6: /* cdfbet, cdfbin, cdffnc, cdfnbn, */
            (*fun)(&which, &(data[callpos(0)][i]), &(data[callpos(1)][i]), &(data[callpos(2)][i]), &(data[callpos(3)][i]), &(data[callpos(4)][i]), &(data[callpos(5)][i]), &errlevel, &bound);
            break;
        }
        if (errlevel != 0)
        {
            cdf_error(fname, errlevel, bound);
            return 1;
        }
    }
#undef callpos
    for (i = 0; i < oarg; ++i)
    {
        LhsVar(i + 1) = Rhs + i + 1;
    }

    PutLhsVar();
    return 0;
}
Exemplo n.º 5
0
/*
 * This function has been updated for the MVC (property get calls).
 * Its code ought to be put within the Java part of the Model.
 */
int ComputeXIntervals(int iObjUID, char xy_type, double ** vector, int * N, int checkdim)
{
    int i = 0;
    double* val = NULL; /* represents the x or y ticks coordinates */
    int nval = 0;

    int n = 0;
    int nx = 0;
    int* piNx = &nx;
    int ny = 0;
    int* piNy = &ny;
    BOOL ishoriz = FALSE;

    getGraphicObjectProperty(iObjUID, __GO_X_NUMBER_TICKS__, jni_int, (void **)&piNx);
    getGraphicObjectProperty(iObjUID, __GO_Y_NUMBER_TICKS__, jni_int, (void **)&piNy);

    /* draw an horizontal axis : YES (horizontal axis) or NO (vertical axis) */
    ishoriz = (nx > ny) ? TRUE : FALSE;

    if (ishoriz == TRUE)
    {
        getGraphicObjectProperty(iObjUID, __GO_X_TICKS_COORDS__, jni_double_vector, (void **)&val);
        nval = nx;
    }
    else
    {
        getGraphicObjectProperty(iObjUID, __GO_Y_TICKS_COORDS__, jni_double_vector, (void **)&val);
        nval = ny;
    }

    if (!val)
    {
        Scierror(999, _("%s: Cannot get coordinates.\n"), "ComputeXIntervals");
        return -1;
    }

    if (xy_type == 'v')
    {
        *N = n = nval;

        if ((*vector = (double *) MALLOC(n * sizeof(double))) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "ComputeXIntervals");
            return -1;
        }

        for (i = 0; i < n; i++)
        {
            (*vector)[i] = val[i];
        }
    }
    else if (xy_type == 'r')
    {
        double step = 0;

        *N = n = (int)val[2] + 1; /* intervals number is given by  ppaxes->x or ppaxes->y */

        if (checkdim)
        {
            if (nval != 3)
            {
                Sciwarning(_("Warning: %s must be changed, %s is '%s' and %s dimension is not %d.\n"), "tics_coord", "xy_type", "r", "tics_coord", 3);
            }

            if (nval < 3)
            {
                Scierror(999, _("%s must be changed FIRST, %s is '%s' and %s dimension < %d.\n"), "tics_coord", "xy_type", "r", "tics_coord", 3);
                *vector = (double *) NULL;
                return -1;
            }
        }

        if ((*vector = (double *) MALLOC(n * sizeof(double))) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "ComputeXIntervals");
            return -1;
        }

        step = (val[1] - val[0]) / (n - 1);

        for (i = 0; i < n - 1; i++)
        {
            (*vector)[i] = val[0] + i * step;
        }

        (*vector)[n - 1] = val[1]; /* xmax */

    }
    else if (xy_type == 'i')
    {
        double step = 0;

        *N = n = (int)val[3] + 1;

        if (checkdim)
        {
            if (nval != 4)
            {
                Sciwarning(_("Warning: %s must be changed, %s is '%s' and %s dimension is not %d.\n"), "tics_coord", "xy_type", "i", "tics_coord", 4);
            }

            if (nval < 4)
            {
                Scierror(999, _("%s must be changed FIRST, %s is '%s' and %s dimension < %d.\n"), "tics_coord", "xy_type", "i", "tics_coord", 4);
                *vector = (double *) NULL;
                return -1;
            }
        }

        if ((*vector = (double *)  MALLOC(n * sizeof(double))) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "ComputeXIntervals");
            return -1;
        }

        step = (val[1] * exp10(val[2]) - val[0] * exp10(val[2])) / val[3];


        for (i = 0; i < n - 1; i++)
        {
            (*vector)[i] = val[0] * exp10(val[2]) + i * step;
        }

        (*vector)[n - 1] = val[1] * exp10(val[2]); /* xmax */

    }

    return 0;
}
Exemplo n.º 6
0
int C2F(xgray)(double *x, double *y, double *z, int *n1, int *n2, char *strflag, double *brect, int *aaint, BOOL flagNax, char *logflags, long int l1)
{
    int iSubwinUID = 0;
    int iGrayplotUID = 0;
    double xx[2], yy[2];
    int nn1 = 1, nn2 = 2;
    double drect[6];
    BOOL bounds_changed = FALSE;
    BOOL isRedrawn = FALSE;
    BOOL axes_properties_changed = FALSE;

    char textLogFlags[3];
    double rotationAngles[2];
    int clipState = 0;
    int autoScale = 0;
    int firstPlot = 0;
    int logFlags[3];
    char dataflag = 0;
    int autoSubticks = 0;

    int iTmp = 0;
    int* piTmp = &iTmp;

    xx[0] = Mini(x, *n1);
    xx[1] = Maxi(x, *n1);
    yy[0] = Mini(y, *n2);
    yy[1] = Maxi(y, *n2);

    /* Adding F.Leray 22.04.04 */
    iSubwinUID = getCurrentSubWin();

    isRedrawn = checkRedrawing();

    rotationAngles[0] = 0.0;
    rotationAngles[1] = 270.0;

    setGraphicObjectProperty(iSubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2);

    /* Force "cligrf" clipping (1) */
    clipState = 1;
    setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

    getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piTmp);
    firstPlot = iTmp;

    getGraphicObjectProperty(iSubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piTmp);
    autoScale = iTmp;

    /* Reset x and y logflags */
    if (firstPlot)
    {
        logFlags[0] = getBooleanLogFlag(logflags[1]);
        logFlags[1] = getBooleanLogFlag(logflags[2]);

        setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, &logFlags[0], jni_bool, 1);
        setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, &logFlags[1], jni_bool, 1);
    }

    if (autoScale)
    {
        /* compute and merge new specified bounds with the data bounds */
        switch (strflag[1])
        {
            case '0':
                /* do not change data bounds */
                break;
            case '1' :
            case '3' :
            case '5' :
            case '7':
                /* Force data bounds=brect */
                re_index_brect(brect, drect);
                break;
            case '2' :
            case '4' :
            case '6' :
            case '8':
            case '9':
                /* Force data bounds to the x and y bounds */
                if ((int)strlen(logflags) < 1)
                {
                    dataflag = 'g';
                }
                else
                {
                    dataflag = logflags[0];
                }

                getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[0] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[1] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[2] = iTmp;

                /* Conversion required by compute_data_bounds2 */
                textLogFlags[0] = getTextLogFlag(logFlags[0]);
                textLogFlags[1] = getTextLogFlag(logFlags[1]);
                textLogFlags[2] = getTextLogFlag(logFlags[2]);

                /* Force data bounds to the x and y bounds */
                compute_data_bounds2(0, dataflag, textLogFlags, xx, yy, nn1, nn2, drect);
                break;
        }

        /* merge data bounds and drect */
        if (!firstPlot && (strflag[1] == '7' || strflag[1] == '8'))
        {
            double* dataBounds;
            getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);

            drect[0] = Min(dataBounds[0], drect[0]); /*xmin*/
            drect[2] = Min(dataBounds[2], drect[2]); /*ymin*/
            drect[1] = Max(dataBounds[1], drect[1]); /*xmax*/
            drect[3] = Max(dataBounds[3], drect[3]); /*ymax*/
        }

        if (strflag[1] != '0')
        {
            bounds_changed = update_specification_bounds(iSubwinUID, drect, 2);
        }
    }

    if (firstPlot)
    {
        bounds_changed = TRUE;
    }

    axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag);

    firstPlot = 0;
    setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);

    /* F.Leray 07.10.04 : trigger algo to init. manual graduation u_xgrads and
    u_ygrads if nax (in matdes.c which is == aaint HERE) was specified */

    /* The MVC AUTO_SUBTICKS property corresponds to !flagNax */
    autoSubticks = !flagNax;
    setGraphicObjectProperty(iSubwinUID, __GO_AUTO_SUBTICKS__, &autoSubticks, jni_bool, 1);

    if (flagNax == TRUE)
    {
        if (logFlags[0] == 0 && logFlags[1] == 0)
        {
            int autoTicks;

            autoTicks = 0;
            setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
        }
        else
        {
            Sciwarning(_("Warning: Nax does not work with logarithmic scaling.\n"));
        }
    }

    /* Constructs the object */
    iGrayplotUID = ConstructGrayplot(getCurrentSubWin(), x, y, z, *n1, *n2, 0);

    /* Failed allocation */
    if (iGrayplotUID == 0)
    {
        Scierror(999, _("%s: No more memory.\n"), "grayplot");
        return -1;
    }

    /* Sets the grayplot as current */
    setCurrentObject(iGrayplotUID);

    return (0);
}