Example #1
0
/**
 * retrieve the labels from the command line and store them into labels
 */
int get_labels_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** labels)
{
    int first_opt = FirstOpt(), kopt;

    if (pos < first_opt)
    {
        int* piAddr = 0;
        int iType = 0;
        char* pstData = NULL;
        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
        getVarType(_pvCtx, piAddr, &iType);

        if (iType)
        {
            getAllocatedSingleString(_pvCtx, piAddr, &pstData);
            *labels = pstData;
        }
        else
        {
            /* jb silvy 03/2006 */
            /* do not change the legend if one already exists */
            char * pSubWinUID = (char*)getOrCreateDefaultSubwin();
            if (sciGetLegendDefined(pSubWinUID))
            {
                *labels = NULL;
            }
            else
            {
                *labels = getDefLegend();
            }
        }
    }
    else if ((kopt = FindOpt("leg", opts)))
    {
        int* piAddr = 0;
        char* pstData = NULL;
        getVarAddressFromPosition(_pvCtx, kopt, &piAddr);
        getAllocatedSingleString(_pvCtx, piAddr, &pstData);
        *labels = pstData;
    }
    else
    {
        /* jb silvy 03/2006 */
        /* do not change the legend if one already exists */
        char* pSubWinUID = (char*)getOrCreateDefaultSubwin();

        if (sciGetLegendDefined(pSubWinUID))
        {
            *labels = NULL;
        }
        else
        {
            *labels = getDefLegend();
        }
    }
    return 1;
}
Example #2
0
/**
 * retrieve the labels from the command line and store them into labels
 */
int get_labels_arg(char *fname, int pos, rhs_opts opts[], char ** labels)
{
    int m,n,l,first_opt=FirstOpt(),kopt;

    if (pos < first_opt)
    {
        if (VarType(pos))
        {
            GetRhsVar(pos,STRING_DATATYPE, &m, &n, &l);
            *labels = cstk(l);
        }
        else
        {
            /* jb silvy 03/2006 */
            /* do not change the legend if one already exists */
            char * pSubWinUID = getOrCreateDefaultSubwin();
            if (sciGetLegendDefined(pSubWinUID))
            {
                *labels = NULL;
            }
            else
            {
                *labels = getDefLegend();
            }
        }
    }
    else if ((kopt=FindOpt("leg",opts)))
    {
        GetRhsVar(kopt,STRING_DATATYPE, &m, &n, &l);
        *labels = cstk(l);
    }
    else
    {
        /* jb silvy 03/2006 */
        /* do not change the legend if one already exists */
        char* pSubWinUID = getOrCreateDefaultSubwin();

        if (sciGetLegendDefined(pSubWinUID))
        {
            *labels = NULL;
        }
        else
        {
            *labels = getDefLegend();
        }
    }
    return 1;
}
Example #3
0
/*--------------------------------------------------------------------------*/
int xgetg(char * str, char * str1, int * len, int  lx0, int lx1)
{
    if (strcmp(str, "fpf") == 0)
    {
        strncpy(str1, getFPF(), 32);
        *len = (int) strlen(str1);
    }
    else if (strcmp(str, "auto clear") == 0)
    {
        int iAutoClear = 0;
        int* piAutoClear = &iAutoClear;

        getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTO_CLEAR__, jni_bool, (void **)&piAutoClear);
        if (iAutoClear == 1)
        {
            strncpy(str1, "on", 2);
            *len = 2;
        }
        else
        {
            strncpy(str1, "off", 3);
            *len = 3;
        }
    }
    return 0;
}
Example #4
0
/*--------------------------------------------------------------------------*/
int setDefaultProperties(int _iFig, BOOL _bDefaultAxes)
{
    //get figure axes
    int iAxes = -1;
    int iDrawing = 0;
    int iColorIndex = 0;
    int iFilled = 0;
    int iAxesVisible = 0;
    int* piAxesSize = NULL;
    double pdblNewColor[COLOR_COMPONENT] = {0.8, 0.8, 0.8};

    iColorIndex = addColor(_iFig, pdblNewColor);

    setGraphicObjectProperty(_iFig, __GO_BACKGROUND__, &iColorIndex, jni_int, 1);
    if (_bDefaultAxes)
    {
        iAxes = getOrCreateDefaultSubwin();
        //set background in figure and axes to new ( or existting ) color
        setGraphicObjectProperty(iAxes, __GO_BACKGROUND__, &iColorIndex, jni_int, 1);

        //a.filled = "off"
        setGraphicObjectProperty(iAxes, __GO_FILLED__, &iFilled, jni_bool, 1);

        //a.axes_visible = "off"
        setGraphicObjectProperty(iAxes, __GO_X_AXIS_VISIBLE__, &iAxesVisible, jni_bool, 1);
        setGraphicObjectProperty(iAxes, __GO_Y_AXIS_VISIBLE__, &iAxesVisible, jni_bool, 1);
        setGraphicObjectProperty(iAxes, __GO_Z_AXIS_VISIBLE__, &iAxesVisible, jni_bool, 1);
    }

    return iAxes;
}
Example #5
0
/*--------------------------------------------------------------------------*/
int sci_xfarcs(char *fname, unsigned long fname_len)
{
    int m1 = 0, n1 = 0, l1 = 0;
    int m2 = 0, n2 = 0, l2 = 0;

    long hdl = 0;

    int i = 0;

    double angle1 = 0.0;
    double angle2 = 0.0;

    CheckRhs(1, 2);

    GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);
    if (m1 != 6)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %s expected.\n"), fname, 1, "(6,n)");
        return 0;
    }

    if (Rhs == 2)
    {
        GetRhsVar(2, MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2);
        CheckVector(2, m2, n2);
        if (n1 != m2 * n2)
        {
            Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2);
            return 0;
        }
    }
    else
    {
        m2 = 1;
        n2 = n1;
        CreateVar(2, MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2);
        for (i = 0; i < n2; ++i)
        {
            *istk(l2 + i) = i + 1;
        }
    }

    getOrCreateDefaultSubwin();

    for (i = 0; i < n1; ++i)
    {
        angle1 = DEG2RAD(*stk(l1 + (6 * i) + 4) / 64.0);
        angle2 = DEG2RAD(*stk(l1 + (6 * i) + 5) / 64.0);
        Objarc(&angle1, &angle2, stk(l1 + (6 * i)), stk(l1 + (6 * i) + 1),
               stk(l1 + (6 * i) + 2), stk(l1 + (6 * i) + 3), istk(l2 + i), istk(l2 + i), TRUE, FALSE, &hdl);
    }

    /** Construct Compound and make it current object **/
    setCurrentObject(ConstructCompoundSeq(n1));

    LhsVar(1) = 0;
    PutLhsVar();

    return 0;
}
Example #6
0
/*--------------------------------------------------------------------------*/
int sci_xarc(char *fname,unsigned long fname_len)
{
    char* psubwinUID = NULL;
    int m1,n1,l1,l2,l3,l4,l5,l6;
    long hdl;
    int curcolor = 0;
    int *piCurColor = &curcolor;
    double angle1 = 0.0;
    double angle2 = 0.0;


    CheckRhs(6,6);
    GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l1);CheckScalar(1,m1,n1);
    GetRhsVar(2,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l2);CheckScalar(2,m1,n1);
    GetRhsVar(3,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l3);CheckScalar(3,m1,n1);
    GetRhsVar(4,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l4);CheckScalar(4,m1,n1);
    GetRhsVar(5,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l5);CheckScalar(5,m1,n1);
    GetRhsVar(6,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l6);CheckScalar(6,m1,n1);

    angle1 = DEG2RAD(*istk(l5) / 64.0); /* convert to radian */
    angle2 = DEG2RAD(*istk(l6) / 64.0);

    psubwinUID = getOrCreateDefaultSubwin();

    getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, &piCurColor);

    if ( strcmp(fname,"xarc") == 0 )
    {
        Objarc (&angle1,&angle2,stk(l1),stk(l2),stk(l3),stk(l4),&curcolor,NULL,FALSE,TRUE,&hdl);
    }
    else /* xfarc case */
    {
        Objarc (&angle1,&angle2,stk(l1),stk(l2),stk(l3),stk(l4),NULL,&curcolor,TRUE,FALSE,&hdl);
    }

    LhsVar(1)=0;
    PutLhsVar();
    return 0;
}
Example #7
0
/*--------------------------------------------------------------------------*/
int sci_drawlater(char * fname, void* pvApiCtx)
{
    int iFalse =  (int)FALSE;
    int iParentFigureUID = 0;
    int* piParentFigureUID = &iParentFigureUID;
    int iSubwinUID = 0;
    int iCurChildUID = 0;
    int iType = -1;
    int *piType = &iType;

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

    if (nbInputArgument(pvApiCtx) <= 0)
    {
        iSubwinUID = getOrCreateDefaultSubwin();
        if (iSubwinUID != 0)
        {
            // Look for top level figure
            iCurChildUID = iSubwinUID;
            do
            {
                iParentFigureUID = getParentObject(iCurChildUID);
                getGraphicObjectProperty(iParentFigureUID, __GO_TYPE__, jni_int, (void **)&piType);
                iCurChildUID = iParentFigureUID;
            }
            while (iParentFigureUID != 0 && iType != __GO_FIGURE__);

            if (iParentFigureUID != 0)
            {
                setGraphicObjectProperty(iParentFigureUID, __GO_IMMEDIATE_DRAWING__, &iFalse, jni_bool, 1);
            }
        }
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #8
0
/*--------------------------------------------------------------------------*/
int sci_xpolys(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    int* piAddr3 = NULL;
    int* l3 = NULL;

    int m1 = 0, n1 = 0;
    int m2 = 0, n2 = 0;
    int m3 = 0, n3 = 0;

    int i = 0;
    long hdl = 0;

    char *pstFigureUID = NULL;
    char *pstSubWinUID = NULL;
    char *pstCompoundUID = NULL;
    int iFalse = 0;

    int iVisible = 0;
    int *piVisible = &iVisible;

    CheckInputArgument(pvApiCtx, 2, 3);

    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;
    }

    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;
    }

    //CheckSameDims
    if (m1 != m2 || n1 != n2)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }


    if (m1 * n1 == 0 || m2 * n2 == 0)
    {
        /* dimension 0, 0 polyline to draw */
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }
    pstSubWinUID = (char*)getOrCreateDefaultSubwin();
    pstFigureUID = (char*)getCurrentFigure();
    // Create compound.
    pstCompoundUID = createGraphicObject(__GO_COMPOUND__);
    setGraphicObjectProperty(pstCompoundUID, __GO_VISIBLE__, &iFalse, jni_bool, 1);
    /* Sets the parent-child relationship for the Compound */
    setGraphicObjectRelationship(pstSubWinUID, pstCompoundUID);

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

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

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

        //CheckDimProp
        if (m3 * n3 < n1)
        {
            Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
            return 1;
        }

        /* Construct the polylines */
        for (i = 0; i < n1; ++i)
        {
            Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, *(int*)(l3 + i), &hdl);
            // Add newly created object to Compound
            setGraphicObjectRelationship(pstCompoundUID, getObjectFromHandle(hdl));
        }
    }
    else
    {
        for (i = 0; i < n1; ++i)
        {
            Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, 1, &hdl);
            // Add newly created object to Compound
            setGraphicObjectRelationship(pstCompoundUID, getObjectFromHandle(hdl));
        }
    }

    getGraphicObjectProperty(pstFigureUID, __GO_VISIBLE__, jni_bool, (void **)&piVisible);

    setGraphicObjectProperty(pstCompoundUID, __GO_VISIBLE__, &iVisible, jni_bool, 1);

    setCurrentObject(pstCompoundUID);

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #9
0
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_xget(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    double dValue = 0;
    wchar_t* pwcsWhat = NULL;
    void* pvApiCtx = NULL;

    if (in.size() == 0)
    {
        return Overload::call(L"%_xget", in, _iRetCount, out);
    }

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

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

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

    types::String* pStr = in[0]->getAs<types::String>();

    if (pStr->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xget", 1);
        return types::Function::Error;
    }

    pwcsWhat = pStr->get(0);

    if (ConfigGraphicVariable::bPropertyFound(pwcsWhat) == false)
    {
        char* pstWhat = wide_string_to_UTF8(pwcsWhat);
        Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xget", pstWhat);
        FREE(pstWhat);
        return types::Function::Error;
    }

    if (in.size() == 2)
    {
        if (in[1]->isDouble() == false)
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), "xget", 2);
            return types::Function::Error;
        }

        types::Double* pDbl = in[1]->getAs<types::Double>();

        //CheckScalar
        if (pDbl->isScalar())
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), "xget", 2);
            return types::Function::Error;
        }

        dValue = pDbl->get(0);
    }

    switch (ConfigGraphicVariable::getPropertyValue(pwcsWhat))
    {
        case 15 : // fpf
        {
            out.push_back(new types::String(ConfigGraphicVariable::getFPF().c_str()));
        }
        break;
        case 2 : // auto clear
        {
            int iAutoClear = 0;
            int* piAutoClear = &iAutoClear;
            getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTO_CLEAR__, jni_bool, (void **)&piAutoClear);
            if (iAutoClear == 1)
            {
                out.push_back(new types::String(L"on"));
            }
            else
            {
                out.push_back(new types::String(L"off"));
            }
        }
        break;
        case 8 : // colormap
        {
            int iObjUID = 0;
            // Force figure creation if none exists.
            getOrCreateDefaultSubwin();
            iObjUID = getCurrentFigure();

            out.push_back((types::InternalType*)get_color_map_property(pvApiCtx, iObjUID));
        }
        break;
        case 20 : // mark
        {
            int iObjUID = getOrCreateDefaultSubwin();
            int iMarkStyle = 0;
            int* piMarkStyle = &iMarkStyle;
            int iMarkSize = 0;
            int* piMarkSize = &iMarkSize;
            types::Double* pDbl = new types::Double(1, 2);

            getGraphicObjectProperty(iObjUID, __GO_MARK_STYLE__, jni_int, (void**)&piMarkStyle);
            getGraphicObjectProperty(iObjUID, __GO_MARK_SIZE__, jni_int, (void**)&piMarkSize);

            pDbl->set(0, (double)iMarkStyle);
            pDbl->set(1, (double)iMarkSize);
            out.push_back(pDbl);
        }
        break;
        case 21 : // mark size
        {
            int iObjUID = getOrCreateDefaultSubwin();
            out.push_back((types::InternalType*)get_mark_size_property(pvApiCtx, iObjUID));
        }
        break;
        case 19 : // line style
        {
            out.push_back((types::InternalType*)get_line_style_property(pvApiCtx, getOrCreateDefaultSubwin()));
        }
        break;
        case 5 : // clipping
        {
            types::Double* pDblClipBox = new types::Double(1, 4);
            double *clipBox = NULL;
            int iObjUID = getOrCreateDefaultSubwin();
            getGraphicObjectProperty(iObjUID, __GO_CLIP_BOX__, jni_double_vector, (void **)&clipBox);
            memcpy(pDblClipBox->get(), clipBox, 4 * sizeof(double));
            out.push_back(pDblClipBox);
        }
        break;
        case 12 : // font
        {
            int iObjUID = getOrCreateDefaultSubwin();
            double dblFontSize = 0;
            double* pdblFontSize = &dblFontSize;
            int iFontStyle = 0;
            int* piFontStyle = &iFontStyle;
            types::Double* pDbl = new types::Double(1, 2);

            getGraphicObjectProperty(iObjUID, __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize);
            getGraphicObjectProperty(iObjUID, __GO_FONT_STYLE__, jni_int, (void**)&piFontStyle);

            pDbl->set(0, (double)iFontStyle);
            pDbl->set(1, dblFontSize);
            out.push_back(pDbl);
        }
        break;
        case 13 : // font size
        {
            double dblFontSize = 0;
            double* pdblFontSize = &dblFontSize;
            getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize);

            out.push_back(new types::Double(dblFontSize));
        }
        break;
        case 9 : // dashes
        {
            int iLineStyle = 0;
            int* piLineStyle = &iLineStyle;

            getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, jni_int, (void**)&piLineStyle);

            out.push_back(new types::Double((double)iLineStyle));
        }
        break;
        case 16 : // hidden3d
        {
            out.push_back((types::InternalType*)get_hidden_color_property(pvApiCtx, getOrCreateDefaultSubwin()));
        }
        break;
        case 30 : // window
        case 11 : // figure
        {
            int iFigureId = 0;
            int* piFigureId = &iFigureId;

            getOrCreateDefaultSubwin();
            getGraphicObjectProperty(getCurrentFigure(), __GO_ID__, jni_int, (void**)&piFigureId);

            out.push_back(new types::Double((double)iFigureId));
        }
        break;
        case 25 : // thickness
        {
            out.push_back((types::InternalType*)get_thickness_property(pvApiCtx, getOrCreateDefaultSubwin()));
        }
        break;
        case 28 : // wdim
        case 31 : // wpdim
        {
            int *piFigureSize = NULL;
            types::Double* pDblFigureSize = new types::Double(1, 2);

            getOrCreateDefaultSubwin();
            getGraphicObjectProperty(getCurrentFigure(), __GO_SIZE__, jni_int_vector, (void **) &piFigureSize);

            pDblFigureSize->set(0, (double) piFigureSize[0]);
            pDblFigureSize->set(1, (double) piFigureSize[1]);
            out.push_back(pDblFigureSize);
        }
        break;
        case 32 : // wpos
        {
            int *piFigurePosition = NULL;
            types::Double* pDblFigurePos = new types::Double(1, 2);

            getOrCreateDefaultSubwin();
            getGraphicObjectProperty(getCurrentFigure(), __GO_POSITION__, jni_int_vector, (void **) &piFigurePosition);

            pDblFigurePos->set(0, (double) piFigurePosition[0]);
            pDblFigurePos->set(1, (double) piFigurePosition[1]);
            out.push_back(pDblFigurePos);
        }
        break;
        case 27 : // viewport
        {
            int *piViewport = NULL;
            types::Double* pDblViewport = new types::Double(1, 2);

            getOrCreateDefaultSubwin();
            getGraphicObjectProperty(getCurrentFigure(), __GO_VIEWPORT__, jni_int_vector, (void **)&piViewport);

            pDblViewport->set(0, (double) piViewport[0]);
            pDblViewport->set(1, (double) piViewport[1]);
            out.push_back(pDblViewport);
        }
        break;
        case 3 : // background
        {
            out.push_back((types::InternalType*)get_background_property(pvApiCtx, getOrCreateDefaultSubwin()));
        }
        break;
        case 7 : // color
        case 14 : // foreground
        case 23 : // pattern
        {
            out.push_back((types::InternalType*)get_foreground_property(pvApiCtx, getOrCreateDefaultSubwin()));
        }
        break;
        case 17 : // lastpattern
        {
            int iNumColors = 0;
            int* piNumColors = &iNumColors;

            getOrCreateDefaultSubwin();
            getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors);

            out.push_back(new types::Double((double)iNumColors));
        }
        break;
        case 18 : // line mode
        {
            int iLineMode = 0;
            int* lineMode = &iLineMode;

            getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_MODE__, jni_bool, (void **)&lineMode);

            out.push_back(new types::Double((double)iLineMode));
        }
        break;
        case 29 : // white
        {
            int iNumColors = 0;
            int* piNumColors = &iNumColors;

            getOrCreateDefaultSubwin();
            getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors);

            /* White is lqst colormap index + 2 */
            out.push_back(new types::Double((double)(iNumColors + 2)));
        }
        break;
        case 33 : // wresize
        {
            // autoresize property
            int iAutoResize = 0;
            int* piAutoResize =  &iAutoResize;

            getOrCreateDefaultSubwin();
            getGraphicObjectProperty(getCurrentFigure(), __GO_AUTORESIZE__, jni_bool, (void **)&piAutoResize);

            out.push_back(new types::Double((double)iAutoResize));
        }
        break;
        case 6 : // clipgrf
        {
            /* clip_state : 0 = off, 1 = on */
            int iClipState = 0;
            int* piClipState = &iClipState;

            getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState);

            out.push_back(new types::Double((double)iClipState));
        }
        break;
        case 4 : // clipoff
        {
            int iClipState = 0;
            int* piClipState = &iClipState;

            getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState);

            /* clip_state : 0 = off, 1 = on */
            if (iClipState == 0)
            {
                out.push_back(new types::Double(1));
            }
            else
            {
                out.push_back(new types::Double(0));
            }
        }
        break;
        default :
        {
            char* pstWhat = wide_string_to_UTF8(pwcsWhat);
            Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xget", pstWhat);
            FREE(pstWhat);
            return types::Function::Error;
        }
    }

    return types::Function::OK;
}
Example #10
0
/*--------------------------------------------------------------------------*/
int sci_xtitle(char * fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddr4 = NULL;
    int* boxPtr = NULL;
    int* piAddrStr = NULL;

    int  narg = 0;
    int  nbLabels = 0; /* number of modified labels */
    int  box = 0;
    BOOL isBoxSpecified = FALSE;
    int iSubwinUID = 0;
    static rhs_opts opts[] =
    {
        { -1, "boxed", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

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

    CheckInputArgument(pvApiCtx, 1, 5);


    nbLabels = nbInputArgument(pvApiCtx);

    /* get the given options from the name in opts */
    if (!getOptionals(pvApiCtx, fname, opts))
    {
        /* error */
        return 0;
    }

    /* compatibility with previous version in which box was put */
    /* at the fourth position */

    if (nbInputArgument(pvApiCtx) == 4)
    {
        int type = getInputArgumentType(pvApiCtx, 4);
        if (type == 1 || type == 8)/* double or int */
        {
            int n = 0, m = 0;
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

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

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

            box = *boxPtr;
            nbLabels--; /* it is not a label text */
            isBoxSpecified = TRUE;
        }
    }

    if (opts[0].iPos != -1 && !isBoxSpecified)
    {
        /* check if "box" is in the options */
        getScalarBoolean(pvApiCtx, opts[0].piAddr, &box);
        if (opts[0].iRows != 1 || opts[0].iCols != 1)
        {
            /* check size */
            Scierror(999, _("%s: Wrong type for input argument: Scalar expected.\n"), fname);
            return 1;
        }
        nbLabels--; /* it is not a label text */
    }

    iSubwinUID = getOrCreateDefaultSubwin();

    for (narg = 1 ; narg <= nbLabels ; narg++)
    {
        int m = 0, n = 0;
        char **Str = NULL;
        int iModifiedLabel = 0;
        int* piModifiedLabel = &iModifiedLabel;

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

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

        if (m * n == 0)
        {
            continue;
        }

        switch (narg)
        {
            case 1:
                getGraphicObjectProperty(iSubwinUID, __GO_TITLE__, jni_int, (void **)&piModifiedLabel);
                break;
            case 2:
                getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LABEL__, jni_int, (void **)&piModifiedLabel);
                break;
            case 3:
                getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LABEL__, jni_int, (void **)&piModifiedLabel);
                break;
            case 4:
                getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LABEL__, jni_int, (void **)&piModifiedLabel);
                break;
            default:
                break;
        }

#if 0
        startFigureDataWriting(pFigure);
#endif

        sciSetText(iModifiedLabel, Str, m, n);

        setGraphicObjectProperty(iModifiedLabel, __GO_FILL_MODE__, &box, jni_bool, 1);

#if 0
        endFigureDataWriting(pFigure);
#endif

        freeArrayOfString(Str, m * n);
    }

    setCurrentObject(iSubwinUID);
