25 #include <openbeam/config.h>
35 template <
class MATRIX,
class ARRAY = MATRIX>
36 void print_html_matrix(
37 std::ostream& out,
const MATRIX& K,
38 const std::vector<std::string>& row_titles,
39 const std::vector<std::string>& col_titles,
40 const ARRAY* rows_to_use =
nullptr,
const ARRAY* cols_to_use =
nullptr)
42 const size_t nCols = K.cols();
43 const size_t nRows = K.rows();
46 int common_factor_pow = 0;
47 std::map<int, int> pow10hits;
48 for (
size_t i = 0; i < nRows; i++)
50 if (rows_to_use && !(*rows_to_use)[i])
continue;
52 for (
size_t j = 0; j < nCols; j++)
54 if (cols_to_use && !(*cols_to_use)[j])
continue;
56 const num_t Kijabs = std::abs(K(i, j));
61 static_cast<int>(log10(Kijabs));
67 if (!pow10hits.empty())
69 std::map<int, int>::const_iterator it_max = pow10hits.begin();
70 for (
auto it = pow10hits.begin(); it != pow10hits.end(); ++it)
72 if (it->second > it_max->second) it_max = it;
74 common_factor_pow = it_max->first;
77 const num_t common_factor =
78 pow(
static_cast<num_t
>(10),
static_cast<num_t
>(common_factor_pow));
79 const num_t common_factor_inv = 1. / common_factor;
82 out <<
"<table border=\"1\" cellpadding=\"9\" cellspacing=\"0\">\n";
86 out <<
"<td bgcolor=\"#E0E0E0\"> </td>";
87 for (
size_t i = 0; i < nCols; i++)
89 if (cols_to_use && !(*cols_to_use)[i])
continue;
96 for (
size_t i = 0; i < nRows; i++)
98 if (rows_to_use && !(*rows_to_use)[i])
continue;
101 out << row_titles[i];
103 for (
size_t j = 0; j < nCols; j++)
105 if (cols_to_use && !(*cols_to_use)[j])
continue;
107 const num_t Kij = K(i, j);
109 out << format(
"<td align=\"right\"> 0 </td>");
112 "<td align=\"right\"> %.3f </td>", Kij * common_factor_inv);
118 out << format(
"( × 10<sup>%i</sup> )<br>\n", common_factor_pow);