      SUBROUTINE LOC(X,N)
C
C     PURPOSE--THIS SUBROUTINE COMPUTES 4 ESTIMATES OF THE
C              LOCATION (TYPICAL VALUE, MEASURE OF CENTRAL
C              TENDANCY) OF THE DATA IN THE INPUT VECTOR X. 
C              THE 4 ESTIMATORS EMPLOYED ARE--
C              1) THE SAMPLE MIDRANGE;
C              2) THE SAMPLE MEAN;
C              3) THE SAMPLE MIDMEAN; AND
C              4) THE SAMPLE MEDIAN.
C              THE ABOVE 4 ESTIMATORS ARE NEAR-OPTIMAL
C              ESTIMATORS OF LOCATION
C              FOR SHORTER-TAILED SYMMETRIC DISTRIBUTIONS,
C              MODERATE-TAILED DISTRIBUTIONS,
C              MODERATE-LONG-TAILED DISTRIBUTIONS,
C              AND LONG-TAILED DISTRIBUTIONS,
C              RESPECTIVELY.
C     INPUT ARGUMENTS--X      = THE SINGLE PRECISION VECTOR OF
C                               (UNSORTED OR SORTED) OBSERVATIONS.
C                      N      = THE INTEGER NUMBER OF OBSERVATIONS
C                               IN THE VECTOR X.
C     OUTPUT--1/4 PAGE OF AUTOMATIC OUTPUT
C             CONSISTING OF THE FOLLOWING 4
C             ESTIMATES OF LOCATION
C             FOR THE DATA IN THE INPUT VECTOR X--
C             1) THE SAMPLE MIDRANGE;
C             2) THE SAMPLE MEAN;
C             3) THE SAMPLE MIDMEAN; AND
C             4) THE SAMPLE MEDIAN.
C     PRINTING--YES.
C     RESTRICTIONS--THE MAXIMUM ALLOWABLE VALUE OF N
C                   FOR THIS SUBROUTINE IS 7500.
C     OTHER DATAPAC   SUBROUTINES NEEDED--SORT.
C     FORTRAN LIBRARY SUBROUTINES NEEDED--NONE.
C     MODE OF INTERNAL OPERATIONS--SINGLE PRECISION.
C     LANGUAGE--ANSI FORTRAN. 
C     REFERENCES--DIXON AND MASSEY, PAGES 14, 70, AND 71
C               --CROW, JOURNAL OF THE AMERICAN STATISTICAL ASSOCIATION,
C                 PAGES 357 AND 387
C               --KENDALL AND STUART, THE ADVANCED THEORY OF
C                 STATISTICS, VOLUME 1, EDITION 2, 1963, PAGE 8.
C     WRITTEN BY--JAMES J. FILLIBEN
C                 STATISTICAL ENGINEERING LABORATORY (205.03)
C                 NATIONAL BUREAU OF STANDARDS
C                 WASHINGTON, D. C. 20234
C                 PHONE:  301-921-2315
C     ORIGINAL VERSION--JUNE      1972. 
C     UPDATED         --NOVEMBER  1975. 
C     UPDATED         --FEBRUARY  1976. 
C
C---------------------------------------------------------------------
C
      DIMENSION X(1)
      DIMENSION Y(15000)
      COMMON /BLOCK2/ WS(15000)
      EQUIVALENCE (Y(1),WS(1))
C
      IPR=6
      IUPPER=15000
