!------------------------------------------------------------------------------
!
!              **************************************************
!              *                 A L P A C K                    *
!              *                                                *
!              * ALADDIN STANDARD INTERFACE SUBROUTINE PACKAGE  *
!              **************************************************
!
!                  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. 2/03/89 BY J.J.SMITH IAEA ATOMIC AND MOLECULAR DATA UNIT
!          MAXIMUM LABEL LENGTH CHANGED FROM 20 TO 40 CHARACTERS
!          VARIABLE ILABEL MODIFIED
!
!##############################################################################
!
SUBROUTINE ALREAD_Z(KLUDF, KESEQN, KEOF, KERMSG)
!
!                        ************************
!                        * READ ENTRY FROM FILE *
!                        ************************
!
!     FIND AND READ THE NEXT ENTRY IN DATA FILE (LOGICAL UNIT NUMBER KLUDF)
!     INTO THE ENTRY BUFFER ARRAY EBUFF.  ALL LINES IN THE DATA FILE MUST BE
!     VALID ALADDIN FORMAT ENTRY LINES, EXCEPT THAT LINES AT THE START OF
!     THE FILE ARE IGNORED UNTIL THE FIRST VALID ALADDIN ENTRY IS FOUND,
!     BEGINNING WITH A "$" IN COLUMN 1.  THESE FIRST LINES CAN THUS BE USED AS
!     HEADER COMMENTS FOR THE DATA FILE.  ONCE READ INTO THE EBUFF BUFFER
!     ARRAY, THE ENTRY IS PARSED BY CALLING THE STANDARD PARSING ROUTINE ALPARS
!
!     THE ENTRY SEQUENCE NUMBER KESEQN IS AUTOMATICALLY INCREMENTED BY THIS
!     ROUTINE, BUT MUST BE INITIALIZED AS ZERO BY THE CALLING ROUTINE AT THE
!     START OF A DATA FILE.  KESEQN .NE. 0 ON ENTRY IMPLIES THAT THIS IS A
!     SUBSEQUENT READ ON A DATA FILE ALREADY READ BY THIS ROUTINE, AND HENCE
!     THE ENTRY LINE DATA ARRAY EBUFF HAS THE FIRST LINE OF THE NEXT ENTRY
!     AVAILABLE AT POSTION NELN + 1.  ENCOUNTERING AN END OF FILE TERMINATING
!     THE CURRENT ENTRY IS NOTED BY SETTING THE STORED FIRST LINE OF THE
!     "NEXT ENTRY" AS THE STRING '$EOF'.  CALLS TO READ THE NEXT ENTRY WITH
!     THIS FLAG PRESENT CAUSE A RETURN WITH THE LAST ENTRY STILL IN PLACE AND
!     KEOF SET .TRUE.  ERROR MESSAGES ARE RETURNED THROUGH THE STRING KERMSG;
!     KERMSG = ' ' INDICATES NO ERRORS.
!
!------------------------------------------------------------------------------
!
!     NOTE: THIS IS A STANDARD ALADDIN ROUTINE; IT INTERFACES ONLY THROUGH
!           THE SUBROUTINE CALL PASSED VARIABLES AND COMMON / ALENT /.
!
!------------------------------------------------------------------------------
!
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use alpcom_mod
  IMPLICIT NONE
  INTEGER keseqn,kludf,irderr
!============
  CHARACTER*(*) KERMSG
  CHARACTER*40 ILABEL
  LOGICAL KEOF
!******************************************************************************
!
!     IF THE ENTRY SEQUENCE NUMBER IS ZERO, THIS IS THE FIRST READ
!     OF A NEW DATA FILE.  SKIP POSSIBLE HEADER COMMENTS TO FIND FIRST
!     LINE OF FIRST ENTRY.  OTHERWISE, SHIFT THE PREVIOUSLY READ FIRST
!     LINE OF THE NEXT ENTRY INTO THE FIRST LINE POSITION.
!
  KEOF = .FALSE.
!
  IF(KESEQN .EQ. 0) THEN
!
100  READ(KLUDF, '(A)', IOSTAT=IRDERR, END=110) EBUFF(1)
110  CONTINUE
!
     IF(IRDERR .NE. 0) THEN
        KERMSG = ' NO ENTRIES IN FILE OR OTHER READ ERROR'
        RETURN
     ENDIF
!
     IF(EBUFF(1)(1:1) .NE. '$') GO TO 100
