From 369ea4fbe2f9bb4bff9348a23ffc2862f677d2d7 Mon Sep 17 00:00:00 2001 From: David van der Spoel Date: Tue, 20 Nov 2012 11:58:18 +0100 Subject: [PATCH] Fixes bug in g_hbond that makes it produce fatal error. Rather than crashing with a range check error when there are no hydrogen bonds the code now prints to stderr and continues normally. Change-Id: Idc9fddf8bfac9989bc1aa3a9c552b08580f99949 --- src/tools/gmx_hbond.c | 105 ++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 49 deletions(-) diff --git a/src/tools/gmx_hbond.c b/src/tools/gmx_hbond.c index bf40208ab0..f851d54502 100644 --- a/src/tools/gmx_hbond.c +++ b/src/tools/gmx_hbond.c @@ -4032,61 +4032,68 @@ int gmx_hbond(int argc,char *argv[]) if (opt2bSet("-hbm",NFILE,fnm)) { t_matrix mat; int id,ia,hh,x,y; - - mat.nx=nframes; - mat.ny=hb->nrhb; - - snew(mat.matrix,mat.nx); - for(x=0; (xd.nrd); id++) - for(ia=0; (iaa.nra); ia++) { - for(hh=0; (hhmaxhydro); hh++) { - if (hb->hbmap[id][ia]) { - if (ISHB(hb->hbmap[id][ia]->history[hh])) { - /* Changed '<' into '<=' in the for-statement below. - * It fixed the previously undiscovered bug that caused - * the last occurance of an hbond/contact to not be - * set in mat.matrix. Have a look at any old -hbm-output - * and you will notice that the last column is allways empty. - * - Erik Marklund May 30, 2006 - */ - for(x=0; (x<=hb->hbmap[id][ia]->nframes); x++) { - int nn0 = hb->hbmap[id][ia]->n0; - range_check(y,0,mat.ny); - mat.matrix[x+nn0][y] = is_hb(hb->hbmap[id][ia]->h[hh],x); + + if ((nframes > 0) && (hb->nrhb > 0)) + { + mat.nx=nframes; + mat.ny=hb->nrhb; + + snew(mat.matrix,mat.nx); + for(x=0; (xd.nrd); id++) + for(ia=0; (iaa.nra); ia++) { + for(hh=0; (hhmaxhydro); hh++) { + if (hb->hbmap[id][ia]) { + if (ISHB(hb->hbmap[id][ia]->history[hh])) { + /* Changed '<' into '<=' in the for-statement below. + * It fixed the previously undiscovered bug that caused + * the last occurance of an hbond/contact to not be + * set in mat.matrix. Have a look at any old -hbm-output + * and you will notice that the last column is allways empty. + * - Erik Marklund May 30, 2006 + */ + for(x=0; (x<=hb->hbmap[id][ia]->nframes); x++) { + int nn0 = hb->hbmap[id][ia]->n0; + range_check(y,0,mat.ny); + mat.matrix[x+nn0][y] = is_hb(hb->hbmap[id][ia]->h[hh],x); + } + y++; } - y++; } } } + mat.axis_x=hb->time; + snew(mat.axis_y,mat.ny); + for(j=0; jtime; - snew(mat.axis_y,mat.ny); - for(j=0; j