!------------------------------------------------------------------------------
!
!            ******************************************
!            *            A L F L I B                 *
!            *                                        *
!            * ALADDIN FITTED FORM SUBROUTINE LIBRARY *
!            ******************************************
!
!                  VERSION 1.0    30/04/1989
!
!     ORIGINAL VERSION DESIGNED AND WRITTEN BY R. A. HULSE, OF THE
!     PRINCETON UNIVERSITY, PLASMA PHYSICS LABORATORY.
!     (PAPER TO BE SUBMITTED TO THE JOURNAL OF COMPUTATIONAL PHYSICS
!      COMMUNICATIONS)
!
!------------------------------------------------------------------------------
!
!     REV: 03/12/89 BY J.J.SMITH IAEA ATOMIC AND MOLECULAR DATA UNIT
!          TO DEFINE A STANDARD, ALL ROUTINES RECEIVE AND PASS NUMERIC
!          ARGUMENTS IN DOUBLE PRECISION
!
!##############################################################################
!
SUBROUTINE ALMEWE_Z(PTE, PCF, KNCF, PRATE, KERMSG)
!
!     GENERALIZED GAUNT FACTOR LINE EXCITATION CALCULATION
!
!     REFERENCE: R. MEWE, ASTRON. AND ASTROPHYS. 20, 215 (1972)
!
!
!     PTE = ELECTRON TEMPERATURE (KEV)
!
!     PCF(1) = PWVL = EXCITATION WAVELENGTH (ANGSTROMS)
!     PCF(2) = PEIJ = EXCITATION ENERGY (eV)
!            (IF PEIJ=0, ASSUME A RESONANCE LINE AND CALCULATE EIJ FROM PWVL)
!     PCF(3) = PFIJ = OSCILLATOR STRENGTH
!     PCF(4) = PBIJ = BRANCHING RATIO
!     PCF(5, 6, 7, 8) = PA, PB, PC, PD = COEFFICIENTS FOR GAUNT FACTOR FORMULA
!
!     KNCF = NUMBER OF COEFFICIENTS SUPPLIED IN PCF (MUST BE 8)
!     PRATE = LINE EXCITATION RATE COEFFICIENT (cm[3]/s)
!     KERMSG = ERROR MESSAGE, ' ' IS OK
!
!     WRITTEN BY R. A. HULSE
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!==============================================================================
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  use alpcom_mod
  use alcom_mod
  implicit none
  INTEGER kncf
!============
  real(fp) PTE,PRATE
  real(fp) ZWVL, ZEIJ, ZFIJ, ZBIJ, ZA, ZB, ZC, ZD, ZY
  real(fp) ZGBAR, ZXCOEF
  real(fp) PCF(*)
  CHARACTER*(*)  KERMSG
!
  IF(PTE .LE. 0.0_fp) THEN
     KERMSG = ' ALMEWE: TE .LE. 0'
     RETURN
  ELSE IF(KNCF .NE. 8) THEN
     KERMSG = ' ALMEWE: INCORRECT NUMBER OF COEFFICIENTS'
     RETURN
  ELSE
     KERMSG = ' '
  ENDIF
!
  ZWVL = PCF(1)
  ZEIJ = PCF(2)
  ZFIJ = PCF(3)
  ZBIJ = PCF(4)
  ZA = PCF(5)
  ZB = PCF(6)
  ZC = PCF(7)
  ZD = PCF(8)
!
  IF(ZEIJ .EQ. 0.0_fp) ZEIJ = 12397.7_fp / ZWVL
!
  ZY = ZEIJ / (1000.0_fp * PTE)
!
!     GAUNT FACTOR
!
  ZGBAR = ZA + (ZB * ZY - ZC * ZY*ZY + ZD) *&
       ( log( (ZY+1.0_fp)/ZY ) - 0.4_fp / ((1.0_fp+ZY)**2)) + ZC * ZY
!
  ZXCOEF = 1.58e-05_fp * ZFIJ * ZGBAR * exp(-ZY)&
       / (sqrt(1000.0_fp*PTE) * ZEIJ)
  PRATE = ZBIJ * ZXCOEF
