-
Notifications
You must be signed in to change notification settings - Fork 0
/
mat_print.cc
99 lines (83 loc) · 2.97 KB
/
mat_print.cc
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* @BEGIN LICENSE
*
* Psi4: an open-source quantum chemistry software package
*
* Copyright (c) 2007-2019 The Psi4 Developers.
*
* The copyrights for code used from other parties are included in
* the corresponding files.
*
* This file is part of Psi4.
*
* Psi4 is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* Psi4 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with Psi4; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @END LICENSE
*/
#include <cstdio>
#include <cstdlib>
#include "psi4/psi4-dec.h"
#include "psi4/libpsi4util/PsiOutStream.h"
/*!
** \file
** \brief Print a matrix to a file in a formatted style
** \ingroup QT
*/
namespace psi {
/*!
** mat_print(): Prints a matrix to a file in a formatted style
**
** \param matrix = matrix to print
** \param rows = number of rows
** \param cols = number of columns
** \param outfile = output file pointer for printing
**
** \ingroup QT
*/
void mat_print(double **matrix, int rows, int cols, std::string out) {
std::shared_ptr<psi::PsiOutStream> printer = (out == "outfile" ? outfile : std::make_shared<PsiOutStream>(out));
div_t fraction;
int i, j;
int cols_per_page, num_pages, last_page, page, first_col;
cols_per_page = 5;
/* Determine the number of cols_per_page groups */
fraction = div(cols, cols_per_page);
num_pages = fraction.quot; /* Number of complete column groups */
last_page = fraction.rem; /* Number of columns in last group */
/* Loop over the complete column groups */
for (page = 0; page < num_pages; page++) {
first_col = page * cols_per_page;
outfile->Printf("\n ");
for (i = first_col; i < first_col + cols_per_page; i++) printer->Printf(" %5d ", i);
printer->Printf("\n");
for (i = 0; i < rows; i++) {
printer->Printf("\n%5d ", i);
for (j = first_col; j < first_col + cols_per_page; j++) printer->Printf("%22.15f", matrix[i][j]);
}
printer->Printf("\n");
}
/* Now print the remaining columns */
if (last_page) {
first_col = page * cols_per_page;
printer->Printf("\n ");
for (i = first_col; i < first_col + last_page; i++) printer->Printf(" %5d ", i);
printer->Printf("\n");
for (i = 0; i < rows; i++) {
printer->Printf("\n%5d ", i);
for (j = first_col; j < first_col + last_page; j++) printer->Printf("%22.15f", matrix[i][j]);
}
printer->Printf("\n");
}
}
} // namespace psi