Debian Codegraph @

doc/stencils/dump-stencil.cpp

raw
1 #include <blitz/array.h>
2 #include <iostream>
3
4 using namespace blitz;
5
6
7 BZ_DECLARE_STENCIL2(footprint,A,B)
8 B = stenciltoapply(stencilargs);
9 BZ_END_STENCIL
10
11
12 template<class T_stencil>
13 void dumpStencil(const T_stencil& stencil)
14 {
15 const int maxN = 5;
16
17 Array<double,2> A(Range(-maxN,maxN),Range(-maxN,maxN)),
18 B(Range(-maxN,maxN), Range(-maxN, maxN));
19
20 A = 0.0;
21 A(0,0) = 1;
22
23 B = 0.0;
24
25 applyStencil(stencil, A, B);
26
27 B.reverseSelf(firstDim);
28 B.reverseSelf(secondDim);
29
30 using namespace blitz::tensor;
31
32 int minrow = first(sum(B != 0.0, j));
33 int maxrow = last(sum(B != 0.0, j));
34 int mincol = first(sum(B(j,i) != 0.0, j));
35 int maxcol = last(sum(B(j,i) != 0.0, j));
36
37 // Code to dump HTML
38 cout << "@html" << endl;
39 cout << "<table cellpadding=2 rules=all>" << endl
40 << "<tr align=right><td></td>";
41
42 for (int j=mincol; j <= maxcol; ++j)
43 cout << "<td>" << j << "</td>";
44
45 cout << "</tr>";
46
47 for (int i=minrow; i <= maxrow; ++i)
48 {
49 cout << "<tr align=right>";
50
51 if (minrow != maxrow)
52 cout << "<td>" << i << "</td>";
53 else
54 cout << "<td></td>";
55
56 for (int j=mincol; j <= maxcol; ++j)
57 {
58 if (B(i,j) != 0.0)
59 {
60 if ((i == 0) && (j == 0))
61 cout << "<td bgcolor=\"#000060\">";
62 else
63 cout << "<td bgcolor=\"#000000\">";
64 cout << "<font color=\"#ffffff\">" << B(i,j) << "</font></td>";
65 }
66 else
67 cout << "<td></td>";
68 }
69
70 cout << "</tr>" << endl;
71 }
72 cout << "</table>" << endl;
73 cout << "@end html" << endl;
74
75 // Code to dump TeX
76 cout << "@tex" << endl;
77 cout << "\\def\\tablevrule{\\vrule height 10pt depth 3pt}" << endl;
78 cout << "\\vskip0.5\\baselineskip\\hskip\\itemindent" << endl;
79 cout << "\\vbox{\\halign{\\hfill#\\quad&\\tablevrule#\\quad" << endl;
80 for (int j=mincol; j <= maxcol; ++j)
81 cout << "&\\hfill#\\quad";
82 cout << "\\cr" << endl;
83 cout << "&& ";
84 for (int j=mincol; j < maxcol; ++j)
85 cout << j << " & " ;
86 cout << maxcol << " \\cr" << endl << "\\noalign{\\hrule}" << endl;
87 for (int i=minrow; i <= maxrow; ++i)
88 {
89 if (minrow != maxrow)
90 cout << i << " && ";
91 else
92 cout << " && ";
93 for (int j=mincol; j <= maxcol; ++j)
94 {
95 if (B(i,j) != 0.0)
96 {
97 if ((i == 0) && (j == 0))
98 cout << "{\\bf " << B(i,j) << "} ";
99 else
100 cout << " " << B(i,j) << " ";
101 }
102 if (j != maxcol)
103 cout << " & ";
104 }
105 if (i != maxrow)
106 cout << "\\cr" << endl;
107 }
108 cout << "\\cr}}" << endl;
109 cout << "@end tex" << endl;
110
111 // Code to dump !TeX && !HTML
112 cout << "@ifnottex" << endl;
113 cout << "@ifnothtml" << endl;
114 cout << "@multitable {12345}";
115 for (int j=mincol; j <= maxcol; ++j)
116 cout << " {12345}";
117 cout << endl << "@item @tab ";
118 for (int j=mincol; j < maxcol; ++j)
119 cout << j << " @tab " ;
120 cout << maxcol << endl << "@item ";
121 for (int i=minrow; i <= maxrow; ++i)
122 {
123 if (minrow != maxrow)
124 cout << i << " @tab ";
125 else
126 cout << "@tab ";
127 for (int j=mincol; j <= maxcol; ++j)
128 {
129 if (B(i,j) != 0.0)
130 {
131 if ((i == 0) && (j == 0))
132 cout << "@strong{" << B(i,j) << "} ";
133 else
134 cout << " " << B(i,j) << " ";
135 }
136 if (j != maxcol)
137 cout << "@tab ";
138 }
139 if (i != maxrow)
140 cout << endl << "@item ";
141 }
142 cout << endl << "@end multitable" << endl;
143 cout << "@end ifnothtml" << endl;
144 cout << "@end ifnottex" << endl;
145
146 #if 0
147 // Code to dump LaTeX
148 cout << "latexcommand(" << endl;
149 cout << "\\begin{tabular}{r|";
150 for (int j=mincol; j <= maxcol; ++j)
151 cout << "r";
152 cout << "}" << endl;
153 cout << " & ";
154 for (int j=mincol; j < maxcol; ++j)
155 cout << j << " & " ;
156 cout << maxcol << " \\\\ \\hline" << endl;
157 for (int i=minrow; i <= maxrow; ++i)
158 {
159 if (minrow != maxrow)
160 cout << i << " & ";
161 else
162 cout << " & ";
163 for (int j=mincol; j <= maxcol; ++j)
164 {
165 if (B(i,j) != 0.0)
166 {
167 if ((i == 0) && (j == 0))
168 cout << "{\\bf " << B(i,j) << "} ";
169 else
170 cout << " " << B(i,j) << " ";
171 }
172 if (j != maxcol)
173 cout << " & ";
174 }
175 if (i != maxrow)
176 cout << " \\\\ " << endl;
177 }
178 cout << endl << "\\end{tabular}" << endl;
179 cout << ")" << endl;
180 #endif
181 }
182
183 int main()
184 {
185 dumpStencil(footprint());
186 }
187