!
  RETURN
END SUBROUTINE ALMEWE_Z
!
!##############################################################################
!
SUBROUTINE ALBELI_Z(PE, PCF, KNCF, PXS, KERMSG)
!
!     ELECTRON IMPACT IONIZATION CROSS SECTION FITS
!
!     REFERENCE: K. L. BELL ET AL, J. PHYS. CHEM. REF. DATA 12, 891
!                (1983)
!
!     THIS IS AN IAEA SUBROUTINE TO CALCULATE CROSS SECTIONS FOR
!     PROJECTILE ENERGY (eV).
!
!     PE =  ELECTRON ENERGY (EV)
!
!     THE NUMBER OF FITTING PARAMETERS VARIES DEPENDING ON THE
!     NUMBER OF TERMS TAKEN IN THE NUMERICAL FITTING AND ON THE
!     ALLOWANCE FOR EXCITATION AUTOIONIZATION IN THE CROSS SECTION
!     TO FIT CROSS SECTIONS WITH EXCITATION AUTOIONIZATION TWO SEPERATE
!     FITS ARE DEFINED. ONE FROM THE IONIZATION THRESHOLD AND A SECOND
!     FIT FOR ENERGIES ABOVE THE AUTOIONIZATION THRESHOLD.
!     THE NUMBER OF PARAMETERS IN ANY ENTRY IS GIVEN BY KNCF
!
!     PCF(1) = IONIZATION POTENTIAL (eV)
!     PCF(2-7) = FITTING PARAMETERS ( CAN BE LESS THAN 6 PARAMETERS)
!
!     IF CROSS SECTION HAS EXCITATION AUTOIONIZATION STRUCTURE THEN
!     FOR THE SECOND FIT
!
!     PCF(8) = AUTOIONIZATION THRESHOLD (eV)
!     PCF(9) = IONIZATION POTENTIAL (eV)
!     PCF(10-15) = FITTING PARAMETERS FOR THIS FIT (CAN BE LESS THAN
!                  6 PARAMETERS)
!
!     KNCF = NUMBER OF PARAMETERS SUPPLIED IN PCF (MUST BE 8)
!     PXS = IONIZATION CROSS SECTION (CM[2])
!     KERMSG = ERROR MESSAGE, ' ' IS OK
!
!     WRITTEN BY J. J. SMITH , IAEA ATOMIC AND MOLECULAR DATA UNIT
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!==============================================================================
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  IMPLICIT NONE
  INTEGER kncf,istart,iend,i
!============
  real(fp) PE, PXS
  real(fp) ION, POWER, POWER1, XS, A, X, X2
  real(fp) PCF(*)
  CHARACTER*(*) KERMSG   
!
  IF(PE .LT. PCF(1)) THEN
     KERMSG = 'ELECTRON ENERGY BELOW THRESHOLD FOR THE REACTION'
     RETURN
  ELSE
     KERMSG = ' '
  ENDIF
!
!---  DETERMINE PARAMETERS TO BE USED
!
  IF (KNCF .GT. 7 .AND. PE .GT. PCF(8) ) THEN
!
!---      AUTOIONIZATION INCLUDED AND ENERGY > AUTOIONIZATION THRESHOLD
!
     ION = PCF(9)
     A=PCF(10)
     ISTART=11
     IEND=KNCF
  ELSE
     ION = PCF(1)
     A=PCF(2)
     ISTART=3
     IF (KNCF .GT. 7) THEN
        IEND=7
     ELSE
        IEND = KNCF
     ENDIF
  ENDIF
!
!---  GENERATE CROSS SECTION
!
  X=ION/PE
  X2= 1.0_fp/X
!
!---  CONTRIBUTION FROM BETHE TERM
!
  XS = A*log(X2)
  IF ( KNCF .GE. ISTART) THEN
!
!---  CONTRIBUTION FROM LEAST SQUARES FIT TERMS
!
     POWER1 = 1.0_fp - X
     POWER = POWER1
     DO I=ISTART,IEND
        XS = XS + PCF(I)*POWER
        POWER = POWER*POWER1
     enddo
  ENDIF
