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, 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)
53 for (i = 0; i < n; i++)
60 bool available(FILE* fp, const void* p, int indent, const char* title)
66 pr_indent(fp, indent);
68 fprintf(fp, "%s: not available\n", title);
70 return (p != nullptr);
73 int pr_title(FILE* fp, int indent, const char* title)
75 pr_indent(fp, indent);
76 fprintf(fp, "%s:\n", title);
77 return (indent + INDENT);
80 int pr_title_n(FILE* fp, int indent, const char* title, int n)
82 pr_indent(fp, indent);
83 fprintf(fp, "%s (%d):\n", title, n);
84 return (indent + INDENT);
87 int pr_title_nxn(FILE* fp, int indent, const char* title, int n1, int n2)
89 pr_indent(fp, indent);
90 fprintf(fp, "%s (%dx%d):\n", title, n1, n2);
91 return (indent + INDENT);
94 void pr_reals(FILE* fp, int indent, const char* title, const real* vec, int n)
98 if (available(fp, vec, indent, title))
100 pr_indent(fp, indent);
101 fprintf(fp, "%s:\t", title);
102 for (i = 0; i < n; i++)
104 fprintf(fp, " %10g", vec[i]);
110 void pr_doubles(FILE* fp, int indent, const char* title, const double* vec, int n)
114 if (available(fp, vec, indent, title))
116 pr_indent(fp, indent);
117 fprintf(fp, "%s:\t", title);
118 for (i = 0; i < n; i++)
120 fprintf(fp, " %10g", vec[i]);
126 void pr_reals_of_dim(FILE* fp, int indent, const char* title, const real* vec, int n, int dim)
129 const char* fshort = "%12.5e";
130 const char* flong = "%15.8e";
133 if (getenv("GMX_PRINT_LONGFORMAT") != nullptr)
142 if (available(fp, vec, indent, title))
144 indent = pr_title_nxn(fp, indent, title, n, dim);
145 for (i = 0; i < n; i++)
147 pr_indent(fp, indent);
148 fprintf(fp, "%s[%5d]={", title, i);
149 for (j = 0; j < dim; j++)
155 fprintf(fp, format, vec[i * dim + j]);
162 void pr_int(FILE* fp, int indent, const char* title, int i)
164 pr_indent(fp, indent);
165 fprintf(fp, "%-30s = %d\n", title, i);
168 void pr_int64(FILE* fp, int indent, const char* title, int64_t i)
170 char buf[STEPSTRSIZE];
172 pr_indent(fp, indent);
173 fprintf(fp, "%-30s = %s\n", title, gmx_step_str(i, buf));
176 void pr_real(FILE* fp, int indent, const char* title, real r)
178 pr_indent(fp, indent);
179 fprintf(fp, "%-30s = %g\n", title, r);
182 void pr_double(FILE* fp, int indent, const char* title, double d)
184 pr_indent(fp, indent);
185 fprintf(fp, "%-30s = %g\n", title, d);
188 void pr_str(FILE* fp, int indent, const char* title, const char* s)
190 pr_indent(fp, indent);
191 fprintf(fp, "%-30s = %s\n", title, s);
194 void pr_strings(FILE* fp, int indent, const char* title, char*** nm, int n, gmx_bool bShowNumbers)
198 if (available(fp, nm, indent, title))
200 indent = pr_title_n(fp, indent, title, n);
201 for (i = 0; i < n; i++)
203 pr_indent(fp, indent);
204 fprintf(fp, "%s[%d]={name=\"%s\"}\n", title, bShowNumbers ? i : -1, *(nm[i]));