Index: mttroot/mtt/bin/trans/make_ode2odes ================================================================== --- mttroot/mtt/bin/trans/make_ode2odes +++ mttroot/mtt/bin/trans/make_ode2odes @@ -7,10 +7,14 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ +## Revision 1.51.2.3 2001/03/07 04:06:55 geraint +## Irix: catch SIGFPE and write data before aborting (.exe). +## GNU/Linux: nada. +## ## Revision 1.51.2.2 2001/03/02 00:45:21 geraint ## Separated Euler and Implicit methods in .cc code and dependencies. ## ## Revision 1.51.2.1 2001/03/01 05:05:53 geraint ## Minor revisions. @@ -302,10 +306,11 @@ #include "${sys}_def.h" #include "${sys}_sympar.h" #ifdef STANDALONE #include +#include extern ColumnVector F${sys}_input ( ColumnVector &x, ColumnVector &y, const double &t, @@ -596,19 +601,20 @@ inline void mtt_write (const double &t, ColumnVector &x, ColumnVector &y, const int &nrows, - const bool aborting = false) + const bool dump_data = false, + ostream &file = cout) { static Matrix data; static int row; - if (aborting) + if (dump_data) { Matrix written_data = data.extract (0, 0, row-1, data.cols ()-1); - save_ascii_data_for_plotting (cout, written_data, "MTT_data"); + save_ascii_data_for_plotting (file, written_data, "MTT_data"); } const int nx = x.length (), ny = y.length (); register int col = 0; @@ -625,35 +631,62 @@ row++; if (nrows == row) { #ifdef STANDALONE - save_ascii_data_for_plotting (cout, data, "MTT_data"); + save_ascii_data_for_plotting (file, data, "MTT_data"); // cout << data << endl; #else // ! STANDALONE set_global_value ("MTT_data", data); #endif } } #ifdef STANDALONE -void handle_sigfpe (int i) -#ifdef __GNUC__ -__attribute__ ((noreturn)); -void handle_sigfpe (int i) -#endif // __GNUC__ +void dump_data (ostream &file) { ColumnVector null (0.0); - cerr << "Error: Caught floating point exception ..." << endl - << " ... writing data to standard output ..." << endl; - mtt_write (0.0, null, null, 0, true); - cerr << " ... aborting." << endl; - abort (); + mtt_write (0.0, null, null, 0, true, file); +} + +void handle_signal (int signum) +{ + // handle some signals to ensure data is written. + psignal (signum, "# Writing data to MTT.core"); + ofstream corefile ("MTT.core"); + dump_data (corefile); + switch (signum) + { + case SIGFPE: + // Intel chips do not raise SIGFPE for DIVZERO :-( + raise (SIGABRT); + break; + case SIGINT: + cerr << "# Continuing." << endl; + break; + case SIGQUIT: + cerr << "# Quitting." << endl; + signal (SIGQUIT, SIG_DFL); + raise (SIGQUIT); + break; + default: + cerr << "# Warning: make_ode2odes needs updating!" << endl; + signal (signum, SIG_DFL); + raise (signum); + break; + } +} + +void set_signal_handlers (void) +{ + signal (SIGFPE, handle_signal); + signal (SIGINT, handle_signal); + signal (SIGQUIT, handle_signal); } int main (void) { - signal (SIGFPE, handle_sigfpe); + set_signal_handlers (); #else DEFUN_DLD (${sys}_ode2odes, args, , "Octave ode2odes representation of system with $method integration method Usage: ${sys}_ode2odes (x, par, simpar) ")