      INTEGER FUNCTION FILCOR(MT1X,MT2X,   PC,FRSROW,MIDROW,NX,A,NZA,Z)
C
C     FILL CORE WITH A TRIANGULAR MATRIX
C
      REAL A(1),Z(1)
      INTEGER PC,FRSROW
C
      COMMON /UNPAKX/IT1,II,JJ,INCR1
C
C     MT1      FIRST PART OF THE MATRIX (UP TO ROW -MIDROW-).
C     MT2      REST OF THE MATRIX
C     PC       PRECISION OF THE MATRIX IN CORE
C     NX       COLUMN SIZE OF THE MATRIX
C     A        STORAGE FOR THE MATRIX
C     Z        BUFFER FOR GINO
C     FRSROW   FIRST ROW OF THE MATRIX TO BE READ
C     ANSWER   LAST ROW READ
C
      MT1 = MT1X
      MT2 = MT2X
      N   = NX
      MT = MT1
      LASROW = FRSROW-1
      IT1 = PC
      INCR1 =1
      JJ = N
      IF( LASROW .GE. MIDROW .AND. MT2 .NE. 0) MT = MT2
      NN = NZA/PC
      NA = 0
C
C     READ IN EACH ROW
C
  105 IF (NA + N -LASROW .GT. NN) GO TO 115
      LASROW  = LASROW +1
      I = PC*NA +1
      II = LASROW
      CALL UNPACK(*106,MT,A(I))
      GO TO 107
  106 K  = I +LASROW*PC-1
      DO 108 J = I,K
  108 A(J) =0.0
  107 IF (LASROW .EQ. N) GO TO 110
      NA = NA + (N-LASROW +1)
      IF( LASROW .NE. MIDROW .OR. MT2 .EQ. 0) GO TO 105
      CALL CLOSE(MT,1)
      MT = MT2
      CALL GOPEN(MT,Z,0)
      GO TO 105
C
C     END OF ROUTINE
C
  110 CALL CLOSE(MT,1)
  115 FILCOR = LASROW
      RETURN
      END