!
!---  SCALE RESULTS TO CM[2]
!
  PXS= 1.0e-13_fp*XS /(PE*ION)
!
  RETURN
END SUBROUTINE ALBELI_Z
SUBROUTINE ALCHEB_Z(PET, PCF, KNCF, PFIT, KERMSG)
!
!     THIS IS AN ORNL:CFADC SUBROUTINE TO CALCULATE CROSS SECTIONS IN
!     (cm[2]) VERSUS ENERGY IN (EV/AMU) OR RATE COEFFICIENTS IN
!     (cm[3]/s) VERSUS MAXWELLIAN TEMPERATURE IN (eV) FROM CHEBYSHEV
!     POLYNOMIAL FITTING COEFFICIENTS
!
!     THESE FITS ARE VALID ONLY BETWEEN THE LIMITS EMIN AND EMAX,
!     WHICH ARE COEFFICIENTS PCF(10) AND PCF(11) IN THE ENTRY DATA FIELD
!
!     PET = COLLISION ENERGY IN eV/amu OR MAXWELLIAN TEMPERATURE IN eV
!
!     KERMSG = BLANK IF NO ERRORS
!
!     PFIT = CROSS SECTION IN cm[2] OR RATE COEFFICIENT IN cm[3]/s
!
!     WRITTEN BY H. HUNTER, CFADC OAK RIDGE NATIONAL LABORATORY
!     (MODIFIED TO ALADDIN CALLING STRUCTURE 4/21/88 R.A. HULSE)
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  IMPLICIT NONE
  INTEGER kncf,k
!============
  real(fp) PET, PFIT
  real(fp) EMIN, EMAX, CHEB, EMINL, EMAXL, ENL, XNORM
  real(fp) TWOX, PREV, PREV2
  real(fp) PCF(*)
  CHARACTER*(*)  KERMSG
  EMIN = PCF(10)
  EMAX = PCF(11)
  IF(PET .GE. EMIN .AND. PET .LE. EMAX) THEN
     KERMSG(1:1) = ' '
  ELSE
     KERMSG = 'OUTSIDE RANGE OF FIT IN ALCHEB'
     RETURN
  ENDIF
!
!     CALCULATE POLYNOMIAL USING RECURSION RELATION
!
  K = 9
  CHEB = PCF(K)
  EMINL = log(EMIN)
  EMAXL = log(EMAX)
  ENL= log(PET)
  K = K-1
  XNORM = (ENL-EMINL-(EMAXL-ENL)) / (EMAXL-EMINL)
  TWOX = 2.0_fp *  XNORM
  PREV2 = 0.0_fp
10 PREV = CHEB
  IF(K .NE. 1) THEN
     CHEB = PCF(K) + TWOX*PREV - PREV2
     PREV2 = PREV
     K = K-1
     GO TO 10
  ENDIF
  CHEB = 0.5_fp*PCF(1) + XNORM*PREV - PREV2
  PFIT = exp(CHEB)
  RETURN
!
END SUBROUTINE ALCHEB_Z
SUBROUTINE ALKING_Z(PET, PCF, KNCF, PFIT, KERMSG)
!
!     THIS IS AN IAEA SUBROUTINE TO CALCULATE THE REACTION RATE
!     COEFFICIENT (cm[3]/s) VERSUS ELECTRON TEMPREATURE (eV).
!
!     THESE FITS ARE VALID ONLY BETWEEN THE LIMITS TMIN AND TMAX,
!     WHICH ARE COEFFICIENTS PCF(2) AND PCF(3) IN THE ENTRY DATA FIELD
!     PCF(1) IS THE TRANSITION ENERGY (eV) FOR THE RECACTION
!
!     PET = MAXWELLIAN TEMPERATURE IN eV
!
!     KERMSG = BLANK IF NO ERRORS
!
!     PFIT = RATE COEFFICIENT IN cm[3]/s
!
!     WRITTEN BY J. J. SMITH , IAEA ATOMIC AND MOLECULAR DATA UNIT
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  IMPLICIT NONE
  INTEGER kncf,i