#if 0
    sciDrawObj(pFigure);
#endif

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #11
0
/*--------------------------------------------------------------------------*/
int sci_drawaxis(char *fname, void* pvApiCtx)
{
    /** XXXXX : un point en suspens c'est le "S" ou une adresse est
     *  stockees ds un unsigned long : est ce sufisant ?
     */
    static rhs_opts opts[] =
    {
        { -1, "dir", -1, 0, 0, NULL},
        { -1, "fontsize", -1, 0, 0, NULL},
        { -1, "format_n", -1, 0, 0, NULL},
        { -1, "seg", -1, 0, 0, NULL},
        { -1, "sub_int", -1, 0, 0, NULL},
        { -1, "textcolor", -1, 0, 0, NULL},
        { -1, "tics", -1, 0, 0, NULL},
        { -1, "ticscolor", -1, 0, 0, NULL},
        { -1, "val", -1, 0, 0, NULL},
        { -1, "x", -1, 0, 0, NULL},
        { -1, "y", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    int iSubwinUID = 0;
    int minrhs = -1, maxrhs = 0, minlhs = 0, maxlhs = 1, nopt = 0;
    char dir = 'l', *format = NULL, tics = 'v', **val = NULL;
    int fontsize = -1, sub_int = 2, seg_flag = 1, textcolor = -1, ticscolor = -1;
    double *x = NULL, *y = NULL;
    int nx = 0, ny = 0, ntics;
    int nb_tics_labels = -1;
    int iRhs = nbInputArgument(pvApiCtx);

    nopt = NumOpt(pvApiCtx);

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

    if (getOptionals(pvApiCtx, fname, opts) == 0)
    {
        /* error */
        return 0;
    }

    iSubwinUID = getOrCreateDefaultSubwin();

    if (opts[0].iPos != -1)
    {
        char* pstDir = NULL;
        //CheckLength
        if (opts[0].iRows != 1 || opts[0].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, opts[0].iPos, opts[0].iRows);
            return 1;
        }

        if (getAllocatedSingleString(pvApiCtx, opts[0].piAddr, &pstDir))
        {
            return 1;
        }
        dir = pstDir[0];
        freeAllocatedSingleString(pstDir);
    }
    if (opts[1].iPos != -1)
    {
        double dblSize = 0;
        //CheckScalar
        if (opts[1].iRows != 1 || opts[1].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[1].iPos);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[1].piAddr, &dblSize);
        fontsize = (int)dblSize;
    }
    if (opts[2].iPos != -1)
    {
        /* verfier ce que l'on recoit avec "" XXX */
        if (getAllocatedSingleString(pvApiCtx, opts[2].piAddr, &format))
        {
            return 1;
        }
    }

    if (opts[3].iPos != -1)
    {
        double dblSeq = 0;
        //CheckScalar
        if (opts[3].iRows != 1 || opts[3].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[3].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }


        getScalarDouble(pvApiCtx, opts[3].piAddr, &dblSeq);
        seg_flag = (int)dblSeq;
    }

    if (opts[4].iPos != -1)
    {
        double dblSub = 0;
        //CheckScalar
        if (opts[4].iRows != 1 || opts[4].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[4].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[4].piAddr, &dblSub);
        sub_int = (int)dblSub;
    }

    if (opts[5].iPos != -1)
    {
        double dblColor = 0;
        //CheckScalar
        if (opts[5].iRows != 1 || opts[5].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[5].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[5].piAddr, &dblColor);
        textcolor = (int)dblColor;
    }

    if (opts[6].iPos != -1)
    {
        char* pstTics = NULL;
        //CheckLength
        if (opts[6].iRows != 1 || opts[6].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, opts[6].iPos, opts[6].iRows);
            freeAllocatedSingleString(format);
            return 1;
        }

        if (getAllocatedSingleString(pvApiCtx, opts[6].piAddr, &pstTics))
        {
            return 1;
        }
        tics = pstTics[0];
        freeAllocatedSingleString(pstTics);
    }

    if (opts[7].iPos != -1)
    {
        double dblColor = 0;
        //CheckScalar
        if (opts[7].iRows != 1 || opts[7].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[7].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[7].piAddr, &dblColor);
        ticscolor = (int)dblColor;
    }

    if (opts[8].iPos != -1)
    {
        if (getAllocatedMatrixOfString(pvApiCtx, opts[8].piAddr, &opts[8].iRows, &opts[8].iCols, &val))
        {
            return 1;
        }
    }

    if (opts[9].iPos != -1)
    {
        getMatrixOfDouble(pvApiCtx, opts[9].piAddr, &opts[9].iRows, &opts[9].iCols, &x);
        nx = opts[9].iRows * opts[9].iCols; /* F.Leray OK here opts[9].iRows and opts[9].iCols are integers. */
    }
    else
    {
        static double x_def[1];
        double *bounds;
        int iCurrentSubwinUID = getCurrentSubWin();

        getGraphicObjectProperty(iCurrentSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&bounds);
        nx = 1;
        x = x_def;
        if (dir == 'l')
        {
            x_def[0] = bounds[0];    /* xMin */
        }
        else if (dir == 'r')
        {
            x_def[0] = bounds[1];    /* xMax */
        }
    }

    if (opts[10].iPos != -1)
    {
        getMatrixOfDouble(pvApiCtx, opts[10].piAddr, &opts[10].iRows, &opts[10].iCols, &y);
        ny = opts[10].iRows * opts[10].iCols;
    }
    else
    {
        static double y_def[1];
        double *bounds;
        int iCurrentSubwinUID = getCurrentSubWin();

        getGraphicObjectProperty(iCurrentSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&bounds);
        ny = 1;
        y = y_def;
        if (dir == 'd')
        {
            y_def[0] = bounds[2];    /* yMin */
        }
        else if (dir == 'u')
        {
            y_def[0] = bounds[3];    /* yMax */
        }
    }

    /* compatibility test */
    switch (tics)
    {
        case 'r':
            if (check_xy(fname, dir, 3, opts[9].iPos, opts[9].iRows, opts[9].iCols, x,
                         opts[10].iPos, opts[10].iRows, opts[10].iCols, y, &ntics) == 0)
            {
                ReturnArguments(pvApiCtx);
                freeAllocatedSingleString(format);
                freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
                return 0;
            }
            break;
        case 'i':
            if (check_xy(fname, dir, 4, opts[9].iPos, opts[9].iRows, opts[9].iCols, x,
                         opts[10].iPos, opts[10].iRows, opts[10].iCols, y, &ntics) == 0)
            {
                ReturnArguments(pvApiCtx);
                freeAllocatedSingleString(format);
                freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
                return 0;
            }
            break;
        case 'v':
            if (check_xy(fname, dir, -1, opts[9].iPos, opts[9].iRows, opts[9].iCols, x,
                         opts[10].iPos, opts[10].iRows, opts[10].iCols, y, &ntics) == 0)
            {
                ReturnArguments(pvApiCtx);
                freeAllocatedSingleString(format);
                freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
                return 0;
            }
            break;
        default:
            Scierror(999, _("%: Wrong value for %s '%c': '%s', '%s' and '%s' expected.\n"), fname, "tics", dir, "r", "v", "i");
            freeAllocatedSingleString(format);
            freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
            return 0;
    }

    if (val != NULL)
    {
        //CheckLength
        if (opts[8].iRows * opts[8].iCols != ntics)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, opts[8].iPos, opts[8].iRows * opts[8].iCols);
            freeAllocatedSingleString(format);
            freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
            return 1;
        }

        nb_tics_labels = opts[8].iRows * opts[8].iCols;
    }

    Objdrawaxis(dir, tics, x, &nx, y, &ny, val, sub_int, format, fontsize, textcolor, ticscolor, 'n', seg_flag, nb_tics_labels);

    freeAllocatedSingleString(format);
    if (val != NULL)
    {
        freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
    }
    createScalarHandle(pvApiCtx, iRhs + 1, getHandle(getCurrentObject()));
    AssignOutputVariable(pvApiCtx, 1) = iRhs + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #12
