      SUBROUTINE FRMRIJ2(ICORE,MAXCOR,IUHF,RLECYC,MAXORD,IBOT,I,J,
     &                   SINGLE,RLETYP)
C
C THIS ROUTINE IS USED TO FORM THE R MATRIX USED IN THE RLE-1 METHOD.
C  PUT THREE T2 VECTORS IN CORE UNTIL WE KNOW WHETHER THIS WORKS OR NOT
C
C THE FORMULA FOR AN R MATRIX ELEMENT IS:
C
C                 (i)   (i-1)      (j)    (j-1)
C      R(I,J) = [T   - T     ] * [T    - T     ]
C
CEND
      IMPLICIT INTEGER (A-Z)
      DIMENSION ICORE(MAXCOR)
      DOUBLE PRECISION R,FACTOR,SDOT,ONEM
      LOGICAL SINGLE,GETT1V
      COMMON /SYMPOP/ IRPDPD(8,22),ISYTYP(2,500),ID(18)
      COMMON /MACHSP/ IINTLN,IFLTLN,IINTFP,IALONE,IBITWD
      COMMON /RMAT/ R(400)
      COMMON /SYM/ POP(8,2),VRT(8,2),NT(2),NF1(2),NF2(2)
      COMMON /RLEIO/ IOLDEST
      DATA ONEM /-1.0/
      INDX(I,J)=I+(J-1)*MAXORD
      IGET(I)  =1+MOD(IOLDEST+MAXORD-I,MAXORD+1)
      RSIZE=MIN(RLECYC-1,MAXORD)
C
      IF(I.NE.0.AND.J.EQ.0)THEN
       IROW=I
       NLSTI=1+IROW
       DO 200 ICOL=1,RSIZE
        R(INDX(IROW,ICOL))=0.0
200    CONTINUE
       DO 201 ISPIN=3,1,IUHF-2
        IADD=0
        GETT1V=.FALSE.
        IF(ISPIN.LT.3.AND.IUHF.EQ.0)THEN
         FACTOR=2.0
        ELSE
         FACTOR=1.0
        ENDIF
        IF(SINGLE.AND.ISPIN.LT.3)THEN
         IADD=NT(ISPIN) 
         GETT1V=.TRUE.
        ENDIF
        SIZET2=ISYMSZ(ISYTYP(1,60+ISPIN),ISYTYP(2,60+ISPIN))
        SIZET=SIZET2+IADD
        IOFFT1=IINTFP*SIZET2
        I000=1
        I010=I000+SIZET*IINTFP
        I020=I010+SIZET*IINTFP
        I030=I020+SIZET*IINTFP
        IF(RLETYP.EQ.3)THEN
         CALL GETLST(ICORE(I000),IGET(NLSTI),1,1,ISPIN+3,70)
        ELSE
         CALL GETLST(ICORE(I000),IGET(NLSTI),1,1,ISPIN,70)
        ENDIF
        CALL GETLST(ICORE(I010),IGET(NLSTI-1),1,1,ISPIN,70)
        CALL SAXPY(SIZET,ONEM,ICORE(I010),1,ICORE(I000),1)
        DO 202 ICOL=1,RSIZE  
         IOFF=INDX(IROW,ICOL)
         NLSTJ=1+ICOL
         NLSTJP1=NLSTJ-1
         IF(RLETYP.EQ.3)THEN
          CALL GETLST(ICORE(I010),IGET(NLSTJ),1,1,ISPIN+3,70)
         ELSE
          CALL GETLST(ICORE(I010),IGET(NLSTJ),1,1,ISPIN,70)
         ENDIF
         CALL GETLST(ICORE(I020),IGET(NLSTJ-1),1,1,ISPIN,70)
         CALL SAXPY(SIZET,ONEM,ICORE(I020),1,ICORE(I010),1)
         R(IOFF)=R(IOFF)+FACTOR*SDOT(SIZET,ICORE(I000),1,ICORE(I010),1)
202     CONTINUE
201    CONTINUE
      ELSEIF(I.EQ.0.AND.J.NE.0)THEN
       ICOL=J
       NLSTJ=1+ICOL
       DO 300 IROW=1,RSIZE
        R(INDX(IROW,ICOL))=0.0
300    CONTINUE
       DO 301 ISPIN=3,1,IUHF-2
        IADD=0
        GETT1V=.FALSE.
        IF(ISPIN.LT.3.AND.IUHF.EQ.0)THEN
         FACTOR=2.0
        ELSE
         FACTOR=1.0
        ENDIF
        IF(SINGLE.AND.ISPIN.LT.3)THEN
         IADD=NT(ISPIN) 
         GETT1V=.TRUE.
        ENDIF
        SIZET2=ISYMSZ(ISYTYP(1,60+ISPIN),ISYTYP(2,60+ISPIN))
        SIZET=SIZET2+IADD
        IOFFT1=IINTFP*SIZET2
        I000=1
        I010=I000+SIZET*IINTFP
        I020=I010+SIZET*IINTFP
        I030=I020+SIZET*IINTFP
        IF(RLETYP.EQ.3)THEN
         CALL GETLST(ICORE(I000),IGET(NLSTJ),1,1,ISPIN+3,70)
        ELSE
         CALL GETLST(ICORE(I000),IGET(NLSTJ),1,1,ISPIN,70)
        ENDIF
        CALL GETLST(ICORE(I010),IGET(NLSTJ-1),1,1,ISPIN,70)
        CALL SAXPY(SIZET,ONEM,ICORE(I010),1,ICORE(I000),1)
        DO 302 IROW=1,RSIZE
         NLSTI=1+IROW
         IOFF=INDX(IROW,ICOL)
         IF(RLETYP.Eq.3)THEN
          CALL GETLST(ICORE(I010),IGET(NLSTI),1,1,ISPIN+3,70)
         ELSE
          CALL GETLST(ICORE(I010),IGET(NLSTI),1,1,ISPIN,70)
         ENDIF
         CALL GETLST(ICORE(I020),IGET(NLSTI-1),1,1,ISPIN,70)
         CALL SAXPY(SIZET,ONEM,ICORE(I020),1,ICORE(I010),1)
         R(IOFF)=R(IOFF)+FACTOR*SDOT(SIZET,ICORE(I000),1,ICORE(I010),1)
302     CONTINUE
301    CONTINUE
      ELSE
       RETURN
      ENDIF
      RETURN
      END