!============
  real(fp) PET, PFIT
  real(fp) CONV, YTEMP, POWER1, POWER, TEN
  real(fp) EMIN, EMAX, TK, CONT
  real(fp) PCF(*)
  CHARACTER*(*)  KERMSG
  DATA CONV/1.16045e+04_fp/
  DATA TEN/1.0e+01_fp/
!
  EMIN = PCF(2)
  EMAX = PCF(3)
  IF(PET .GE. EMIN .AND. PET .LE. EMAX) THEN
     KERMSG = ' '
  ELSE
     KERMSG = 'OUTSIDE RANGE OF FIT IN ALKING'
     RETURN
  ENDIF
!
!     FORM THE ELECTRON TEMPREATURE IN DEGREES KELVIN
!
  TK = PET*CONV
  YTEMP = PCF(4)
!
!     GENERATE THE RATE COEFFICIENT FROM THE LOG POLYNOMIAL EXPRESSION
!
  POWER1 = log10(TK)
  POWER = POWER1
  DO I=5,KNCF
     CONT=PCF(I)*POWER
     YTEMP = YTEMP+CONT
     POWER = POWER * POWER1
  enddo
  PFIT = TEN**YTEMP
  RETURN
!
END SUBROUTINE ALKING_Z
!
!##############################################################################
!
SUBROUTINE ALPHACX_Z(PE, PCF, KNCF, PFIT, KERMSG)
!
!     THIS IS A SUBROUTINE TO CALCULATE CROSS SECTION FOR
!     PROJECTILE ENERGY (eV/amu).
!
!     THE APPROXIMATE RANGE OF VALIITY OF THE FIT IS GIVEN BY THE
!     PARAMETERS PCF(1) AND PCF(2) WHICH ARE THE SCALED ENERGIES
!     PE/DSQRT(Q) (eV/u), WHERE Q IS THE CHARGE STATE OF THE ION.
!
!     PE = PROJECTILE ENERGY (eV/amu)
!
!     KERMSG = BLANK IF NO ERRORS
!
!     PFIT = CROSS SECTION IN cm[2]
!
!     PCF(1) = LOWER LIMIT OF THE RANGE OF VALIDITY OF THE SCALED
!              PROJECTILE ENERGY IN eV/(u*sqrt(q)).
!     PCF(2) = UPPER LIMIT OF THE RANGE OF VALIDITY OF THE SCALED
!              PROJECTILE ENERGY IN eV/(u*sqrt(q)).
!     PCF(3-6) = A, B, C, D FITTING PARAMETERS
!     PCF(7) = Q, THE CHARGE STATE OF THE PROJECTILE ION. THIS MUST BE
!              INPUT INTO THE COEFFICIENT ARRAY. THIS IS NOT INCLUDED
!              IN THE DATA ENTRIES.
!
!     WRITTEN BY J. J. SMITH , IAEA ATOMIC AND MOLECULAR DATA UNIT
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  IMPLICIT NONE
  INTEGER kncf
!============
  real(fp) PE, PFIT
  real(fp) PEK, Q, Q2, A, B, C, D, F1, F2, ELOW, EHIGH
  real(fp) PCF(*)
  CHARACTER*(*)  KERMSG
!
  A = PCF(3)
  B = PCF(4)
  C = PCF(5)
  D = PCF(6)
  Q = PCF(7)
  Q2 = sqrt(Q)
!
!---  DETERMINE THE SCALED PROJECTILE ENERGY (E/DSQRT(Q)) IN KeV/amu
!
  PEK = PE*1.0e-03_fp/Q2
!
!---  CHECK THAT THE ENERGY IS WITHIN THE VALID ENERGY RANGES
!
  ELOW = PCF(1)*1.0e-03_fp
  EHIGH = PCF(2)*1.0e-03_fp
!
  KERMSG = ' '
  IF (PEK .LT. ELOW .OR. PEK .GT. EHIGH) THEN
     KERMSG = 'OUTSIDE RANGE OF FIT IN ALPHACX'
     RETURN
  ENDIF