0
/*--------------------------------------------------------------------------*/
int sci_xgetmouse(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    double* l2 = NULL;

    int  m1 = 1, n1 = 3;
    int mouseButtonNumber = 0;
    int windowsID = 0;
    int sel[2], m = 0, n = 0;

    int pixelCoords[2];
    double userCoords2D[2] = {0.0, 0.0};

    int selPosition = 0;

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

    switch (nbInputArgument(pvApiCtx))
    {
        case 1:
            if (checkInputArgumentType(pvApiCtx, 1, sci_boolean))
            {
                selPosition = 1;
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: Boolean vector expected.\n"), fname, 1);
                return FALSE;
            }
            break;
        default:
            // Call Java xgetmouse
            // No need to set any option.
            break;
    }

    // Select current figure or create it
    getOrCreateDefaultSubwin();

    // Call Java to get mouse information
    if (selPosition != 0)
    {
        int* l1Sel = NULL;
        sciErr = getVarAddressFromPosition(pvApiCtx, selPosition, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

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

        //CheckDims
        if (m * n != 2 || 1 != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, selPosition, 2, 1);
            return 1;
        }

        sel[0] = (int)l1Sel[0];
        sel[1] = (int)l1Sel[1];

        // Call Java xgetmouse
        CallJxgetmouseWithOptions(sel[0], sel[1]);
    }
    else
    {
        CallJxgetmouse();
    }

    // Get return values
    mouseButtonNumber = getJxgetmouseMouseButtonNumber();
    pixelCoords[0] = (int) getJxgetmouseXCoordinate();
    pixelCoords[1] = (int) getJxgetmouseYCoordinate();

    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;
    }

    // No need to calculate coordinates if callback or close is trapped
    if (mouseButtonNumber == -1000 || mouseButtonNumber == -2)
    {
        l1[0] = -1;
        l1[1] = -1;
        l1[2] = (double) mouseButtonNumber;
    }
    else
    {
        // Convert pixel coordinates to user coordinates
        int iClickedSubwinUID = getCurrentSubWin();
        updateSubwinScale(iClickedSubwinUID);
        sciGet2dViewCoordFromPixel(iClickedSubwinUID, pixelCoords, userCoords2D);

        l1[0] = userCoords2D[0];
        l1[1] = userCoords2D[1];
        l1[2] = (double) mouseButtonNumber;
    }
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;

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

            l2[0] = windowsID; /* this is the window number */
            AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
            ReturnArguments(pvApiCtx);
            return 0;
    }
    ReturnArguments(pvApiCtx);
    return -1;
}
Example #13
0
int plot2dn(int ptype, char *logflags, double *x, double *y, int *n1, int *n2, int *style, char *strflag, char *legend, double *brect, int *aaint,
            BOOL flagNax, int lstr1, int lstr2)
{
    int iSubwinUID = 0;
    int iCurFigureUID = 0;
    int closeflag = 0;
    int jj = 0;
    long hdl = 0;
    int *pObj = NULL;
    int cmpt = 0;
    int with_leg = 0;
    double drect[6];
    char dataflag = 0;

    BOOL bounds_changed = FALSE;
    BOOL axes_properties_changed = FALSE;

    double rotationAngles[2];
    int clipState = 0;
    int autoScale = 0;
    int logFlags[3];
    int iTmp = 0;
    int *piTmp = &iTmp;
    char textLogFlags[3];
    int firstPlot = 0;
    int newFirstPlot = 0;
    int autoSubticks = 0;

    iSubwinUID = getOrCreateDefaultSubwin();

    /*
     * Check if the auto_clear property is on and then erase everything
     * To be implemented
     */
    checkRedrawing();

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

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

    /* Force logflags to those given by argument */

    getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piTmp);
    firstPlot = 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);
    }

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

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

    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]);

                compute_data_bounds2(0, dataflag, textLogFlags, x, y, *n1, *n2, drect);

                break;
        }

        /* merge data bounds and drect */
        if (!firstPlot && (strflag[1] == '5' || strflag[1] == '7' || strflag[1] == '8' || strflag[1] == '9'))
        {
            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;
    }

    /* Adapted to the MVC */
    axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag);

    /* just after strflag2axes_properties */
    newFirstPlot = 0;
    setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &newFirstPlot, jni_bool, 1);

    with_leg = (strflag[0] == '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)
    {
        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;

        if (logFlags[0] == 0 && logFlags[1] == 0)
        {
            int autoTicks = 0;
            int i = 0;
            int iSize = 0;
            double dblFabs = 0;
            char** stringVector = NULL;

            if (aaint[1] == -1)
            {
                autoTicks = 1;
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else if (aaint[1] == 0)
            {
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0);
                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else
            {
                double* dXGrads = (double*) MALLOC(aaint[1] * sizeof(double));

                // Compute X grads
                dXGrads[0] = drect[0];
                if (aaint[1] > 1)
                {
                    double pas = (drect[1] - drect[0]) / (aaint[1] - 1);
                    for (i = 0; i < aaint[1]; i++)
                    {
                        dXGrads[i] = drect[0] + pas * i;
                    }
                }

                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, dXGrads, jni_double_vector, aaint[1]);
                // Create X Labels
                stringVector = (char **) MALLOC(aaint[1] * sizeof(char*));
                for (i = 0; i < aaint[1]; i++)
                {
                    iSize = 6;
                    if (dXGrads[i] < 0)
                    {
                        iSize += 2;
                    }
                    dblFabs = fabs(dXGrads[i]);
                    if (dblFabs >= 10)
                    {
                        iSize = iSize + (int)floor(log10(dblFabs));
                    }

                    stringVector[i] = (char*) MALLOC(iSize * sizeof(char));
                    sprintf(stringVector[i], "%.3f", dXGrads[i]);
                    stringVector[i][iSize - 1] = '\0';
                }

                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[1]);

                for (i = 0; i < aaint[1]; i++)
                {
                    FREE(stringVector[i]);
                }

                FREE(stringVector);
                FREE(dXGrads);
                stringVector = NULL;
            }

            if (aaint[3] == -1)
            {
                autoTicks = 1;
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else if (aaint[3] == 0)
            {
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0);
                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else
            {
                double* dYGrads = (double*) MALLOC(aaint[3] * sizeof(double));

                // Compute Y grads
                dYGrads[0] = drect[2];
                if (aaint[3] > 1)
                {
                    double pas = (drect[3] - drect[2]) / (aaint[3] - 1);
                    for (i = 0; i < aaint[3]; i++)
                    {
                        dYGrads[i] = drect[2] + pas * i;
                    }
                }

                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, dYGrads, jni_double_vector, aaint[3]);

                // Create Y Labels
                stringVector = (char**) MALLOC(aaint[3] * sizeof(char*));
                for (i = 0; i < aaint[3]; i++)
                {
                    iSize = 6;
                    if (dYGrads[i] < 0)
                    {
                        iSize += 2;
                    }
                    dblFabs = fabs(dYGrads[i]);
                    if (dblFabs >= 10)
                    {
                        iSize = iSize + (int)floor(log10(dblFabs));
                    }
                    stringVector[i] = (char*) MALLOC(iSize * sizeof(char));
                    sprintf(stringVector[i], "%.3f", dYGrads[i]);
                    stringVector[i][iSize - 1] = '\0';
                }

                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[3]);

                for (i = 0; i < aaint[3]; i++)
                {
                    FREE(stringVector[i]);
                }

                FREE(stringVector);
                FREE(dYGrads);
                stringVector = NULL;
            }

            // X and Y subticks
            setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_SUBTICKS__, aaint, jni_int, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_SUBTICKS__, &aaint[2], jni_int, 1);
        }
        else
        {
            sciprint(_("Warning: Nax does not work with logarithmic scaling.\n"));
        }

    }

    /*---- Drawing the curves and the legends ----*/
    if (*n1 != 0)
    {
        if ((pObj = (int*)MALLOC((*n1 + 1) * sizeof(int))) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "plot2d");
            return -1;
        }

        /*A.Djalel 3D axes */
        for (jj = 0; jj < *n1; jj++)
        {
            int iObjUID = 0;

            if (style[jj] > 0)
            {
                BOOL isline = TRUE;

                if (ptype == 3)
                {
                    isline = FALSE;
                }
                iObjUID = ConstructPolyline(getCurrentSubWin(), &(x[jj * (*n2)]),
                                            &(y[jj * (*n2)]), PD0, closeflag, *n2, ptype,
                                            &style[jj], NULL, NULL, NULL, NULL, isline, FALSE, FALSE, FALSE);
            }
            else
            {
                int minusstyle = -style[jj];

                iObjUID = ConstructPolyline(getCurrentSubWin(), &(x[jj * (*n2)]),
                                            &(y[jj * (*n2)]), PD0, closeflag, *n2, ptype,
                                            NULL, NULL, &minusstyle, NULL, NULL, FALSE, FALSE, TRUE, FALSE);
            }
            if (iObjUID == 0)
            {
                // skip
                Scierror(999, _("%s: No more memory.\n"), "plot2d");
            }
            else
            {
                setCurrentObject(iObjUID);

                pObj[cmpt] = iObjUID;
                cmpt++;
            }

        }

        /*---- Drawing the Legends ----*/
        if (with_leg)
        {
            int iLegUID = 0;
            char **Str;
            int nleg;

            if (scitokenize(legend, &Str, &nleg))
            {
                FREE(pObj);
                Scierror(999, _("%s: No more memory.\n"), "plot2d");
                return 0;
            }

            iLegUID = ConstructLegend(getCurrentSubWin(), Str, pObj, Min(nleg, cmpt));

            if (iLegUID != 0)
            {
                int legendLocation;
                int contourMode;

                /* 9: LOWER_CAPTION */
                legendLocation = 9;
                setGraphicObjectProperty(iLegUID, __GO_LEGEND_LOCATION__, &legendLocation, jni_int, 1);

                contourMode = 0;

                setGraphicObjectProperty(iLegUID, __GO_FILL_MODE__, &contourMode, jni_bool, 1);
                setGraphicObjectProperty(iLegUID, __GO_LINE_MODE__, &contourMode, jni_bool, 1);
            }

            freeArrayOfString(Str, nleg);
        }

        /*---- construct Compound ----*/
        if (cmpt > 0)
        {
            int parentVisible = 0;
            int *piParentVisible = &parentVisible;
            int iCompoundUID = createCompound(iSubwinUID, pObj, cmpt);
            setCurrentObject(iCompoundUID);
        }
        FREE(pObj);

    }
    /* End of the curves and legend block */

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

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddr2 = NULL;
    int* l2 = NULL;

    int m1 = 0, n1 = 0;
    int m2 = 0, n2 = 0;

    long hdl = 0;
    int iCurrentSubWin = 0;

    int i = 0;

    double angle1 = 0.0;
    double angle2 = 0.0;

    CheckInputArgument(pvApiCtx, 1, 2);

    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;
    }

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

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

        // Retrieve a matrix of double at position 2.
        sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr2, &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;
        }

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

        if (n1 != m2 * n2)
        {
            Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2);
            return 0;
        }
    }
    else
    {
        m2 = 1;
        n2 = n1;
        sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, 2, m2, n2, &l2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        for (i = 0; i < n2; ++i)
        {
            *((int*)(l2 + i)) = i + 1;
        }
    }

    iCurrentSubWin = getOrCreateDefaultSubwin();

    for (i = 0; i < n1; ++i)
    {
        angle1 = DEG2RAD(*(l1 + (6 * i) + 4) / 64.0);
        angle2 = DEG2RAD(*(l1 + (6 * i) + 5) / 64.0);
        Objarc(&angle1, &angle2, (l1 + (6 * i)), (l1 + (6 * i) + 1),
               (l1 + (6 * i) + 2), (l1 + (6 * i) + 3), (int*)(l2 + i), (int*)(l2 + i), TRUE, FALSE, &hdl);
    }

    /** Construct Compound and make it current object **/
    {
        int o = createCompoundSeq(iCurrentSubWin, n1);
        setCurrentObject(o);
    }

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

    return 0;
}
Example #15
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;
}
Example #16
0
/*--------------------------------------------------------------------------*/
int sci_stringbox(char * fname, void *pvApiCtx)
{
    SciErr sciErr;
    int* piAddrstackPointer = NULL;
    long long* stackPointer = NULL;
    char** strStackPointer   = NULL;
    double* pdblStackPointer = NULL;

    int type = -1;
    int *piType = &type;

    int iParentAxes = 0;
    int* piParentAxes = &iParentAxes;
    double* textCorners = NULL;
    int two   = 2;
    int four  = 4;
    double corners[4][2]; /* the four edges of the boundingRect */

    /* The function should be called with stringbox(handle) */
    CheckInputArgument(pvApiCtx,  1, 6);
    CheckOutputArgument(pvApiCtx,  0, 1);

    if (nbInputArgument(pvApiCtx) == 1)
    {
        int m;
        int n;
        /* A text handle should be specified */

        int iTextUID = 0;
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1);
            return 0;
        }

        /* get the handle */
        sciErr = getVarAddressFromPosition(pvApiCtx,  1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of handle at position  1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &m, &n, &stackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: A ''%s'' handle expected.\n"), fname,  1, "Text");
            return 1;
        }

        if (m * n != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A ''%s'' handle expected.\n"), fname, 1, "Text");
            return 0;
        }

        /* Get the handle and check that this is a text handle */
        iTextUID = getObjectFromHandle((long int) * stackPointer);

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

        getGraphicObjectProperty(iTextUID, __GO_TYPE__, jni_int, (void **)&piType);

        if (type != __GO_LABEL__ && type != __GO_TEXT__)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1);
            return 0;
        }

        getGraphicObjectProperty(iTextUID, __GO_PARENT_AXES__, jni_int, (void **)&piParentAxes);

        updateTextBounds(iTextUID);

        /*
         * To do: performs a projection/unprojection to obtain the bounding box in object coordinates
         * but using a rotation matrix corresponding to the default rotation angles (view == 2d)
         */

        getGraphicObjectProperty(iTextUID, __GO_CORNERS__, jni_double_vector, (void **)&textCorners);

        corners[1][0] = textCorners[0];
        corners[1][1] = textCorners[1];

        corners[0][0] = textCorners[3];
        corners[0][1] = textCorners[4];

        corners[3][0] = textCorners[6];
        corners[3][1] = textCorners[7];

        corners[2][0] = textCorners[9];
        corners[2][1] = textCorners[10];
    }
    else if (nbInputArgument(pvApiCtx) == 2)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d or %d to %d expected.\n"), fname, 1, 3, 6);
        return 0;
    }
    else
    {
        int iParentSubwinUID = getOrCreateDefaultSubwin();
        char ** text = NULL;
        int textNbRow;
        int textNbCol;
        double xPos;
        double yPos;
        double angle = DEFAULT_ANGLE;
        int fontId;
        int *pfontId = &fontId;
        double fontSize;
        double *pfontSize = &fontSize;

        getGraphicObjectProperty(iParentSubwinUID, __GO_FONT_STYLE__, jni_int, (void**)&pfontId);
        getGraphicObjectProperty(iParentSubwinUID, __GO_FONT_SIZE__, jni_double, (void **)&pfontSize);

        /* Check that first argument is a string */
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: 2D array of strings expected.\n"), fname, 1);
            return 0;
        }
        sciErr = getVarAddressFromPosition(pvApiCtx,  1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

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

        /* retrieve it */
        text = strStackPointer;

        /* Second and third arguments should be scalars */
        if (getScalarFromStack(2, fname, &xPos, pvApiCtx) < 0)
        {
            freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
            return 0;
        }

        if (getScalarFromStack(3, fname, &yPos, pvApiCtx) < 0)
        {
            freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
            return 0;
        }

        if (nbInputArgument(pvApiCtx) >= 4)
        {
            /* angle is defined */
            if (getScalarFromStack(4, fname, &angle, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
        }

        if (nbInputArgument(pvApiCtx) >= 5)
        {
            double fontIdD;
            /* font style is defined */
            if (getScalarFromStack(5, fname, &fontIdD, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
            fontId = (int) fontIdD;
        }

        if (nbInputArgument(pvApiCtx) >= 6)
        {
            /* font size is defined */
            if (getScalarFromStack(6, fname, &fontSize, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
        }

        /* compute the box */
        getTextBoundingBox(text, textNbRow, textNbCol, xPos, yPos, angle, fontId, fontSize, corners);
        freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
    }


    /* copy everything into the lhs */
    sciErr = allocMatrixOfDouble(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, two, four, &pdblStackPointer);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    pdblStackPointer[0] = corners[1][0];
    pdblStackPointer[1] = corners[1][1];
    pdblStackPointer[2] = corners[0][0];
    pdblStackPointer[3] = corners[0][1];
    pdblStackPointer[4] = corners[3][0];
    pdblStackPointer[5] = corners[3][1];
    pdblStackPointer[6] = corners[2][0];
    pdblStackPointer[7] = corners[2][1];

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #17
0
/*--------------------------------------------------------------------------*/
int sci_xtitle( char * fname, unsigned long fname_len )
{
    int  narg;
    int  nbLabels; /* number of modified labels */
    int  box = 0;
    BOOL isBoxSpecified = FALSE;
    char * psubwinUID = NULL;
    static rhs_opts opts[] = { {-1,"boxed","i" ,0,0,0},
    {-1,NULL   ,NULL,0,0,0} };

    if (Rhs <= 0)
    {
        sci_demo(fname, fname_len);
        return 0;
    }

    CheckRhs(1,5);


    nbLabels = Rhs;

    /* get the given options from the name in opts */
    if ( !get_optionals(fname,opts) )
    {
        /* error */
        return 0;
    }

    /* compatibility with previous version in which box was put */
    /* at the fourth position */

    if ( Rhs == 4 )
    {
        int type = GetType(4);
        if ( type == 1 || type == 8 )/* double or int */
        {
            int n,m;
            int boxPtr   = -1 ; /* pointer of box on the stack */
            GetRhsVar(4,MATRIX_OF_INTEGER_DATATYPE,&m,&n,&boxPtr);
            CheckScalar(4,m,n);
            box = *istk( boxPtr );
            nbLabels--; /* it is not a label text */
            isBoxSpecified = TRUE;
        }
    }

    if ( opts[0].position != -1 && !isBoxSpecified )
    {
        /* check if "box" is in the options */
        box = *istk(opts[0].l) ;
        if ( opts[0].m * opts[0].n != 1 )
        {
            /* check size */
            Scierror( 999, _("%s: Wrong type for input argument: Scalar expected.\n"), fname );
            return 1;
        }
        nbLabels--; /* it is not a label text */
    }

    psubwinUID = getOrCreateDefaultSubwin();

    for ( narg = 1 ; narg <= nbLabels ; narg++)
    {
        int m,n;
        char **Str;
        char * modifiedLabel = NULL;

        GetRhsVar(narg,MATRIX_OF_STRING_DATATYPE,&m,&n,&Str);
        if ( m*n == 0 )
        {
            continue;
        }

        switch(narg)
        {
            case 1:
                getGraphicObjectProperty(psubwinUID, __GO_TITLE__, jni_string, &modifiedLabel);
                break;
            case 2:
                getGraphicObjectProperty(psubwinUID, __GO_X_AXIS_LABEL__, jni_string, &modifiedLabel);
            break;
            case 3:
                getGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_LABEL__, jni_string, &modifiedLabel);
                break;
            case 4:
                getGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_LABEL__, jni_string, &modifiedLabel);
                break;
            default:
                break;
        }

#if 0
        startFigureDataWriting(pFigure);
#endif

        sciSetText(modifiedLabel, Str, m, n);

        setGraphicObjectProperty(modifiedLabel, __GO_FILL_MODE__, &box, jni_bool, 1);

#if 0
        endFigureDataWriting(pFigure);
#endif

        freeArrayOfString(Str,m*n);
    }

    setCurrentObject(psubwinUID);
#if 0
    sciDrawObj(pFigure);
#endif

    LhsVar(1)=0;
    C2F(putlhsvar)();
    return 0;
}
Example #18
0
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_xset(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    wchar_t* pwcsWhat = NULL;
    std::list<types::Double*> lpDblInputs;
    int iSubwinUID = 0;

    if (in.size() == 0)
    {
        return Overload::call(L"%_xset", in, _iRetCount, out);
    }

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

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

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

    types::String* pStr = in[0]->getAs<types::String>();

    if (pStr->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 1);
        return types::Function::Error;
    }

    pwcsWhat = pStr->get(0);

    if (ConfigGraphicVariable::bPropertyFound(pwcsWhat) == false)
    {
        char* pstWhat = wide_string_to_UTF8(pwcsWhat);
        Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xset", pstWhat);
        FREE(pstWhat);
        return types::Function::Error;
    }

    // Only in case of "fpf" and "auto clear", the second argument is a string
    // Only "default" case have one input argument
    if (ConfigGraphicVariable::getPropertyValue(pwcsWhat) != 15 && // fpf
            ConfigGraphicVariable::getPropertyValue(pwcsWhat) != 2  && // auto clear
            ConfigGraphicVariable::getPropertyValue(pwcsWhat) != 10)   // default
    {
        for (unsigned int i = 1 ; i < in.size() ; i++)
        {
            if (in[i]->isDouble() == false)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), "xset", i + 1);
            }
        }
    }

    switch (ConfigGraphicVariable::getPropertyValue(pwcsWhat))
    {
        case 15 : // fpf
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

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

            types::String* pStrValue = in[1]->getAs<types::String>();
            if (pStrValue->isScalar() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            ConfigGraphicVariable::setFPF(pStrValue->get(0));
        }
        break;
        case 2 : // auto clear
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

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

            types::String* pStrValue = in[1]->getAs<types::String>();
            if (pStrValue->isScalar() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int bAutoClear = 0;
            if (wcscmp(pStrValue->get(0), L"on") == 0)
            {
                bAutoClear = 1;
            }

            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTO_CLEAR__, &bAutoClear, jni_bool, 1);
        }
        break;
        case 5 : // clipping
        {
            int clipState = 2;
            double dvalues[4];
            if (in.size() == 2)
            {
                types::Double* pDblArg = in[1]->getAs<types::Double>();
                if (pDblArg->getSize() != 4)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: A %d-element vector expected.\n"), "xset", 2, 4);
                    return types::Function::Error;
                }

                memcpy(dvalues, pDblArg->get(), 4 * sizeof(double));
            }
            else if (in.size() != 5)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d or %d expected.\n"), "xset", 2, 5);
                return types::Function::Error;
            }
            else
            {
                for (int i = 0; i < 4 ; i++)
                {
                    dvalues[i] = in[i + 1]->getAs<types::Double>()->get(0);
                }
            }

            iSubwinUID = getOrCreateDefaultSubwin();
            setGraphicObjectProperty(iSubwinUID, __GO_CLIP_BOX__, dvalues, jni_double_vector, 4);
            setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);
        }
        break;
        case 8 : // colormap
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            types::Double* pDblArg = in[1]->getAs<types::Double>();
            getOrCreateDefaultSubwin();
            setGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP__, pDblArg->get(), jni_double_vector, pDblArg->getSize());
        }
        break;
        case 21 : // mark size
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int markSize = (int)in[1]->getAs<types::Double>()->get(0);
            int markSizeUnit = 1; /* force switch to tabulated mode : old syntax / 0 : point, 1 : tabulated */

            iSubwinUID = getOrCreateDefaultSubwin();
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE__, &markSize, jni_int, 1);
        }
        break;
        case 20 : // mark
        {
            if (in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 3);
                return types::Function::Error;
            }

            int markStyle = (int) in[1]->getAs<types::Double>()->get(0);
            int markSize = (int) in[2]->getAs<types::Double>()->get(0);
            int markSizeUnit = 1; /* force switch to tabulated mode : old syntax / 0 : point, 1 : tabulated */
            int markMode = 1;

            iSubwinUID = getOrCreateDefaultSubwin();
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_MODE__, &markMode, jni_bool, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1); /* force switch to tabulated mode : old syntax */
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_STYLE__, &markStyle, jni_int, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE__, &markSize, jni_int, 1);
        }
        break;
        case 13 : // font size
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }
            double fontSize = in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, &fontSize, jni_double, 1);
        }
        break;
        case 10 : // default
        {
            if (in.size() != 1)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 1);
                return types::Function::Error;
            }

            unsigned short* defcolors = ConfigGraphicVariable::getDefaultColormap();

            int piFigurePosition[2] = {200, 200};
            int piFigureSize[2]     = {500, 500};
            int piAxesSize[2]       = {498, 366};
            int piViewPort[2]       = {0, 0};
            int piEmptyMatrix[4]    = {1, 0, 0, 0};

            // init variables
            int iZero   = 0;
            BOOL bTrue  = TRUE;
            BOOL bFalse = FALSE;
            int m       = NUMCOLORS_SCI;
            int i       = 0;
            int iCopy   = 3;
            int defaultBackground = -2;

            // reset format
            ConfigGraphicVariable::setFPF(L"");

            double* pdblColorMap = new double[m * 3];
            if (pdblColorMap == NULL)
            {
                Scierror(999, _("%s: No more memory.\n"), "xset");
                return types::Function::Error;
            }

            // Create figure if it not exist.
            int iFigureUID = getCurrentFigure();
            if (iFigureUID == 0)
            {
                iFigureUID = createNewFigureWithAxes();
                setCurrentFigure(iFigureUID);
                delete[] pdblColorMap;
                return types::Function::OK;
            }

            // Create new axes and set it in current figure
            int iSubWinUID = getCurrentSubWin();
            if (iSubWinUID != 0)
            {
                int iChildrenCount  = 0;
                int* childrencount  = &iChildrenCount;
                int* childrenUID    = 0;
                int iHidden         = 0;
                int *piHidden       = &iHidden;

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

                for (i = 0; i < childrencount[0]; ++i)
                {
                    getGraphicObjectProperty(childrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
                    if (iHidden == 0)
                    {
                        deleteGraphicObject(childrenUID[i]);
                    }
                }
            }

            cloneAxesModel(iFigureUID);

            // Set default figure properties
            setGraphicObjectProperty(iFigureUID, __GO_POSITION__, piFigurePosition, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_SIZE__, piFigureSize, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_AXES_SIZE__, piAxesSize, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_AUTORESIZE__, &bTrue, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_VIEWPORT__, piViewPort, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_NAME__, _("Figure n°%d"), jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_INFO_MESSAGE__, "", jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_PIXEL_DRAWING_MODE__, &iCopy, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_ANTIALIASING__, &iZero, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_IMMEDIATE_DRAWING__, &bTrue, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_BACKGROUND__, &defaultBackground, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_VISIBLE__, &bTrue, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_ROTATION_TYPE__, &iZero, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_EVENTHANDLER__, "", jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_EVENTHANDLER_ENABLE__, &bFalse, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_USER_DATA__, piEmptyMatrix, jni_int_vector, 4);
            setGraphicObjectProperty(iFigureUID, __GO_RESIZEFCN__, "", jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_TAG__, "", jni_string, 1);

            for (i = 0; i < m; i++)
            {
                pdblColorMap[i]         = (double)(defcolors[3 * i] / 255.0);
                pdblColorMap[i + m]     = (double)(defcolors[3 * i + 1] / 255.0);
                pdblColorMap[i + 2 * m] = (double)(defcolors[3 * i + 2] / 255.0);
            }

            setGraphicObjectProperty(iFigureUID, __GO_COLORMAP__, pdblColorMap, jni_double_vector, 3 * m);
            setGraphicObjectProperty(iFigureUID, __GO_PARENT__, "", jni_string, 1);
            delete[] pdblColorMap;
        }
        break;
        case 6 : // clipgrf
        {
            int clipState = 1;
            /* special treatement for xset("cligrf") */
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, &clipState, jni_int, 1);
        }
        break;
        case 4 : // clipoff
        {
            int clipState = 0;
            /* special treatement for xset("clipoff") */
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, &clipState, jni_int, 1);
        }
        break;
        case 16 : // hidden3d
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int hiddenColor = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_HIDDEN_COLOR__, &hiddenColor, jni_int, 1);
        }
        break;
        case 12 : // font
        {
            if (in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 3);
                return types::Function::Error;
            }

            int fontStyle = (int) in[1]->getAs<types::Double>()->get(0);
            double fontSize = in[2]->getAs<types::Double>()->get(0);

            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, &fontSize, jni_double, 1);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_STYLE__, &fontStyle, jni_int, 1);
        }
        break;
        case 11 : // window
        case 30 : // figure
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            // Find if window already exists, if not create a new one
            int iID = (int)in[1]->getAs<types::Double>()->get(0);
            int iFigureUID = getFigureFromIndex(iID);
            int iAxesUID = 0;
            int* piAxesUID = &iAxesUID;

            if (iFigureUID == 0)
            {
                iFigureUID = createNewFigureWithAxes();
                setGraphicObjectProperty(iFigureUID, __GO_ID__, &iID, jni_int, 1);
            }

            setCurrentFigure(iFigureUID);
            getGraphicObjectProperty(iFigureUID, __GO_SELECTED_CHILD__, jni_int, (void**)&piAxesUID);
            setCurrentSubWin(iAxesUID);
        }
        break;
        case 14 : // foreground
        case 7 : // color
        case 23 : // pattern
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iColor = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_COLOR__, &iColor, jni_int, 1);
        }
        break;
        case 3 : // background
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iColor = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_BACKGROUND__, &iColor, jni_int, 1);
        }
        break;
        case 25 : // thickness
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            sciSetLineWidth(getOrCreateDefaultSubwin(), (int)in[1]->getAs<types::Double>()->get(0));
        }
        break;
        case 19 : // line style
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int lineStyle = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, &lineStyle, jni_int, 1);
        }
        break;
        case 9 : // dashes
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int lineStyle = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, &lineStyle, jni_int, 1);
        }
        break;
        case 33 : // wresize
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iAutoResizeMode = (int)in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTORESIZE__, &iAutoResizeMode, jni_bool, 1);
        }
        break;
        case 32 : // wpos
        {
            int figurePosition[2];
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            getOrCreateDefaultSubwin();

            figurePosition[0] = (int)in[1]->getAs<types::Double>()->get(0);
            figurePosition[1] = (int)in[1]->getAs<types::Double>()->get(1);
            setGraphicObjectProperty(getCurrentFigure(), __GO_POSITION__, figurePosition, jni_int_vector, 2);
        }
        break;
        case 31 : // wpdim
        case 28 : // wdim
        {
            int figureSize[2] = {0, 0};
            if (in.size() != 2 && in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d or %d expected.\n"), "xset", 2, 3);
                return types::Function::Error;
            }

            figureSize[0] = (int)in[1]->getAs<types::Double>()->get(0);
            if (in.size() == 3)
            {
                figureSize[1] = (int)in[2]->getAs<types::Double>()->get(0);
            }

            /* Xwindows limits dimensions to 2^16 */
            if ((figureSize[0] > 65535) || (figureSize[1] > 65535))
            {
                figureSize[0] = std::min(figureSize[0], 65535);
                figureSize[1] = std::min(figureSize[1], 65535);
                if (ConfigVariable::getWarningMode())
                {
                    sciprint(_("%s: window dimensions have been set less than 2^16.\n"), "xset");
                }
            }

            getOrCreateDefaultSubwin();
            setGraphicObjectProperty(getCurrentFigure(), __GO_SIZE__, figureSize, jni_int_vector, 2);
        }
        break;
        case 27 : // viewport
        {
            if (in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 3);
                return types::Function::Error;
            }

            int viewport[4] = {0, 0, 0, 0};
            viewport[0] = (int)in[1]->getAs<types::Double>()->get(0);
            viewport[1] = (int)in[2]->getAs<types::Double>()->get(0);

            getOrCreateDefaultSubwin();
            setGraphicObjectProperty(getCurrentFigure(), __GO_VIEWPORT__, viewport, jni_int_vector, 2);
        }
        break;
        case 18 : // line mode
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iSubwinUID = getOrCreateDefaultSubwin();
            int iZero = 0;
            int iOne = 1;

            if (in[1]->getAs<types::Double>()->get(0) == 0)
            {
                setGraphicObjectProperty(iSubwinUID, __GO_LINE_MODE__, &iZero, jni_bool, 1);
            }
            else
            {
                setGraphicObjectProperty(iSubwinUID, __GO_LINE_MODE__, &iOne, jni_bool, 1);
            }
        }
        break;
        default :
        {
            char* pstWhat = wide_string_to_UTF8(pwcsWhat);
            Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xset", pstWhat);
            FREE(pstWhat);
            return types::Function::Error;
        }
    }

    return types::Function::OK;
}
Example #19
0
/*------------------------------------------------------------------------*/
int sci_plot2d( char * fname, unsigned long fname_len )
{

    int m1 = 0, n1 = 0, l1 = 0, m2 = 0, n2 = 0, l2 = 0, lt = 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;
    double xd[2];
    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];

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

    if (Rhs == 0)
    {
        sci_demo(fname, fname_len);
        return 0;
    }

    CheckRhs(1, 9);

    iskip = 0;
    if ( get_optionals(fname, opts) == 0)
    {
        PutLhsVar();
        return 0 ;
    }

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

    if (FirstOpt() == 2 + iskip)       				/** plot2d([loglags,] y, <opt_args>); **/
    {
        GetRhsVar(1 + iskip, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2);

        if (m2 == 1 && n2 > 1)
        {
            m2 = n2;
            n2 = 1;
        }
        m1 = m2;
        n1 = n2;
        CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE,  &m1, &n1, &l1);

        for (i = 0; i < m2 ; ++i)
        {
            for (j = 0 ; j < n2 ;  ++j)
            {
                *stk( l1 + i + m2 * j) = (double) i + 1;
            }
        }
    }
    else if (FirstOpt() >= 3 + iskip)     /** plot2d([loglags,] x, y[, style [,...]]); **/
    {

        /* x */
        GetRhsVar(1 + iskip, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1);

        /* y */
        GetRhsVar(2 + iskip, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &l2);

        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(1 + iskip, 2 + iskip, !test);

        if (m1 * n1 == 0)
        {
            /* default x=1:n */
            CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE,  &m2, &n2, &lt);
            if (m2 == 1 && n2 > 1)
            {
                m2 = n2;
                n2 = 1;
            }
            for (i = 0; i < m2 ; ++i)
            {
                for (j = 0 ; j < n2 ;  ++j)
                {
                    *stk( 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 */
            CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE,  &m2, &n2, &lt);
            for (i = 0; i < m2 ; ++i)
            {
                for (j = 0 ; j < n2 ;  ++j)
                {
                    *stk( lt + i + m2 * j) = *stk(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 */
            CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE,  &m1, &n2, &lt);
            for (j = 0 ; j < n2 ;  ++j)
            {
                *stk( lt + j ) = *stk(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( fname, 3 + iskip, n1, opts, &style ) ;

    GetStrf( fname, 4 + iskip, opts, &strf ) ;

    GetLegend( fname, 5 + iskip, opts, &legend );

    GetRect( fname, 6 + iskip, opts, &rect );

    GetNax( 7 + iskip, opts, &nax, &flagNax ) ;

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

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

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

        GetOptionalIntArg(fname, 9, "frameflag", &frame, 1, opts);
        if ( frame != &frame_def )
        {
            strfl[1] = (char)(*frame + 48);
        }

        GetOptionalIntArg(fname, 9, "axesflag", &axes, 1, opts);

        if (axes != &axes_def)
        {
            strfl[2] = (char)(*axes + 48);
        }
    }

    /* 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])
            {
                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 */
            {
                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 */
            {
                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' :
                    xd[0] = 1.0;
                    xd[1] = (double)m1;
                    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(stk(l1), size_x) <= 0.0 )
                {
                    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(stk(l2), size_y) <= 0.0 )
                {
                    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, stk(l1), stk(l2), &n1, &m1, style, strf, legend, rect, nax, flagNax);

    LhsVar(1) = 0;
    PutLhsVar();
    return 0;
}
Example #20
0
/*--------------------------------------------------------------------------*/
int sci_xget(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    char* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    char* l3 = NULL;

    int m1 = 0, m2 = 0, n2 = 0, i = 0;
    int one = 1;

    BOOL keyFound = FALSE;

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

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

    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, &l1))
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
        return 1;
    }

    /* check if key is valid */
    for (i = 0; i < NUMSETFONC ; i++)
    {
        if (strcmp((l1), KeyTab_[i]) == 0)
        {
            keyFound = TRUE;
            break;
        }
    }

    if (!keyFound)
    {
        Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), fname, (l1));
        freeAllocatedSingleString(l1);
        return -1;
    }

    if (nbInputArgument(pvApiCtx) == 2)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            freeAllocatedSingleString(l1);
            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);
            freeAllocatedSingleString(l1);
            return 1;
        }

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

    }

    if (strcmp(l1, "fpf") == 0 || strcmp(l1, "auto clear") == 0)
    {
        int bufl;
        char buf[4096];
        /*     special case for global variables set */
        xgetg((l1), buf, &bufl, m1, bsiz);
        if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, bufl * one, (const char **)&l3))
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            freeAllocatedSingleString(l1);
            return 1;
        }

        strncpy((l3), buf, bufl);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "colormap") == 0)
    {
        int iObjUID = 0;
        // Force figure creation if none exists.
        getOrCreateDefaultSubwin();
        iObjUID = getCurrentFigure();

        get_color_map_property(pvApiCtx, iObjUID);

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "mark") == 0)
    {
        int iObjUID = getOrCreateDefaultSubwin();
        int iMarkStyle = 0;
        int* piMarkStyle = &iMarkStyle;
        int iMarkSize = 0;
        int* piMarkSize = &iMarkSize;
        double pdblResult[2];

        getGraphicObjectProperty(iObjUID, __GO_MARK_STYLE__, jni_int, (void**)&piMarkStyle);
        getGraphicObjectProperty(iObjUID, __GO_MARK_SIZE__, jni_int, (void**)&piMarkSize);
        pdblResult[0] = iMarkStyle;
        pdblResult[1] = iMarkSize;

        createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblResult);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "mark size") == 0)
    {
        int iObjUID = getOrCreateDefaultSubwin();
        get_mark_size_property(pvApiCtx, iObjUID);

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "line style") == 0)
    {
        get_line_style_property(pvApiCtx, getOrCreateDefaultSubwin());

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "clipping") == 0)
    {
        double *clipBox = NULL;
        int iObjUID = getOrCreateDefaultSubwin();

        getGraphicObjectProperty(iObjUID, __GO_CLIP_BOX__, jni_double_vector, (void **)&clipBox);

        createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 4, clipBox);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "font") == 0)
    {
        int iObjUID = getOrCreateDefaultSubwin();
        double dblFontSize = 0;
        double* pdblFontSize = &dblFontSize;
        int iFontStyle = 0;
        int* piFontStyle = &iFontStyle;
        double pdblResult[2];

        getGraphicObjectProperty(iObjUID, __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize);
        getGraphicObjectProperty(iObjUID, __GO_FONT_STYLE__, jni_int, (void**)&piFontStyle);

        pdblResult[0] = iFontStyle;
        pdblResult[1] = dblFontSize;


        createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblResult);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "font size") == 0)
    {
        double dblFontSize = 0;
        double* pdblFontSize = &dblFontSize;
        getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize);

        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dblFontSize);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "dashes") == 0)
    {
        int iLineStyle = 0;
        int* piLineStyle = &iLineStyle;

        getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, jni_int, (void**)&piLineStyle);

        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iLineStyle);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "hidden3d") == 0)
    {
        get_hidden_color_property(pvApiCtx, getOrCreateDefaultSubwin());

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "window") == 0 || strcmp(l1, "figure") == 0)
    {
        int iFigureId = 0;
        int* piFigureId = &iFigureId;

        getOrCreateDefaultSubwin();
        getGraphicObjectProperty(getCurrentFigure(), __GO_ID__, jni_int, (void**)&piFigureId);
        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iFigureId);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "thickness") == 0)
    {
        get_thickness_property(pvApiCtx, getOrCreateDefaultSubwin());

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "wdim") == 0 || strcmp(l1, "wpdim") == 0)
    {
        int *piFigureSize = NULL;
        double pdblFigureSize[2];

        getOrCreateDefaultSubwin();
        getGraphicObjectProperty(getCurrentFigure(), __GO_SIZE__, jni_int_vector, (void **) &piFigureSize);
        pdblFigureSize[0] = (double) piFigureSize[0];
        pdblFigureSize[1] = (double) piFigureSize[1];

        createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblFigureSize);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "wpos") == 0)
    {
        int *piFigurePosition = NULL;
        double pdblFigurePosition[2];

        getOrCreateDefaultSubwin();
        getGraphicObjectProperty(getCurrentFigure(), __GO_POSITION__, jni_int_vector, (void **) &piFigurePosition);
        pdblFigurePosition[0] = piFigurePosition[0];
        pdblFigurePosition[1] = piFigurePosition[1];

        createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblFigurePosition);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "viewport") == 0)
    {
        int* viewport = NULL;
        double pdblViewport[2];

        getOrCreateDefaultSubwin();
        getGraphicObjectProperty(getCurrentFigure(), __GO_VIEWPORT__, jni_int_vector, (void **)&viewport);
        pdblViewport[0] = viewport[0];
        pdblViewport[1] = viewport[1];

        createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblViewport);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "background") == 0)
    {
        get_background_property(pvApiCtx, getOrCreateDefaultSubwin());

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (  strcmp(l1, "color") == 0
               || strcmp(l1, "foreground") == 0
               || strcmp(l1, "pattern") == 0)
    {
        get_foreground_property(pvApiCtx, getOrCreateDefaultSubwin());

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "lastpattern") == 0)
    {
        int iNumColors = 0;
        int* piNumColors = &iNumColors;

        getOrCreateDefaultSubwin();
        getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors);

        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNumColors);

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "line mode") == 0)
    {
        int iLineMode = 0;
        int* lineMode = &iLineMode;

        getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_MODE__, jni_bool, (void **)&lineMode);

        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iLineMode);

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "white") == 0)
    {
        int iNumColors = 0;
        int* piNumColors = &iNumColors;

        getOrCreateDefaultSubwin();
        getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors);

        /* White is lqst colormap index + 2 */
        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNumColors + 2);

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "wresize") == 0)
    {
        // autoresize property
        int iAutoResize = 0;
        int* piAutoResize =  &iAutoResize;

        getOrCreateDefaultSubwin();
        getGraphicObjectProperty(getCurrentFigure(), __GO_AUTORESIZE__, jni_bool, (void **)&piAutoResize);

        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iAutoResize);

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "clipgrf") == 0)
    {
        /* clip_state : 0 = off, 1 = on */
        int iClipState = 0;
        int* piClipState = &iClipState;

        getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState);

        createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iClipState);
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else if (strcmp(l1, "clipoff") == 0)
    {
        int iClipState = 0;
        int* piClipState = &iClipState;

        getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState);

        /* clip_state : 0 = off, 1 = on */
        if (iClipState == 0)
        {
            createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1);
        }
        else
        {
            createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 0);
        }
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else
    {
        Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), fname, (l1));
        freeAllocatedSingleString(l1);
        return -1;
    }

    freeAllocatedSingleString(l1);
    return 0;
}
Example #21
0
/*--------------------------------------------------------------------------*/
int sci_param3d1(char *fname, void *pvApiCtx)
{
    SciErr sciErr;
    int izcol = 0, isfac = 0;
    double *zcol = NULL;
    static double  ebox_def [6] = { 0, 1, 0, 1, 0, 1};
    double *ebox = ebox_def;
    static int iflag_def[3] = {1, 2, 4};
    int iflag[3] , *ifl = NULL;
    double  alpha_def = 35.0 , theta_def = 45.0;
    double *alpha = &alpha_def, *theta = &theta_def;
    int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0;
    int m3n = 0, n3n = 0, m3l = 0;
    static rhs_opts opts[] =
    {
        { -1, "alpha", -1, 0, 0, NULL},
        { -1, "ebox", -1, 0, 0, NULL},
        { -1, "flag", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "theta", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    char * labels = NULL;

    int* piAddr1  = NULL;
    int* piAddr2  = NULL;
    int* piAddr3  = NULL;
    int* piAddr31 = NULL;
    int* piAddr32 = NULL;

    double* l1  = NULL;
    double* l2  = NULL;
    double* l3  = NULL;
    double* l3n = NULL;

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

    CheckInputArgument(pvApiCtx, 3, 8);

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

    if (FirstOpt(pvApiCtx) < 4)
    {
        Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4);
        return (0);
    }

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    if (m1 == 1 && n1 > 1)
    {
        m1 = n1;
        n1 = 1;
    }

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

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

    if (m1 * n1 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }
    //CheckSameDims
    if (m1 != m2 || n1 != n2)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    switch (getInputArgumentType(pvApiCtx, 3))
    {
        case 1 :
            izcol = 0;

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

            break;
        case 15 :
            izcol = 1;
            /* z = list(z,colors) */
            sciErr = getListItemNumber(pvApiCtx, piAddr3, &m3l);
            if (sciErr.iErr)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                printError(&sciErr, 0);
                return 1;
            }

            if (m3l != 2)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: List of size %d expected.\n"),
                         fname, 2, m3l, 2);
                return 0;
            }

            sciErr = getListItemAddress(pvApiCtx, piAddr3, 1, &piAddr31);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            sciErr = getMatrixOfDouble(pvApiCtx, piAddr31, &m3, &n3, &l3); /* z */
            if (sciErr.iErr)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                printError(&sciErr, 0);
                return 1;
            }

            sciErr = getListItemAddress(pvApiCtx, piAddr3, 2, &piAddr32);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            sciErr = getMatrixOfDouble(pvApiCtx, piAddr32, &m3n, &n3n, &l3n); /* z */
            if (sciErr.iErr)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                printError(&sciErr, 0);
                return 1;
            }

            zcol  = (l3n);
            if (m3n * n3n != n3)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, 3, n3);
                return 0;
            }
            break;
        default :
            OverLoad(3);
            return 0;
    }

    if (m3 == 1 && n3 > 1)
    {
        m3 = n3;
        n3 = 1;
    }
    //CheckSameDims
    if (m1 != m3 || n1 != n3)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }


    GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts);
    GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts);
    GetLabels(pvApiCtx, fname, 6, opts, &labels);
    iflag_def[1] = 8;
    ifl = &(iflag_def[1]);
    GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &ifl, 2, opts);
    iflag[0] = iflag_def[0];
    iflag[1] = ifl[0];
    iflag[2] = ifl[1];

    GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts);

    if (m1 == 1 && n1 > 1)
    {
        m1 = n1;
        n1 = 1;
    }

    getOrCreateDefaultSubwin();

    /* NG beg */
    isfac = -1;

    Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), zcol, &m1, &n1, theta, alpha, labels, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04*/

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #22
0
void Objfpoly (double  * x    ,
               double  * y    ,
               int   n    ,
               int * style,
               long    * hdl  ,
               int   shading)
{
    char* psubwinUID = NULL;
    char* pobjUID = NULL;

    int fillcolor = 0;
    int contourcolor = 0;
    int *piContourColor = &contourcolor;

    int closed = 1; /* we close the polyline by default */

    psubwinUID = (char*)getOrCreateDefaultSubwin();

    checkRedrawing();

    if (shading == 2)
    {
        /* interpolated shading is "on" */
        pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n,
                                    1, NULL, style, NULL, NULL, NULL, FALSE, TRUE, FALSE, TRUE);
    }
    else
    {

        /* flat mode is "on" */
        if (*style < 0)
        {
            fillcolor = abs(*style);
            pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n,
                                        1, NULL, &fillcolor, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE);
        }
        else if (*style == 0)
        {
            getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piContourColor);
            pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n,
                                        1, &contourcolor, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
        }
        else
        {
            /* *style > 0*/
            fillcolor = *style;
            getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piContourColor);
            pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n,
                                        1, &contourcolor, &fillcolor, NULL, NULL, NULL, TRUE, TRUE, FALSE, FALSE);
        }

    }

    if (pobjUID == NULL)
    {
        Scierror(999, _("%s: No more memory.\n"), "Objfpoly");
        return;
    }

    setCurrentObject(pobjUID);
    *hdl = getHandle(pobjUID);

    releaseGraphicObjectProperty(__GO_PARENT__, pobjUID, jni_string, 1);
}
Example #23
0
/*--------------------------------------------------------------------------*/
int sci_xfpolys(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    int* piAddr3 = NULL;
    int* l3 = NULL;

    int m1 = 0, n1 = 0;
    int m2 = 0, n2 = 0;
    int m3 = 0, n3 = 0;
    int mn2 = 0;

    int v1 = 0;                 /* v1 is the flag used for flat (v1==1) or interpolated (v1==2) shading */
    int i = 0;
    long hdl = 0;

    char *pstSubWinUID = NULL;
    char *pstFigureUID = NULL;
    char *pstCompoundUID = NULL;
    int iSubWinForeground = 0;

    int iImmediateDrawing = 0;
    int *piImmediateDrawing = &iImmediateDrawing;
    int iFalse = 0;

    int iColorMapSize = 0;
    int* piColorMapSize = &iColorMapSize;
    int iForeGround = 0;
    int* piForeGround = &iForeGround;

    int iVisible = 0;
    int *piVisible = &iVisible;

    CheckInputArgument(pvApiCtx, 2, 3);

    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;
    }

    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;
    }

    //CheckSameDims
    if (m1 != m2 || n1 != n2)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }

    mn2 = m2 * n2;
    if (mn2 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

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

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


        if (m3 * n3 == m1 * n1)
        {
            //CheckSameDims
            if (m1 != m3 || n1 != n3)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
                return 1;
            }

            v1 = 2;             /* interpolated shading */

            if (m3 != 3 && m3 != 4)
            {
                Scierror(999, _("%s: Interpolated shading only works for polygons of size %d or %d\n"), fname, 3, 4);
                return 0;
            }
        }
        else
        {
            //CheckVector
            if (m3 != 1 && n3 != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 3);
                return 1;
            }

            //CheckDimProp
            if (m3 * n3 != n2)
            {
                Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
                return 1;
            }

            v1 = 1;             /* flat shading */
        }
    }
    else
    {
        int un = 1, ix = 0;

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

        for (ix = 0; ix < n2; ++ix)
        {
            *(int*)(l3 + ix) = 0;
        }
        m3 = n3 = 1;
    }

    pstSubWinUID = (char*)getOrCreateDefaultSubwin();
    getGraphicObjectProperty(pstSubWinUID, __GO_PARENT__, jni_string, (void**)&pstFigureUID);
    getGraphicObjectProperty(pstFigureUID, __GO_IMMEDIATE_DRAWING__, jni_bool, (void **)&piImmediateDrawing);
    setGraphicObjectProperty(pstFigureUID, __GO_IMMEDIATE_DRAWING__, &iFalse, jni_bool, 1);

    //get color map size
    getGraphicObjectProperty(pstFigureUID, __GO_COLORMAP_SIZE__, jni_int, (void**)&piColorMapSize);

    //get current foreground color
    getGraphicObjectProperty(pstSubWinUID, __GO_LINE_COLOR__, jni_int, (void**)&piForeGround);

    // Create compound.
    pstCompoundUID = createGraphicObject(__GO_COMPOUND__);
    setGraphicObjectProperty(pstCompoundUID, __GO_VISIBLE__, &iFalse, jni_bool, 1);
    /* Sets the parent-child relationship for the Compound */
    setGraphicObjectRelationship(pstSubWinUID, pstCompoundUID);

    for (i = 0; i < n1; ++i)
    {
        if (m3 == 1 || n3 == 1) /* color vector specified */
        {
            if (*(int*)(l3 + i) == 0)
            {
                if (iForeGround == -1)
                {
                    iSubWinForeground = iColorMapSize + 1;
                }
                else if (iForeGround == -2)
                {
                    iSubWinForeground = iColorMapSize + 2;
                }
                else
                {
                    iSubWinForeground = iForeGround;
                }

                Objpoly((l1 + (i * m1)), (l2 + (i * m1)), m1, 1, iSubWinForeground, &hdl);
            }
            else
            {
                Objfpoly((l1 + (i * m1)), (l2 + (i * m1)), m1, (int*)(l3 + i), &hdl, v1);
            }
        }
        else                    /* we have a color matrix used for interpolated shading : one color per vertex */
        {
            Objfpoly((l1 + (i * m1)), (l2 + (i * m1)), m1, (int*)(l3 + i * m3), &hdl, v1);
        }

        // Add newly created object to Compound
        setGraphicObjectRelationship(pstCompoundUID, getObjectFromHandle(hdl));
    }


    setCurrentObject(pstCompoundUID);

    setGraphicObjectProperty(pstFigureUID, __GO_IMMEDIATE_DRAWING__, &piImmediateDrawing, jni_bool, 1);
    getGraphicObjectProperty(pstFigureUID, __GO_VISIBLE__, jni_bool, (void **)&piVisible);

    setGraphicObjectProperty(pstCompoundUID, __GO_VISIBLE__, &iVisible, jni_bool, 1);


    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #24
