Beispiel #1
0
void ex_rd()
{
    /* note:
    * an empty line is converted to NULL.
    * no '\n' chars are returned.
    */
    char buf[200];
    struct item* p;
    int fd, i;

    SECURITY_CHECK;
    fd = topfix();
    i = 0;
    while ((read(fd, &buf[i], 1) == 1) && i < 200 && buf[i] != '\n')
        i++;
    if (i == 200)
        error(ERR_limit, "input buffer overflow");
    if (i > 0) {
        p = newdat(CH, 1, i);
        copy(CH, (char*)buf, (char*)p->datap, i);
    }
    else
        p = newdat(CH, 1, 0);
    *sp++ = p;
}
Beispiel #2
0
ex_miot()
{
    struct item *p;
    data *dp;
    int i;

    i = topfix();
    if(i < 0) {			/* must allocate something to ")reset" properly */
        *sp++ = newdat(DA, 1, 0);
        error("miot D");
    }
    p = newdat(DA, 1, i);
    dp = p->datap;
    datum = thread.iorg;
    for(; i; i--) {
        *dp++ = datum;
        datum += one;
    }
    *sp++ = p;
}
Beispiel #3
0
ex_mrho()
{
    struct item *p, *q;
    data *dp;
    int i;

    p = fetch1();
    q = newdat(DA, 1, p->rank);
    dp = q->datap;
    for(i=0; i<p->rank; i++) *dp++ = p->dim[i];
    pop();
    *sp++ = q;
}
Beispiel #4
0
/* extend - used by ex_base and ex_iprod */
struct item*
extend(int ty, int n, data d)
{
    int i;
    struct item* q;

    if (ty != DA)
        error(ERR_domain, "not numeric type");
    q = newdat(ty, 1, n);
    for (i = 0; i < n; i++)
        q->datap[i] = d;
    return (q);
}
Beispiel #5
0
ex_asgn()
{
	struct nlist *p;
	struct item *q;

	p = (struct nlist *)sp[-1];
	switch(p->type){
	case QX:
		pop();
		p = nlook("Llx");
		if(p == 0){
			/*
			 * allocate new name:
			 */
			for(p=nlist; p->namep; p++) ;
			p->namep = alloc(4);
			copy(CH, "Llx", p->namep, 4);
			p->type = LV;
			p->use = 0;
			p->itemp = newdat(CH, 0, 0);
		}
		sp++;				/* reset stack */
		break;
	case QD:
		pop();
		ex_print();
		return;
	case QC:
		pop();
/*		ex_plot();  */		/* don't understand QC data yet -- MEC */
		return;
	case QQ:
		pop();
		epr0();				/* print w/out '\n'  (in a2.c) */
		return;
	case LV:
		if (((struct nlist *)p->itemp) && ((struct nlist *)p)->itemp->type == LBL) error("asgn to label");
		break;
	default:
		error("asgn lv");
	}
	if(p->use != 0 && p->use != DA) error("asgn var");
	sp--;
	q = fetch1();
	erase(p);
	p->use = DA;
	((struct nlist *)p)->itemp = q;
	sp[-1] = (struct item *)p;
}
Beispiel #6
0
ex_drho()
{
    struct item *p, *q, *r;
    int s, i;
    data *dp;
    char *cp;

    p = fetch2();
    q = sp[-2];
    if(p->type != DA || p->rank > 1 || q->size < 0) error("rho C");

    /* Allow null vector to be reshaped if one of the
     * dimensions is null.
     */

    if (!q->size) {
        dp = p->datap;
        for(i=0; i < p->size; i++) if (fix(*dp++) == 0) goto null_ok;
        error("rho C");
    }
null_ok:
    s = 1;
    dp = p->datap;
    for(i=0; i<p->size; i++) {
        if (*dp < 0) error("rho C");		/* Negative dimensions illegal */
        s *= fix(*dp++);
    }
    r = newdat(q->type, p->size, s);
    dp = p->datap;
    for(i=0; i<p->size; i++) r->dim[i] = fix(*dp++);
    cp = (char *)r->datap;
    while(s > 0) {
        i = s;
        if(i > q->size) i = q->size;
        cp += copy(q->type, q->datap, cp, i);
        s -= i;
    }
    pop();
    pop();
    *sp++ = r;
}
Beispiel #7
0
void ex_cdyad(data (*f)(), struct item* ap, struct item** ap1)
{
    int i;
    struct item *p, *p1;
    char* cp;
    data d1, d2;

    p = ap;
    p1 = ap1;
    if (p->rank == 0 || p->size == 1) {
        d1 = ((struct chrstrct*)p->datap)->c[0];
        pop();
        p = p1;
        cp = (char*)p->datap;
        for (i = 0; i < p->size; i++) {
            d2 = *cp;
            *cp = (*f)(d1, d2);
            cp++;
        }
    }
    else if (p1->rank == 0 || p1->size == 1) {
        sp--;
        d1 = ((struct chrstrct*)p1->datap)->c[0];
        pop();
        *sp++ = p;
        cp = (char*)p->datap;
        for (i = 0; i < p->size; i++) {
            d2 = *cp;
            *cp = (*f)(d2, d1);
            cp++;
        }
    }
    else {
        if (p1->rank != p->rank)
            error(ERR_rank, "cdyad - arrays do not match");
        for (i = 0; i < p->rank; i++) {
            if (p->dim[i] != p1->dim[i])
                error(ERR_length, "cdyad - dimensions do not match");
        }
        cp = (char*)p1->datap;
        for (i = 0; i < p->size; i++) {
            d1 = ((struct chrstrct*)p->datap)->c[i];
            d2 = *cp;
            *cp = (*f)(d1, d2);
            cp++;
        }
        p = p1;
        pop();
    }
    /*
    * now convert the character vector to
    * a numeric array.  Someday, we can make this a
    * call to whomever creates "logical" type data.
    */
    p1 = p;
    cp = (char*)p->datap;
    p = newdat(DA, p->rank, p->size);
    for (i = 0; i < p->rank; i++)
        p->dim[i] = p1->dim[i];
    for (i = 0; i < p->size; i++)
        p->datap[i] = (*cp++) & 0377;
    pop();
    *sp++ = p;
}
Beispiel #8
0
void comk(int k)
{
    struct item* p;
    data d;
    int i, dk, ndk;

    p = sp[-1];
    bidx(sp[-2]);

    /* "getdat" returns the value of the data item which
    * it is called to fetch.  If this is non-zero, just
    * use the existing data on the stack (an example in
    * APL would be "x/y" where x != 0.  If this is zero,
    * the result is the null item, which is created by
    * "newdat" and pushed on the stack.
    */

    if (p->rank == 0 || (p->rank == 1 && p->size == 1)) {
        if (getdat(p)) {
            pop();
            return;
        }
        p = newdat(idx.type, 1, 0);
        pop();
        pop();
        *sp++ = p;
        return;
    }

    if (idx.rank == 0 && p->rank == 1) {
        /* then scalar right arg ok */
        dk = p->dim[0];
        ndk = 0;
        for (i = 0; i < dk; i++) {
            if (getdat(p))
                ndk++;
        }
        p = newdat(idx.type, 1, ndk);
        d = getdat(sp[-2]);
        for (i = 0; i < ndk; i++)
            putdat(p, d);
        pop();
        pop();
        *sp++ = p;
        return;
    }
    if (k < 0 || k >= idx.rank)
        error(ERR_index, "");
    dk = idx.dim[k];
    if (p->rank != 1 || p->size != dk)
        error(ERR_length, "");
    ndk = 0;
    for (i = 0; i < dk; i++) {
        if (getdat(p))
            ndk++;
    }
    p = newdat(idx.type, idx.rank, (idx.size / dk) * ndk);
    copy(IN, (char*)idx.dim, (char*)p->dim, idx.rank);
    p->dim[k] = ndk;
    *sp++ = p;

    indexIterateInit(&idx);
    while (indexIterate(&idx)) {
        com1(k);
    }

    sp--;
    pop();
    pop();
    *sp++ = p;
}
Beispiel #9
0
//-----------------------------------------------------------------------------
void DatPanel::toolLeft(QBoxLayout *l)
{
	QAction *a;
	QMenu *o;
	QToolButton *bb;

	// size menu
	o = menu->addMenu(tr("Sizes"));
	a = new QAction(QPixmap(":/png/document-new.png"), tr("Create new"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(create()));
	a->setToolTip(tr("Recreate the data with new sizes and fill it by zeros (Ctrl+Shift+N)."));
	a->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_N);	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);

	a = new QAction(QPixmap(size_xpm), tr("Resize"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(reSize()));
	a->setToolTip(tr("Resize (interpolate) the data to specified sizes (Ctrl+Shift+R)."));
	a->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_R);	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);

	a = new QAction(QPixmap(squize_xpm), tr("Squeeze"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(squize()));
	a->setToolTip(tr("Keep only each n-th element of the data array."));
	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);

	a = new QAction(QPixmap(crop_xpm), tr("Cro&p"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(crop()));
	a->setToolTip(tr("Crop the data edges. Useful to cut off the zero-filled area."));
	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);

	a = new QAction(QPixmap(oper_of_xpm), tr("Transform"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(newdat()));
	a->setToolTip(tr("Transform data along dimension(s) (Ctrl+Shift+T)."));
	a->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_T);	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);

	a = new QAction(QPixmap(oper_dir_xpm), tr("Make new (Ctrl+Shift+M)"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(oper()));
	a->setToolTip(tr("Make another data."));
	a->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_M);	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);

	a = new QAction(QPixmap(hist_xpm), tr("Histogram (Ctrl+Shift+H)"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(hist()));
	a->setToolTip(tr("Find histogram of data."));
	a->setShortcut(Qt::CTRL+Qt::SHIFT+Qt::Key_H);	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);

