From 9fdbc97459909d8069d0e9c9b3eeaf0286f32514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 11 Aug 2010 22:35:20 +0000 Subject: [PATCH] Correct a nasty bug where we were not correctly defining new conn pointers in the first cell (i.e., c==0) in add_well_connections(). With this change, computing the number of existing connections is split across loop iterations, but the new approach has the added benefit of actually being correct. Preliminary testing is promising and suggests this is on the right track, but we still do not re-enable the MEX code. --- mex_ip_simple.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mex_ip_simple.c b/mex_ip_simple.c index 561c6a31..eb78345b 100644 --- a/mex_ip_simple.c +++ b/mex_ip_simple.c @@ -285,10 +285,11 @@ add_well_connections(const mxArray *W, int nc, int nf, tmp = mxRealloc(*conn, (pconn[nc] + neconn) * sizeof *tmp); if (tmp != NULL) { - n = pconn[nc] - pconn[nc - 1]; /* # exisiting conns */ - pconn[nc] += neconn; /* ubnd, *LAST* bin */ + n = pconn[nc]; /* Preserve original ubound */ + pconn[nc] += neconn; /* New ubound, *LAST* bin */ - for (c = nc - 1; c > 0; c--) { + for (c = nc - 1; c >= 0; c--) { + n -= pconn[c]; /* => n == # exisiting conns */ dst = pconn[c + 1] - (n + cwork[c]); src = pconn[c + 0]; @@ -299,7 +300,7 @@ add_well_connections(const mxArray *W, int nc, int nf, /* Set cell's pointer for new connections. */ cwork[c] = dst + n; - n = pconn[c] - pconn[c - 1]; + n = pconn[c]; /* Preserve original ubound */ pconn[c] = dst; }