  The quadrature error associated with a regular quadrature rule for evaluation
of a layer potential increases rapidly when the evaluation point approaches the
surface and the integral becomes nearly singular. Error estimates are needed to
determine when the accuracy is insufficient and a more costly special
quadrature method should be utilized.
  The final result of this paper are such quadrature error estimates for the
composite Gauss-Legendre rule and the global trapezoidal rule, when applied to
evaluate layer potentials defined over smooth curved surfaces in R^3. The
estimates have no unknown coefficients and can be efficiently evaluated given
the discretization of the surface, invoking a local one-dimensional
root-finding procedure. They are derived starting with integrals over curves,
using complex analysis involving contour integrals, residue calculus and branch
cuts. By complexifying the parameter plane, the theory can be used to derive
estimates also for curves in in R^3. These results are then used in the
derivation of the estimates for integrals over surfaces. In this procedure, we
also obtain error estimates for layer potentials evaluated over curves in R^2.
Such estimates combined with a local root-finding procedure for their
evaluation were earlier derived for the composite Gauss-Legendre rule for layer
potentials written on complex form [4]. This is here extended to provide
quadrature error estimates for both complex and real formulations of layer
potentials, both for the Gauss-Legendre and the trapezoidal rule.
  Numerical examples are given to illustrate the performance of the quadrature
error estimates. The estimates for integration over curves are in many cases
remarkably precise, and the estimates for curved surfaces in R^3 are also
sufficiently precise, with sufficiently low computational cost, to be
practically useful.