!
  ELSE IF(EBUFF(NELN+1) .EQ. '$EOF') THEN
     KEOF = .TRUE.
     KERMSG = ' '
     RETURN
!
  ELSE
!
!       MOVE FIRST LINE OF NEXT ENTRY (BUFFERED IN AT END OF CURRENT ENTRY)
!       INTO FIRST LINE POSITION BEFORE READING REST OF ENTRY FROM FILE
!
     EBUFF(1) = EBUFF(NELN+1)
!
  ENDIF
!
!     THE FIRST LINE OF THE NEW ENTRY IS NOW IN PLACE;
!     INCREMENT THE ENTRY SEQUENCE NUMBER AND INTIALIZE THE ENTRY LINE COUNTER
!
  KESEQN = KESEQN + 1
  NELN = 1
!
!     LOOP TO ADD ALL LINES FOR THIS ENTRY INTO EBUFF, PLUS THE FIRST
!     LINE OF THE NEXT ENTRY IS READ IN ORDER TO FIND THE '$' LABEL.
!     THIS EXTRA LINE IS HELD IN ORDER JUST AFTER THIS ENTRY IN EBUFF(NELN+1).
!     OCCURENCE OF AN END OF FILE IS FLAGGED BY SPECIAL LINE ENTRY '$EOF'
!
200 IF(NELN .GE. NELNMX) THEN
     KERMSG = ' ENTRY DATA LINE ARRAY OVERFLOW'
     RETURN
  ENDIF
!
  NELN = NELN + 1
!
  READ(KLUDF, '(A)', IOSTAT=IRDERR, END=220) EBUFF(NELN)
  220 CONTINUE
!
  IF(IRDERR .GT. 0) THEN
     KERMSG = ' DATA FILE READ ERROR'
     RETURN
  ENDIF
!
  IF(IRDERR .LT. 0) EBUFF(NELN) = '$EOF'
!
!     IF '$' IN !OLUMN 1 THIS IS THE FIRST LINE OF THE NEXT ENTRY
!
  IF(EBUFF(NELN)(1:1) .NE. '$') GO TO 200
!
!     DECREMENT NELN TO POINT TO LAST LINE OF THIS ENTRY
!
  NELN = NELN - 1
!
!------------------------------------------------------------------------------
!
!     USE STANDARD ALADDIN PARSER TO PARSE THIS ENTRY INTO STANDARD
!     LABELS AND POINTERS; NOTE THAT THESE CAN BE RE-INTERPRETED OR
!     THE ENTRY RE-READ DIFFERENTLY LATER BY NON-STANDARD ACCESS ROUTINES.
!
  CALL ALPARS_Z(KERMSG)
!
  RETURN
END SUBROUTINE ALREAD_Z
!
!##############################################################################
!
      SUBROUTINE ALPARS_Z(KERMSG)
!
!                      ***************************
!                      * ALADDIN STANDARD PARSER *
!                      ***************************
!
!     PARSE THE DATABASE FILE ENTRY LINES CONTAINED IN THE BUFFER EBUFF
!     INTO HIERARCHICAL LABELS AND BOOLEAN LABELS, PLUS POINTERS TO
!     POSSIBLE COMMENT LINES AND THE COEFFICIENT LINES IN THE ENTRY.
!     KERMSG RETURNS ERROR MESSAGES; KERMSG = ' ' INDICATES NO ERRORS.
!
!------------------------------------------------------------------------------
!
!     NOTE: THIS IS A ALADDIN STANDARD ROUTINE, WHICH INTERFACES ONLY THROUGH
!           THE SUBROUTINE CALL PASSED VARIABLE AND COMMON / ALENT /.
!
!------------------------------------------------------------------------------
!     REV. 2/03/89 BY J.J.SMITH IAEA ATOMIC AND MOLECULAR DATA UNIT
!          MAXIMUM LABEL LENGTH CHANGED FROM 20 TO 40 CHARACTERS
!          VARIABLE ILABEL MODIFIED
!
!------------------------------------------------------------------------------
!
  use alpcom_mod
  IMPLICIT NONE
!
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  INTEGER ilptr,icptr,ilblnc,iflag
!============
  CHARACTER*(*) KERMSG
  CHARACTER*40 ILABEL
!
!------------------------------------------------------------------------------
!
!     INITIALIZE LINE AND CHARACTER POINTERS AT THE START OF THE ENTRY
!
  ILPTR = 1
  ICPTR = 1