0
/*--------------------------------------------------------------------------*/
int sci_plot3d(char * fname, unsigned long fname_len)
{
    SciErr sciErr;
    static double  ebox_def [6] = { 0, 1, 0, 1, 0, 1};
    double *ebox = ebox_def;
    static int iflag_def[3] = {2, 2, 4};
    int *iflag = iflag_def;
    double  alpha_def = 35.0 , theta_def = 45.0;
    double *alpha = &alpha_def, *theta = &theta_def;
    int m1 = 0, n1 = 0,  m2 = 0, n2 = 0, m3 = 0, n3 = 0;
    int m3n = 0, n3n = 0, m3l = 0;

    int izcol = 0,  isfac = 0;
    double *zcol = NULL;

    static rhs_opts opts[] =
    {
        { -1, "alpha", -1, 0, 0, NULL},
        { -1, "ebox", -1, 0, 0, NULL},
        { -1, "flag", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "theta", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    char * legend = NULL;

    int* piAddr1  = NULL;
    int* piAddr2  = NULL;
    int* piAddr3  = NULL;
    int* piAddr31 = NULL;
    int* piAddr32 = NULL;

    double* l1  = NULL;
    double* l2  = NULL;
    double* l3  = NULL;
    double* l3n = NULL;

    /*
    ** This overload the function to call demo script
    ** the demo script is called %_<fname>
    */
    if (nbInputArgument(pvApiCtx) <= 0)
    {
        sci_demo(fname, fname_len);
        return 0;
    }

    CheckInputArgument(pvApiCtx, 3, 8);

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

    if (FirstOpt() < 4)
    {
        Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4);
        return -1;
    }

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    if (m1 * n1 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

    if (nbInputArgument(pvApiCtx) >= 3)
    {
        /*     third argument can be a matrix z or a list list(z,zcol) */
        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        switch (getInputArgumentType(pvApiCtx, 3))
        {
            case sci_matrix :
                //get variable address
                sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

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

                izcol = 0;
                break;
            case sci_list :
                izcol = 1;
                /* z = list(z,colors) */
                sciErr = getListItemNumber(pvApiCtx, piAddr3, &m3l);
                if (sciErr.iErr)
                {
                    Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
                    printError(&sciErr, 0);
                    return 1;
                }

                if (m3l != 2)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: List of size %d expected.\n"),
                             fname, 2, m3l, 2);
                    return 1;
                }

                sciErr = getListItemAddress(pvApiCtx, piAddr3, 1, &piAddr31);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                sciErr = getMatrixOfDouble(pvApiCtx, piAddr31, &m3, &n3, &l3); /* z */
                if (sciErr.iErr)
                {
                    Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
                    printError(&sciErr, 0);
                    return 1;
                }

                sciErr = getListItemAddress(pvApiCtx, piAddr3, 2, &piAddr32);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                sciErr = getMatrixOfDouble(pvApiCtx, piAddr32, &m3n, &n3n, &l3n); /* z */
                if (sciErr.iErr)
                {
                    Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
                    printError(&sciErr, 0);
                    return 1;
                }

                zcol  = (l3n);
                if (m3n * n3n != n3 &&  m3n * n3n != m3 * n3)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d expected.\n"), fname, 3, n3, m3 * n3);
                    return 1;
                }
                /*
                *   Added by E Segre 4/5/2000. In the case where zcol is a
                *   matrix of the same size as z, we set izcol to 2. This
                *   value is later transmitted to the C2F(fac3dg) routine,
                *   which has been modified to do the interpolated shading
                *    (see the file SCI/modules/graphics/src/c/Plo3d.c
                */
                if (m3n * n3n == m3 * n3)
                {
                    izcol = 2 ;
                }
                break;
            default :
                OverLoad(3);
                return 0;
        }
    }
    iflag_def[1] = 8;

    GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts);
    GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts);
    GetLabels(pvApiCtx, fname, 6, opts, &legend);
    GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &iflag, 3, opts);
    GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts);

    if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1)
    {
        if (! (m1 == m2 && m2 == m3 && n1 == n2 && n2 == n3))
        {
            Scierror(999, _("%s: Wrong value for input arguments #%d, #%d and #%d: Incompatible length.\n"), fname, 1, 2, 3);
            return 1;
        }
    }
    else
    {
        if (m2 * n2 != n3)
        {
            Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 2, 3);
            return 1;
        }

        if (m1 * n1 != m3)
        {
            Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 1, 3);
            return 1;
        }

        if (m1 * n1 <= 1 || m2 * n2 <= 1)
        {
            Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: %s expected.\n"), fname, 2, 3, ">= 2");
            return 1;
        }
    }

    if (m1 * n1 == 0 || m2 * n2 == 0 || m3 * n3 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

    getOrCreateDefaultSubwin();

    /******************** 24/05/2002 ********************/
    if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1) /* NG beg */
    {
        isfac = 1;
    }
    else
    {
        isfac = 0;
    }


    Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), zcol, &m3, &n3, theta, alpha, legend, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04 and 19.03.04*/

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

}
Example #25
0
/*--------------------------------------------------------------------------*/
int sci_xrects(char *fname, void *pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddr2 = NULL;
    int* l2 = NULL;

    int m1 = 0, n1 = 0, m2 = 0, n2 = 0;
    long  hdl = 0;
    int i = 0;
    int iSubwinUID = 0;

    int foreground = 0;
    int *piForeground = &foreground;
    int iCompoundUID = 0;

    CheckInputArgument(pvApiCtx, 1, 2);

    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;
    }

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


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

        // Retrieve a matrix of double at position 2.
        sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr2, &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;
        }

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

        if (m2 * n2 != n1)
        {
            Scierror(999, _("%s: Incompatible length for input arguments #%d and #%d.\n"), fname, 1, 2);
            return 0;
        }
    }
    else
    {
        m2 = 1;
        n2 = n1;

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

        for (i = 0; i < n2; ++i)
        {
            l2[i] = 0;
        }
    }

    iSubwinUID = getOrCreateDefaultSubwin();

    // Create compound.
    iCompoundUID = createGraphicObject(__GO_COMPOUND__);
    /* Sets the parent-child relationship for the Compound */
    setGraphicObjectRelationship(iSubwinUID, iCompoundUID);

    /** Get Subwin line color */
    getGraphicObjectProperty(iSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piForeground);

    for (i = 0; i < n1; ++i)
    {
        /*       j = (i==0) ? 0 : 1; */
        if (l2[i] == 0)
        {
            /** fil(i) = 0 rectangle i is drawn using the current line style (or color).**/
            /* color setting is done now */

            Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3),
                    &foreground, NULL, FALSE, TRUE, &hdl);
        }
        else
        {
            if (l2[i] < 0)
            {
                /** fil(i) < 0 rectangle i is drawn using the line style (or color) **/
                int tmp = - (*(int*)(l2 + i));
                Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3),
                        &tmp, NULL, FALSE, TRUE, &hdl);
            }
            else
            {
                /** fil(i) > 0   rectangle i is filled using the pattern (or color) **/
                Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3),
                        NULL, l2 + i, TRUE, FALSE, &hdl);
            }
        }
        // Add newly created object to Compound
        setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl));
    }

    /** make Compound current object **/
    setCurrentObject(iCompoundUID);
    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    return 0;
}
Example #26
0
/*--------------------------------------------------------------------------*/
int sci_fec(char *fname, void *pvApiCtx)
{
    SciErr sciErr;
    int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0, mn1 = 0;

    static rhs_opts opts[] =
    {
        { -1, "colminmax", -1, 0, 0, NULL},
        { -1, "colout", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "mesh", -1, 0, 0, NULL},
        { -1, "nax", -1, 0, 0, NULL},
        { -1, "rect", -1, 0, 0, NULL},
        { -1, "strf", -1, 0, 0, NULL},
        { -1, "zminmax", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    char* strf      = NULL;
    char strfl[4];
    char* legend    = NULL;
    double* rect    = NULL;
    double* zminmax = NULL;
    int* colminmax  = NULL;
    int* nax        = NULL;
    int* colOut     = NULL;
    BOOL flagNax    = FALSE;
    BOOL withMesh   = FALSE;

    int* piAddr1 = NULL;
    int* piAddr2 = NULL;
    int* piAddr3 = NULL;
    int* piAddr4 = NULL;

    double* l1 = NULL;
    double* l2 = NULL;
    double* l3 = NULL;
    double* l4 = NULL;

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

    CheckInputArgument(pvApiCtx, 4, 12);

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

    if (FirstOpt(pvApiCtx) < 5)
    {
        Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 5);
        return -1;
    }

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    //CheckSameDims
    if (m1 != m2 || n1 != n2)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }


    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    if (n3 < 5)
    {
        Scierror(999, _("%s: Wrong number of columns for input argument #%d: at least %d expected.\n"), fname, 3, 5);
        return 0;
    }
    // remove number and flag
    n3 -= 2;

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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


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

    GetStrf(pvApiCtx, fname, 5, opts, &strf);
    GetLegend(pvApiCtx, fname, 6, opts, &legend);
    GetRect(pvApiCtx, fname, 7, opts, &rect);
    GetNax(pvApiCtx, 8, opts, &nax, &flagNax);
    GetZminmax(pvApiCtx, fname, 9, opts, &zminmax);
    GetColminmax(pvApiCtx, fname, 10, opts, &colminmax);
    GetColOut(pvApiCtx, fname, 11, opts, &colOut);
    GetWithMesh(pvApiCtx, fname, 12, opts, &withMesh);

    getOrCreateDefaultSubwin();

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

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

    Objfec ((l1), (l2), (l3), (l4), &mn1, &m3, &n3, strf, legend, rect, nax, zminmax, colminmax, colOut, withMesh, flagNax);

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

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

    int* piAddrl = NULL;
    double* l = NULL;

    int color[] = {0, 0, 0};              /* Default color */
    double thickness[] = { -1, -1, -1};
    int style[] = {3, 3, 3};
    int m = 0, n = 0, mn = 0;
    int i;
    int iObjUID = 0;

    CheckInputArgument(pvApiCtx, 0, 3);

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

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

        mn = m * n;

        if (mn == 0 || mn > 3)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar or a row vector expected.\n"), fname, 1);
            return 1;
        }

        if (mn == 1)
        {
            color[0] = (int) l[0];
            color[1] = color[0];
            color[2] = color[0];
        }
        else
        {
            for (i = 0; i < mn; i++)
            {
                color[i] = (int) l[i];
            }
        }
    }

    iObjUID = getOrCreateDefaultSubwin();

    setGraphicObjectProperty(iObjUID, __GO_X_AXIS_GRID_COLOR__, color, jni_int, 1);
    setGraphicObjectProperty(iObjUID, __GO_Y_AXIS_GRID_COLOR__, color + 1, jni_int, 1);
    setGraphicObjectProperty(iObjUID, __GO_Z_AXIS_GRID_COLOR__, color + 2, jni_int, 1);

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

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

        mn = m * n;

        if (mn == 0 || mn > 3)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar or a row vector expected.\n"), fname, 2);
            return 1;
        }

        if (mn == 1)
        {
            thickness[0] = l[0];
            thickness[1] = l[0];
            thickness[2] = l[0];
        }
        else
        {
            for (i = 0; i < mn; i++)
            {
                thickness[i] = l[i];
            }
        }

        setGraphicObjectProperty(iObjUID, __GO_X_AXIS_GRID_THICKNESS__, thickness, jni_double, 1);
        setGraphicObjectProperty(iObjUID, __GO_Y_AXIS_GRID_THICKNESS__, thickness + 1, jni_double, 1);
        setGraphicObjectProperty(iObjUID, __GO_Z_AXIS_GRID_THICKNESS__, thickness + 2, jni_double, 1);
    }

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

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

        mn = m * n;

        if (mn == 0 || mn > 3)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar or a row vector expected.\n"), fname, 3);
            return 1;
        }

        if (mn == 1)
        {
            style[0] = (int) l[0];
            style[1] = style[0];
            style[2] = style[0];
        }
        else
        {
            for (i = 0; i < mn; i++)
            {
                style[i] = (int) l[i];
            }
        }

        setGraphicObjectProperty(iObjUID, __GO_X_AXIS_GRID_STYLE__, style, jni_int, 1);
        setGraphicObjectProperty(iObjUID, __GO_Y_AXIS_GRID_STYLE__, style + 1, jni_int, 1);
        setGraphicObjectProperty(iObjUID, __GO_Z_AXIS_GRID_STYLE__, style + 2, jni_int, 1);
    }

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

    return 0;
}
Example #28
0
/*------------------------------------------------------------------------*/
int sci_param3d(char * fname, void *pvApiCtx)
{
    SciErr sciErr;
    int izcol = 0, isfac = 0;
    static double  ebox_def[6] = { 0, 1, 0, 1, 0, 1};
    double *ebox = ebox_def;
    static int iflag_def[3] = {1, 2, 4};
    int iflag[3], *ifl = NULL, ix1 = 0, one = 1;
    double  alpha_def = 35.0 , theta_def = 45.0;
    double *alpha = &alpha_def, *theta = &theta_def;
    int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0;
    int m3n = 0, n3n = 0; /* F.Leray 19.03.04*/

    static rhs_opts opts[] =
    {
        { -1, "alpha", -1, 0, 0, NULL},
        { -1, "ebox", -1, 0, 0, NULL},
        { -1, "flag", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "theta", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    char * labels = NULL;

    int* piAddr1 = NULL;
    int* piAddr2 = NULL;
    int* piAddr3 = NULL;

    double* l1 = NULL;
    double* l2 = NULL;
    double* l3 = NULL;

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

    CheckInputArgument(pvApiCtx, 3, 8);

    if (getOptionals(pvApiCtx, fname, opts) == 0)
    {
        ReturnArguments(pvApiCtx);
        return 0;
    }
    if (FirstOpt(pvApiCtx) < 4)
    {
        Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4);
        return(0);
    }

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    if (m1 * n1 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }
    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

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

    //CheckSameDims
    if (m1 != m2 || n1 != n2)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }

    //CheckSameDims
    if (m2 != m3 || n2 != n3)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 2, m2, n2);
        return 1;
    }


    GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts);
    GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts);
    GetLabels(pvApiCtx, fname, 6, opts, &labels);

    iflag_def[1] = 8;
    ifl = &(iflag_def[1]);
    GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &ifl, 2, opts);
    iflag[0] = iflag_def[0];
    iflag[1] = ifl[0];
    iflag[2] = ifl[1];
    GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts);

    getOrCreateDefaultSubwin();

    ix1 = m1 * n1;

    /* NG beg */
    isfac = -1;
    izcol = 0;

    Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), (double *) NULL, &ix1, &one, theta, alpha, labels, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04 */


    /* NG end */
    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Example #29
