#include "fpreproc/fp_const.h"
*DECK ZSQRT
      SUBROUTINE ZSQRT (AR, AI, BR, BI)
C***BEGIN PROLOGUE  ZSQRT
C***SUBSIDIARY
C***PURPOSE  Subsidiary to ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZAIRY and
C            ZBIRY
C***LIBRARY   SLATEC
C***TYPE      ALL (ZSQRT-A)
C***AUTHOR  Amos, D. E., (SNL)
C***DESCRIPTION
C
C     REAL*8 COMPLEX SQUARE ROOT, B=CSQRT(A)
C
C***SEE ALSO  ZAIRY, ZBESH, ZBESI, ZBESJ, ZBESK, ZBESY, ZBIRY
C***ROUTINES CALLED  ZABS
C***REVISION HISTORY  (YYMMDD)
C   830501  DATE WRITTEN
C   910415  Prologue converted to Version 4.0 format.  (BAB)
C***END PROLOGUE  ZSQRT
      IMPLICIT NONE
      REAL*8 AR, AI, BR, BI, ZM, DTHETA, DPI, DRT
      REAL*8 ZABS
      EXTERNAL ZABS
      DATA DRT , DPI / CONST(7.071067811865475244008443621,-1),
     1                 CONST(3.141592653589793238462643383,+0)/
C***FIRST EXECUTABLE STATEMENT  ZSQRT
      ZM = ZABS(AR,AI)
      ZM = SQRT(ZM)
      IF (AR.EQ.CONST(0.0,+0)) GO TO 10
      IF (AI.EQ.CONST(0.0,+0)) GO TO 20
      DTHETA = atan(AI/AR)
      IF (DTHETA.LE.CONST(0.0,+0)) GO TO 40
      IF (AR.LT.CONST(0.0,+0)) DTHETA = DTHETA - DPI
      GO TO 50
   10 IF (AI.GT.CONST(0.0,+0)) GO TO 60
      IF (AI.LT.CONST(0.0,+0)) GO TO 70
      BR = CONST(0.0,+0)
      BI = CONST(0.0,+0)
      RETURN
   20 IF (AR.GT.CONST(0.0,+0)) GO TO 30
      BR = CONST(0.0,+0)
      BI = SQRT(ABS(AR))
      RETURN
   30 BR = SQRT(AR)
      BI = CONST(0.0,+0)
      RETURN
   40 IF (AR.LT.CONST(0.0,+0)) DTHETA = DTHETA + DPI
   50 DTHETA = DTHETA*CONST(0.5,+0)
      BR = ZM*COS(DTHETA)
      BI = ZM*SIN(DTHETA)
      RETURN
   60 BR = ZM*DRT
      BI = ZM*DRT
      RETURN
   70 BR = ZM*DRT
      BI = -ZM*DRT
      RETURN
      END
! 22Jun2000 fgtok -s r8_precision.sub "r8con.csh conversion"
! 22Jun2000 fgtok
