      SUBROUTINE LLINTL(BEGIN,DVALUE,DLINK,AVAIL,VAL,ERSTAT)
      IMPLICIT NONE
C
C**********************************************************************
C
C   NAME- LLINTL
C
C   LANGUAGE- VS FORTRAN  TYPE- SUBROUTINE      COMPUTER- NAS 9000
C
C   VERSION- 1.0    DATE- 08/23/89   PROGRAMMER- G. RAJASHEKAR, SMSRC
C   VERSION- 2.0    DATE- 04/29/96   PROGRAMMER- FRANK TILLEY (SMSRC)
C     FOR REHOSTING TO CRAY: CHANGED I*4 TO INT.
C
C   FUNCTION - THIS SUBROUTINE WILL INSERT A TAIL NODE (WITH THE INPUT
C              VALUE) TO THE LINKED LIST FOR THE GIVEN CLASS BY USING
C              THE AVAILABLE NODE IN THE STORAGE POOL. THIS ROUTINE
C              ALSO RETURNS THE POSITION OF THE NEXT NODE THAT WILL BE
C              AVAILABLE IN THE STORAGE POOL.
C
C   CALLING SEQUENCE PARAMETERS-
C
C   NAME     TYPE    I/O     FUNCTION
C   ----     ----    ---     --------
C   BEGIN    INT      I      POINTER TO THE STARTING POSITION OF THE
C                            LINKED LIST IN THE STORAGE POOL.
C
C   DVALUE   INT     I/O     INTEGER VALUE ARRAY OF DIMENSION MPNOD.
C
C   DLINK    INT     I/O     INTEGER LINK ARRAY OF DIMENSION MPNOD.
C
C   AVAIL    INT     I/O     TO UPDATE THE POSITION OF
C                            THE AVAILABLE NODE.
C
C   VAL      INT      I      VALUE TO BE INSERTED AT
C                            THE TAIL OF THE LIST.
C
C   ERSTAT   INT      O      ERROR STATUS: NON-ZERO IF THE STORAGE POOL IS FULL.
C
C
      INCLUDE 'LLPARM'
C
      INTEGER   DVALUE(MPNOD),DLINK(MPNOD),VAL,AVAIL,BEGIN, ERSTAT
C
C   LOCAL PARAMETERS-
C
C   VARIABLE             TYPE  FUNCTION
C   --------             ----  --------
C   NAVL                 INT   NODE AVAILABLE FOR PRESENT INSERTION.
C
C   TAIL                 INT   THE POSITION OF THE PRESENT TAIL NODE.
C
C   NEXT                 INT   TEMP VARIABLE TO HOLD THE NEXT LINK.
C
C
      INTEGER   NAVL,TAIL,NEXT
C
C   SUBPROGRAMS CALLED - GETNOD
C
C   FUNCTIONS USED - NONE
C
C   EXIT STATES - NONE
C
C**********************************************************************
C
C--- THIS ROUTINE WILL RETURN THE POSITION OF THE AVAILABLE NODE IN
C    THE STORAGE POOL FOR THE PRESENT INSERTION. THIS ROUTINE WILL
C    ALSO UPDATE THE NODE AVAILABLE FOR FUTURE INSERTIONS.
C
      ERSTAT = 0
      CALL GETNOD(DLINK,MPNOD,AVAIL,NAVL,ERSTAT)
      IF (ERSTAT.NE.0) GO TO 9000
C
C*** IF THE LIST IS NEW THEN THE VALUE IS INSERTED IN THE SECOND
C    NODE AND THE HEAD NODE (WHICH WILL BE USED TO STORE THE
C    LENGTH OF THE LINKED LIST) IS SET TO 0.
C
      IF (NAVL.EQ.BEGIN) THEN
         DVALUE(DLINK(BEGIN)) = VAL
         CALL GETNOD(DLINK,MPNOD,AVAIL,NAVL,ERSTAT)
         IF (ERSTAT.NE.0) GO TO 9000
         DLINK(DLINK(BEGIN)) = 0
      ELSE
C
C*** IF THE LIST IS ALREADY EXISTING, THEN THE VALUE IS INSERTED
C    AT THE TAIL OF THE LIST.
C
C--- THIS PART OF THE PROGRAM WILL FIND OUT THE PRESENT POSITION
C    OF THE TAIL IN THE LINKED LIST.
C
         NEXT = DLINK(BEGIN)
C
  10     CONTINUE
            IF (DLINK(NEXT).EQ.0) THEN
                TAIL = NEXT
                GOTO 20
            ELSE
                NEXT = DLINK(NEXT)
            END IF
         GOTO 10
C
  20     CONTINUE
C
C--- ONCE THE TAIL NODE IS FOUND, A NEW TAIL NODE IS CREATED
C    USING THE AVAILABLE NODE AND THE INPUT VALUE IS STORED IN
C    THE NEW TAIL NODE. THE LINKS ARE UPDATED.
C
         DLINK(TAIL) = NAVL
         DLINK(NAVL) = 0
         DVALUE(NAVL) = VAL
      END IF
C
C--- THE LENGTH OF THE LINKED LIST IS UPDATED
C
      DVALUE(BEGIN) = DVALUE(BEGIN) + 1
C
 9000 RETURN 
C
      END