0
/*--------------------------------------------------------------------------*/
int sci_xpoly(char * fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    int* piAddrl3 = NULL;
    char* l3 = NULL;
    int* piAddrl4 = NULL;
    double* l4 = NULL;

    char *psubwinUID = NULL;
    char* pobjUID = NULL;

    int m1 = 0, n1 = 0, m2 = 0 , n2 = 0, m4 = 0, n4 = 0, close = 0, mn2 = 0;

    long hdl = 0;/* NG */
    int mark = 0;/* NG */
    int markMode = 0;
    int lineMode = 0;
    int foreground = 0;
    int iTmp = 0;
    int* piTmp = &iTmp;

    CheckInputArgument(pvApiCtx, 2, 4);
    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;
    }

    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;
    }

    //CheckSameDims
    if (m1 != m2 || n1 != n2)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }

    mn2 = m2 * n2;

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

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

        if (strcmp((l3), "lines") == 0)
        {
            strcpy(C2F(cha1).buf, "xlines");
            mark = 1; /* NG */
        }
        else if (strcmp((l3), "marks") == 0)
        {
            strcpy(C2F(cha1).buf, "xmarks");
            mark = 0; /* NG */
        }
        else
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 3, "lines", "marks");
            return 0;
        }
    }
    else
    {
        strcpy(C2F(cha1).buf, "xlines");
        mark = 1; /* NG */
    }

    if (nbInputArgument(pvApiCtx) >= 4)
    {
        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;
        }

        close = (int)  * (l4);
    }
    /* NG beg */

    psubwinUID = (char*)getOrCreateDefaultSubwin();

    Objpoly ((l1), (l2), mn2, close, mark, &hdl);

    pobjUID = (char*)getObjectFromHandle(hdl); /* the polyline newly created */

    setGraphicObjectRelationship(psubwinUID, pobjUID);

    /*
     * The contour properties set calls below were
     * already present and have been updated for the MVC.
     */
    if (mark == 0)
    {
        /* marks are enabled but markstyle & foreground
           is determined by parents' markstyle & foreground */

        markMode = 1;
        lineMode = 0;

        getGraphicObjectProperty(psubwinUID, __GO_MARK_STYLE__, jni_int, (void**)&piTmp);
        setGraphicObjectProperty(pobjUID, __GO_MARK_STYLE__, piTmp, jni_int, 1);
    }
    else
    {
        markMode = 0;
        lineMode = 1;

        getGraphicObjectProperty(psubwinUID, __GO_LINE_STYLE__, jni_int, (void**)&piTmp);
        sciSetLineStyle(pobjUID, iTmp);
    }

    getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piTmp);
    foreground = iTmp;

    setGraphicObjectProperty(pobjUID, __GO_LINE_COLOR__, &foreground, jni_int, 1);

    setGraphicObjectProperty(pobjUID, __GO_MARK_MODE__, &markMode, jni_bool, 1);
    setGraphicObjectProperty(pobjUID, __GO_LINE_MODE__, &lineMode, jni_bool, 1);

    /* NG end */
    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    freeAllocatedSingleString(l3);

    return 0;
}
Example #30
0
void Objfpoly (double  * x    ,
               double  * y    ,
               int   n    ,
               int * style,
               long    * hdl  ,
               int   shading)
{
    int iSubwinUID = 0;
    int iObjUID = 0;

    int fillcolor = 0;
    int contourcolor = 0;
    int *piContourColor = &contourcolor;

    int closed = 1; /* we close the polyline by default */
    double rect[6];

    iSubwinUID = getOrCreateDefaultSubwin();

    checkRedrawing();

    if (n)
    {
        MiniMaxi(x, n, rect, rect + 1);
        MiniMaxi(y, n, rect + 2, rect + 3);

        updateXYDataBounds(iSubwinUID, rect);
    }

    if (shading == 2)
    {
        /* interpolated shading is "on" */
        iObjUID = ConstructPolyline(iSubwinUID, x, y, PD0, closed, n,
                                    1, NULL, style, NULL, NULL, NULL, FALSE, TRUE, FALSE, TRUE);
    }
    else
    {

        /* flat mode is "on" */
        if (*style < 0)
        {
            fillcolor = abs(*style);
            iObjUID = ConstructPolyline(iSubwinUID, x, y, PD0, closed, n,
                                        1, NULL, &fillcolor, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE);
        }
        else if (*style == 0)
        {
            getGraphicObjectProperty(iSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piContourColor);
            iObjUID = ConstructPolyline(iSubwinUID, x, y, PD0, closed, n,
                                        1, &contourcolor, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
        }
        else
        {
            /* *style > 0*/
            fillcolor = *style;
            getGraphicObjectProperty(iSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piContourColor);
            iObjUID = ConstructPolyline(iSubwinUID, x, y, PD0, closed, n,
                                        1, &contourcolor, &fillcolor, NULL, NULL, NULL, TRUE, TRUE, FALSE, FALSE);
        }

    }

    if (iObjUID == NULL)
    {
        Scierror(999, _("%s: No more memory.\n"), "Objfpoly");
        return;
    }

    setCurrentObject(iObjUID);
    *hdl = getHandle(iObjUID);
}