/*------------------------------------------------------------*/
int main(void)
{
#ifdef _MSC_VER
    if ( StartScilab(NULL, NULL, NULL) == FALSE )
#else
    if ( StartScilab(getenv("SCI"), NULL, NULL) == FALSE )
#endif
    {
        fprintf(stderr, "Error while calling StartScilab\n");
        return -1;
    }

    first_example();

    second_example() ;

    third_example() ;

    if ( TerminateScilab(NULL) == FALSE )
    {
        fprintf(stderr, "Error while calling TerminateScilab\n");
        return -2;
    }
    return 0;
}
int main(void)
{
    /****** INITIALIZATION **********/
#ifdef _MSC_VER
    if ( StartScilab(NULL, NULL, NULL) == FALSE )
#else
    if ( StartScilab(getenv("SCI"), NULL, NULL) == FALSE )
#endif
    {
        fprintf(stderr, "Error while calling StartScilab\n");
        return -1;
    }

    /****** ACTUAL Scilab TASKS *******/

    SendScilabJob("myMatrix=['sample','for the help']");
    SendScilabJob("disp(myMatrix);"); // Will display !sample  for the help  !
    SendScilabJob("disp([2,3]+[-44,39]);"); // Will display   - 42.    42.

    /****** TERMINATION **********/
    if ( TerminateScilab(NULL) == FALSE )
    {
        fprintf(stderr, "Error while calling TerminateScilab\n");
        return -2;
    }
    return 0;
}
Example #3
0
/*--------------------------------------------------------------------------*/
int main(void)
/* int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR szCmdLine, int iCmdShow) */
{
    if ( StartScilab(NULL, NULL, NULL) == FALSE ) printf("Error : StartScilab\n");
    printf("\nexample 1\n");
    example1();
    printf("\npress return\n");
    getchar();

    printf("\nexample 2\n");
    example2();
    printf("\npress return\n");
    getchar();

    printf("\nexample 3\n");
    example3();
    printf("\npress return\n");
    getchar();


    if ( TerminateScilab(NULL) == FALSE ) printf("Error : TerminateScilab\n");
    return 0;
}
/*------------------------------------------------------------*/
int main(void)
{
#ifdef _MSC_VER
    if ( StartScilab(NULL, NULL, 0) == FALSE )
#else
    if ( StartScilab(getenv("SCI"), NULL, 0) == FALSE )
#endif
    {
        fprintf(stderr,"Error while calling StartScilab\n");
        return -1;
    }

    /******************************** WRITE ****************************/

    /*
    * Write a line matrix into Scilab
    * A=[ 1 3 3 2 ];
    */
    {
        double A[] = {1,3,3,2};   /* Declare the matrix */
        int rowA = 1, colA = 4; /* Size of the matrix */
        char variableName[] = "A";
        SciErr sciErr;

        /*
        * Write it into Scilab's memory 
        */
        sciErr = createNamedMatrixOfDouble(pvApiCtx,variableName,rowA,colA, A);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /*
        * Prior to Scilab 5.2:
        * C2F(cwritemat)(variableName, &rowA, &colA, A,strlen(variableName));
        */

        printf("Display from Scilab of A:\n");
        SendScilabJob("disp(A);"); /* Display A */
    }

    /* 
    * Write a matrix into Scilab
    * B=[1 4 2 3; 
    *    3 9 8 2 ]
    * Note that it is done column by column
    */ 
    {
        double B[] = {1,3,4,9,2,8,3,2};   /* Declare the matrix */
        int rowB = 2, colB = 4; /* Size of the matrix */
        char variableNameB[] = "B";
        SciErr sciErr;

        /*
        * Write it into Scilab's memory 
        */
        sciErr = createNamedMatrixOfDouble(pvApiCtx,variableNameB,rowB,colB, B);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /*
        * Prior to Scilab 5.2:
        * C2F(cwritemat)(variableNameB, &rowB, &colB, B, strlen(variableNameB));
        */

        printf("\n");
        printf("Display from Scilab of B:\n");
        SendScilabJob("disp(B);"); /* Display B */
    }	

    /******************************** READ ****************************/

    /* Load the previously set variable A */
    {
        int rowA_ = 0,colA_ = 0,lp = 0;
        int i = 0, j = 0;
        double *matrixOfDouble = NULL;

        char variableToBeRetrieved[]="A";
        SciErr sciErr;

        /* First, retrieve the size of the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, NULL);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * 	C2F(cmatptr)(variableToBeRetrieved, &rowA_, &colA_, &lp, strlen(variableToBeRetrieved));
        */


        /* Alloc the memory */
        matrixOfDouble=(double*)malloc((rowA_*colA_)*sizeof(double));

        /* Load the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, matrixOfDouble);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * C2F(creadmat)(variableToBeRetrieved,&rowA_,&colA_,matrixOfDouble,strlen(variableToBeRetrieved) );
        */

        printf("\n");
        printf("Display from A (size: %d, %d):\n", rowA_, colA_);
        for(i=0; i < rowA_*colA_; i++)
        {
            fprintf(stdout,"A[%d] = %5.2f\n",i,matrixOfDouble[i]);
        }

        if (matrixOfDouble) 
        {
            free(matrixOfDouble);
            matrixOfDouble=NULL;
        }
    }


    /* Load the previously set variable B */
    {
        int rowB_ = 0, colB_ = 0, lp_ = 0;
        double *matrixOfDoubleB = NULL;
        int i = 0, j = 0;

        char variableToBeRetrievedB[] = "B";
        SciErr sciErr;

        /* First, retrieve the size of the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, NULL);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * C2F(cmatptr)(variableToBeRetrievedB, &rowB_, &colB_, &lp_, strlen(variableToBeRetrievedB));
        */


        /* Alloc the memory */
        matrixOfDoubleB = (double*)malloc((rowB_*colB_)*sizeof(double));

        /* Load the matrix */
        sciErr = readNamedMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, matrixOfDoubleB);
        if(sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* 
        * Prior to Scilab 5.2:
        * C2F(creadmat)(variableToBeRetrievedB,&rowB_,&colB_,matrixOfDoubleB,strlen(variableToBeRetrievedB) );
        */


        printf("\n");
        printf("Display from B raw (size: %d, %d):\n",rowB_, colB_);
        for(i=0; i < rowB_*colB_; i++)
        {
            /* Display the raw matrix */
            fprintf(stdout,"B[%d] = %5.2f\n",i,matrixOfDoubleB[i]);
        }

        printf("\n");
        printf("Display from B formated (size: %d, %d):\n",rowB_, colB_);
        for(j = 0 ; j < rowB_ ; j++)
        {
            for(i = 0 ; i < colB_ ; i++)
            {
                /* Display the formated matrix ... the way the user
                * expect */
                printf("%5.2f ",matrixOfDoubleB[i * rowB_ + j]);
            }
            printf("\n"); /* New row of the matrix */
        }

        if (matrixOfDoubleB) 
        {
            free(matrixOfDoubleB);
            matrixOfDoubleB=NULL;
        }
    }


    if ( TerminateScilab(NULL) == FALSE ) {
        fprintf(stderr,"Error while calling TerminateScilab\n");
        return -2;
    }		
}
/*------------------------------------------------------------*/
int main(void)
{
    void* pvApiCtx = NULL;
#ifdef _MSC_VER
    if ( StartScilab(NULL, NULL, 0) == FALSE )
#else
    if ( StartScilab(getenv("SCI"), NULL, 0) == FALSE )
#endif
    {
        fprintf(stderr, "Error while calling StartScilab\n");
        return -1;
    }

    /******************************** WRITE ****************************/
    /*
     * Write a line complex matrix into Scilab
     * A=[ 1+%i 3 3+7*%i 2-2*%i ];
     */
    {
        /* Declare the complex matrix */
        double A[] = {1, 3, 3, 2};
        double A_img[] = {1, 0, 7, -2};

        int rowA = 1, colA = 4; /* Size of the complex matrix
							* (note that colA = sizeof(A)/2
							*/
        char variableName[] = "A";
        SciErr sciErr;

        /* Write it into Scilab's memory */
        sciErr = createNamedComplexMatrixOfDouble(pvApiCtx, variableName, rowA, colA, A, A_img);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }
        printf("Display from Scilab of A:\n");
        SendScilabJob("disp(A);"); /* Display A */
    }

    /*
    * Write a matrix into Scilab
    * B=[1+%i 4-%i 2+1/2*%i 3;
    *    3 9 8+42*%i 2 ]
    * Note that it is done column by column
    */
    {

        double B[] = {1, 3, 4, 9, 2, 8, 3, 2};
        double B_img[] = {1, 0.233, -1, -0.2, 0.5, 42, -23, 123}; /* Declare the matrix */

        int rowB = 2, colB = 4; /* Size of the matrix */
        char variableNameB[] = "B";
        SciErr sciErr;

        /* Write it into Scilab's memory */
        sciErr = createNamedComplexMatrixOfDouble(pvApiCtx, variableNameB, rowB, colB, B, B_img);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        printf("\n");
        printf("Display from Scilab of B:\n");
        SendScilabJob("disp(B);"); /* Display B */
    }


    /******************************** READ ****************************/

    /* Load the previously set variable A */
    {
        int rowA_ = 0, colA_ = 0, lp = 0;
        int i = 0, j = 0;
        double *matrixOfComplex = NULL;
        double *matrixOfComplex_img = NULL;

        char variableToBeRetrieved[] = "A";
        SciErr sciErr;

        /* First, retrieve the size of the matrix */
        sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, NULL, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        /* Alloc the memory */
        matrixOfComplex = (double*)malloc((rowA_ * colA_ * 2) * sizeof(double));
        matrixOfComplex_img = matrixOfComplex + (rowA_ * colA_);

        /* Load the matrix */
        sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, matrixOfComplex, matrixOfComplex_img);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }


        printf("\n");
        printf("Display raw A (size: %d, %d):\n", rowA_, colA_);
        for (i = 0; i < rowA_ * colA_ * 2; i++) /* *2 is because complex part is store
										 * at the end
										 */
        {
            fprintf(stdout, "A[%d] = %5.2f\n", i, matrixOfComplex[i]);
        }

        printf("\n");
        printf("Display formated A (size: %d, %d):\n", rowA_, colA_);
        for (i = 0; i < rowA_ * colA_; i++)
        {
            fprintf(stdout, "%5.2f + %5.2f.i ", matrixOfComplex[i], matrixOfComplex[i + colA_]);
        }
        printf("\n");

        if (matrixOfComplex)
        {
            free(matrixOfComplex);
            matrixOfComplex = NULL;
        }
    }

    /* Load the previously set variable B */
    {
        int rowB_ = 0, colB_ = 0, lp_ = 0;
        int i = 0, j = 0;

        double *matrixOfComplexB = NULL;
        double *matrixOfComplexB_img = NULL;
        char variableToBeRetrievedB[] = "B";
        SciErr sciErr;
        /* First, retrieve the size of the matrix */

        sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, NULL, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }


        /* Alloc the memory */
        matrixOfComplexB = (double*)malloc((rowB_ * colB_) * sizeof(double));
        matrixOfComplexB_img = (double*)malloc((rowB_ * colB_) * sizeof(double));

        /* Load the matrix */
        sciErr = readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, matrixOfComplexB, matrixOfComplexB_img);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }


        printf("\n");
        printf("Display from B raw - real part (size: %d, %d):\n", rowB_, colB_);
        for (i = 0; i < rowB_ * colB_; i++) /* *2 is because complex part is store
										  * at the end
										  */
        {
            /* Display the raw matrix */
            fprintf(stdout, "B[%d] = %5.2f\n", i, matrixOfComplexB[i]);
        }
        printf("Display from B raw - imaginary part (size: %d, %d):\n", rowB_, colB_);
        for (i = 0; i < rowB_ * colB_; i++) /* *2 is because complex part is store
										  * at the end
										  */
        {
            /* Display the raw matrix */
            fprintf(stdout, "B[%d] = %5.2f\n", i, matrixOfComplexB_img[i]);
        }

        printf("\n");
        printf("Display from B formated (size: %d, %d):\n", rowB_, colB_);
        for (j = 0 ; j < rowB_ ; j++)
        {
            for (i = 0 ; i < colB_ ; i++)
            {
                /* Display the formated matrix ... the way the user
                 * expect */
                printf("%5.2f + %5.2f.i  ", matrixOfComplexB[i * rowB_ + j], matrixOfComplexB_img[i * rowB_ + j]);
            }
            printf("\n"); /* New row of the matrix */
        }

        if (matrixOfComplexB)
        {
            free(matrixOfComplexB);
            matrixOfComplexB = NULL;
        }
        if (matrixOfComplexB_img)
        {
            free(matrixOfComplexB_img);
            matrixOfComplexB_img = NULL;
        }
    }

    if ( TerminateScilab(NULL) == FALSE )
    {
        fprintf(stderr, "Error while calling TerminateScilab\n");
        return -2;
    }
    return 0;
}
Example #6
0
/*------------------------------------------------------------*/
int main(void)
{
#ifdef _MSC_VER
    if ( StartScilab(NULL, NULL, 0) == FALSE )
#else
    if ( StartScilab(getenv("SCI"), NULL, 0) == FALSE )
#endif
    {
        fprintf(stderr, "Error while calling StartScilab\n");
        return -1;
    }

    /******************************** WRITE ****************************/

    /*
    * Write a single string into Scilab
    * A="my Message";
    */
    {
        SciErr sciErr;

        int row = 2, col = 1; /* Size of the matrix */
        /* Declare the string */
        char **myMatrixOfString = (char**)malloc(sizeof(char*) * row * col);
        char variableName[] = "A";
        myMatrixOfString[0] = "my Message";
        myMatrixOfString[1] = "on two lines";

        /* Write it into Scilab's memory */
        sciErr = createNamedMatrixOfString(pvApiCtx, variableName, row, col, myMatrixOfString);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        printf("Display from Scilab of A:\n");
        SendScilabJob("disp(A);"); /* Display A */
    }

    {
        /*
        * Write a matrix into Scilab
        * B=['My' 'Great' ;
        *    'String' ';)' ]
        * Note that it is done column by column
        */
        int row = 2, col = 2; /* Size of the matrix */
        /* Declare the string */
        char **myMatrixOfStringB = (char**)malloc(sizeof(char*) * row * col);
        char variableNameB[] = "B";
        SciErr sciErr;

        printf("\n");

        myMatrixOfStringB[0] = "My";
        myMatrixOfStringB[1] = "String";
        myMatrixOfStringB[2] = "Great";
        myMatrixOfStringB[3] = ";)";

        sciErr = createNamedMatrixOfString(pvApiCtx, variableNameB, row, col, myMatrixOfStringB);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }


        printf("\n");
        printf("Display from Scilab of B:\n");
        SendScilabJob("disp(B);"); /* Display B */
    }
    /******************************** READ ****************************/

    /* Load the previously set variable A */
    {

        char variableToBeRetrieved[] = "A";
        int iRows       = 0;
        int iCols       = 0;
        int i, j;
        int* piAddr     = NULL;
        int* piLen      = NULL;
        char** pstData  = NULL;
        SciErr sciErr;

        //first call to retrieve dimensions
        sciErr = readNamedMatrixOfString(pvApiCtx, variableToBeRetrieved, &iRows, &iCols, NULL, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        piLen = (int*)malloc(sizeof(int) * iRows * iCols);
        //second call to retrieve length of each string
        sciErr = readNamedMatrixOfString(pvApiCtx, variableToBeRetrieved, &iRows, &iCols, piLen, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
        for (i = 0 ; i < iRows * iCols ; i++)
        {
            pstData[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
        }
        //third call to retrieve data
        sciErr = readNamedMatrixOfString(pvApiCtx, variableToBeRetrieved, &iRows, &iCols, piLen, pstData);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }


        printf("\n");
        printf("Load and display of A:\n");
        for (j = 0 ; j < iCols ; j++)
        {
            for (i = 0 ; i < iRows ; i++)
            {
                /* Display the formated matrix with same scilab indice */
                printf("[%d,%d] = %s\n", j + 1, i + 1, pstData[j * iRows + i]);
            }
        }

        printf("\n");
        free(piLen);
        for (i = 0 ; i < iRows * iCols ; i++)
        {
            free(pstData[i]);
        }
        free(pstData);

    }


    /* Load an element of a the previously set variable B */
    {

        char variableToBeRetrieved[] = "B";
        int iRows       = 0;
        int iCols       = 0;
        int i, j;
        int* piAddr     = NULL;
        int* piLen      = NULL;
        char** pstData  = NULL;
        SciErr sciErr;

        //first call to retrieve dimensions
        sciErr = readNamedMatrixOfString(pvApiCtx, variableToBeRetrieved, &iRows, &iCols, NULL, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        piLen = (int*)malloc(sizeof(int) * iRows * iCols);
        //second call to retrieve length of each string
        sciErr = readNamedMatrixOfString(pvApiCtx, variableToBeRetrieved, &iRows, &iCols, piLen, NULL);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }

        pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
        for (i = 0 ; i < iRows * iCols ; i++)
        {
            pstData[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
        }
        //third call to retrieve data
        sciErr = readNamedMatrixOfString(pvApiCtx, variableToBeRetrieved, &iRows, &iCols, piLen, pstData);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
        }


        printf("\n");
        printf("Load and display of B:\n");
        for (j = 0 ; j < iCols ; j++)
        {
            for (i = 0 ; i < iRows ; i++)
            {
                /* Display the formated matrix with same scilab indice */
                printf("[%d,%d] = %s\n", j + 1, i + 1, pstData[j * iRows + i]);
            }
        }

        printf("\n");
        free(piLen);
        for (i = 0 ; i < iRows * iCols ; i++)
        {
            free(pstData[i]);
        }
        free(pstData);

    }

    if ( TerminateScilab(NULL) == FALSE )
    {
        fprintf(stderr, "Error while calling TerminateScilab\n");
        return -2;
    }
    return 0;
}