aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/eqn/matrix.c
blob: c3eddedfff9d8a8f43ba19488d62f7ace5bff3a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "e.h"

int
startcol(int type)	/* mark start of column in lp[] array */
{
	int oct = ct;

	lp[ct++] = type;
	lp[ct++] = 0;	/* count, to come */
	lp[ct++] = 0;	/* separation, to come */
	return oct;
}

void column(int oct, int sep)	/* remember end of column that started at lp[oct] */
{
	int i, type;

	lp[oct+1] = ct - oct - 3;
	lp[oct+2] = sep;
	type = lp[oct];
	if (dbg) {
		printf(".\t%d column of", type);
		for (i = oct+3; i < ct; i++ )
			printf(" S%d", lp[i]);
		printf(", rows=%d, sep=%d\n", lp[oct+1], lp[oct+2]);
	}
}

void matrix(int oct)	/* matrix is list of columns */
{
	int nrow, ncol, i, j, k, val[100];
	double b, hb;
	char *space;
	extern char *Matspace;

	space = Matspace;	/* between columns of matrix */
	nrow = lp[oct+1];	/* disaster if rows inconsistent */
				/* also assumes just columns */
				/* fix when add other things */
	ncol = 0;
	for (i = oct+1; i < ct; i += lp[i]+3 ) {
		ncol++;
		dprintf(".\tcolct=%d\n", lp[i]);
	}
	for (k=1; k <= nrow; k++) {
		hb = b = 0;
		j = oct + k + 2;
		for (i=0; i < ncol; i++) {
			hb = max(hb, eht[lp[j]]-ebase[lp[j]]);
			b = max(b, ebase[lp[j]]);
			j += nrow + 3;
		}
		dprintf(".\trow %d: b=%g, hb=%g\n", k, b, hb);
		j = oct + k + 2;
		for (i=0; i<ncol; i++) {
			ebase[lp[j]] = b;
			eht[lp[j]] = b + hb;
			j += nrow + 3;
		}
	}
	j = oct;
	for (i=0; i<ncol; i++) {
		pile(j);
		val[i] = yyval;
		j += nrow + 3;
	}
	yyval = salloc();
	eht[yyval] = eht[val[0]];
	ebase[yyval] = ebase[val[0]];
	lfont[yyval] = rfont[yyval] = 0;
	dprintf(".\tmatrix S%d: r=%d, c=%d, h=%g, b=%g\n",
		yyval,nrow,ncol,eht[yyval],ebase[yyval]);
	printf(".ds %d \"", yyval);
	for( i=0; i<ncol; i++ )  {
		printf("\\*(%d%s", val[i], i==ncol-1 ? "" : space);
		sfree(val[i]);
	}
	printf("\n");
}