Ejemplo n.º 1
0
/*--------------------------------------------------------------------------*/
void sciblk4(scicos_block *Blocks, int flag)
{
    /*counter and address variable declaration*/
    int i = 0, j = 0, k = 0, topsave = 0;
    int ierr = 0;
    int kfun = 0;

    int *header = NULL, ne1 = 0;
    double *le111 = NULL;

    int *il_xd = NULL, *il_res = NULL, *il_out = NULL, *il_outptr = NULL;
    int *il_xprop = NULL;

    int *il_z = NULL, *il_oz = NULL, *il_ozptr = NULL, *il_x = NULL;
    int *il_mode = NULL, *il_evout = NULL, *il_g = NULL;
    double *l_mode = NULL;
    double *l_xprop = NULL;

    /* variable for output typed port */
    int nout = 0;

    int nv = 0, mv = 0;
    int *ptr = NULL, *funtyp = NULL;

    /* set number of left and right hand side parameters */
    int mlhs = 1, mrhs = 2;

    /* Save Top counter */
    topsave = Top;

    /* Retrieve block number */
    kfun = get_block_number();

    /* Retrieve funtyp by import structure */
    strcpy(C2F(cha1).buf, "funtyp");
    ierr = getscicosvarsfromimport(C2F(cha1).buf, (void**)&ptr, &nv, &mv);
    if (ierr == 0)
    {
        goto err;
    }
    funtyp = (int *) ptr;

    /****************************
     * create scilab tlist Blocks
     ****************************/
    if ((createblklist(&Blocks[0], &ierr, (i = -1), funtyp[kfun - 1])) == 0)
    {
        goto err;
    }

    /* * flag * */
    C2F(itosci)(&flag, (i = 1, &i), (j = 1, &j));
    if (C2F(scierr)() != 0)
    {
        goto err;
    }

    /**********************
     * Call scilab function
     **********************/
    C2F(scifunc)(&mlhs, &mrhs);
    if (C2F(scierr)() != 0)
    {
        goto err;
    }

    /***************************
     * Update C block structure
     **************************/
    /* get header of output variable Blocks of sciblk4 */
    header = (int *) stk(*Lstk(Top));

    /* switch to appropriate flag */
    switch (flag)
    {

            /**************************
             * update continuous state
             **************************/
        case 0 :
        {
            if (Blocks[0].nx != 0)
            {
                /* 14 - xd */
                il_xd = (int *) listentry(header, 14);
                ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }

                if ((funtyp[kfun - 1] == 10004) || (funtyp[kfun - 1] == 10005))
                {
                    /* 15 - res */
                    il_res = (int *) listentry(header, 15);
                    ierr = sci2var(il_res, Blocks[0].res, SCSREAL_N); /* double */
                    if (ierr != 0)
                    {
                        goto err;
                    }
                }
            }
        }
        break;

        /**********************
         * update output state
         **********************/
        case 1 :
        {
            /* 21 - outptr */
            if (Blocks[0].nout != 0)
            {
                il_out = (int*) listentry(header, 21);
                nout = il_out[1];

                for (j = 0; j < nout; j++)
                {
                    il_outptr = (int *) listentry(il_out, j + 1);
                    ierr = sci2var(il_outptr, Blocks[0].outptr[j], Blocks[0].outsz[2 * nout + j]);
                    if (ierr != 0)
                    {
                        goto err;
                    }
                }
            }
        }
        break;

        /***********************
         * update discrete state
         ***********************/
        case 2 :
        {
            /* 7 - z */
            if (Blocks[0].nz != 0)
            {
                il_z = (int *) listentry(header, 7);
                if (Blocks[0].scsptr > 0)
                {
                    le111 = (double *) listentry(header, 7);
                    ne1 = header[7 + 2] - header[7 + 1];
                    C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j));
                }
                else
                {
                    ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */
                    if (ierr != 0)
                    {
                        goto err;
                    }
                }
            }

            /* 11 - oz */
            if (Blocks[0].noz != 0)
            {
                il_oz = (int *) listentry(header, 11);
                /* C blocks : extract */
                if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004))
                {
                    for (j = 0; j < Blocks[0].noz; j++)
                    {
                        il_ozptr = (int *) listentry(il_oz, j + 1);
                        if (Blocks[0].oztyp[j] == SCSUNKNOW_N)
                        {
                            ne1 = Blocks[0].ozsz[j];
                            C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \
                                           (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k));
                        }
                        else
                        {
                            ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]);
                            if (ierr != 0)
                            {
                                goto err;
                            }
                        }
                    }
                }
                /* sci blocks : don't extract */
                else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005))
                {
                    ne1 = Blocks[0].ozsz[0];
                    C2F(unsfdcopy)(&ne1, (double *)il_oz, \
                                   (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j));
                }
            }

            if (Blocks[0].nx != 0)
            {
                /* 13 - x */
                il_x = (int *) listentry(header, 13);
                ierr = sci2var(il_x, Blocks[0].x, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }

                /* 14 - xd */
                il_xd = (int *) listentry(header, 14);
                ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }
            }
        }
        break;

        /***************************
         * update event output state
         ***************************/
        case 3 :
        {
            /* 23 - evout */
            il_evout = (int *) listentry(header, 23);
            ierr = sci2var(il_evout, Blocks[0].evout, SCSREAL_N); /* double */
            if (ierr != 0)
            {
                goto err;
            }
        }
        break;

        /**********************
         * state initialisation
         **********************/
        case 4 :
        {
            /* 7 - z */
            if (Blocks[0].nz != 0)
            {
                il_z = (int *) listentry(header, 7);
                if (Blocks[0].scsptr > 0)
                {
                    le111 = (double *) listentry(header, 7);
                    ne1 = header[7 + 2] - header[7 + 1];
                    C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j));
                }
                else
                {
                    ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */
                    if (ierr != 0)
                    {
                        goto err;
                    }
                }
            }

            /* 11 - oz */
            if (Blocks[0].noz != 0)
            {
                il_oz = (int *) listentry(header, 11);
                /* C blocks : extract */
                if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004))
                {
                    for (j = 0; j < Blocks[0].noz; j++)
                    {
                        il_ozptr = (int *) listentry(il_oz, j + 1);
                        if (Blocks[0].oztyp[j] == SCSUNKNOW_N)
                        {
                            ne1 = Blocks[0].ozsz[j];
                            C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \
                                           (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k));
                        }
                        else
                        {
                            ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]);
                            if (ierr != 0)
                            {
                                goto err;
                            }
                        }
                    }
                }
                /* sci blocks : don't extract */
                else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005))
                {
                    ne1 = Blocks[0].ozsz[0];
                    C2F(unsfdcopy)(&ne1, (double *)il_oz, \
                                   (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j));
                }
            }

            if (Blocks[0].nx != 0)
            {
                /* 13 - x */
                il_x = (int *) listentry(header, 13);
                ierr = sci2var(il_x, Blocks[0].x, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }

                /* 14 - xd */
                il_xd = (int *) listentry(header, 14);
                ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }
            }
        }
        break;

        /*********
         * finish
         *********/
        case 5 :
        {
            /* 7 - z */
            if (Blocks[0].nz != 0)
            {
                il_z = (int *) listentry(header, 7);
                if (Blocks[0].scsptr > 0)
                {
                    le111 = (double *) listentry(header, 7);
                    ne1 = header[7 + 2] - header[7 + 1];
                    C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j));
                }
                else
                {
                    ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */
                    if (ierr != 0)
                    {
                        goto err;
                    }
                }
            }

            /* 11 - oz */
            if (Blocks[0].noz != 0)
            {
                il_oz = (int *) listentry(header, 11);
                /* C blocks : extract */
                if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004))
                {
                    for (j = 0; j < Blocks[0].noz; j++)
                    {
                        il_ozptr = (int *) listentry(il_oz, j + 1);
                        if (Blocks[0].oztyp[j] == SCSUNKNOW_N)
                        {
                            ne1 = Blocks[0].ozsz[j];
                            C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \
                                           (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k));
                        }
                        else
                        {
                            ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]);
                            if (ierr != 0)
                            {
                                goto err;
                            }
                        }
                    }
                }
                /* sci blocks : don't extract */
                else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005))
                {
                    ne1 = Blocks[0].ozsz[0];
                    C2F(unsfdcopy)(&ne1, (double *)il_oz, \
                                   (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j));
                }
            }
        }
        break;

        /*****************************
         * output state initialisation
         *****************************/
        case 6 :
        {
            /* 7 - z */
            if (Blocks[0].nz != 0)
            {
                il_z = (int *) listentry(header, 7);
                if (Blocks[0].scsptr > 0)
                {
                    le111 = (double *) listentry(header, 7);
                    ne1 = header[7 + 2] - header[7 + 1];
                    C2F(unsfdcopy)(&ne1, le111, (i = -1, &i), Blocks[0].z, (j = -1, &j));
                }
                else
                {
                    ierr = sci2var(il_z, Blocks[0].z, SCSREAL_N); /* double */
                    if (ierr != 0)
                    {
                        goto err;
                    }
                }
            }

            /* 11 - oz */
            if (Blocks[0].noz != 0)
            {
                il_oz = (int *) listentry(header, 11);
                /* C blocks : extract */
                if ((funtyp[kfun - 1] == 4) || (funtyp[kfun - 1] == 10004))
                {
                    for (j = 0; j < Blocks[0].noz; j++)
                    {
                        il_ozptr = (int *) listentry(il_oz, j + 1);
                        if (Blocks[0].oztyp[j] == SCSUNKNOW_N)
                        {
                            ne1 = Blocks[0].ozsz[j];
                            C2F(unsfdcopy)(&ne1, (double *)il_ozptr, \
                                           (i = 1, &i), (double *)Blocks[0].ozptr[j], (k = 1, &k));
                        }
                        else
                        {
                            ierr = sci2var(il_ozptr, Blocks[0].ozptr[j], Blocks[0].oztyp[j]);
                            if (ierr != 0)
                            {
                                goto err;
                            }
                        }
                    }
                }
                /* sci blocks : don't extract */
                else if ((funtyp[kfun - 1] == 5) || (funtyp[kfun - 1] == 10005))
                {
                    ne1 = Blocks[0].ozsz[0];
                    C2F(unsfdcopy)(&ne1, (double *)il_oz, \
                                   (i = 1, &i), (double *)Blocks[0].ozptr[0], (j = 1, &j));
                }
            }

            if (Blocks[0].nx != 0)
            {
                /* 13 - x */
                il_x = (int *) listentry(header, 13);
                ierr = sci2var(il_x, Blocks[0].x, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }

                /* 14 - xd */
                il_xd = (int *) listentry(header, 14);
                ierr = sci2var(il_xd, Blocks[0].xd, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }
            }

            /* 21 - outptr */
            if (Blocks[0].nout != 0)
            {
                il_out = (int *) listentry(header, 21);
                nout = il_out[1];
                for (j = 0; j < nout; j++)
                {
                    il_outptr = (int *) listentry(il_out, j + 1);
                    ierr = sci2var(il_outptr, Blocks[0].outptr[j], Blocks[0].outsz[2 * nout + j]);
                    if (ierr != 0)
                    {
                        goto err;
                    }
                }
            }
        }
        break;

        /*******************************************
         * define property of continuous time states
         * (algebraic or differential states)
         *******************************************/
        case 7 :
        {
            if (Blocks[0].nx != 0)
            {
                /* 40 - x */
                il_xprop = (int *) listentry(header, 40);
                l_xprop = (double *)(il_xprop + 4);
                for (nv = 0; nv < Blocks[0].nx; nv++)
                {
                    Blocks[0].xprop[nv] = (int) l_xprop[nv];
                }
            }
        }
        break;

        /****************************
         * zero crossing computation
         ****************************/
        case 9 :
        {
            /* 33 - g */
            il_g = (int *) listentry(header, 33);
            ierr = sci2var(il_g, Blocks[0].g, SCSREAL_N); /* double */
            if (ierr != 0)
            {
                goto err;
            }

            if (get_phase_simulation() == 1)
            {
                /* 39 - mode */
                il_mode = (int *) listentry(header, 39);
                // Alan, 16/10/07 : fix : mode is an int array
                l_mode = (double *)(il_mode + 4);
                for (nv = 0; nv < (il_mode[1]*il_mode[2]); nv++)
                {
                    Blocks[0].mode[nv] = (int) l_mode[nv];
                }
                //ierr=sci2var(il_mode,Blocks[0].mode,SCSINT_N); /* int */
                //if (ierr!=0) goto err;
            }
        }
        break;

        /**********************
         * Jacobian computation
         **********************/
        case 10 :
        {
            if ((funtyp[kfun - 1] == 10004) || (funtyp[kfun - 1] == 10005))
            {
                /* 15 - res */
                il_res = (int *) listentry(header, 15);
                ierr = sci2var(il_res, Blocks[0].res, SCSREAL_N); /* double */
                if (ierr != 0)
                {
                    goto err;
                }
            }
        }
        break;
    }

    /* Restore initial position Top */
    Top = topsave;
    return;

    /* if error then restore initial position Top
     * and set_block_error with flag -1 */