!
  IF(Q .LT. 5 .OR. Q .GT. 26) THEN
     KERMSG =&
          'THE CHARGE STATE (Q) MUST BE IN THE RANGE 5 <= Q <= 26'
     RETURN
  ENDIF
!
  F1 = A * Q * log ( B * Q2 / PEK )
  F2 = ( C * PEK * PEK / Q )  +  D * ( ( PEK / Q2 ) ** 4.5_fp )
  PFIT = F1 / ( 1.0_fp + F2 )
!
  RETURN
!
END SUBROUTINE ALPHACX_Z
!
!##############################################################################
!
SUBROUTINE ALJAN1_Z(PET, PCF, KNCF, PFIT, KERMSG)
!
!     THIS IS A SUBROUTINE TO CALCULATE CROSS SECTIONS (cm[2])
!     VERSUS ENERGY (eV) OR ELECTRON IMPACT REACTION RATE
!     COEFFICIENT (cm[3]/s) VERSUS ELECTRON TEMPREATURE (eV).
!     USING THE LOG NATURAL POLYNOMIAL FIT OF JANEV ET AL.
!
!     THESE FITS ARE VALID ONLY BETWEEN THE LIMITS EMIN AND EMAX,
!     WHICH ARE PARAMETERS PCF(1) AND PCF(2) IN THE ENTRY DATA FIELD
!     THE PARAMETERS PCF(3-11) ARE THE COEFICIENTS FOR THE FIITING
!     FORMULA.
!
!     PET = COLLISION ENERGY IN eV
!
!     KERMSG = BLANK IF NO ERRORS
!
!     PFIT = CROSS SECTION IN cm[2]
!
!     WRITTEN BY J. J. SMITH , IAEA ATOMIC AND MOLECULAR DATA UNIT
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  IMPLICIT NONE
  INTEGER kncf,i
!============
  real(fp) PET, PFIT
  real(fp) EMIN, EMAX, ALOGE1, ALOGE, XJAN, XCON
  real(fp) PCF(*)
  CHARACTER*(*)  KERMSG
!
  EMIN=PCF(1)
  EMAX = PCF(2)
  IF(PET .GE. EMIN .AND. PET .LE. EMAX) THEN
     KERMSG = ' '
  ELSE
     KERMSG = 'OUTSIDE RANGE OF FIT IN ALJANXS'
     RETURN
  ENDIF
!
!     CALCULATE NATUTRAL LOG POLYNOMIAL
!
  ALOGE1 = log(PET)
  ALOGE = ALOGE1
  XJAN = PCF(3)
  DO I=4,11
     XCON = PCF(I)*ALOGE
     XJAN = XJAN + XCON
     ALOGE=ALOGE * ALOGE1
!MG10   ALOGE=ALOGE * ALOGE1
  enddo
  PFIT = exp(XJAN)
  RETURN
!
END SUBROUTINE ALJAN1_Z
!
!##############################################################################
!
SUBROUTINE ETABSQ_Z(PE, PCF, KNCF, PYIELD, KERMSG)
!
!     THIS IS A SUBROUTINE TO CALCULATE THE YIELDS (ATOMS/ION) OF
!     ION-INDUCED SPUTTERING OF MONATOMIC SOLID
!
!     PE = COLLISION ENERGY IN eV
!
!     KERMSG = BLANK IF NO ERRORS
!
!     PYIELD = YIELD OF ATOMS/IONS PER INCIDENT ION
!
!     PCF(1) = ATOMIC NUMBER OF INCIDENT ION
!     PCF(2) = ATOMIC MASS OF INCIDENT ION
!     PCF(3) = ATOMIC NUMBER OF TARGET
!     PCF(4) = ATOMIC MASS OF TARGET
!     PCF(5) = SUBLIMATION ENERGY OF TARGET (EV)
!     PCF(6) = Q VALUE FOR TARGET
!
!     WRITTEN BY J. J. SMITH , IAEA ATOMIC AND MOLECULAR DATA UNIT
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use iso_c_binding, only: fp => c_double
  IMPLICIT NONE
  INTEGER kncf