!
!     INITIALIZE RETURN QUANTITIES
!
  NHL = 0
  NBL = 0
  NCMLN = 0
  NCFLN = 0
  KERMSG = ' '
!
!------------------------------------------------------------------------------
!
!     THE ACCESS LABEL (WITH '$' PREFIX) IS ALWAYS FIRST BOOLEAN LABEL
!
  CALL ALXLBL_Z(EBUFF, NELN, ILPTR, ICPTR, ILABEL, ILBLNC, IFLAG)
!
  IF(IFLAG .NE. 0 .OR. ILABEL(1:1) .NE. '$') THEN
     KERMSG = ' INVALID ACCESS LABEL LINE'
     RETURN
  ENDIF
!
  NBL = 1
  BL(1) = ILABEL
!
!------------------------------------------------------------------------------
!
!     HIERARCHICAL LABEL SEARCH AND STORE LOOP
!
100 CALL ALXLBL_Z(EBUFF, NELN, ILPTR, ICPTR, ILABEL, ILBLNC, IFLAG)
!
!     ACT ON HIERACRCHICAL LABEL SEARCH ERROR FLAGS
!
!     0 = OK
!     -1 = LABEL TRUNCATED; ERROR RETURN
!     1 = END OF ENTRY REACHED WHILE STILL IN HL FIELD; ERROR RETURN
!
  IF(IFLAG .EQ. -1) THEN
     KERMSG = ' HIERARCHICAL LABEL "'//ILABEL//'" TRUNCATED'
     RETURN
  ENDIF
!
  IF(IFLAG .EQ. 1) THEN
!       KERMSG = ' PREMATURE END OF ENTRY, HIERARCHICAL LABEL FIELD'
     RETURN
  ENDIF
!
!     IF '&' OR '#' PREFIX HAS BEEN FOUND, MOVE TO BOOLEAN LABEL PROCESSING
!
  IF(ILABEL .EQ. '&') GO TO 200
  IF(ILABEL(1:1) .EQ. '#') GO TO 250
!
!     THIS IS ANOTHER HIERARCHICAL LABEL; STORE AND LOOP FOR NEXT LABEL
!
  IF(NHL .GE. NHLMX) THEN
     KERMSG = ' HIERARCHICAL LABEL ARRAY OVERFLOW'
     RETURN
  ENDIF
!
  NHL = NHL + 1
  HL(NHL) = ILABEL
  GO TO 100
!
!------------------------------------------------------------------------------
!
!     BOOLEAN LABEL SEARCH AND STORE LOOP
!
!     NOTE THAT ACCESS LABEL HAS ALREADY BEEN STORED AS BL(1)
!
200 CALL ALXLBL_Z(EBUFF, NELN, ILPTR, ICPTR, ILABEL, ILBLNC, IFLAG)
!
!     ACT ON BOOLEAN LABEL SEARCH ERROR FLAGS
!
!     0 = OK
!     -1 = LABEL TRUNCATED; ERROR RETURN
!     1 = END OF ENTRY REACHED, ERROR RETURN
!
  IF(IFLAG .EQ. -1) THEN
     KERMSG = ' BOOLEAN LABEL "'//ILABEL//'" TRUNCATED'
     RETURN
  ENDIF
!
  IF(IFLAG .EQ. 1) THEN
     KERMSG = ' PREMATURE END OF ENTRY IN BOOLEAN LABEL FIELD'
     RETURN
  ENDIF
!
!     THIS IS ANOTHER BOOLEAN LABEL; STORE AND LOOP FOR NEXT LABEL
!
250 IF(NBL .GE. NBLMX) THEN
     KERMSG = ' BOOLEAN LABEL ARRAY OVERFLOW'
     RETURN
  ENDIF
!
  NBL = NBL + 1
  BL(NBL) = ILABEL
!
!     IF THIS WAS A '#' PREFIX LABEL, END OF BOOLEAN FIELD;
!     MOVE TO COMMENT LINE PROCESSING
!
!     NOTE THAT THE EVALUATION LABEL (INCLUDING '#' PREFIX) IS ALWAYS
!     STORED AS THE LAST BOOLEAN LABEL
!
  IF(ILABEL(1:1) .NE. '#') GO TO 200
!
!------------------------------------------------------------------------------
!
!     LOOK FOR COMMENT LINES, FLAGGED BY '!' IN COLUMN 1
!
  LCMPTR = ILPTR + 1
