From eac31a20dbcedaad053f36c6b0de450325ecff0c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 30 Dec 2007 22:49:51 +0000 Subject: [PATCH] better error handling and gsl stuff etc. --- common.c | 10 ++++++++++ common.h | 9 +++++++++ energy.c | 13 +++---------- project.c | 43 +++++++++++++++++++++++-------------------- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/common.c b/common.c index bc4dcae..ba61341 100644 --- a/common.c +++ b/common.c @@ -43,5 +43,15 @@ void xprod(double r[D3], const double a[D3], const double b[D3]) { r[2]= a[0]*b[1] - a[1]*b[0]; } +void libdie(const char *lib, int l, const char *str) { + fprintf(stderr,"%s library call failed, line %d: %s\n", lib, l, str); +} + +void gsldie(int l, const char *what, int status) { + fprintf(stderr,"gsl function failed, line %d: %s: %s\n", + l, what, gsl_strerror(status)); + exit(-1); +} + void diee(const char *what) { perror(what); exit(16); } void flushoutput(void) { if (fflush(stdout)||ferror(stdout)) diee("stdout"); } diff --git a/common.h b/common.h index 1b79fe8..52f2e5b 100644 --- a/common.h +++ b/common.h @@ -35,11 +35,20 @@ void xprod(double r[D3], const double a[D3], const double b[D3]); void flushoutput(void); void diee(const char *what); +void libdie(const char *lib, int l, const char *str); +#define XA(w) ((w) ? (void)0 : libdie("X", __LINE__, #w)) + +void gsldie(int l, const char *what, int status); +#define GA(w) ({int _ga_r= (w); if (w) gsldie(__LINE__,#w,_ga_r);}) + #define FOR_COORD(k) \ for ((k)=0; (k)