      SUBROUTINE RANGES( ENVFIL, PRTFIL, MAXNR, NR, R )

C     *** Read receiver ranges ***

      IMPLICIT NONE
      INTEGER ENVFIL, PRTFIL, MAXNR, NR, IR
      REAL R( * )

      NR = 0
      R( 2 ) = 0.0
      R( 3 ) = -999.9
      READ( ENVFIL, * ) NR, ( R( IR ), IR = 1, NR )

      IF ( NR .GT. MAXNR ) THEN
         WRITE( PRTFIL, * ) 'NR, MAXNR = ', NR, MAXNR
         CALL ERROUT( PRTFIL, 'F', 'RANGES', 'Too many range points' )
      ENDIF

      CALL SUBTAB( R, NR )
      CALL SORT(   R, NR )

      WRITE( PRTFIL, * )
      WRITE( PRTFIL, * ) 'Number of ranges   = ', NR
      WRITE( PRTFIL, * ) ( R( IR ), IR = 1, MIN( NR, 51 ) )

C     ------ Convert ranges to meters
      DO IR = 1, NR
         R( IR ) = 1000.0 * R( IR )
      END DO      

C     ------ For a point source can't have receiver at origin
C      IF ( OPT(1:1) .EQ. 'R' .AND. R( 1 ) .LE. 0.0 ) 
      IF ( R( 1 ) .LE. 0.0 ) R( 1 ) = MIN( 1.0, R( 2 ) )

      RETURN
      END