300 ILPTR = ILPTR + 1
!
  IF(ILPTR .GT. NELN) THEN
!
!     NOTE THAT IT IS LEGAL TO HAVE NO COEFFICIENTS IN AN ENTRY
!
     NCMLN = NELN - LCMPTR + 1
     NCFLN = 0
     RETURN
  ENDIF
!
  IF(EBUFF(ILPTR)(1:1) .EQ. '!') GO TO 300
!
  LCFPTR = ILPTR
  NCMLN = LCFPTR - LCMPTR
  NCFLN = NELN - LCFPTR + 1
!
  RETURN
END SUBROUTINE ALPARS_Z
!
!##############################################################################
!
SUBROUTINE ALXLBL_Z(KLINE, KNL, KLPTR, KCPTR,&
     KLABEL, KLBLNC, KFLAG)
!
!                     *********************************
!                     * EXTRACT BLANK-DELIMITED LABEL *
!                     *********************************
!
!     SEARCH FOR THE NEXT BLANK-DELIMITED LABEL STRING TO BE FOUND IN THE
!     CHARACTER DATA ARRAY KLINE (KNL LINES LONG), BEGINNING AT CHARACTER
!     POSITION KCPTR OF LINE KLPTR.  THE NEXT LABEL MAY START AT KCPTR OR
!     MAY BE PRECEEDED BY ANY NUMBER OF BLANKS.  IF KCPTR .GT. LEN(KLINE),
!     THE ROUTINE WILL START AT THE BEGINNING OF THE NEXT LINE.  THE
!     LABEL IS RETURNED IN KLABEL, ALONG WITH ITS NUMBER OF CHARACTERS, KLBLNC.
!     THE KLPTR AND KCPTR POINTERS ARE RETURNED POSITIONED READY FOR THE NEXT
!     CALL, 2 CHARACTERS AFTER THE END OF THE FOUND LABEL.  KFLAG = 0 FOR
!     NORMAL RETURNS, KFLAG = 1 WHEN NO MORE LABELS EXIST BEFORE THE END OF
!     THE KLINE ARRAY, KFLAG = -1 FOR LABEL TRUNCATED TO KLBLNC = LEN(KLABEL)
!     CHARACTERS TO FIT INTO KLABEL.
!
!------------------------------------------------------------------------------
!
!     NOTE: THIS IS AN ALADDIN STANDARD SUBROUTINE, WHICH INTERFACES ONLY
!           THROUGH THE PASSED VARIABLES IN THE SUBROUTINE CALL.
!
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  IMPLICIT NONE
  INTEGER klptr,kcptr,klblnc,kflag,knl,ibindx,ieptr
!============
  CHARACTER*(*) KLINE(KNL)
  CHARACTER*(*) KLABEL
!
!------------------------------------------------------------------------------
!
!     MOVE TO NEXT LINE IF KCPTR POINTS BEYOND END OF THIS LINE;
!     RETURN WITH KFLAG = 1 IF THIS WOULD GO BEYOND END OF KLINE ARRAY
!
100 IF(KCPTR .GT. LEN(KLINE(1))) THEN
     IF(KLPTR .LT. KNL) THEN
        KLPTR = KLPTR + 1
        KCPTR = 1
     ELSE
        KFLAG = 1
        RETURN
     ENDIF
  ENDIF
!
!------------------------------------------------------------------------------
!
!     SEARCH FOR NEXT BLANK CHARACTER IN FIELD BEGINNING AT POINTER POSITION
!
  IBINDX= INDEX(KLINE(KLPTR)(KCPTR:), ' ')
!
  IF(IBINDX .EQ. 1) THEN
!
!     LEADING BLANK AT FIRST SEARCHED POSITION; INCREMENT POINTER AND TRY AGAIN
!
     KCPTR = KCPTR + 1
     GO TO 100
!
  ELSE IF(IBINDX .EQ. 0) THEN
!
!       NO BLANKS FOUND; LABEL MUST EXTEND TO END OF LINE, POSITION
!       END OF LABEL POINTER AT END OF LINE
!
     IEPTR = LEN(KLINE(KLPTR))
!
  ELSE
!
!       TRAILING BLANK FOUND AFTER LABEL; POSITION END OF LABEL POINTER
!       AT LAST CHARACTER OF LABEL, JUST BEFORE TRAILING BLANK
!
     IEPTR = KCPTR + IBINDX - 2
