1 #include <blitz/array.h>
2 #include <iostream.h>
3 #include <complex.h>
4 
5 using namespace blitz;
6 
7 
8 BZ_DECLARE_STENCIL2(footprint,A,B)
9     B = stenciltoapply;
10 BZ_END_STENCIL
11 
12 
13 template<class T_stencil>
dumpStencil(const T_stencil & stencil)14 void dumpStencil(const T_stencil& stencil)
15 {
16     const int maxN = 5;
17 
18     Array<double,2> A(Range(-maxN,maxN),Range(-maxN,maxN)),
19      B(Range(-maxN,maxN), Range(-maxN, maxN));
20 
21     A = 0.0;
22     A(0,0) = 1;
23 
24     B = 0.0;
25 
26     applyStencil(stencil, A, B);
27 
28     B.reverseSelf(firstDim);
29     B.reverseSelf(secondDim);
30 
31     using namespace blitz::tensor;
32 
33     int minrow = first(sum(B != 0.0, j));
34     int maxrow = last(sum(B != 0.0, j));
35     int mincol = first(sum(B(j,i) != 0.0, j));
36     int maxcol = last(sum(B(j,i) != 0.0, j));
37 
38     // Code to dump HTML
39     cout << "htmlcommand(" << endl;
40     cout << "<table cellpadding=2 rules=all>" << endl
41          << "<tr align=right><td></td>";
42 
43     for (int j=mincol; j <= maxcol; ++j)
44         cout << "<td>" << j << "</td>";
45 
46     cout << "</tr>";
47 
48     for (int i=minrow; i <= maxrow; ++i)
49     {
50         cout << "<tr align=right>";
51 
52         if (minrow != maxrow)
53             cout << "<td>" << i << "</td>";
54         else
55             cout << "<td></td>";
56 
57         for (int j=mincol; j <= maxcol; ++j)
58         {
59             if (B(i,j) != 0.0)
60             {
61                 if ((i == 0) && (j == 0))
62                     cout << "<td bgcolor=\"#000060\">";
63                 else
64                     cout << "<td bgcolor=\"#000000\">";
65                 cout << "<font color=\"#ffffff\">" << B(i,j) << "</font></td>";
66             }
67             else
68                 cout << "<td></td>";
69         }
70 
71         cout << "</tr>" << endl;
72     }
73     cout << "</table>";
74     cout << ")" << endl;
75 
76 
77     // Code to dump LaTeX
78     cout << "latexcommand(" << endl;
79     cout << "\\begin{tabular}{r|";
80     for (int j=mincol; j <= maxcol; ++j)
81         cout << "r";
82     cout << "}" << endl;
83     cout << " & ";
84     for (int j=mincol; j < maxcol; ++j)
85         cout << j << " & " ;
86     cout << maxcol << " \\\\ \\hline" << 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 << " \\\\  " << endl;
107     }
108     cout << endl << "\\end{tabular}" << endl;
109     cout << ")" << endl;
110 }
111 
main()112 int main()
113 {
114     dumpStencil(footprint());
115 }
116 
117