An algorithm for second order initial and boundary value problems with an automatic error estimate based on a third derivative method