Remove variable precision gro writing
authorBerk Hess <hess@kth.se>
Tue, 23 Aug 2016 10:13:35 +0000 (12:13 +0200)
committerBerk Hess <hess@kth.se>
Tue, 23 Aug 2016 10:13:35 +0000 (12:13 +0200)
The gro precision is now fixed to 3, 4 and 5 decimal places for
x, v and box respectively to ensure compatibility with other software.
Variable precision reading is still supported.

Fixes #2037.

Change-Id: I0e593622ee0380c3934a7b7b6826ae29aed00a59

src/gromacs/fileio/confio.cpp
src/gromacs/fileio/groio.cpp
src/gromacs/fileio/groio.h
src/gromacs/fileio/trxio.cpp
src/gromacs/gmxana/gmx_confrms.cpp
src/gromacs/gmxana/gmx_trjconv.cpp

index 3203b1c720f90125c3fff12272d27e1c7fda78d8..a370d48890df143cacf5fde6a60ff4445b478b55 100644 (file)
@@ -75,7 +75,7 @@ void write_sto_conf_indexed(const char *outfile, const char *title,
     {
         case efGRO:
             out = gmx_fio_fopen(outfile, "w");
-            write_hconf_indexed_p(out, title, atoms, nindex, index, 3, x, v, box);
+            write_hconf_indexed_p(out, title, atoms, nindex, index, x, v, box);
             gmx_fio_fclose(out);
             break;
         case efG96:
@@ -130,7 +130,7 @@ void write_sto_conf(const char *outfile, const char *title, const t_atoms *atoms
     switch (ftp)
     {
         case efGRO:
-            write_conf_p(outfile, title, atoms, 3, x, v, box);
+            write_conf_p(outfile, title, atoms, x, v, box);
             break;
         case efG96:
             clear_trxframe(&fr, TRUE);
@@ -185,7 +185,7 @@ void write_sto_conf_mtop(const char *outfile, const char *title,
     {
         case efGRO:
             out = gmx_fio_fopen(outfile, "w");
-            write_hconf_mtop(out, title, mtop, 3, x, v, box);
+            write_hconf_mtop(out, title, mtop, x, v, box);
             gmx_fio_fclose(out);
             break;
         default:
index d627a203381d47329234e0618555d470dc5304bf..9b4e9f30585a15032d06cd8f02e6aaf2f6f59d9d 100644 (file)
@@ -78,6 +78,11 @@ void get_coordnum(const char *infile, int *natoms)
     gmx_fio_fclose(in);
 }
 
+/* Note that the .gro reading routine still support variable precision
+ * for backward compatibility with old .gro files.
+ * We have removed writing of variable precision to avoid compatibility
+ * issues with other software packages.
+ */
 static gmx_bool get_w_conf(FILE *in, const char *infile, char *title,
                            t_symtab *symtab, t_atoms *atoms, int *ndec,
                            rvec x[], rvec *v, matrix box)
@@ -403,75 +408,47 @@ int gro_first_x_or_v(FILE *status, t_trxframe *fr)
     return fr->natoms;
 }
 
-static void make_hconf_format(int pr, gmx_bool bVel, char format[])
+static const char *get_hconf_format(bool haveVelocities)
 {
-    int l, vpr;
-
-    /* build format string for printing,
-       something like "%8.3f" for x and "%8.4f" for v */
-    if (pr < 0)
-    {
-        pr = 0;
-    }
-    if (pr > 30)
-    {
-        pr = 30;
-    }
-    l   = pr+5;
-    vpr = pr+1;
-    if (bVel)
+    if (haveVelocities)
     {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df\n",
-                l, pr, l, pr, l, pr, l, vpr, l, vpr, l, vpr);
+        return "%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f\n";
     }
     else
     {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df\n", l, pr, l, pr, l, pr);
+        return "%8.3f%8.3f%8.3f\n";
     }
 
 }
 
-static void write_hconf_box(FILE *out, int pr, const matrix box)
+static void write_hconf_box(FILE *out, const matrix box)
 {
-    char format[100];
-    int  l;
-
-    if (pr < 5)
-    {
-        pr = 5;
-    }
-    l = pr+5;
-
     if (box[XX][YY] || box[XX][ZZ] || box[YY][XX] || box[YY][ZZ] ||
         box[ZZ][XX] || box[ZZ][YY])
     {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df"
-                "%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df%%%d.%df\n",
-                l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr);
-        fprintf(out, format,
+        fprintf(out, "%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f%10.5f\n",
                 box[XX][XX], box[YY][YY], box[ZZ][ZZ],
                 box[XX][YY], box[XX][ZZ], box[YY][XX],
                 box[YY][ZZ], box[ZZ][XX], box[ZZ][YY]);
     }
     else
     {
-        sprintf(format, "%%%d.%df%%%d.%df%%%d.%df\n", l, pr, l, pr, l, pr);
-        fprintf(out, format,
+        fprintf(out, "%10.5f%10.5f%10.5f\n",
                 box[XX][XX], box[YY][YY], box[ZZ][ZZ]);
     }
 }
 
 void write_hconf_indexed_p(FILE *out, const char *title, const t_atoms *atoms,
-                           int nx, const int index[], int pr,
+                           int nx, const int index[],
                            const rvec *x, const rvec *v, const matrix box)
 {
-    char resnm[6], nm[6], format[100];
+    char resnm[6], nm[6];
     int  ai, i, resind, resnr;
 
     fprintf(out, "%s\n", (title && title[0]) ? title : gmx::bromacs().c_str());
     fprintf(out, "%5d\n", nx);
 
-    make_hconf_format(pr, v != NULL, format);
+    const char *format = get_hconf_format(v != NULL);
 
     for (i = 0; (i < nx); i++)
     {
@@ -513,15 +490,14 @@ void write_hconf_indexed_p(FILE *out, const char *title, const t_atoms *atoms,
         }
     }
 
-    write_hconf_box(out, pr, box);
+    write_hconf_box(out, box);
 
     fflush(out);
 }
 
-void write_hconf_mtop(FILE *out, const char *title, gmx_mtop_t *mtop, int pr,
+void write_hconf_mtop(FILE *out, const char *title, gmx_mtop_t *mtop,
                       const rvec *x, const rvec *v, const matrix box)
 {
-    char                    format[100];
     int                     i, resnr;
     gmx_mtop_atomloop_all_t aloop;
     t_atom                 *atom;
@@ -530,7 +506,7 @@ void write_hconf_mtop(FILE *out, const char *title, gmx_mtop_t *mtop, int pr,
     fprintf(out, "%s\n", (title && title[0]) ? title : gmx::bromacs().c_str());
     fprintf(out, "%5d\n", mtop->natoms);
 
-    make_hconf_format(pr, v != NULL, format);
+    const char *format = get_hconf_format(v != NULL);
 
     aloop = gmx_mtop_atomloop_all_init(mtop);
     while (gmx_mtop_atomloop_all_next(aloop, &i, &atom))
@@ -552,12 +528,12 @@ void write_hconf_mtop(FILE *out, const char *title, gmx_mtop_t *mtop, int pr,
         }
     }
 
-    write_hconf_box(out, pr, box);
+    write_hconf_box(out, box);
 
     fflush(out);
 }
 
-void write_hconf_p(FILE *out, const char *title, const t_atoms *atoms, int pr,
+void write_hconf_p(FILE *out, const char *title, const t_atoms *atoms,
                    const rvec *x, const rvec *v, const matrix box)
 {
     int     *aa;
@@ -568,17 +544,17 @@ void write_hconf_p(FILE *out, const char *title, const t_atoms *atoms, int pr,
     {
         aa[i] = i;
     }
-    write_hconf_indexed_p(out, title, atoms, atoms->nr, aa, pr, x, v, box);
+    write_hconf_indexed_p(out, title, atoms, atoms->nr, aa, x, v, box);
     sfree(aa);
 }
 
 void write_conf_p(const char *outfile, const char *title,
-                  const t_atoms *atoms, int pr,
+                  const t_atoms *atoms,
                   const rvec *x, const rvec *v, const matrix box)
 {
     FILE *out;
 
     out = gmx_fio_fopen(outfile, "w");
-    write_hconf_p(out, title, atoms, pr, x, v, box);
+    write_hconf_p(out, title, atoms, x, v, box);
     gmx_fio_fclose(out);
 }
index 9ca94f1aadc2b74da9188121bedddc3b43f06d0a..3391e7df3dd44e11a1982d22a255c630e938c63f 100644 (file)
@@ -60,19 +60,19 @@ int gro_first_x_or_v(FILE *status, struct t_trxframe *fr);
 /* read first/next x and/or v frame from gro file */
 
 void write_hconf_indexed_p(FILE *out, const char *title, const t_atoms *atoms,
-                           int nx, const int index[], int ndec,
+                           int nx, const int index[],
                            const rvec *x, const rvec *v, const matrix box);
 
-void write_hconf_mtop(FILE *out, const char *title, struct gmx_mtop_t *mtop, int pr,
+void write_hconf_mtop(FILE *out, const char *title, struct gmx_mtop_t *mtop,
                       const rvec *x, const rvec *v, const matrix box);
 
-void write_hconf_p(FILE *out, const char *title, const t_atoms *atoms, int ndec,
+void write_hconf_p(FILE *out, const char *title, const t_atoms *atoms,
                    const rvec *x, const rvec *v, const matrix box);
 /* Write a Gromos file with precision ndec: number of decimal places in x,
  * v has one place more. */
 
 void write_conf_p(const char *outfile, const char *title,
-                  const t_atoms *atoms, int pr,
+                  const t_atoms *atoms,
                   const rvec *x, const rvec *v, const matrix box);
 
 #ifdef __cplusplus
index c58be3f56165b91bc1d2de68d1fdd91586a0330a..94432e65f9fc9e85a7c3fc4d25efded40d4fc565 100644 (file)
@@ -426,7 +426,6 @@ int write_trxframe_indexed(t_trxstatus *status, const t_trxframe *fr, int nind,
             if (ftp == efGRO)
             {
                 write_hconf_indexed_p(gmx_fio_getfp(status->fio), title, fr->atoms, nind, ind,
-                                      prec2ndec(prec),
                                       fr->x, fr->bV ? fr->v : NULL, fr->box);
             }
             else
@@ -578,7 +577,7 @@ int write_trxframe(t_trxstatus *status, t_trxframe *fr, gmx_conect gc)
             if (gmx_fio_getftp(status->fio) == efGRO)
             {
                 write_hconf_p(gmx_fio_getfp(status->fio), title, fr->atoms,
-                              prec2ndec(prec), fr->x, fr->bV ? fr->v : NULL, fr->box);
+                              fr->x, fr->bV ? fr->v : NULL, fr->box);
             }
             else
             {
index 03e0422fc2e47d7cddb3ca15816e447a4eb7dbde..7285a059bdcd212450c9b640b180997a46dd2acc 100644 (file)
@@ -812,9 +812,9 @@ int gmx_confrms(int argc, char *argv[])
             fp = gmx_ffopen(outfile, "w");
             if (!bOne)
             {
-                write_hconf_p(fp, *top1->name, atoms1, 3, x1, v1, box1);
+                write_hconf_p(fp, *top1->name, atoms1, x1, v1, box1);
             }
-            write_hconf_p(fp, *top2->name, atoms2, 3, x2, v2, box2);
+            write_hconf_p(fp, *top2->name, atoms2, x2, v2, box2);
             gmx_ffclose(fp);
             break;
         default:
index 575d3a583f7057e28bd69729a0393f08c28747b7..d7769a86334313eddc6b1029bf87245d9c1bdcba 100644 (file)
@@ -1814,7 +1814,7 @@ int gmx_trjconv(int argc, char *argv[])
                                 switch (ftp)
                                 {
                                     case efGRO:
-                                        write_hconf_p(out, title, &useatoms, prec2ndec(frout.prec),
+                                        write_hconf_p(out, title, &useatoms,
                                                       frout.x, frout.bV ? frout.v : NULL, frout.box);
                                         break;
                                     case efPDB: