From: Carsten Kutzner Date: Fri, 15 Aug 2014 14:44:44 +0000 (+0200) Subject: Fixed output of eigenvalues in g_covar. Fixes #1575 X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=0a27e96b15d7ea4cfffa179512cc858123e91d7b;p=alexxy%2Fgromacs.git Fixed output of eigenvalues in g_covar. Fixes #1575 Commit 972032bfb8cd38 introduced a bug that would lead to eigenvalues only written to .xvg file if "-last" is explicitly stated on the command line. Otherwise no eigenvalues would appear in the .xvg file. The eigenvalues are written in a loop from '0' to 'end', but since 'end' is initialized with '-1', the loop would never be executed. This patch moves the code that computes 'end' one block upwards before the output to file. Change-Id: I738c9dd77ff9e6e2daae89b6d2063755dfba88af --- diff --git a/src/tools/gmx_covar.c b/src/tools/gmx_covar.c index fc7d55e70f..5313c407e7 100644 --- a/src/tools/gmx_covar.c +++ b/src/tools/gmx_covar.c @@ -133,7 +133,7 @@ int gmx_covar(int argc, char *argv[]) { "-pbc", FALSE, etBOOL, {&bPBC}, "Apply corrections for periodic boundary conditions" } }; - FILE *out; + FILE *out = NULL; /* initialization makes all compilers happy */ t_trxstatus *status; t_trxstatus *trjout; t_topology top; @@ -560,18 +560,7 @@ int gmx_covar(int argc, char *argv[]) fprintf(stderr, "\nWARNING: eigenvalue sum deviates from the trace of the covariance matrix\n"); } - fprintf(stderr, "\nWriting eigenvalues to %s\n", eigvalfile); - - sprintf(str, "(%snm\\S2\\N)", bM ? "u " : ""); - out = xvgropen(eigvalfile, - "Eigenvalues of the covariance matrix", - "Eigenvector index", str, oenv); - for (i = 0; (i < end); i++) - { - fprintf (out, "%10d %g\n", (int)i+1, eigenvalues[ndim-1-i]); - } - ffclose(out); - + /* Set 'end', the maximum eigenvector and -value index used for output */ if (end == -1) { if (nframes-1 < ndim) @@ -586,6 +575,19 @@ int gmx_covar(int argc, char *argv[]) end = ndim; } } + + fprintf(stderr, "\nWriting eigenvalues to %s\n", eigvalfile); + + sprintf(str, "(%snm\\S2\\N)", bM ? "u " : ""); + out = xvgropen(eigvalfile, + "Eigenvalues of the covariance matrix", + "Eigenvector index", str, oenv); + for (i = 0; (i < end); i++) + { + fprintf (out, "%10d %g\n", (int)i+1, eigenvalues[ndim-1-i]); + } + ffclose(out); + if (bFit) { /* misuse lambda: 0/1 mass weighted analysis no/yes */