      SUBROUTINE PROF(MM, M, N, A, CLAB, RLAB, TITLE, WORK1, DMWRK2,
     *                WORK2, IERR, OUNIT)
C
C<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
C
C   PURPOSE
C   -------
C
C      COMPUTES AND OUTPUTS PROFILES OF THE VARIABLES SUCH THAT THE
C      LINEAR REGRESSION LINES THROUGH EACH CASE HAVE THE SMALLEST
C      TOTAL ERROR
C
C   DESCRIPTION
C   -----------
C
C   1.  THE VARIABLES SHOULD BE SCALED SIMILARLY (CLUSTER SUBROUTINE
C       STAND CAN BE USED TO STANDARDIZE THE VARIABLES).
C
C   2.  THE EIGENVECTORS OF THE A'A MATRIX ARE DETERMINED AND THE
C       LARGEST TWO ARE USED TO MAKE THE LINES CONNECTING EACH CASE FOR
C       ALL VARIABLES AS SMOOTH AS POSSIBLE.
C
C   3.  THE HORIZONTAL LOCATION OF THE PROFILE IS FOUND USING THE
C       RATIOS OF THE VALUES IN THE FIRST TWO EIGENVECTORS.  THE
C       VERTICAL SCALE OF THE PROFILE IS FOUND BY MULTIPLYING THE DATA
C       VALUE BY THE RECIPROCALS OF THE VALUES IN THE FIRST
C       EIGENVECTOR.
C
C       IN OTHER WORDS, A(I,J) IS PLOTTED AT (XLOC, YLOC), WHERE
C
C          XLOC = EIGENVECTOR(J,2) / EIGENVECTOR(J,1)
C       AND
C          YLOC = A(I,J) / EIGENVECTOR(J,1)
C
C       WHERE EIGENVECTOR IS THE MATRIX WHOSE COLUMNS ARE THE TWO
C          LARGEST EIGENVECTORS
C
C   4.  IF TWO PROFILES HAVE THE SAME XLOC VALUE, THE PROFILE THAT IS
C       PLOTTED AT THAT XLOC VALUE WILL BE THE UNION OF THE TWO
C       PROFILES.  THEREFORE, TWO INSTANCES OF THE SAME CASE COULD BE
C       PLOTTED ON THAT PROFILE.  SINCE THE MAXIMUM NUMBER OF PROFILES
C       THAT CAN BE PLOTTED IN A SINGLE CALL IS 25, THIS ROUTINE IS NOT
C       RECOMMEMDED FOR A LARGE NUMBER OF VARIABLES.
C
C   5.  IF TWO CASES ARE TO BE PLOTTED IN THE SAME POSITION ON A
C       PARTICULAR PROFILE, THE SECOND CASE IS PLOTTED AND THE FIRST
C       CASE IS IGNORED.  THEREFORE, IF A PROFILE IS MISSING SOME
C       CASES, THE DATA SHOULD BE ANALYZED TO LOCATE "VERY CLOSE" CASES
C       IN ORDER TO DETERMINE THE APPROXIMATE POSITION OF THE MISSING
C       CASES.  THE PROFILES ARE WRITTEN ON FORTRAN UNIT OUNIT.
C
C   6.  TO OBTAIN A PROFILE OF THE VARIABLES FOR EACH CASE, SEE CLUSTER
C       SUBROUTINE LINE.
C
C   INPUT PARAMETERS
C   ----------------
C
C   MM    INTEGER SCALAR (UNCHANGED ON OUTPUT).
C         THE FIRST DIMENSION OF THE MATRIX A.  MUST BE AT LEAST M.
C
C   M     INTEGER SCALAR (UNCHANGED ON OUTPUT).
C         THE NUMBER OF CASES.
C
C   N     INTEGER SCALAR (UNCHANGED ON OUTPUT).
C         THE NUMBER OF VARIABLES.
C
C   A     REAL MATRIX WHOSE FIRST DIMENSION MUST BE MM AND WHOSE SECOND
C            DIMENSION MUST BE AT LEAST N (UNCHANGED ON OUTPUT).
C         THE MATRIX OF DATA VALUES.
C
C         A(I,J) IS THE VALUE FOR THE J-TH VARIABLE FOR THE I-TH CASE.
C
C   CLAB  VECTOR OF 4-CHARACTER VARIABLES DIMENSIONED AT LEAST N.
C            (UNCHANGED ON OUTPUT).
C         THE LABELS OF THE VARIABLES.
C
C   RLAB  VECTOR OF 4-CHARACTER VARIABLES DIMENSIONED AT LEAST M.
C            (UNCHANGED ON OUTPUT).
C         THE LABELS OF THE CASES.
C
C   TITLE 10-CHARACTER VARIABLE (UNCHANGED ON OUTPUT).
C         TITLE OF THE DATA SET.
C
C   WORK1 REAL VECTOR DIMENSIONED AT LEAST 5*N.
C         WORK VECTOR
C
C   DMWRK2 INTEGER SCALAR (UNCHANGED ON OUTPUT).
C         THE FIRST DIMENSION OF THE MATRIX WORK2.  MUST BE AT LEAST N.
C
C   WORK2 REAL MATRIX WHOSE FIRST DIMENSION MUST BE DMWRK2 AND WHOSE
C            SECOND DIMENSION MUST BE AT LEAST N.
C         WORK MATRIX.
C
C   OUNIT INTEGER SCALAR (UNCHANGED ON OUTPUT).
C         UNIT NUMBER FOR OUTPUT.
C
C   OUTPUT PARAMETER
C   ----------------
C
C   IERR  INTEGER SCALAR.
C         ERROR FLAG.
C
C         IERR = 0, NO ERRORS WERE DETECTED DURING EXECUTION
C
C         IERR = K, CONVERGENCE WAS NOT OBTAINED DURING COMPUTATION OF
C                   EIGENVALUES.  EIGENVALUES 1, ..., K-1 ARE CORRECT.
C                   ERROR FLAG FROM CMLIB SUBROUTINE SSIEV.  EXECUTION
C                   IS TERMINATED.
C
C   REFERENCE
C   ---------
C
C     HARTIGAN, J. A. (1975).  CLUSTERING ALGORITHMS, JOHN WILEY &
C        SONS, INC., NEW YORK.  PAGES 28-32, 42.
C
C<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
C
      INTEGER DMWRK2, B, EIGVL, OUNIT
      DIMENSION A(MM,*), WORK1(*), WORK2(DMWRK2,*)
      CHARACTER*10 TITLE
      CHARACTER*4 CLAB(*), RLAB(*), AA(25), BB, BL
      DATA BB,BL/'''   ','    '/
      DATA YMIN,YMAX,XMIN,XMAX/4*0./
C
      IERR = 0
      B = 2*N
      EIGVL = B + 2*N
C
C     FIND THE EIGENVECTORS
C
      CALL EIGEN(MM,M,N,A,DMWRK2,WORK2,WORK1(EIGVL+1),WORK1(1),IERR,
     *           OUNIT)
      IF (IERR .NE. 0) RETURN
C
C     REPLACE THE FIRST EIGENVECTORS WITH THE TWO LARGEST
C
      DO 20 I = 1 , N
         WORK2(I,1) = WORK2(I,N)*1000.
  20     WORK2(I,2) = WORK2(I,N-1)*1000.
C
C     DETERMINE SCALE AND POSITION PARAMETERS FOR THE PROFILES
C
      DO 30 I = 1 , N
         WORK1(B+I) = 1. / WORK2(I,1)
         WORK1(B+N+I) = WORK2(I,2) / WORK2(I,1)
 30   CONTINUE
C
C     DETERMINE THE MINIMUM AND MAXIMUM FOR EACH PROFILE
C
      YY=WORK1(B+1)*A(1,1)
      XX=WORK1(B+N+1)
      YMIN=YY
      YMAX=YY
      XMIN=XX
      XMAX=XX
      DO 40 I=1,M
         DO 40 J=1,N
            YY=WORK1(B+J)*A(I,J)
            XX=WORK1(B+N+J)
            IF(YY.LT.YMIN) YMIN=YY
            IF(YY.GT.YMAX) YMAX=YY
            IF(XX.LT.XMIN) XMIN=XX
            IF(XX.GT.XMAX) XMAX=XX
   40 CONTINUE
C
C     SET SCALES
C
      NP=M/20+1
      FY=(NP*50)/(YMAX-YMIN+.000001)
      FX=25/(XMAX-XMIN+.000001)
C
C     DETERMINE THE X-LOCATIONS FOR THE PROFILES AND ADJUST IF ANY
C     COINCIDE
C
      DO 50 I = 1 , N
 50      WORK1(EIGVL+I) = REAL(INT((WORK1(B+N+I)-XMIN)*FX+1))
      ITER = 0
 60   ICOIN = 0
      ITER = ITER + 1
      DO 70 I = 1 , N
         DO 70 J = I+1, N
            IF (WORK1(EIGVL+I) .EQ. WORK1(EIGVL+J)) THEN
               IF (WORK1(EIGVL+I) .NE. 1.) THEN
                  WORK1(EIGVL+I) = REAL(INT(WORK1(EIGVL+I))-1)
                  ICOIN = 1
                  GOTO 80
               ELSE
                  WORK1(EIGVL+I) = REAL(INT(WORK1(EIGVL+I))+1)
                  ICOIN = 1
                  GOTO 80
               ENDIF
            ENDIF
 70   CONTINUE
 80   IF (ICOIN .EQ. 1 .AND. ITER .LE. 5) GOTO 60
C
C     WRITE TITLES
C
      IF (OUNIT .GT. 0) THEN
         WRITE(OUNIT,1) TITLE
    1    FORMAT('1',' PROFILES OF ',A10)
         WRITE(OUNIT,2)
    2    FORMAT('0 VARIABLE     TOP   BOTTOM ')
      ENDIF
      DO 90 J=1,N
         Y1=YMAX/WORK1(B+J)
         Y2=YMIN/WORK1(B+J)
         IF (OUNIT .GT. 0) THEN
            WRITE(OUNIT,3) CLAB(J),Y2,Y1
    3       FORMAT(2X,A4,3X,2F10.4)
         ENDIF
   90 CONTINUE
C
C     WRITE PROFILES
C
      IL=-1
  100 IL=IL+1
C
C     INITIALIZE LINE
C
      DO 110 I=1,25
  110    AA(I)=BL
      DO 120 J=1,N
         JJ=INT(WORK1(EIGVL+J))
         AA(JJ)=BB
  120    IF(IL.EQ.0) AA(JJ)=CLAB(J)
      IF(IL.NE.0) THEN
C
C     FILL IN VALUES ON LINE
C
         DO 130 J=1,N
            DO 130 I=1,M
               K=(WORK1(B+J)*A(I,J)-YMIN)*FY+1
               IF(K.EQ.IL) THEN
                  JJ=INT(WORK1(EIGVL+J))
                  IF(JJ.GE.1.AND.JJ.LE.25) AA(JJ)=RLAB(I)
               ENDIF
  130    CONTINUE
      ENDIF
      IF (OUNIT .GT. 0) THEN
         WRITE(OUNIT,5) IL,(AA(I),I=1,25)
    5    FORMAT(1X,I3,1X,25(1X,A4))
      ENDIF
      IF(IL.LE.NP*50) GO TO 100
      RETURN
      END