!============
  real(fp) PE, PYIELD
  real(fp) M1, Z1, M2, Z2, Q, ETA, SN, SE, K, ALPHA, US
  real(fp) Z123, Z223, SQRETA, ETH, GAMMA
  real(fp) PCF(*)
  CHARACTER*(*)  KERMSG
!
  Z1 = PCF(1)
  M1 = PCF(2)
  Z2 = PCF(3)
  M2 = PCF(4)
  US = PCF(5)
  Q = PCF(6)
!
  KERMSG = ' '
!
!---- DETERMINE THRESHOLD ENERGY
!
  GAMMA = 4.0_fp * M1 * M2 / ( (M1 + M2) **2 )
  IF (M1 .GE. M2) THEN
     ETH = (4.0_fp/3.0_fp)**6.0_fp * US/GAMMA
  ELSE
     ETH = (US/GAMMA)*((2.0_fp*(M1+M2))/(M1+2.0_fp* M2))**6.0_fp
  ENDIF
  IF (PE .LT. ETH ) THEN
     KERMSG =&
          ' INCIDENT ION ENERGY BELOW THRESHOLD FOR REACTION'
     RETURN
  ENDIF
!
!---- DETERMINE COMPONENTS OF EQUATION FOR YIELD
!
  Z123 = Z1**0.666666_fp
  Z223 = Z2**0.666666_fp
  ETA = 0.03255_fp*M2*PE/(M1+M2)
  ETA = ETA/(Z1 * Z2 * sqrt(Z123 + Z223))
  SQRETA= sqrt(ETA)
!
  SN =  3.441_fp * SQRETA * log (ETA + 2.718_fp)/&
       (1.0_fp + 6.355_fp * SQRETA + ETA * (-1.708_fp + 6.882_fp * SQRETA))
!
  SE =  SQRETA * 0.079_fp * ((M1+M2)**1.5_fp) * Z123 * sqrt(Z2)/&
       (M1**1.5_fp * M2**0.5_fp * ((Z123 + Z223)**0.75_fp))
!
  K = 8.478_fp*Z1*Z2*M1/(sqrt(Z123+Z223) * (M1+M2))
  ALPHA = 0.1_fp+0.155_fp*((M2/M1)**0.730_fp) +&
       0.001_fp*((M2/M1)**1.5_fp)
!
!       IF Q=0 SET Q=ALPHA
!
  IF (Q .EQ. 0.0_fp) Q=ALPHA
!
!     FINALLY DETERMINE THE SPUTTERING YIELD
!
  PYIELD = 0.42_fp * ALPHA * Q * K * SN  *&
       ((1.0_fp - sqrt (ETH/PE))**2.8_fp)  /&
       (US * ( 1.0_fp + (0.35_fp * US * SE)))
  RETURN
!
END SUBROUTINE ETABSQ_Z
!
!##############################################################################
!
SUBROUTINE RTABSQ_Z(CION, CTARGT, RTABCF, KERMSG)
!
!     THIS IS A SUBROUTINE TO READ DATA FOR THE YIELDS (ATOMS/ION) OF
!     ION-INDUCED SPUTTERING OF MONATOMIC SOLIDS
!
!     CION  = THE USER SUPPLIED ATOMIC SPECIES FOR THE INCIDENT ION
!     CTARGT = THE USER SUPPLIED ATOMIC SPECIES OF THE TARGET
!
!     RTABCF = ARRAY OF COEFFICIENT DATA FOR PARTICULAR INCIDENT ION/
!              TARGET PAIR NEEDED BY ROUTINE ETABSQ FOR THE FUNCTION
!              EVALUATION
!
!     RTABCF(1) = ATOMIC NUMBER OF INCIDENT ION
!     RTABCF(2) = ATOMIC MASS OF INCIDENT ION
!     RTABCF(3) = ATOMIC NUMBER OF TARGET
!     RTABCF(4) = ATOMIC MASS OF TARGET
!     RTABCF(5) = SUBLIMATION ENERGY OF TARGET (EV)
!     RTABCF(6) = Q VALUE FOR TARGET
!
!     SELF SPUTTERING DATA IS ONLY AVAILABLE FOR THOSE SOLIDS WITH A
!     '*' IN THE TABLE AS READ IN VARIABLE FSELF.
!
!     WRITTEN BY J. J. SMITH , IAEA ATOMIC AND MOLECULAR DATA UNIT
!
!- Modifications
!     26-May-1999    james.conboy@jet.uk
!                    CHAR*(*) > CHAR*80, pgf90 bug workaround
!------------------------------------------------------------------------------
!
  use iso_c_binding, only: fp => c_double
  use alpcom_mod
  use alcom_mod
  IMPLICIT NONE
