docs: def V_horiz_spherical(D, L, a, h, headonly=False):
      r'''Calculates volume of a tank with spherical heads, according to [1]_.
  
      .. math::
          V_f = A_fL + \frac{\pi a}{6}(3R^2 + a^2),\;\; h = R, |a|\le R
  
      .. math::
          V_f = A_fL + \frac{\pi a}{3}(3R^2 + a^2),\;\; h = D, |a|\le R
  
      .. math::
          V_f = A_fL + \pi a h^2\left(1 - \frac{h}{3R}\right),\;\; h = 0,
          \text{ or } |a| = 0, R, -R
  
      .. math::
          V_f = A_fL + \frac{a}{|a|}\left\{\frac{2r^3}{3}\left[\cos^{-1}
          \frac{R^2 - rw}{R(w-r)} + \cos^{-1}\frac{R^2 + rw}{R(w+r)}
          - \frac{z}{r}\left(2 + \left(\frac{R}{r}\right)^2\right)
          \cos^{-1}\frac{w}{R}\right] - 2\left(wr^2 - \frac{w^3}{3}\right)
          \tan^{-1}\frac{y}{z} + \frac{4wyz}{3}\right\}
          ,\;\; h \ne R, D; a \ne 0, R, -R, |a| \ge 0.01D
  
      .. math::
          V_f = A_fL + \frac{a}{|a|}\left[2\int_w^R(r^2 - x^2)\tan^{-1}
          \sqrt{\frac{R^2-x^2}{r^2-R^2}}dx - A_f z\right]
          ,\;\; h \ne R, D; a \ne 0, R, -R, |a| < 0.01D
  
      .. math::
          Af = R^2\cos^{-1}\frac{R-h}{R} - (R-h)\sqrt{2Rh - h^2}
  
      .. math::
          r = \frac{a^2 + R^2}{2|a|}
  
      .. math::
          w = R - h
  
      .. math::
          y = \sqrt{2Rh-h^2}
  
      .. math::
          z = \sqrt{r^2 - R^2}
  
      Parameters
      ----------
      D : float
          Diameter of the main cylindrical section, [m]
      L : float
          Length of the main cylindrical section, [m]
      a : float
          Distance the spherical head extends on one side, [m]
      h : float
          Height, as measured up to where the fluid ends, [m]
      headonly : bool, optional
          Function returns only the volume of a single head side if True
  
      Returns
      -------
      V : float
          Volume [m^3]
  
      Examples
      --------
      Matching example from [1]_, with inputs in inches and volume in gallons.
  
      >>> V_horiz_spherical(D=108., L=156., a=42., h=36)/231.
      2303.9615116986183
  
      References
      ----------
      .. [1] Jones, D. "Calculating Tank Volume." Text. Accessed December 22, 2015.
         http://www.webcalc.com.br/blog/Tank_Volume.PDF'''
      R = D/2.
      r = (a**2 + R**2)/2./abs(a)
      w = R - h
      y = (2*R*h - h**2)**0.5
      z = (r**2 - R**2)**0.5
      Af = R**2*acos((R-h)/R) - (R-h)*(2*R*h - h**2)**0.5
  
      if h == R and abs(a) <= R:
          Vf = pi*a/6*(3*R**2 + a**2)
      elif h == D and abs(a) <= R:
          Vf = pi*a/3*(3*R**2 + a**2)
      elif h == 0 or a == 0 or a == R or a == -R:
          Vf = pi*a*h**2*(1 - h/3./R)
      elif abs(a) >= 0.01*D:
          Vf = a/abs(a)*(
          2*r**3/3.*(acos((R**2 - r*w)/(R*(w-r))) + acos((R**2+r*w)/(R*(w+r)))
          - z/r*(2+(R/r)**2)*acos(w/R))
          - 2*(w*r**2 - w**3/3)*atan(y/z) + 4*w*y*z/3)
      else:
          def V_horiz_spherical_toint(x):
              return (r**2 - x**2)*atan(((R**2 - x**2)/(r**2 - R**2))**0.5)
          from scipy.integrate import quad
          integrated = quad(V_horiz_spherical_toint, w, R)[0]
          Vf = a/abs(a)*(2*integrated - Af*z)
      if headonly:
          Vf = Vf/2.
      else:
          Vf += Af*L
      return Vf