!
  ENDIF
!
!------------------------------------------------------------------------------
!
!     LABEL FOUND; STARTS AT KCPTR, ENDS AT IEPTR
!
  KLABEL = KLINE(KLPTR)(KCPTR:IEPTR)
  KLBLNC = IEPTR - KCPTR + 1
!
!     FLAG SUCCESSFUL RETURN, OR -1 IF LABEL WAS TRUNCATED TO FIT IN KLABEL
!
  IF(KLBLNC .LE. LEN(KLABEL)) THEN
     KFLAG = 0
  ELSE
     KLBLNC = LEN(KLABEL)
     KFLAG = -1
  ENDIF
!
!     POSITION CHARACTER POINTER FOR EXIT AT POSITION JUST BEYOND THE
!     TRAILING BLANK; NOTE THAT IF THIS IS BEYOND THE END OF THE LINE,
!     THE NEXT CALL WILL SHIFT THE POINTERS AS REQUIRED
!
  KCPTR = IEPTR + 2
!
  RETURN
END SUBROUTINE ALXLBL_Z
!
!##############################################################################
!
SUBROUTINE ALCOMP_Z(KHSL, KNHSL, KBASL, KNBASL,&
     KBNSL, KNBNSL, KMATCH)
!
!                 *************************************
!                 * ALADDIN STANDARD LABEL COMPARATOR *
!                 *************************************
!
!     THIS ROUTINE TAKES THE SUPPLIED SEARCH LABELS AND DETERMINES IF
!     THE PARSED ENTRY CURRENTLY IN COMMON / ALENT / MATCHES THIS
!     SEARCH CRITERION.  IN ORDER TO DO SO, THE HIERARCHICAL LABELS
!     MUST MATCH EXACTLY, EXCEPT THAT "*" AS A SEARCH LABEL ACTS AS A
!     WILDCARD, MATCHING ANY ENTRY LABEL IN THAT POSITION.  THE "**"
!     WILDCARD EXTENDS THE WILDCARD MATCH TO ANY NUMBER OF HIERARCHICAL
!     LABELS TO THE RIGHT OF THAT POSITION.  BOOLEAN .AND. SEARCH LABELS
!     MUST APPEAR IN THE ENTRY BOOLEAN FIELD FOR A MATCH TO BE SUCCESSFUL,
!     WHILE BOOLEAN .NOT. SEARCH LABELS MUST *NOT* APPEAR IN THE ENTRY
!     FOR A SUCCESFUL MATCH.
!
!     NOTE: LABEL COMPARISONS ARE UPPER-CASE/LOWER-CASE INSENSITIVE, USING
!           THE LOGICAL FUNCTION ALCIEQ INSTEAD OF THE .EQ. OPERATOR
!
!     KHSL   HIERARCHICAL SEARCH LABELS
!     KNHSL  NUMBER OF HIERARCHICAL SEARCH LABELS
!     KBASL  BOOLEAN .AND. SEARCH LABELS
!     KNBASL NUMBER OF BOOLEAN .AND. SEARCH LABELS
!     KBNSL  BOOLEAN .NOT. SEARCH LABELS
!     KNBNSL NUMBER OF BOOLEAN .NOT. SEARCH LABELS
!
!     KMATCH LOGICAL .TRUE./.FALSE. RETURN ON A SUCCESFUL MATCH
!
!------------------------------------------------------------------------------
!
!     NOTE: THIS IS AN ALADDIN STANDARD SUBROUTINE.  IT INTERFACES ONLY
!           THROUGH THE SUBROUTINE CALL PASSED VARIABLES AND COMMON / ALENT/.
!
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  use alpcom_mod
  IMPLICIT NONE
  INTEGER knbasl,knbnsl,knhsl,jhsl,jbasl,jbl,jbnsl
!============
  CHARACTER*(*) KHSL(*), KBASL(*), KBNSL(*)
  LOGICAL KMATCH
  LOGICAL ALCIEQ_Z
  EXTERNAL ALCIEQ_Z
!
!     INITIALIZE RETURN SUCCESS FLAG AS FALSE TO SIMPLIFY RETURNS
!
  KMATCH = .FALSE.
!
!     DO HIERARCHICAL SEARCH LABEL COMPARISON IF THERE
!     ARE ANY HSL'S
!
  IF(KNHSL .GT. 0) THEN
     DO JHSL = 1, KNHSL
