Ejemplo n.º 1
0
/*------------------------------------------------------------*/
static int third_example(void)
{
    int code = 0;
    char **JOBS = NULL;
    const int SizeJOBS = 6;
    int i = 0;
    printf("\nExample 3:\n");
    printf("Send many jobs.\n");
    JOBS = (char**)malloc(sizeof(char**) * SizeJOBS);

    for (i = 0; i < SizeJOBS; i++)
    {
        JOBS[i] = (char*)malloc(sizeof(char*) * 1024);
    }

    strcpy(JOBS[0], "A=1 ..");
    strcpy(JOBS[1], "+3;");
    strcpy(JOBS[2], "B = 8;");
    /* strcpy(JOBS[2],"b = V_NOT_EXIST;"); */
    strcpy(JOBS[3], "+3;");
    strcpy(JOBS[4], "disp('C=');");
    strcpy(JOBS[5], "C=A+B;disp(C);"); /* C = 12 */

    code = SendScilabJobs(JOBS, SizeJOBS);

    if (code)
    {
        char lastjob[4096]; // bsiz in scilab 4096 max
        if (GetLastJob(lastjob, 4096))
        {
            printf("Error %s\n", lastjob);
        }
    }

    for (i = 0; i < SizeJOBS; i++)
    {
        if (JOBS[i])
        {
            free(JOBS[i]);
            JOBS[i] = NULL;
        }
    }
    return 0;
}
Ejemplo n.º 2
0
/*--------------------------------------------------------------------------*/
static int example2(void)
{
    int code = 0;

    char **JOBS = NULL;
    const int SizeJOBS = 5;
    int i = 0;
    int m = 0, n = 0;
    double *cxtmp = NULL;

    JOBS = (char**)malloc(sizeof(char**) * SizeJOBS);

    for (i = 0; i < SizeJOBS; i++)
    {
        JOBS[i] = (char*)malloc(sizeof(char*) * 1024);
    }

    strcpy(JOBS[0], "A=1 ..");
    strcpy(JOBS[1], "+3;");
    strcpy(JOBS[2], "B = 8;");
    strcpy(JOBS[3], "+3;");
    strcpy(JOBS[4], "C=A+B;"); /* C = 12 */


    for (i = 0; i < SizeJOBS; i++)
    {
        printf("JOBS[%d] = %s\n", i, JOBS[i]);
    }

    code = SendScilabJobs(JOBS, SizeJOBS);

    if (code)
    {
        char lastjob[4096]; // bsiz in scilab 4096 max
        if (GetLastJob(lastjob, 4096))
        {
            printf("Error %s\n", lastjob);
        }
    }

    m = 1;
    n = 1;
    cxtmp = (double*)malloc((m * n) * sizeof(double));

    ReadMatrix("C", &m, &n, cxtmp);

    printf("Result :\n");
    for (i = 0; i < m * n; i++)
    {
        fprintf(stdout, "C[%d] = %5.2f\n", i, cxtmp[i]);
    }

    for (i = 0; i < SizeJOBS; i++)
    {
        if (JOBS[i])
        {
            free(JOBS[i]);
            JOBS[i] = NULL;
        }
    }
    return 1;
}