/*	a = new QAction(QPixmap(":/png/view-refresh.png"), tr("Refresh"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(refresh()));
	a->setToolTip(tr("Refresh data values."));
	o->addAction(a);
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);*/

/*	a = new QAction(tr("Rearrange"), this);	// TODO: move in generalized dialog
	connect(a, SIGNAL(triggered()), this, SLOT(rearrange()));
	a->setToolTip(tr("Rearrange data sizes without changing data values."));
	o->addAction(a);
	a = new QAction(tr("Fill in range"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(inrange()));
	a->setToolTip(tr("Fill data equidistantly from one value to another."));
	o->addAction(a);
	a = new QAction(tr("Normalize"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(norm()));
	a->setToolTip(tr("Normalize data so that its minimal\nand maximal values be in specified range."));
	o->addAction(a);
	a = new QAction(tr("Norm. slices"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(normsl()));
	a->setToolTip(tr("Normalize each data slice perpendicular to some direction\nso that its minimal and maximal values be in specified range."));
	o->addAction(a);*/

	l->addStretch(1);

	a = new QAction(QPixmap(":/png/tab-close.png"), tr("Close tab"), this);
	connect(a, SIGNAL(triggered()), this, SLOT(close()));
	a->setToolTip(tr("Close this data tab."));
	bb = new QToolButton(this);	l->addWidget(bb);	bb->setDefaultAction(a);
}
Beispiel #10
0
ex_index()
{
	struct item *p, *q;
	int i, j, f, n, lv;

	n = *pcp++;
	f = *pcp;
	p = sp[-1];
	if(f == ASGN) {
		pcp++;
		if(p->type != LV) error("indexed assign value");
		if(((struct nlist *)p)->use != DA) fetch1();		/* error("used before set"); */
		q = ((struct nlist *)p)->itemp;
	}
	else q = fetch1();
	if(q->rank != n) error("subscript C");
	idx.rank = 0;
	for(i=0; i<n; i++) {
		p = sp[-i-2];
		if(p->type == EL) {
			idx.dim[idx.rank++] = q->dim[i];
			continue;
		}
		p = fetch(p);
		sp[-i-2] = p;
		for(j=0; j<p->rank; j++) idx.dim[idx.rank++] = p->dim[j];
	}
	size();
	if(f == ASGN) {
		p = fetch(sp[-n-2]);
		sp[-n-2] = p;
		if (p->size > 1) {
			if(idx.size != p->size) error("assign C");
			f = 1; /* v[i] <- v */
		}
		else {
			if (idx.size && !p->size) error("assign C");
			/* Note -- for idx.size = 0, no assign occurs
			 * anyway, so it is safe to set "datum" to 0
			 */
			datum = p->size ? getdat(p) : 0;
			f = 2; /* v[i] <- s */
		}
		ex_elid();
	}
	else {
		p = newdat(q->type, idx.rank, idx.size);
		copy(IN, idx.dim, p->dim, idx.rank);
		*sp++ = p;
		f = 0; /* v[i] */
	}
	bidx(q);
	index1(0, f);
	if(f == 0) {
		p = sp[-1];
		sp--;
		for(i=0; i<=n; i++) pop();
		*sp++ = p;
	}
	else {
		pop();		/* pop ELID */
		sp--;		/* skip over LV */
		for(i=0; i<n; i++) pop();
	}
}
Beispiel #11
0
ex_elid()
{
	*sp++ = newdat(EL, 0, 0);
}
Beispiel #12
0
void ex_index()
{
    struct item *p, *q;
    int i, j, f, n;

    n = *gsip->ptr++;
    f = *gsip->ptr;
    p = sp[-1];
    if (f == ASGN) {
        gsip->ptr++;
        if (p->itemType != LV)
            error(ERR_value, "not a local variable");
        if (((SymTabEntry*)p)->entryUse != DA)
            fetch1();
        q = ((SymTabEntry*)p)->itemp;
    }
    else
        q = fetch1();
    if (q->rank != n)
        error(ERR_index, "");
    idx.rank = 0;
    for (i = 0; i < n; i++) {
        p = sp[-i - 2];
        if (p->itemType == EL) {
            idx.dim[idx.rank++] = q->dim[i];
            continue;
        }
        p = fetch(p);
        sp[-i - 2] = p;
        for (j = 0; j < p->rank; j++)
            idx.dim[idx.rank++] = p->dim[j];
    }
    size();
    if (f == ASGN) {
        p = fetch(sp[-n - 2]);
        sp[-n - 2] = p;
        if (p->size > 1) {
            if (idx.size != p->size)
                error(ERR_length, "");
            f = 1; /* v[i] <- v */

        } else {
            if (idx.size && !p->size)
                error(ERR_length, "");
            /* Note -- for idx.size = 0, no assign occurs
          * anyway, so it is safe to set "datum" to 0
          */
            datum = p->size ? getdat(p) : 0;
            f = 2; /* v[i] <- s */
        }
        ex_elid();

    } else {
        p = newdat(q->itemType, idx.rank, idx.size);
        copy(IN, (char*)idx.dim, (char*)p->dim, idx.rank);
        *sp++ = p;
        f = 0; /* v[i] */
    }
    bidx(q);
    index1(0, f);
    if (f == 0) {
        p = sp[-1];
        sp--;
        for (i = 0; i <= n; i++)
            pop();
        *sp++ = p;
    }
    else {
        pop(); /* pop ELID */
        sp--;  /* skip over LV */
        for (i = 0; i < n; i++)
            pop();
    }
}