/* pfield.c --- Implementation of the Potter head field equations.
 * (C) 2000, C. Bond. All rights reserved.
 *
 *		"Analytic Expression for the Fringe Field of Finite
 *		 Pole-Tip Length Recording Heads", Robert I. Potter,
 *		 IEEE Trans. on Mag., Vol. MAG-11, pp. 80-81,
 *		 January 1975.
 *
 *		The above cited paper presented an expression for
 *		calculating the Hx field value for a thin film
 *		head. Potter's results were used by Szczech in
 *		a comparison with his own method (1979).
 * 
 *		Some limitations on the method are:
 *
 *			1) Use of Karlquist field for central pulse,
 *			2) Assumption of equal pole thicknesses,
 *			3) No equation for Hy field.
 *
 *		Because of limitation 2), the calling conventions for
 *		this routine do not require a head geometry structure.
 *		All relevant quantities are passed directly as function
 *		parameters, and the (normalized) Hx field value is the
 *		returned result.
 */
#include <math.h>
#include "model.h"
double pfield(double g,double p,double x,double y)
{
	double g2,x2,y2,a1,a2,inv_r2,t1,t2,t3,xpg1,xpg2;
	

/* Compute auxiliary variables. */
	g2 = g / 2.0;
	x2 = x * x;
	y2 = y * y;
	inv_r2 = 1.0 / (x2 + y2);
	xpg1 = x + p + g2;
	xpg2 = x - p - g2;	

/* Compute Hx field value using Eq.(7). */

	t1 = (atan((x + g2) / y) - atan((x - g2) / y)) / g;
	
	t2 = inv_r2 * 0.5 * y;
	
	a1 = atan(xpg1 / y) - atan(xpg2 / y) - pi;
	a1 *= ((x2 - y2) * inv_r2);
	a2 = log((xpg1 * xpg1 + y2) / (xpg2 * xpg2 +y2));
	a2 *= (x * y * inv_r2);
	t3 = (0.25 * (p + g2) * inv_r2) * (a1 + a2) ;

	return inv_pi*(t1 - t2 + t3);	
}

