      SUBROUTINE ITERT(KERNEL,RHFCN,N,TN,WN,M,TM,WM,XM,XMZ,KMM,KMN,
     *   KNM,RHS,IMKNN,LUFACT,R,RH,DELN,NUP,NHALF,IFLG)
C
C   THIS ROUTINE CALCULATES ONE ITERATE XM GIVEN THE INITIAL GUESS
C   XMZ. THE ROUTINE IS DIVIDED ACCORDING TO WHETHER OR NOT
C   M .GT. NUPPER.
C
      REAL KERNEL,KMM,KMN,KNM,IMKNN,LUFACT
      DIMENSION TN(N),WN(N),TM(M),WM(M),XM(M),XMZ(M),KMM(NUP,NUP),
     *   KMN(NUP,NHALF),KNM(NHALF,NUP),RHS(M),IMKNN(NUP,NUP),
     *   LUFACT(NUP,NUP),R(M),RH(N),DELN(N)
      EXTERNAL KERNEL
C
C   M .GT. NUPPER MEANS THAT THE MATRICES KMM,KMN,KNM CAN NO LONGER
C   BE STORED DUE TO LACK OF SPACE.
      IF (M .GT. NUP) GO TO 13
      IF(IFLG .EQ. 1) GO TO 3
C   IF IFLG=0, THEN THE MATRICES KMM AND KNM MUST BE COMPUTED
C   AND STORED.
      DO 2 J=1,M
      DO 1 I=1,M
1     KMM(I,J)=WM(J)*KERNEL(TM(I),TM(J))
      DO 2 I=1,N
2     KNM(I,J)=WM(J)*KERNEL(TN(I),TM(J))
C   COMPUTE  RESIDUALS R(I)=RHFCN(TM(I))-XMZ(I)+KM(TM(I))*XMZ(I)
3     DO 5 I=1,M
      SUM=0.0
      DO 4 J=1,M
4     SUM=SUM+KMM(I,J)*XMZ(J)
5     R(I)=RHS(I)-(XMZ(I)-SUM)
C
C   COMPUTE RH=KM*R AT ALL TN(I).
      DO 7 I=1,N
      RH(I)=0.0
      DO 7 J=1,M
7     RH(I)=RH(I)+KNM(I,J)*R(J)
C   CALCULATE DELN=((I-KN)**(-1))*KM*R AT ALL TN(I).
C
C*******************************************************************
C                                                                  *
      CALL LNSYS(IMKNN,LUFACT,NUP,N,RH,DELN,4,IND)
C                                                                  *
C   SEE THE ORIGINAL REFERENCE IN IEGS.                            *
C*******************************************************************
C
C   CALCULATE NEW XM.
      DO 12 I=1,M
      SUM=0.0
      DO 10 J=1,M
10    SUM=SUM+KMM(I,J)*R(J)
      DO 11 J=1,N
11    SUM=SUM+KMN(I,J)*DELN(J)
12    XM(I)=SUM+R(I)+XMZ(I)
      RETURN
C   ENTRANCE WHEN M .GT. NUP.
C   CALCULATE RESIDUALS.
13    DO 15 I=1,M
      SUM=0.0
      DO 14 J=1,M
14    SUM=SUM+WM(J)*KERNEL(TM(I),TM(J))*XMZ(J)
15    R(I)=RHS(I)-(XMZ(I)-SUM)
C   CALCULATE RH=KM*R.
      DO 17 I=1,N
      RH(I)=0.0
      DO 17 J=1,M
17    RH(I)=RH(I)+WM(J)*KERNEL(TN(I),TM(J))*R(J)
C
C*******************************************************************
C                                                                  *
      CALL LNSYS(IMKNN,LUFACT,NUP,N,RH,DELN,4,IND)
C                                                                  *
C   SEE THE ORIGINAL REFERENCE IN IEGS.                            *
C*******************************************************************
C
C   CALCULATE XM.
      DO 22 I=1,M
      SUM=0.0
      DO 20 J=1,M
20    SUM=SUM+WM(J)*KERNEL(TM(I),TM(J))*R(J)
      DO 21 J=1,N
21    SUM=SUM+WN(J)*KERNEL(TM(I),TN(J))*DELN(J)
22    XM(I)=SUM+R(I)+XMZ(I)
      RETURN
      END
