Improved error message
authorMark Abraham <mark.j.abraham@gmail.com>
Tue, 31 Jan 2012 13:43:18 +0000 (00:43 +1100)
committerMark Abraham <mark.j.abraham@gmail.com>
Wed, 1 Feb 2012 01:56:29 +0000 (12:56 +1100)
Users would be confused by "Atom N3 is used in an interaction of
type atom in the topology database..." so when "atom" is the
bondtype we don't mention the fact.

Also changed variable name from bDontQuit to bAllowMissing for
consistency with variable names used in pdb2gmx when calling
this code.

Change-Id: Ie8cb3ba64f39d3746b470fa6ae44f5a6f4b6a16c

src/kernel/pgutil.c
src/kernel/pgutil.h

index 404f9ed5fca73b090deb0829d57229d592ba23ef..7a3e7d86818beb272b4a08cd946016726a58bdb6 100644 (file)
 #include "string.h"
 #include "gmx_fatal.h"
 
+#define BUFSIZE 1024
 static void atom_not_found(int fatal_errno,const char *file,int line,
                           const char *atomname,int resind,
-                          const char *bondtype,gmx_bool bDontQuit)
+                          const char *bondtype,gmx_bool bAllowMissing)
 {
-  if (strcmp(bondtype,"check") != 0) {
-    if (bDontQuit) {
-      gmx_warning("WARNING: Atom %s is used in an interaction of type %s in the\n"
-                 "topology database, but an atom of that name was not found in\n"
-                 "residue number %d.\n",
-                 atomname,bondtype,resind+1);
-    } else {
-      gmx_fatal(fatal_errno,file,line,
-               "Atom %s is used in an interaction of type %s in the topology\n"
-               "database, but an atom of that name was not found in residue\n"
-               "number %d.\n",
-               atomname,bondtype,resind+1);
+    char message_buffer[BUFSIZE];
+    if (strcmp(bondtype,"check") != 0)
+    {
+        if (0 != strcmp(bondtype, "atom"))
+        {
+            snprintf(message_buffer, 1024,
+                     "Atom %s is used in an interaction of type %s in the topology\n"
+                     "database, but an atom of that name was not found in residue\n"
+                     "number %d.\n",
+                     atomname,bondtype,resind+1);
+        }
+        else
+        {
+            snprintf(message_buffer, 1024,
+                     "Atom %s is used in the topology database, but an atom of that\n"
+                     "name was not found in residue number %d.\n",
+                     atomname,resind+1);
+        }
+        if (bAllowMissing)
+        {
+            gmx_warning("WARNING: %s", message_buffer);
+        }
+        else
+        {
+            gmx_fatal(fatal_errno,file,line,message_buffer);
+        }
     }
-  }
 }
        
 atom_id search_atom(const char *type,int start,int natoms,t_atom at[],
                    char ** const * anm,
-                   const char *bondtype,gmx_bool bDontQuit)
+                   const char *bondtype,gmx_bool bAllowMissing)
 {
   int     i,resind=-1;
   gmx_bool    bPrevious,bNext;
@@ -88,7 +102,7 @@ atom_id search_atom(const char *type,int start,int natoms,t_atom at[],
        return (atom_id) i;
     }
     if (!(bNext && at[start].resind==at[natoms-1].resind))
-      atom_not_found(FARGS,type,at[start].resind,bondtype,bDontQuit);
+      atom_not_found(FARGS,type,at[start].resind,bondtype,bAllowMissing);
   }
   else {
     /* The previous residue */
@@ -99,7 +113,7 @@ atom_id search_atom(const char *type,int start,int natoms,t_atom at[],
       if (gmx_strcasecmp(type,*(anm[i]))==0)
        return (atom_id) i;
     if (start > 0)
-      atom_not_found(FARGS,type,at[start].resind,bondtype,bDontQuit);
+      atom_not_found(FARGS,type,at[start].resind,bondtype,bAllowMissing);
   }
   return NO_ATID;
 }
index 70fe397c62bc9939b0d53c329ab33d21192c555b..b4ac091894b803475b2cecd7e5b82aa8f65967df 100644 (file)
 extern atom_id search_atom(const char *type,int start,
                           int natoms,t_atom at[],
                           char ** const * anm,
-                          const char *bondtype,gmx_bool bDontQuit);
+                          const char *bondtype,gmx_bool bAllowMissing);
 /* Search an atom in array of pointers to strings, starting from start
  * if type starts with '-' then searches backwards from start.
  * bondtype is only used for printing the error/warning string,
  * when bondtype="check" no error/warning is issued.
- * When bDontQuit=FALSE an fatal error is issued, otherwise a warning.
+ * When bAllowMissing=FALSE an fatal error is issued, otherwise a warning.
  */
 
 extern void set_at(t_atom *at,real m,real q,int type,int resind);