From ee5b89f39619c06dd5d6f103eb5e4eac5135946b Mon Sep 17 00:00:00 2001 From: eschnett Date: Sat, 13 Aug 2011 18:57:05 +0000 Subject: Flush stdout and stderr before and after outputting a parameter warning. This helps prevent mixing of stdout and stderr when both are redirected to the same file. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4714 17b73243-c579-4c4c-a9d2-2d5706c11dac --- src/main/DebugDefines.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++- src/main/WarnLevel.c | 6 +++ 2 files changed, 139 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/DebugDefines.c b/src/main/DebugDefines.c index 76f70b2f..bc7a68eb 100644 --- a/src/main/DebugDefines.c +++ b/src/main/DebugDefines.c @@ -11,6 +11,8 @@ #include "cctk_Config.h" #include "cctk_Flesh.h" #include "cctk_DebugDefines.h" +#include "cctk_WarnLevel.h" +#include "definethisthorn.h" static const char *rcsid = "$Header$"; @@ -46,44 +48,174 @@ CCTK_FILEVERSION(main_DebugDefines_c); the linear index for the given spatial indices @endreturndesc @@*/ +int CCTK_GFIndex0D (const cGH *GH) +{ + return (0); +} + int CCTK_GFIndex1D (const cGH *GH, int i) { - GH = GH; +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d cctk_lsh=[%d]", + i, GH->cctk_lsh[0]); + } +#endif return (i); } int CCTK_GFIndex2D (const cGH *GH, int i, int j) { +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0] || + j < 0 || j >= GH->cctk_lsh[1]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d j=%d cctk_lsh=[%d,%d]", + i, j, GH->cctk_lsh[0], GH->cctk_lsh[1]); + } +#endif return (i + GH->cctk_lsh[0]*j); } int CCTK_GFIndex3D (const cGH *GH, int i, int j, int k) { +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0] || + j < 0 || j >= GH->cctk_lsh[1] || + k < 0 || k >= GH->cctk_lsh[2]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d j=%d k=%d cctk_lsh=[%d,%d,%d]", + i, j, k, GH->cctk_lsh[0], GH->cctk_lsh[1], GH->cctk_lsh[2]); + } +#endif return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*k)); } int CCTK_GFIndex4D (const cGH *GH, int i, int j, int k, int l) { +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0] || + j < 0 || j >= GH->cctk_lsh[1] || + k < 0 || k >= GH->cctk_lsh[2] || + l < 0 || l >= GH->cctk_lsh[3]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d j=%d k=%d l=%d cctk_lsh=[%d,%d,%d,%d]", + i, j, k, l, GH->cctk_lsh[0], GH->cctk_lsh[1], GH->cctk_lsh[2], GH->cctk_lsh[3]); + } +#endif return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*(k + GH->cctk_lsh[2] * l))); } +int CCTK_VectGFIndex0D (const cGH *GH, int n) +{ +#ifdef CCTK_DEBUG + if (n < 0) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Vector index out of bounds. n=%d", + n); + } +#endif + return (n); +} + int CCTK_VectGFIndex1D (const cGH *GH, int i, int n) { +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d cctk_lsh=[%d]", + i, GH->cctk_lsh[0]); + } + if (n < 0) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Vector index out of bounds. n=%d", + n); + } +#endif return (i + GH->cctk_lsh[0]*n); } int CCTK_VectGFIndex2D (const cGH *GH, int i, int j, int n) { +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0] || + j < 0 || j >= GH->cctk_lsh[1]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d j=%d cctk_lsh=[%d,%d]", + i, j, GH->cctk_lsh[0], GH->cctk_lsh[1]); + } + if (n < 0) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Vector index out of bounds. n=%d", + n); + } +#endif return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*n)); } int CCTK_VectGFIndex3D (const cGH *GH, int i, int j, int k, int n) { +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0] || + j < 0 || j >= GH->cctk_lsh[1] || + k < 0 || k >= GH->cctk_lsh[2]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d j=%d k=%d cctk_lsh=[%d,%d,%d]", + i, j, k, GH->cctk_lsh[0], GH->cctk_lsh[1], GH->cctk_lsh[2]); + } + if (n < 0) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Vector index out of bounds. n=%d", + n); + } +#endif return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*(k + GH->cctk_lsh[2]*n))); } int CCTK_VectGFIndex4D (const cGH *GH, int i, int j, int k, int l, int n) { +#ifdef CCTK_DEBUG + if (i < 0 || i >= GH->cctk_lsh[0] || + j < 0 || j >= GH->cctk_lsh[1] || + k < 0 || k >= GH->cctk_lsh[2] || + l < 0 || l >= GH->cctk_lsh[3]) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Grid function index out of bounds. i=%d j=%d k=%d l=%d cctk_lsh=[%d,%d,%d,%d]", + i, j, k, l, GH->cctk_lsh[0], GH->cctk_lsh[1], GH->cctk_lsh[2], GH->cctk_lsh[3]); + } + if (n < 0) + { + CCTK_VWarn (CCTK_WARN_ABORT, + __LINE__, __FILE__, CCTK_THORNSTRING, + "Vector index out of bounds. n=%d", + n); + } +#endif return (i + GH->cctk_lsh[0]*(j + GH->cctk_lsh[1]*(k + GH->cctk_lsh[2]* (l + GH->cctk_lsh[3]*n)))); } diff --git a/src/main/WarnLevel.c b/src/main/WarnLevel.c index a315ad73..c5557ffe 100644 --- a/src/main/WarnLevel.c +++ b/src/main/WarnLevel.c @@ -741,6 +741,8 @@ int CCTK_VParamWarn (const char *thorn, highlight_warning_messages = ! highlight_warning_messages_ptr || *highlight_warning_messages_ptr; + fflush (stdout); + /* print to stderr */ if (highlight_warning_messages) { @@ -760,6 +762,8 @@ int CCTK_VParamWarn (const char *thorn, bold_stderr (OFF); } + fflush (stderr); + /* print to stdout */ if (highlight_warning_messages) { @@ -779,6 +783,8 @@ int CCTK_VParamWarn (const char *thorn, bold_stdout (OFF); } + fflush (stdout); + param_errors++; return (0); -- cgit v1.2.3