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,2016,2017 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.
45 #include "gromacs/math/vec.h"
46 #include "gromacs/utility/strconvert.h"
47 #include "gromacs/utility/txtdump.h"
49 void pr_ivec(FILE* fp
, int indent
, const char* title
, const int vec
[], int n
, gmx_bool bShowNumbers
)
53 if (available(fp
, vec
, indent
, title
))
55 indent
= pr_title_n(fp
, indent
, title
, n
);
56 for (i
= 0; i
< n
; i
++)
58 pr_indent(fp
, indent
);
59 fprintf(fp
, "%s[%d]=%d\n", title
, bShowNumbers
? i
: -1, vec
[i
]);
64 void pr_ivec_block(FILE* fp
, int indent
, const char* title
, const int vec
[], int n
, gmx_bool bShowNumbers
)
68 if (available(fp
, vec
, indent
, title
))
70 indent
= pr_title_n(fp
, indent
, title
, n
);
75 while (j
< n
&& vec
[j
] == vec
[j
- 1] + 1)
79 /* Print consecutive groups of 3 or more as blocks */
84 pr_indent(fp
, indent
);
85 fprintf(fp
, "%s[%d]=%d\n", title
, bShowNumbers
? i
: -1, vec
[i
]);
91 pr_indent(fp
, indent
);
92 fprintf(fp
, "%s[%d,...,%d] = {%d,...,%d}\n", title
, bShowNumbers
? i
: -1,
93 bShowNumbers
? j
- 1 : -1, vec
[i
], vec
[j
- 1]);
100 void pr_bvec(FILE* fp
, int indent
, const char* title
, const gmx_bool vec
[], int n
, gmx_bool bShowNumbers
)
104 if (available(fp
, vec
, indent
, title
))
106 indent
= pr_title_n(fp
, indent
, title
, n
);
107 for (i
= 0; i
< n
; i
++)
109 pr_indent(fp
, indent
);
110 fprintf(fp
, "%s[%d]=%s\n", title
, bShowNumbers
? i
: -1, gmx::boolToString(vec
[i
]));
115 void pr_ivecs(FILE* fp
, int indent
, const char* title
, const ivec vec
[], int n
, gmx_bool bShowNumbers
)
119 if (available(fp
, vec
, indent
, title
))
121 indent
= pr_title_nxn(fp
, indent
, title
, n
, DIM
);
122 for (i
= 0; i
< n
; i
++)
124 pr_indent(fp
, indent
);
125 fprintf(fp
, "%s[%d]={", title
, bShowNumbers
? i
: -1);
126 for (j
= 0; j
< DIM
; j
++)
132 fprintf(fp
, "%d", vec
[i
][j
]);
140 static void printRealVector(FILE* fp
, int indent
, const char* title
, const T vec
[], int n
, gmx_bool bShowNumbers
)
142 if (available(fp
, vec
, indent
, title
))
144 indent
= pr_title_n(fp
, indent
, title
, n
);
145 for (int i
= 0; i
< n
; i
++)
147 pr_indent(fp
, indent
);
148 fprintf(fp
, "%s[%d]=%12.5e\n", title
, bShowNumbers
? i
: -1, vec
[i
]);
153 void pr_rvec(FILE* fp
, int indent
, const char* title
, const real vec
[], int n
, gmx_bool bShowNumbers
)
155 printRealVector
<real
>(fp
, indent
, title
, vec
, n
, bShowNumbers
);
158 void pr_fvec(FILE* fp
, int indent
, const char* title
, const float vec
[], int n
, gmx_bool bShowNumbers
)
160 printRealVector
<float>(fp
, indent
, title
, vec
, n
, bShowNumbers
);
163 void pr_dvec(FILE* fp
, int indent
, const char* title
, const double vec
[], int n
, gmx_bool bShowNumbers
)
165 printRealVector
<double>(fp
, indent
, title
, vec
, n
, bShowNumbers
);
169 void pr_rvecs_len(FILE* fp
, int indent
, const char* title
, const rvec vec
[], int n
)
173 if (available(fp
, vec
, indent
, title
))
175 indent
= pr_title_nxn(fp
, indent
, title
, n
, DIM
);
176 for (i
= 0; i
< n
; i
++)
178 pr_indent(fp
, indent
);
179 fprintf(fp
, "%s[%5d]={", title
, i
);
180 for (j
= 0; j
< DIM
; j
++)
186 fprintf(fp
, "%12.5e", vec
[i
][j
]);
188 fprintf(fp
, "} len=%12.5e\n", norm(vec
[i
]));
193 void pr_rvecs(FILE* fp
, int indent
, const char* title
, const rvec vec
[], int n
)
195 const char* fshort
= "%12.5e";
196 const char* flong
= "%15.8e";
200 if (getenv("GMX_PRINT_LONGFORMAT") != nullptr)
209 if (available(fp
, vec
, indent
, title
))
211 indent
= pr_title_nxn(fp
, indent
, title
, n
, DIM
);
212 for (i
= 0; i
< n
; i
++)
214 pr_indent(fp
, indent
);
215 fprintf(fp
, "%s[%5d]={", title
, i
);
216 for (j
= 0; j
< DIM
; j
++)
222 fprintf(fp
, format
, vec
[i
][j
]);
230 void pr_rvecs_of_dim(FILE* fp
, int indent
, const char* title
, const rvec vec
[], int n
, int dim
)
232 const char* fshort
= "%12.5e";
233 const char* flong
= "%15.8e";
237 if (getenv("GMX_PRINT_LONGFORMAT") != nullptr)
246 if (available(fp
, vec
, indent
, title
))
248 indent
= pr_title_nxn(fp
, indent
, title
, n
, dim
);
249 for (i
= 0; i
< n
; i
++)
251 pr_indent(fp
, indent
);
252 fprintf(fp
, "%s[%5d]={", title
, i
);
253 for (j
= 0; j
< dim
; j
++)
259 fprintf(fp
, format
, vec
[i
][j
]);