err:
    Top = topsave;
    if (ierr != 0) /*var2sci or sci2var error*/
    {
        /* Please update me !*/
        if (ierr < 1000) /*var2sci error*/
        {
            switch (ierr)
            {
                case 1  :
                    Scierror(888, _("%s: error %d. Stack is full.\n"), "var2sci", ierr);
                    break;

                case 2  :
                    Scierror(888, _("%s: error %d. No more space on the stack for new data.\n"), "var2sci", ierr);
                    break;

                default :
                    Scierror(888, _("%s: error %d. Undefined error.\n"), "var2sci", ierr);
                    break;
            }
        }
        else /*sci2var error*/
        {
            switch (ierr)
            {
                case 1001  :
                    Scierror(888, _("%s: error %d. Only int or double object are accepted.\n"), "sci2var", ierr);
                    break;

                case 1002  :
                    Scierror(888, _("%s: error %d. Bad double object sub_type.\n"), "sci2var", ierr);
                    break;

                case 1003  :
                    Scierror(888, _("%s: error %d. Bad int object sub_type.\n"), "sci2var", ierr);
                    break;

                case 1004  :
                    Scierror(888, _("%s: error %d. A type of a scilab object has changed.\n"), "sci2var", ierr);
                    break;

                default    :
                    Scierror(888, _("%s: error %d. Undefined error.\n"), "sci2var", ierr);
                    break;
            }
        }
    }
    set_block_error(-1);
}
Ejemplo n.º 2
0
int
copyinout(Ftw_t* ftw)
{
	register File_t*	f = &state.out->file;
	register char*		s;
	register off_t		c;
	register ssize_t	n;
	register int		rfd;
	register int		wfd;

	if (getfile(state.out, f, ftw) && selectfile(state.out, f))
	{
		s = f->name;
		f->name = stash(&state.out->path.copy, NiL, state.pwdlen + f->namesize);
		strcpy(stpcpy(f->name, state.pwd), s + (*s == '/'));
		if ((wfd = openout(state.out, f)) >= 0)
		{
			if ((rfd = openin(state.out, f)) >= 0)
			{
#if defined(SEEK_DATA) && defined(SEEK_HOLE)
				off_t		data;
				off_t		hole;
				int		more;

				data = 0;
				more = 1;
				while (more)
				{
					if ((hole = lseek(rfd, data, SEEK_HOLE)) < data)
					{
						hole = lseek(rfd, 0, SEEK_END);
						more = 0;
					}
					while ((c = hole - data) > 0)
					{
						if (c > state.buffersize)
							c = state.buffersize;
						if (lseek(rfd, data, SEEK_SET) != data || (n = read(rfd, state.tmp.buffer, (size_t)c)) <= 0)
						{
							error(ERROR_SYSTEM|2, "%s: read error", f->name);
							more = 0;
							break;
						}
						if (lseek(wfd, data, SEEK_SET) != data || write(wfd, state.tmp.buffer, n) != n)
						{
							error(ERROR_SYSTEM|2, "%s: write error", f->name);
							more = 0;
							break;
						}
						state.out->io->count += n;
						data += n;
					}
					if (!more)
						break;
					if ((data = lseek(rfd, hole, SEEK_DATA)) < hole)
					{
						if ((data = lseek(rfd, -1, SEEK_END)) < 0 || (data + 1) > hole && (lseek(wfd, data, SEEK_SET) != data || write(wfd, "", 1) != 1))
							error(ERROR_SYSTEM|2, "%s: write error", f->name);
						state.out->io->count += 1;
						break;
					}
				}
#else
				holeinit(wfd);
				for (c = f->st->st_size; c > 0; c -= n)
				{
					if ((n = read(rfd, state.tmp.buffer, (size_t)((c > state.buffersize) ? state.buffersize : c))) <= 0)
					{
						error(ERROR_SYSTEM|2, "%s: read error", f->name);
						break;
					}
					if (holewrite(wfd, state.tmp.buffer, n) != n)
					{
						error(ERROR_SYSTEM|2, "%s: write error", f->name);
						break;
					}
					state.out->io->count += n;
				}
				holedone(wfd);
#endif
				closeout(state.out, f, wfd);
				closein(state.out, f, rfd);
				setfile(state.out, f);
				listentry(f);
			}
			else
				closeout(state.out, f, wfd);
		}
		else if (wfd != -1)
			listentry(f);
	}
	return 0;
}
Ejemplo n.º 3
0
/*--------------------------------------------------------------------------*/
int sci_data2sig(char *fname, unsigned long fname_len)
{
    int m1 = 0, n1 = 0, it = 0;
    int p1 = 0;
    int *il1 = NULL;
    int m1h = 0, n1h = 0;
    int *ilh1 = NULL;
    int m2h = 0, n2h = 0;
    int *ilh2 = NULL;
    int *ilh3 = NULL;
    int m2 = 0, n2 = 0, it2 = 0;
    int *il2 = NULL;
    int il = 0, l = 0;
    int l_tmp = 0;

    int i = 0, j = 0, TopSave = 0;

    char *str_stlst[] = {"st", "dims", "values", "time"};
    char *str_hmlst[] = {"hm", "dims", "entries"};

    double step_time = 1;

    int  ismat = 0;

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

    il1 = (int *) GetData(1);
    m1  = il1[1];
    n1  = il1[2];
    it  = il1[3];
    if ((il1[0] != 1) && (il1[0] != 8))
    {
        if (il1[0] == 17)
        {
            ilh1 = (int *) (listentry(il1, 1));
            m1h  = ilh1[1];
            n1h  = ilh1[2];
            if ((ilh1[m1h * n1h + 5] != 17) || (ilh1[m1h * n1h + 6] != 22))
            {
                Scierror(888, _("%s : First argument must be a matrix or an hypermatrix\nof real, complex or integer numbers.\n"), fname);
                return 0;
            }
            ilh2 = (int *) (listentry(il1, 2));
            m2h  = ilh2[1];
            n2h  = ilh2[2];
            if (n2h != 3)
            {
                Scierror(888, _("%s : Only hypermatrix with 3 dimensions is allowed.\n"), fname);
                return 0;
            }
            m1     = ilh2[4];
            n1     = ilh2[5];
            p1     = ilh2[6];
            ilh3   = (int *) (listentry(il1, 3));
            if ((ilh3[0] != 1) && (ilh3[0] != 8))
            {
                Scierror(888, _("%s : First argument must be a matrix or an hypermatrix\nof real, complex or integer numbers.\n"), fname);
                return 0;
            }
            it     = ilh3[3];
        }
        else
        {
            Scierror(888, _("%s : First argument must be a matrix or an hypermatrix\nof real, complex or integer numbers.\n"), fname);
            return 0;
        }
    }

    if (Rhs == 2)
    {
        il2 = (int *) GetData(2);
        m2  = il2[1];
        n2  = il2[2];
        it2 = il2[3];
        if ((m2 * n2) != 1)
        {
            Scierror(888, _("%s : Second argument must be a scalar.\n"), fname);
            return 0;
        }
        if ((il2[0] != 1) || (it2 != 0))
        {
            Scierror(888, _("%s : Second argument must be a real.\n"), fname);
            return 0;
        }
        step_time = *((double *) &il2[4]);
    }

    TopSave = Top;

    str2sci(str_stlst, 1, 4);

    Top           = Top + 1;
    il            = iadr(*Lstk(Top));
    l             = sadr(il + 4);
    *istk(il)     = 8;
    *istk(il + 1)   = 1;
    *istk(il + 2)   = 2;
    *istk(il + 3)   = 4;
    *istk(il + 4)   = 1;
    *istk(il + 5)   = 1;
    *Lstk(Top + 1)  = l + 1;

    if ((m1 != 1) && (n1 != 1))
    {
        ismat = 1;
    }

    switch (il1[0])
    {
        case 1 :
        {
            Top            = Top + 1;
            il             = iadr(*Lstk(Top));
            l              = sadr(il + 4);
            *istk(il)      = 1;
            if (ismat)
            {
                *istk(il + 1)  = m1;
                *istk(il + 2)  = n1;
            }
            else
            {
                *istk(il + 1)  = n1 * m1;
                *istk(il + 2)  = 1;
            }
            *istk(il + 3)    = it;
            if (it == 0)
            {
                for (i = 0; i < (m1 * n1); i++)
                {
                    stk(l)[i]  = *((double *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + n1 * m1;
            }
            else if (it == 1)
            {
                for (i = 0; i < (2 * m1 * n1); i++)
                {
                    stk(l)[i]  = *((double *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + 2 * n1 * m1;
            }
            break;
        }

        case 8 :
        {
            Top            = Top + 1;
            il             = iadr(*Lstk(Top));
            l              = sadr(il + 4);
            *istk(il)      = 8;
            if (ismat)
            {
                *istk(il + 1)  = m1;
                *istk(il + 2)  = n1;
            }
            else
            {
                *istk(il + 1)  = m1 * n1;
                *istk(il + 2)  = 1;
            }
            *istk(il + 3)    = it;
            if (it == 4)
            {
                for (i = 0; i < (m1 * n1); i++)
                {
                    *((long *)(istk(il + 4)) + i)  = *((long *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + (int)(ceil((n1 * m1) / 2) + 1);
            }
            else if (it == 2)
            {
                for (i = 0; i < (m1 * n1); i++)
                {
                    *((short *)(istk(il + 4)) + i)  = *((short *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + (int)(ceil((n1 * m1) / 4) + 1);
            }
            else if (it == 1)
            {
                for (i = 0; i < (m1 * n1); i++)
                {
                    *((char *)(istk(il + 4)) + i)  = *((char *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + (int)(ceil((n1 * m1) / 8) + 1);
            }
            else if (it == 14)
            {
                for (i = 0; i < (m1 * n1); i++)
                {
                    *((unsigned long *)(istk(il + 4)) + i)  = *((unsigned long *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + (int)(ceil((n1 * m1) / 2) + 1);
            }
            else if (it == 12)
            {
                for (i = 0; i < (m1 * n1); i++)
                {
                    *((unsigned short *)(istk(il + 4)) + i)  = *((unsigned short *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + (int)(ceil((n1 * m1) / 4) + 1);
            }
            else if (it == 11)
            {
                for (i = 0; i < (m1 * n1); i++)
                {
                    *((unsigned char *)(istk(il + 4)) + i)  = *((unsigned char *)(&il1[4]) + i);
                }
                *Lstk(Top + 1) = l + (int)(ceil((n1 * m1) / 8) + 1);
            }
            break;
        }

        case 17 :
        {
            str2sci(str_hmlst, 1, 3);

            Top           = Top + 1;
            il            = iadr(*Lstk(Top));
            l             = sadr(il + 4);
            *istk(il)     = 8;
            *istk(il + 1)   = 1;
            *istk(il + 2)   = n2h;
            *istk(il + 3)   = 4;
            for (i = 0; i < (n2h); i++)
            {
                *((long *)(istk(il + 4)) + i)  = *((long *)(&ilh2[4]) + i);
            }
            *Lstk(Top + 1) = l + (int)(ceil((n2h) / 2) + 1);

            switch (ilh3[0])
            {
                case 1 :
                {
                    Top            = Top + 1;
                    il             = iadr(*Lstk(Top));
                    l              = sadr(il + 4);
                    *istk(il)      = 1;
                    *istk(il + 1)    = m1 * n1 * p1;
                    *istk(il + 2)    = 1;
                    *istk(il + 3)    = it;
                    if (it == 0)
                    {
                        for (i = 0; i < (m1 * n1 * p1); i++)
                        {
                            stk(l)[i]  = *((double *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + n1 * m1 * p1;
                    }
                    else if (it == 1)
                    {
                        for (i = 0; i < (2 * m1 * n1 * p1); i++)
                        {
                            stk(l)[i] = *((double *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + 2 * n1 * m1 * p1;
                    }
                    break;
                }
                case 8 :
                {
                    Top            = Top + 1;
                    il             = iadr(*Lstk(Top));
                    l              = sadr(il + 4);
                    *istk(il)      = 8;
                    *istk(il + 1)    = m1 * n1 * p1;
                    *istk(il + 2)    = 1;
                    *istk(il + 3)    = it;
                    if (it == 4)
                    {
                        for (i = 0; i < (m1 * n1 * p1); i++)
                        {
                            *((long *)(istk(il + 4)) + i)  = *((long *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + (int)(ceil((n1 * m1 * p1) / 2) + 1);
                    }
                    else if (it == 2)
                    {
                        for (i = 0; i < (m1 * n1 * p1); i++)
                        {
                            *((short *)(istk(il + 4)) + i)  = *((short *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + (int)(ceil((n1 * m1 * p1) / 4) + 1);
                    }
                    else if (it == 1)
                    {
                        for (i = 0; i < (m1 * n1 * p1); i++)
                        {
                            *((char *)(istk(il + 4)) + i)  = *((char *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + (int)(ceil((n1 * m1 * p1) / 8) + 1);
                    }
                    else if (it == 14)
                    {
                        for (i = 0; i < (m1 * n1 * p1); i++)
                        {
                            *((unsigned long *)(istk(il + 4)) + i)  = *((unsigned long *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + (int)(ceil((n1 * m1 * p1) / 2) + 1);
                    }
                    else if (it == 12)
                    {
                        for (i = 0; i < (m1 * n1 * p1); i++)
                        {
                            *((unsigned short *)(istk(il + 4)) + i)  = *((unsigned short *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + (int)(ceil((n1 * m1 * p1) / 4) + 1);
                    }
                    else if (it == 11)
                    {
                        for (i = 0; i < (m1 * n1 * p1); i++)
                        {
                            *((unsigned char *)(istk(il + 4)) + i)  = *((unsigned char *)(&ilh3[4]) + i);
                        }
                        *Lstk(Top + 1) = l + (int)(ceil((n1 * m1 * p1) / 8) + 1);
                    }
                    break;
                }
            }
            C2F(mkmlist)((i = 3, &i));
            break;
        }
    }

    Top           = Top + 1;
    il            = iadr(*Lstk(Top));
    l             = sadr(il + 4);
    *istk(il)     = 1;
    if (il1[0] == 17)
    {
        *istk(il + 1)   = p1;
    }
    else
    {
        if (ismat)
        {
            *istk(il + 1) = m1;
        }
        else
        {
            *istk(il + 1) = n1 * m1;
        }
    }
    *istk(il + 2)   = 1;
    *istk(il + 3)   = 0;
    for (i = 0; i < (*istk(il + 1)); i++)
    {
        stk(l)[i]  = (double) i * step_time;
    }
    *Lstk(Top + 1) = l + *istk(il + 1);

    C2F(mkmlist)((i = 4, &i));

    Top = TopSave;

    i = 4;
    j = 1;
    if (Rhs == 2)
    {
        CreateVar(3, MATRIX_ORIENTED_TYPED_LIST_DATATYPE, &i, &j, &l_tmp);
        LhsVar(1) = 3;
    }
    else
    {
        CreateVar(2, MATRIX_ORIENTED_TYPED_LIST_DATATYPE, &i, &j, &l_tmp);
        LhsVar(1) = 2;
    }

    PutLhsVar();
    return 0;
}
Ejemplo n.º 4
0
void
filein(register Archive_t* ap, register File_t* f)
{
	register off_t	c;
	register int	n;
	register char*	s;
	int		dfd;
	int		wfd;
	long		checksum;
	Filter_t*	fp;
	Proc_t*		pp;
	Tv_t		t1;
	Tv_t		t2;
	struct stat	st;

	if (f->skip)
		goto skip;
	else if (state.list)
	{
		if (fp = filter(ap, f))
		{
			for (n = 0; s = fp->argv[n]; n++)
			{
				while (*s)
					if (*s++ == '%' && *s == '(')
						break;
				if (*s)
				{
					s = fp->argv[n];
					listprintf(state.tmp.str, ap, f, s);
					if (!(fp->argv[n] = sfstruse(state.tmp.str)))
						nospace();
					break;
				}
			}
			pp = procopen(*fp->argv, fp->argv, NiL, NiL, PROC_WRITE);
			if (s)
				fp->argv[n] = s;
			if (!pp)
			{
				error(2, "%s: %s: cannot execute filter %s", ap->name, f->path, *fp->argv);
				goto skip;
			}
			if (!ap->format->getdata || !(*ap->format->getdata)(&state, ap, f, pp->wfd))
			{
				checksum = 0;
				for (c = f->st->st_size; c > 0; c -= n)
				{
					n = (c > state.buffersize) ? state.buffersize : c;
					if (!(s = bget(ap, n, NiL)))
					{
						error(ERROR_SYSTEM|2, "%s: read error", f->name);
						break;
					}
					if (write(pp->wfd, s, n) != n)
					{
						error(ERROR_SYSTEM|2, "%s: write error", f->name);
						break;
					}
					if (ap->format->checksum)
						checksum = (*ap->format->checksum)(&state, ap, f, s, n, checksum);
				}
			}
			if (ap->format->checksum && checksum != f->checksum)
				error(1, "%s: %s checksum error (0x%08x != 0x%08x)", f->name, ap->format->name, checksum, f->checksum);
			/*
			 * explicitly ignore exit status
			 */

			procclose(pp);
			return;
		}
		listentry(f);
		goto skip;
	}
	else switch (f->delta.op)
	{
	case DELTA_create:
		if (f->delta.base)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		if (ap->delta->format->flags & PSEUDO)
			goto regular;
		if ((wfd = openout(ap, f)) < 0)
			goto skip;
		else
			paxdelta(NiL, ap, f, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, f->st->st_size, 0);
		break;
	case DELTA_update:
		if (!f->delta.base || (unsigned long)f->delta.base->mtime.tv_sec >= (unsigned long)f->st->st_mtime)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		c = f->st->st_size;
		if ((wfd = openout(ap, f)) < 0)
			goto skip;
		if (state.ordered)
		{
			if (!f->delta.base->uncompressed)
				paxdelta(NiL, ap, f, DELTA_SRC|DELTA_BIO|DELTA_SIZE, ap->delta->base, f->delta.base->size, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
			else if (!paxdelta(NiL, ap, f, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap->delta->base, f->delta.base->size, DELTA_TAR|DELTA_TEMP|DELTA_OUTPUT, &dfd, 0))
				paxdelta(NiL, ap, f, DELTA_SRC|DELTA_FD|DELTA_SIZE|DELTA_FREE, dfd, f->delta.base->uncompressed, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
		}
		else if (!f->delta.base->uncompressed)
			paxdelta(NiL, ap, f, DELTA_SRC|DELTA_FD|DELTA_OFFSET|DELTA_SIZE, ap->delta->base->io->fd, f->delta.base->offset, f->delta.base->size, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
		else if (!paxdelta(NiL, ap, f, DELTA_DEL|DELTA_FD|DELTA_OFFSET|DELTA_SIZE, ap->delta->base->io->fd, f->delta.base->offset, f->delta.base->size, DELTA_TAR|DELTA_TEMP|DELTA_OUTPUT, &dfd, 0))
			paxdelta(NiL, ap, f, DELTA_SRC|DELTA_FD|DELTA_SIZE|DELTA_FREE, dfd, f->delta.base->uncompressed, DELTA_TAR|DELTA_FD|DELTA_FREE|DELTA_OUTPUT|DELTA_COUNT, wfd, DELTA_DEL|DELTA_BIO|DELTA_SIZE, ap, c, 0);
		break;
	case DELTA_verify:
		if (!f->delta.base || f->delta.base->mtime.tv_sec != f->st->st_mtime)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		if ((*state.statf)(f->name, &st))
			error(2, "%s: not copied from base archive", f->name);
		else if (st.st_size != f->delta.base->size || state.modtime && tvcmp(tvmtime(&t1, &st), tvmtime(&t2, f->st)))
			error(1, "%s: changed from base archive", f->name);
		break;
	case DELTA_delete:
		if (!f->delta.base)
			error(3, "%s: base archive mismatch [%s#%d]", f->name, __FILE__, __LINE__);
		/*FALLTHROUGH*/
	default:
	regular:
		wfd = openout(ap, f);
		if (wfd >= 0)
		{
			holeinit(wfd);
			if (!ap->format->getdata || !(*ap->format->getdata)(&state, ap, f, wfd))
			{
				checksum = 0;
				for (c = f->st->st_size; c > 0; c -= n)
				{
					n = (c > state.buffersize) ? state.buffersize : c;
					if (!(s = bget(ap, n, NiL)))
					{
						error(ERROR_SYSTEM|2, "%s: read error", f->name);
						break;
					}
					if (holewrite(wfd, s, n) != n)
					{
						error(ERROR_SYSTEM|2, "%s: write error", f->name);
						break;
					}
					if (ap->format->checksum)
						checksum = (*ap->format->checksum)(&state, ap, f, s, n, checksum);
				}
			}
			holedone(wfd);
			closeout(ap, f, wfd);
			setfile(ap, f);
			if (ap->format->checksum && checksum != f->checksum)
				error(1, "%s: %s checksum error (0x%08x != 0x%08x)", f->name, ap->format->name, checksum, f->checksum);
		}
		else if (ap->format->getdata)
			(*ap->format->getdata)(&state, ap, f, wfd);
		else
		{
			if (wfd < -1)
				listentry(f);
			goto skip;
		}
		break;
	}
	listentry(f);
	return;
 skip:
	fileskip(ap, f);
}
Ejemplo n.º 5
0
/*--------------------------------------------------------------------------*/
int sci_callblk(char *fname, unsigned long fname_len)
{
    /* auxilary variables -dimension and address-
    * for scilab stack variables
    */
    int *il1 = NULL;
    int m1 = 0, n1 = 0;
    int *il2_1 = NULL;
    int m2_1 = 0, n2_1 = 0;
    int *il2 = NULL;
    int m2 = 0, n2 = 0;
    int *il3 = NULL;
    int m3 = 0, n3 = 0;

    /* local variable */
    int len_str = 0;
    char *str = NULL;
    int ierr = 0, ret = 0;
    int j = 0;
    int TopSave = 0;
    int l_tmp = 0;

    /* length of the scilab list scicos struct */
    int nblklst = 41;

    /* variable for callf */
    scicos_flag flag = 0;
    double t = 0.;

    scicos_block Block;
    memset(&Block, 0, sizeof(scicos_block));

    /* check number of rhs/lhs param */
    CheckRhs(3, 3);
    CheckLhs(1, 1);

    /* check rhs 1 (input scilab structure) */
    il1 = (int *) GetData(1);
    m1  = il1[1];
    n1  = il1[2];
    if (il1[0] != 16)
    {
        Scierror(888, _("%s : First argument must be a scicos_block typed list.\n"), fname);
        return 0;
    }

    il2_1 = (int *) (listentry(il1, 1));
    m2_1  = il2_1[1];
    n2_1  = il2_1[2];
    if ((il2_1[0] != 10) || ((m2_1 * n2_1) != nblklst))
    {
        Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
        return 0;
    }
    len_str = il2_1[5] - 1;
    if (len_str != 0)
    {
        if ((str = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL)
        {
            Scierror(888, _("%s: Memory allocation error.\n"), fname);
            return 0;
        }
        str[len_str] = '\0';
        C2F(cvstr)(&len_str, &il2_1[5 + nblklst], str, (j = 1, &j), len_str);
        ret = strcmp("scicos_block", str);
        FREE(str);
        if (ret != 0)
        {
            Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
            return 0;
        }
    }
    else
    {
        Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
        return 0;
    }

    /* convert scilab scicos struct to a C scicos struct */
    ret = extractblklist(il1, &Block, &ierr);

    /* error table */
    switch (ierr)
    {
        case -39 :
            Scierror(888, _("%s: Memory allocation error.\n"), fname);
            break;

        case 98  :
            Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
            break;

        default:
            break;
    }

    if (ierr != 0)
    {
        FREE(Block.z);
        FREE(Block.ozsz);
        FREE(Block.oztyp);
        for (j = 0; j < Block.noz; j++)
        {
            FREE(Block.ozptr[j]);
        }
        FREE(Block.ozptr);
        FREE(Block.x);
        FREE(Block.xd);
        FREE(Block.xprop);
        FREE(Block.res);
        FREE(Block.insz);
        for (j = 0; j < Block.nin; j++)
        {
            FREE(Block.inptr[j]);
        }
        FREE(Block.inptr);
        FREE(Block.outsz);
        for (j = 0; j < Block.nout; j++)
        {
            FREE(Block.outptr[j]);
        }
        FREE(Block.outptr);
        FREE(Block.evout);
        FREE(Block.rpar);
        FREE(Block.ipar);
        FREE(Block.oparsz);
        FREE(Block.opartyp);
        for (j = 0; j < Block.nopar; j++)
        {
            FREE(Block.oparptr[j]);
        }
        FREE(Block.oparptr);
        FREE(Block.g);
        FREE(Block.jroot);
        if (strlen(Block.label) != 0)
        {
            FREE(Block.label);
        }
        FREE(Block.mode);
        if (strlen(Block.uid) != 0)
        {
            FREE(Block.uid);
        }
        return 0;
    }

    /* check rhs 2 (flag) */
    il2 = (int *) GetData(2);
    m2  = il2[1];
    n2  = il2[2];
    if ((il2[0] != 1) || (m2 * n2 != 1))
    {
        Scierror(888, _("%s : Second argument must be scalar.\n"), fname);
        return 0;
    }
    flag = (scicos_flag) * ((double *)(&il2[4]));

    /* check rhs 3 (time) */
    il3 = (int *) GetData(3);
    m3  = il3[1];
    n3  = il3[2];

    if ((il3[0] != 1) || (m3 * n3 != 1))
    {
        Scierror(888, _("%s : Third argument must be scalar.\n"), fname);
        return 0;
    }
    t = *((double *)(&il3[4]));

    /* call block */
    callf(&t, &Block, &flag);

    /* build output  scilab structure */
    TopSave = Top;

    ierr = createblklist(&Block, &ierr, -1, Block.type);

    FREE(Block.z);
    FREE(Block.ozsz);
    FREE(Block.oztyp);
    for (j = 0; j < Block.noz; j++)
    {
        FREE(Block.ozptr[j]);
    }
    FREE(Block.ozptr);
    FREE(Block.x);
    FREE(Block.xd);
    FREE(Block.res);
    FREE(Block.insz);
    for (j = 0; j < Block.nin; j++)
    {
        FREE(Block.inptr[j]);
    }
    FREE(Block.inptr);
    FREE(Block.outsz);
    for (j = 0; j < Block.nout; j++)
    {
        FREE(Block.outptr[j]);
    }
    FREE(Block.outptr);
    FREE(Block.evout);
    FREE(Block.rpar);
    FREE(Block.ipar);
    FREE(Block.oparsz);
    FREE(Block.opartyp);
    for (j = 0; j < Block.nopar; j++)
    {
        FREE(Block.oparptr[j]);
    }
    FREE(Block.oparptr);
    FREE(Block.g);
    FREE(Block.jroot);
    if (strlen(Block.label) != 0)
    {
        FREE(Block.label);
    }
    FREE(Block.mode);
    if (Block.uid != NULL && strlen(Block.uid) != 0)
    {
        FREE(Block.uid);
    }

    Top = TopSave;

    CreateVar(4, TYPED_LIST_DATATYPE, &nblklst, (j = 1, &j), &l_tmp);
    LhsVar(1) = 4;
    PutLhsVar();

    return 0;
}