Good programming practice: bug trapping

The Runge-Kutta algorithm always advances the solution two points at a time (dk$=$2). Thus, k2$-$k1 should always be an even number. This is quite clear to us now as we are designing the routine. However, in a few weeks schint() will be buried deep in the heart of our code, and we are likely to forget about this restriction and produce code with bugs which are quite difficult to track.

To avoid such problems, well designed routines will, under all possible circumstances, either work appropriately or print a message as to the nature of the problem (including the values of the offending variables so that you'll know what the problem is) and then exit the program.

Thus, you should make one of the first things that schint() does to check that k2-k1 is even number and, if not, to print a very explicit message such as ``Error in schint: k2-k1 must be even in routine schint, but k1=999 and k2=0.'' and exit the program with the statement

exit(1);
The argument ``1'' is a standard Unix argument to signal to the operating system that the program did not end happily.

Tomas Arias 2005-02-17