subroutine csroot(xr,xi,yr,yi) double precision xr,xi,yr,yi c c (yr,yi) = complex dsqrt(xr,xi) c branch chosen so that yr .ge. 0.0 and sign(yi) .eq. sign(xi) c double precision s,tr,ti,pythag tr = xr ti = xi s = dsqrt(0.5d0*(pythag(tr,ti) + dabs(tr))) if (tr .ge. 0.0d0) yr = s if (ti .lt. 0.0d0) s = -s if (tr .le. 0.0d0) yi = s if (tr .lt. 0.0d0) yr = 0.5d0*(ti/yi) if (tr .gt. 0.0d0) yi = 0.5d0*(ti/yr) return end