*DECK B1GAMA
      DOUBLE PRECISION FUNCTION B1GAMA(IAPROX,B2,SIG)
*
*-----------------------------------------------------------------------
*
*Purpose:
* compute the gamma function for a P1 or B1 calculation.
*
*Copyright:
* Copyright (C) 2002 Ecole Polytechnique de Montreal
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version
*
*Author(s): A. Hebert
*
*Parameters: input
* IAPROX  type of beta function calculation:
*         =0: LKRD; =1: P0 or P1; =2: B0 or B1.
* B2      buckling.
* SIG     total macroscopic cross section.
*
*Parameters: output
* B1GAMA  value of the gamma function.
*
*-----------------------------------------------------------------------
*
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
*----
*  SUBROUTINE ARGUMENTS
*----
      INTEGER IAPROX
      DOUBLE PRECISION B2,SIG
*----
*  LOCAL VARIABLES
*----
      CHARACTER HSMG*131
*
      SIG2=SIG*SIG
      B1GAMA=0.0D0
      IF(IAPROX.LE.1) THEN
*        P0 OR P1 APPROXIMATION
         B1GAMA=1.0D0
      ELSE IF(IAPROX.EQ.2) THEN
*        B0 OR B1 APPROXIMATION
         IF(B2.EQ.0.0) THEN
            B1GAMA=1.0D0
         ELSE IF(B2.GT.0.05D0*SIG2) THEN
            TMP=SQRT(B2)/SIG
            BBS=SIG/SQRT(B2)
            ATG=ATAN(TMP)
            B1GAMA=ATG/(3.0D0*BBS*(1.0D0-BBS*ATG))
         ELSE IF((B2.LE.0.05D0*SIG2).AND.(B2.GE.-0.05D0*SIG2)) THEN
            TMP=B2/SIG2
            B1GAMA=1.0D0+TMP*(4.0D0/15.0D0-12.0D0*TMP/175.0D0
     1      +92.0D0*TMP*TMP/2625.0D0)
         ELSE IF((B2.LT.-0.05D0*SIG2).AND.(B2.GE.-0.995D0*SIG2)) THEN
            TMP=SQRT(-B2)
            SB=SIG/TMP
            BLN=0.5D0*LOG((SIG+TMP)/(SIG-TMP))
            B1GAMA=BLN/(3.0D0*SB*(SB*BLN-1.0D0))
         ELSE
            WRITE(HSMG,'(22HB1GAMA: THE BUCKLING (,1P,E12.4,8H) IS SMA,
     1      9HLLER THAN,E12.4,1H.)') B2,-0.995D0*SIG2
            CALL XABORT(HSMG)
         ENDIF
      ELSE
         CALL XABORT('B1GAMA: INVALID VALUE OF IAPROX.')
      ENDIF
      RETURN
      END