C
C     CHECK THE INPUT ARGUMENTS FOR ERRORS
C
      XMID=0.0
      XMEAN=0.0
      XMIDM=0.0
      XMED=0.0
      IF(N.LT.1.OR.N.GT.IUPPER)GOTO50
      IF(N.EQ.1)GOTO55
      HOLD=X(1)
      DO60I=2,N
      IF(X(I).NE.HOLD)GOTO90
   60 CONTINUE
      WRITE(IPR, 9)HOLD
      GOTO90
   50 WRITE(IPR,17)IUPPER
      WRITE(IPR,47)N
      RETURN
   55 WRITE(IPR,18) 
      XMID=X(1)
      XMEAN=X(1)
      XMIDM=X(1)
      XMED=X(1)
      GOTO301
   90 CONTINUE
    9 FORMAT(1H ,109H***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUME
     1NT (A VECTOR) TO THE LOC    SUBROUTINE HAS ALL ELEMENTS = ,E15.8,6
     1H *****)
   17 FORMAT(1H , 98H***** FATAL ERROR--THE SECOND INPUT ARGUMENT TO THE
     1 LOC    SUBROUTINE IS OUTSIDE THE ALLOWABLE (1,,I6,16H) INTERVAL *
     1****)
   18 FORMAT(1H ,100H***** NON-FATAL DIAGNOSTIC--THE SECOND INPUT ARGUME
     1NT TO THE LOC    SUBROUTINE HAS THE VALUE 1 *****)
   47 FORMAT(1H , 35H***** THE VALUE OF THE ARGUMENT IS ,I8   ,6H *****)
C
C-----START POINT-----------------------------------------------------
C
      AN=N
C
C     SORT THE DATA,
C     THEN COMPUTE THE SAMPLE MIDRANGE. 
C
      CALL SORT(X,N,Y)
      XMID=(Y(1)+Y(N))/2.0
C
C     COMPUTE THE SAMPLE MEAN 
C
      SUM=0.0
      DO100I=1,N
      SUM=SUM+Y(I)
  100 CONTINUE
      XMEAN=SUM/AN
C
C     COMPUTE THE SAMPLE MIDMEAN
C
      IFLAG=N-(N/4)*4
      AIFLAG=IFLAG
      IMIN=N/4+1
      IMAX=N-IMIN+1 
      SUM=0.0
      SUM=SUM+Y(IMIN)*(4.0-AIFLAG)/4.0
      SUM=SUM+Y(IMAX)*(4.0-AIFLAG)/4.0
      IMINP1=IMIN+1 
      IMAXM1=IMAX-1 
      IF(IMINP1.GT.IMAXM1)GOTO250
      DO200I=IMINP1,IMAXM1
      SUM=SUM+Y(I)
  200 CONTINUE
  250 XMIDM=SUM/(AN/2.0)
C
C     COMPUTE THE SAMPLE MEDIAN
C
      IFLAG=N-(N/2)*2
      NMID=N/2
      NMIDP1=NMID+1 
      IF(IFLAG.EQ.0)XMED=(Y(NMID)+Y(NMIDP1))/2.0
      IF(IFLAG.EQ.1)XMED=Y(NMIDP1)
C
C     WRITE EVERYTHING OUT
C
  301 DO300I=1,5
      WRITE(IPR,999)
  300 CONTINUE
      WRITE(IPR,305)
      WRITE(IPR,999)
      WRITE(IPR,310)N
      WRITE(IPR,999)
      WRITE(IPR,999)
      WRITE(IPR,315)XMID
      WRITE(IPR,320)XMEAN
      WRITE(IPR,325)XMIDM
      WRITE(IPR,330)XMED
C
  305 FORMAT(1H ,30X,35HESTIMATES OF THE LOCATION PARAMETER)
  310 FORMAT(1H ,34X,21H(THE SAMPLE SIZE N = ,I5,1H))
  315 FORMAT(1H ,38HTHE SAMPLE MIDRANGE IS                ,E15.8)
  320 FORMAT(1H ,38HTHE SAMPLE MEAN IS                    ,E15.8)
  325 FORMAT(1H ,38HTHE SAMPLE 25 PERCENT TRIMMED MEAN IS ,E15.8)
  330 FORMAT(1H ,38HTHE SAMPLE MEDIAN IS                  ,E15.8)
  999 FORMAT(1H )
C
      RETURN
      END 