!============
! idecl:  explicitize implicit INTEGER declarations:
  INTEGER i,iline,icferr
!============
! idecl:  explicitize implicit REAL declarations:
  real(fp) atmno,atmass,subeng,q
!============
  CHARACTER*(*)  KERMSG
  CHARACTER*2 CION, CTARGT, CATOM
  CHARACTER*1 FSELF
  real(fp) RTABCF (*)
!
  KERMSG = ' '
!
!       INITIALISE COEFFICIENT ARRAY ELEMENTS TO ZERO. ON ENTRY THEY
!       MAY BE NON-ZERO FROM LAST CALL
!
  RTABCF(1:5) = 0.0_fp
!
!       READ AND CONVERT DATA IN INPUT TABLE HELD IN BUFFER EBUFF
!       AND LOOK FOR VALID ION AND TARGET COMBINATION MATCHING
!       VALUES IN CION AND CTARGT.
!
!       THE FIRST SIX LINES OF COEFFICIENT BLOCK DESCRIBE THE TABLE
!       FORMAT, THESE SHOULD NOT BE PROCESSED
!
  ILINE = LCFPTR + 6
!
10 READ(EBUFF(ILINE),&
        '(BN,1X,A2,6X,F4.0,7X,F7.2,8X,F5.2,7X,F5.2,13X,A1)',&
        END=100, IOSTAT=ICFERR) CATOM, ATMNO, ATMASS, SUBENG, Q, FSELF
!
!       IF NOT INTERNAL READ ERROR, LOOP BACK FOR NEXT COEFFICIENT
!       OTHERWISE, ERROR RETURN
!
  IF(ICFERR .EQ. 0) GO TO 20
!
  KERMSG = ' READ ERROR IN LINE OF TABLE "'//EBUFF(ILINE)//'"'
  RETURN
!
20 IF ( CATOM .EQ. CION) THEN
     RTABCF(1) = ATMNO
     RTABCF(2) = ATMASS
  ENDIF
  IF ( CATOM .EQ. CTARGT) THEN
!
!       CHECK SUBLIMATION ENERGY ALL TARGETS MUST HAVE A NON-ZERO VALUE
!
     IF ( SUBENG .EQ. 0.0_fp) THEN
        KERMSG = ' NO SUBLIMATION ENERGY FOR TARGET IN INPUT TABLE'
        RETURN
     ENDIF
     RTABCF(3) = ATMNO
     RTABCF(4) = ATMASS
     RTABCF(5) = SUBENG
     RTABCF(6) = Q
  ENDIF
!
!       CHECK IF THE TARGET AND ION  HAVE BOTH BEEN RETREIVED
!
  IF ( (RTABCF(1) .NE. 0.0_fp) .AND. (RTABCF(3) .NE. 0.0_fp)) THEN
!
!         IF TARGET AND ION ARE IDENTICAL (SELF SPUTTERING) THEN
!         CHECK IF THE EMPIRICAL FORMULA IS VALID FOR SELF SPUTTERING
!         (VALID IF FSELF ='*' )
!
     IF (CTARGT .EQ. CION .AND. FSELF .NE. '*')&
          KERMSG =&
          'THERE IS NO DATA FOR SELF SPUTTERING FOR TARGET IN TABLE'
     RETURN
  ENDIF
  ILINE = ILINE + 1
  GO TO 10
!
100  KERMSG = 'END OF TABLE FILE NO ION/TARGET MATCH FOUND'
end SUBROUTINE RTABSQ_Z
!
!------------------------------------------------------------------------------
! 30Jun2000 fgtok -s r8_precision.sub "r8con.csh conversion"
