C+ C NAME: C nrZbrac C PURPOSE: C Bracket one or more zeros in a given interval for a function of one C independent variable C CATEGORY: C Math: finding roots C CALLING SEQUENCE: logical function nrZbrac(Func,X1,X2,iFix) C INPUTS: C FUNC real function to be tested; should be declared external in C the calling program C X1,X2 real limits of interval to be tested C iFix integer C OUTPUTS: C nrZbrac logical .TRUE. if zero is bracketed; .FALSE. if not C X1,X2 real values bracketing zeroes C SEE ALSO: C nrZbrak, nrZBrent C RESTRICTIONS: C XB1 and XB2 must be declared in the calling program with a dimension C equal or greater than the input value of NB. C PROCEDURE: C "Outward search" for roots. The interval is expanded outward by C a factor 1.6*(X2-X1) until a zero is bracketed. C See Press et al., "Numerical Recipes", Cambridge UP (1989), par. 9.1, C p. 245 C- real Func real X1 real X2 integer iFix parameter (Factor = 1.6) parameter (nTry = 50 ) nrZbrac = .FALSE. if (X1 .eq. X2) return ! No initial guess provided F1 = Func(X1) F2 = Func(X2) nrZbrac = F1*F2 .lt. 0 do J=1,nTry if (nrZbrac) return if (iFix .eq. 1) then ! Expand to X2-side only X2 = X2+Factor*(X2-X1) F2 = Func(X2) else if (iFix .eq. 2) then ! Expand to X1-side only X1 = X1+Factor*(X1-X2) F1 = Func(X1) else if (abs(F1) .lt. abs(F2)) then X1 = X1+Factor*(X1-X2) F1 = Func(X1) else X2 = X2+Factor*(X2-X1) F2 = Func(X2) end if nrZbrac = F1*F2 .lt. 0 end do return end