      SUBROUTINE SDRD( ENVFIL, PRTFIL, ZMIN, ZMAX,
     &   MAXNSD, NSD, SD,
     &   MAXNRD, NRD, RD )

      IMPLICIT NONE
      INTEGER ENVFIL, PRTFIL, MAXNSD, NSD, MAXNRD, NRD, IS, IR
      REAL SD( * ), RD( * ), ZMIN, ZMAX

C     *** Read source depths ***

      NSD = 0
      SD( 2 ) = 0.0
      SD( 3 ) = -999.9
      READ( ENVFIL, * ) NSD, ( SD( IS ), IS = 1, NSD )

      IF ( NSD .GT. MAXNSD ) THEN
         WRITE( PRTFIL, * ) 'NSD, MAXNSD = ', NSD, MAXNSD
         CALL ERROUT( PRTFIL, 'F', 'SDRD', 'Too many sources'  )
      ELSE IF ( NSD .LE. 0 ) THEN
         WRITE( PRTFIL, * ) ' NSD = ', NSD
         CALL ERROUT( PRTFIL, 'F', 'SDRD',
     &      'Number of sources must be positive'  )
      ENDIF

      CALL SUBTAB( SD, NSD )
      CALL SORT(   SD, NSD )

      WRITE( PRTFIL, * )
      WRITE( PRTFIL, * ) 'Number of sources   = ', NSD
      IF ( NSD .GE. 1 )
     &   WRITE( PRTFIL, * ) ( SD( IS ), IS = 1, MIN( NSD, 51 ) )
      IF ( NSD .GT. 51 ) WRITE( PRTFIL, * ) ' ... ', SD( NSD )

C     *** Read receiver depths ***

      NRD = 0
      RD( 2 ) = 0.0
      RD( 3 ) = -999.9
      READ( ENVFIL, * ) NRD, ( RD( IR ), IR = 1, NRD )

      IF ( NRD .GT. MAXNRD ) THEN
         WRITE( PRTFIL, * ) 'NRD, MAXNRD = ', NRD, MAXNRD
         CALL ERROUT( PRTFIL, 'F', 'SDRD', 'Too many receivers'  )
      ELSE IF ( NRD .LE. 0 ) THEN
         WRITE( PRTFIL, * ) ' NRD = ', NRD
         CALL ERROUT( PRTFIL, 'F', 'SDRD',
     &      'Number of receivers must be positive'  )
      ENDIF

      CALL SUBTAB( RD, NRD )
      CALL SORT(   RD, NRD )

      WRITE( PRTFIL, * )
      WRITE( PRTFIL, * ) 'Number of receivers = ', NRD
      IF ( NRD .GE. 1 )
     &   WRITE( PRTFIL, * ) ( RD( IR ), IR = 1, MIN( NRD, 51 ) )
      IF ( NRD .GT. 51 ) WRITE( PRTFIL, * ) ' ... ', RD( NRD )

C     *** Check for SD/RD in upper or lower halfspace ***

      DO IS = 1, NSD
         IF      ( SD( IS ) .LT. ZMIN ) THEN
            SD( IS ) = ZMIN
            CALL ERROUT( PRTFIL, 'W', 'SDRD',
     &         'Source in upper halfspace shifted to interface' )
         ELSE IF ( SD( IS ) .GT. ZMAX ) THEN
            SD( IS ) = ZMAX
            CALL ERROUT( PRTFIL, 'W', 'SDRD',
     &         'Source in lower halfspace shifted to interface' )
         ENDIF
      END DO

      DO IR = 1, NRD
         IF      ( RD( IR ) .LT. ZMIN ) THEN
            RD( IR ) = ZMIN
            CALL ERROUT( PRTFIL, 'W', 'SDRD',
     &         'Receiver in upper halfspace shifted to interface' )
         ELSE IF ( RD( IR ) .GT. ZMAX ) THEN
            RD( IR ) = ZMAX
            CALL ERROUT( PRTFIL, 'W', 'SDRD',
     &         'Receiver in lower halfspace shifted to interface' )
         ENDIF
      END DO

      RETURN
      END
