2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
7 * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
8 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
9 * and including many others, as listed in the AUTHORS file in the
10 * top-level source directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
40 /* This file is completely threadsafe - please keep it that way! */
47 #include "gromacs/utility/cstringutil.h"
49 int pr_indent(FILE* fp, int n)
51 for (int i = 0; i < n; i++)
58 bool available(FILE* fp, const void* p, int indent, const char* title)
64 pr_indent(fp, indent);
66 fprintf(fp, "%s: not available\n", title);
68 return (p != nullptr);
71 int pr_title(FILE* fp, int indent, const char* title)
73 pr_indent(fp, indent);
74 fprintf(fp, "%s:\n", title);
75 return (indent + INDENT);
78 int pr_title_n(FILE* fp, int indent, const char* title, int n)
80 pr_indent(fp, indent);
81 fprintf(fp, "%s (%d):\n", title, n);
82 return (indent + INDENT);
85 int pr_title_nxn(FILE* fp, int indent, const char* title, int n1, int n2)
87 pr_indent(fp, indent);
88 fprintf(fp, "%s (%dx%d):\n", title, n1, n2);
89 return (indent + INDENT);
92 void pr_reals(FILE* fp, int indent, const char* title, const real* vec, int n)
94 if (available(fp, vec, indent, title))
96 pr_indent(fp, indent);
97 fprintf(fp, "%s:\t", title);
98 for (int i = 0; i < n; i++)
100 fprintf(fp, " %10g", vec[i]);
106 void pr_doubles(FILE* fp, int indent, const char* title, const double* vec, int n)
108 if (available(fp, vec, indent, title))
110 pr_indent(fp, indent);
111 fprintf(fp, "%s:\t", title);
112 for (int i = 0; i < n; i++)
114 fprintf(fp, " %10g", vec[i]);
120 void pr_reals_of_dim(FILE* fp, int indent, const char* title, const real* vec, int n, int dim)
122 const char* fshort = "%12.5e";
123 const char* flong = "%15.8e";
124 const char* format = (getenv("GMX_PRINT_LONGFORMAT") != nullptr) ? flong : fshort;
126 if (available(fp, vec, indent, title))
128 indent = pr_title_nxn(fp, indent, title, n, dim);
129 for (int i = 0; i < n; i++)
131 pr_indent(fp, indent);
132 fprintf(fp, "%s[%5d]={", title, i);
133 for (int j = 0; j < dim; j++)
139 fprintf(fp, format, vec[i * dim + j]);
146 void pr_int(FILE* fp, int indent, const char* title, int i)
148 pr_indent(fp, indent);
149 fprintf(fp, "%-30s = %d\n", title, i);
152 void pr_int64(FILE* fp, int indent, const char* title, int64_t i)
154 char buf[STEPSTRSIZE];
156 pr_indent(fp, indent);
157 fprintf(fp, "%-30s = %s\n", title, gmx_step_str(i, buf));
160 void pr_real(FILE* fp, int indent, const char* title, real r)
162 pr_indent(fp, indent);
163 fprintf(fp, "%-30s = %g\n", title, r);
166 void pr_double(FILE* fp, int indent, const char* title, double d)
168 pr_indent(fp, indent);
169 fprintf(fp, "%-30s = %g\n", title, d);
172 void pr_str(FILE* fp, int indent, const char* title, const char* s)
174 pr_indent(fp, indent);
175 fprintf(fp, "%-30s = %s\n", title, s);
178 void pr_strings(FILE* fp, int indent, const char* title, char*** nm, int n, gmx_bool bShowNumbers)
180 if (available(fp, nm, indent, title))
182 indent = pr_title_n(fp, indent, title, n);
183 for (int i = 0; i < n; i++)
185 pr_indent(fp, indent);
186 fprintf(fp, "%s[%d]={name=\"%s\"}\n", title, bShowNumbers ? i : -1, *(nm[i]));