!
!     '*' IN A HIERARCHICAL SEARCH LABEL POSITION IS A WILD CARD MATCH
!
        IF(KHSL(JHSL) .EQ. '*') cycle
!
!     '**' IN A HIERARCHICAL SEARCH LABEL POSITION IS WILD CARD MATCH
!     TO REST OF HIERACHICAL SEARCH LABEL FIELD; PROCEED TO BOOLEAN SEARCH
!
        IF(KHSL(JHSL) .EQ. '**') GO TO 150
!
!     IF THIS POSITION DOES NOT MATCH, OR DOES NOT EXIST IN ENTRY,
!     THEN THIS ENTRY IS REJECTED; GET NEXT ENTRY
!
        IF(JHSL .GT. NHL) RETURN
        IF( .NOT. ALCIEQ_Z(KHSL(JHSL), HL(JHSL)) ) RETURN
!
     enddo
  ENDIF
!
!     ALL HIERARCHICAL SEARCH LABELS MATCH; HOWEVER, WITHOUT A "**" WILDCARD,
!     REJECT ENTRY IF IT HAS MORE HL THAN IN SEARCH REQUEST
!
  IF(NHL .GT. KNHSL) RETURN
!
!     ENTRY HAS MATCHED HIERARCHICAL SEARCH LABELS; PROCEED TO BOOLEAN SEARCH
!     SEARCH FAILS IF THERE ARE .AND. SEARCH LABELS AND NO ENTRY BL'S
!     SEARCH AUTOMATICALLY SUCCEEDS IF THER ARE NO SEARCH LABELS INPUT
!
150 IF(KNBASL .GT. 0 .AND. NBL .EQ. 0) RETURN
  IF(KNBASL .GT. 0 .AND. NBL .GT. 0) THEN
!
     DO JBASL = 1, KNBASL
!
        DO JBL = 1, NBL
           IF( ALCIEQ_Z(KBASL(JBASL), BL(JBL)) ) cycle
        enddo
!
!     COMPLETING .AND. LOOP WITHOUT A MATCH MEANS THIS ENTRY IS REJECTED
!
        RETURN
     enddo
  ENDIF
!
  IF(KNBNSL .GT. 0 .AND. NBL .GT. 0) THEN
     DO JBNSL = 1, KNBNSL
!
        DO JBL = 1, NBL
!
!     A MATCH WITH A BOOLEAN .NOT. LABEL CAUSES REJECTION OF THIS ENTRY
           !
           IF( ALCIEQ_Z(KBNSL(JBNSL), BL(JBL)) ) RETURN
        enddo
!
     enddo
  ENDIF
!
!     THIS ENTRY SATISFIES ALL SEARCH CRITERIA
!
  KMATCH = .TRUE.
!
  RETURN
END SUBROUTINE ALCOMP_Z
!
LOGICAL FUNCTION ALCIEQ_Z(KA, KB)
!
!     CASE-INSENSITIVE CHARACTER STRING .EQ. FUNCTION
!
!     NOTE: INPUT STRINGS KA AND KB ARE LEFT UNCHANGED BY THIS ROUTINE
!
!============
! idecl:  explicitize implicit INTEGER declarations:
  IMPLICIT NONE
  INTEGER j,idx
!============
  CHARACTER*(*) KA, KB
  CHARACTER*132 IUCA, IUCB
  CHARACTER*26 IUC, ILC
!
  IUC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  ILC = 'abcdefghijklmnopqrstuvwxyz'
!
!     CONVERT BOTH STRINGS TO UPPER CASE AND THEN COMPARE
!
  IUCA = KA
  DO J = 1, LEN(KA)
     IDX = INDEX(ILC, KA(J:J))
     IF(IDX .NE. 0) IUCA(J:J) = IUC(IDX:IDX)
  enddo

  IUCB = KB
  DO J = 1, LEN(KB)
     IDX = INDEX(ILC, KB(J:J))
     IF(IDX .NE. 0) IUCB(J:J) = IUC(IDX:IDX)
  enddo
!
  ALCIEQ_Z = IUCA .EQ. IUCB
!
  RETURN
