      SUBROUTINE HEADER( TITLE, SD, NSD, RD, NRD,
     &   R, NR, FREQ, ATTEN, PLTTYP, XS, YS, THETA )

C     Routine to write header to disk file

C     TITLE  is an arbitrary title
C     SD     is a vector of source   depths, SD(1:NSD)
C     RD     is a vector of receiver depths, RD(1:NRD)
C     R      is a vector of receiver ranges, R(1:NR)
C     FREQ   is the frequency
C     ATTEN  is the stabilizing attenuation (which is only
C        important for FFP runs. Use zero for other cases.)

      INTEGER SHDFIL
      PARAMETER ( SHDFIL = 25, MXRECL = 200000 ) ! MXRECL=4095 for VAX

      REAL*4 R( * ), RD( * ), SD( * )
      CHARACTER TITLE*( * ), PLTTYP*10

      LRECL = MAX( 40, NSD, NRD, 2 * NR )   ! words/record

      IF ( LRECL .GT. MXRECL ) THEN
         STOP 'FATAL ERROR: Record is too large'
      ENDIF

      OPEN ( FILE = 'SHDFIL', UNIT = SHDFIL, STATUS = 'UNKNOWN',
     &   ACCESS = 'DIRECT', RECL = 4 * LRECL, FORM = 'UNFORMATTED')

      WRITE( SHDFIL, REC = 1 ) LRECL, TITLE(1:80)
      WRITE( SHDFIL, REC = 2 ) PLTTYP, XS, YS, THETA
      WRITE( SHDFIL, REC = 3 ) FREQ, NSD, NRD, NR
      WRITE( SHDFIL, REC = 4 ) ( SD( I ), I = 1, NSD )
      WRITE( SHDFIL, REC = 5 ) ( RD( I ), I = 1, NRD )
      WRITE( SHDFIL, REC = 6 ) ( R(  I ), I = 1, NR  )

      RETURN
      END
C**********************************************************************C
      SUBROUTINE WRTFLD( P, NRD, NR, IREC )

C     Write the field to disk

      INTEGER SHDFIL
      PARAMETER ( SHDFIL = 25 )

      COMPLEX P( NRD, * )

      DO I = 1, NRD
         IREC = IREC + 1
         WRITE( SHDFIL, REC = IREC ) ( P( I, J ), J = 1, NR )
      END DO

      RETURN
      END
