/* magphs.f -- translated by f2c (version of 3 February 1990  3:36:42).
   You must link the resulting object file with the libraries:
	-lF77 -lI77 -lm -lc   (in that order)
*/

#include "f2c.h"

/* Common Block Declarations */

struct {
    doublereal twopi, xlog2, xlog10, root2, rad, boltz, charge, ctok, gmin, 
	    reltol, abstol, vntol, trtol, chgtol, eps0, epssil, epsox, pivtol,
	     pivrel;
} knstnt_;

#define knstnt_1 knstnt_

/*<       subroutine magphs(cvar,xmag,xphs) >*/
/* Subroutine */ int magphs_(cvar, xmag, xphs)
complex *cvar;
doublereal *xmag, *xphs;
{
    /* Builtin functions */
    double r_imag(), sqrt(), atan2();

    /* Local variables */
    static doublereal ximag, xreal;

/*<       implicit double precision (a-h,o-z) >*/

/*     this routine computes the magnitude and phase of its complex arg- 
*/
/* ument cvar, storing the results in xmag and xphs. */

/* spice version 2g.6  sccsid=knstnt 3/15/83 */
/*<       common /knstnt/ twopi,xlog2,xlog10,root2,rad,boltz,charge,ctok, >*/
/*<      1   gmin,reltol,abstol,vntol,trtol,chgtol,eps0,epssil,epsox, >*/
/*<      2   pivtol,pivrel >*/
/*<       complex cvar >*/


/*<       xreal=dble(real(cvar)) >*/
    xreal = (doublereal) cvar->r;
/*<       ximag=dble(aimag(cvar)) >*/
    ximag = (doublereal) r_imag(cvar);
/*<       xmag=dsqrt(xreal*xreal+ximag*ximag) >*/
    *xmag = sqrt(xreal * xreal + ximag * ximag);
/*<       if (xmag.ge.1.0d-20) go to 10 >*/
    if (*xmag >= 1e-20) {
	goto L10;
    }
/*<       xmag=1.0d-20 >*/
    *xmag = 1e-20;
/*<       xphs=0.0d0 >*/
    *xphs = 0.;
/*<       return >*/
    return 0;
/*<    10 xphs=rad*datan2(ximag,xreal) >*/
L10:
    *xphs = knstnt_1.rad * atan2(ximag, xreal);
/*<       return >*/
    return 0;
/*<       end >*/
} /* magphs_ */

