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,2019, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
39 /* This file is completely threadsafe - please keep it that way! */
46 #include "gromacs/utility/cstringutil.h"
48 int pr_indent(FILE* fp, int n)
52 for (i = 0; i < n; i++)
59 bool available(FILE* fp, const void* p, int indent, const char* title)
65 pr_indent(fp, indent);
67 fprintf(fp, "%s: not available\n", title);
69 return (p != nullptr);
72 int pr_title(FILE* fp, int indent, const char* title)
74 pr_indent(fp, indent);
75 fprintf(fp, "%s:\n", title);
76 return (indent + INDENT);
79 int pr_title_n(FILE* fp, int indent, const char* title, int n)
81 pr_indent(fp, indent);
82 fprintf(fp, "%s (%d):\n", title, n);
83 return (indent + INDENT);
86 int pr_title_nxn(FILE* fp, int indent, const char* title, int n1, int n2)
88 pr_indent(fp, indent);
89 fprintf(fp, "%s (%dx%d):\n", title, n1, n2);
90 return (indent + INDENT);
93 void pr_reals(FILE* fp, int indent, const char* title, const real* vec, int n)
97 if (available(fp, vec, indent, title))
99 pr_indent(fp, indent);
100 fprintf(fp, "%s:\t", title);
101 for (i = 0; i < n; i++)
103 fprintf(fp, " %10g", vec[i]);
109 void pr_doubles(FILE* fp, int indent, const char* title, const double* vec, int n)
113 if (available(fp, vec, indent, title))
115 pr_indent(fp, indent);
116 fprintf(fp, "%s:\t", title);
117 for (i = 0; i < n; i++)
119 fprintf(fp, " %10g", vec[i]);
125 void pr_reals_of_dim(FILE* fp, int indent, const char* title, const real* vec, int n, int dim)
128 const char* fshort = "%12.5e";
129 const char* flong = "%15.8e";
132 if (getenv("GMX_PRINT_LONGFORMAT") != nullptr)
141 if (available(fp, vec, indent, title))
143 indent = pr_title_nxn(fp, indent, title, n, dim);
144 for (i = 0; i < n; i++)
146 pr_indent(fp, indent);
147 fprintf(fp, "%s[%5d]={", title, i);
148 for (j = 0; j < dim; j++)
154 fprintf(fp, format, vec[i * dim + j]);
161 void pr_int(FILE* fp, int indent, const char* title, int i)
163 pr_indent(fp, indent);
164 fprintf(fp, "%-30s = %d\n", title, i);
167 void pr_int64(FILE* fp, int indent, const char* title, int64_t i)
169 char buf[STEPSTRSIZE];
171 pr_indent(fp, indent);
172 fprintf(fp, "%-30s = %s\n", title, gmx_step_str(i, buf));
175 void pr_real(FILE* fp, int indent, const char* title, real r)
177 pr_indent(fp, indent);
178 fprintf(fp, "%-30s = %g\n", title, r);
181 void pr_double(FILE* fp, int indent, const char* title, double d)
183 pr_indent(fp, indent);
184 fprintf(fp, "%-30s = %g\n", title, d);
187 void pr_str(FILE* fp, int indent, const char* title, const char* s)
189 pr_indent(fp, indent);
190 fprintf(fp, "%-30s = %s\n", title, s);
193 void pr_strings(FILE* fp, int indent, const char* title, char*** nm, int n, gmx_bool bShowNumbers)
197 if (available(fp, nm, indent, title))
199 indent = pr_title_n(fp, indent, title, n);
200 for (i = 0; i < n; i++)
202 pr_indent(fp, indent);
203 fprintf(fp, "%s[%d]={name=\"%s\"}\n", title, bShowNumbers ? i : -1, *(nm[i]));