END FUNCTION ALCIEQ_Z
!
!##############################################################################
!
SUBROUTINE ALRECF_Z(PCF, KNCF, KNCFMX, KERMSG)
!
!                  ****************************************
!                  * CONVERT COEFFICIENTS TO REAL NUMBERS *
!                  ****************************************
!
!     USING THE COEFFICIENT FIELD POINTERS IN COMMON / ALENT /,
!     PARSE THE COEFFICIENT LINES INTO REAL NUMBERS IN THE OUTPUT
!     ARRAY PCF.  KNCF RETURNS THE NUMBER OF COEFFICIENTS FOUND, WHILE
!     KNCFMX IS THE SUPPLIED DIMENSIONED LENGTH OF THE PCF ARRAY.
!     PROCESSING ERROR MESSAGES ARE RETURNED VIA KERMSG, WITH KERMSG = ' '
!     INDICATING NO ERRORS.
!
!                               **NOTE**
!
!     THE INDIVIDUAL COEFFICIENT VALUES ARE PARSED FROM THE COEFFICIENT
!     FIELD LINES AS BLANK-DELIMITED LABELS, USING THE ALXLBL ROUTINE.
!     THEREFORE, INDIVIDUAL DATA VALUES MUST BE BLANK DELIMITED (E.G.,
!     COMMAS ARE NOT VALID), AND MUST *NOT* CONTAIN ANY INTERNAL
!     BLANKS, OTHERWISE READ ERRORS WILL OCCUR !
!
!------------------------------------------------------------------------------
!
!     NOTE: THIS IS AN ALADDIN STANDARD SUBROUTINE.  IT INTERFACES USING
!           ONLY THE SUBROUTINE CALL PASSED VARIABLES AND COMMON / ALENT /.
!
!------------------------------------------------------------------------------
!
!     REV. 2/03/89 BY J.J.SMITH IAEA ATOMIC AND MOLECULAR DATA UNIT
!          PCF CHANGED FROM SINGLE TO DOUBLE PRECISION
!
!------------------------------------------------------------------------------
!
!============
! idecl:  explicitize implicit INTEGER declarations:
 use iso_c_binding, only: fp => c_double
 use alpcom_mod
 IMPLICIT NONE
 INTEGER kncfmx,kncf,ilptr,icptr,ilblnc,iflag,icferr
!============
 real(fp) PCF(*)
 CHARACTER*(*) KERMSG
 CHARACTER*40 ILABEL
!
 KERMSG = ' '
 KNCF = 0
 FEXTN = .TRUE.
!
 IF(NCFLN .EQ. 0) RETURN
!
 ILPTR = LCFPTR
 ICPTR = 1
!
400 CALL ALXLBL_Z(EBUFF, NELN, ILPTR, ICPTR, ILABEL, ILBLNC, IFLAG)
!
!     ACT ON LABEL SEARCH ERROR FLAGS
!
!     0 = OK
!     -1 = COEFFICIENT STRING TRUNCATED; ERROR RETURN
!     1 = END OF ENTRY REACHED PREMATURELY; ERROR RETURN
!
 IF(IFLAG .EQ. -1) THEN
    KERMSG = ' COEFFICIENT "'//ILABEL//'" TRUNCATED'
    RETURN
 ENDIF
!
 IF(IFLAG .EQ. 1) THEN
    IF(ILPTR .NE. NELN)&
         KERMSG = ' PREMATURE END OF COEFFICIENT FIELD'
    RETURN
 ENDIF
!
!     CONVERT THIS 'LABEL' TO A REAL NUMBER
!
 IF(KNCF .GE. KNCFMX) THEN
    KERMSG = ' COEFFICIENT ARRAY OVERFLOW'
    RETURN
 ENDIF
!
!     CHECK FOR THE LENGTH OF THE COEFFICIENT IF > 12 SET THE NUMBER
!     LENGTH FLAG TO TRUE.
!
 IF (ILBLNC .GT. 12) FEXTN =.FALSE.
!
 KNCF = KNCF + 1
 READ(ILABEL, '(BN,F20.0)', IOSTAT=ICFERR) PCF(KNCF)
!
!     IF NOT INTERNAL READ ERROR, LOOP BACK FOR NEXT COEFFICIENT
!     OTHERWISE, ERROR RETURN
!
 IF(ICFERR .EQ. 0) GO TO 400
!
 KERMSG = ' READ ERROR FOR COEFFICIENT "'//ILABEL//'"'
 RETURN
END SUBROUTINE ALRECF_Z
!
!------------------------------------------------------------------------------
! 30Jun2000 fgtok -s r8_precision.sub "r8con.csh conversion"
