      PROGRAM POD

C     Converts a complex pressure field into a prob. of detection

      INTEGER PRTFIL, SHDFIL, PODFIL
      PARAMETER ( INPFIL = 5, PRTFIL = 6, SHDFIL = 26, PODFIL = 25,
     &   MAXNSD = 4094, MAXNRD = 4094, MAXNR = 4094 )

      REAL    R( MAXNR ), SD( MAXNSD ), RD( MAXNRD ), TL( MAXNR )
      COMPLEX P( MAXNR )
      CHARACTER TITLE*80, PLTTYP*10
C
      WRITE( PRTFIL, * ) 'FOM, SIGMA?'
      READ(  INPFIL, * )  FOM, SIGMA

C     *** Read/write header ***

      CALL RDHEAD( SHDFIL, 'SHDFILIN', MAXNR, MAXNSD, MAXNRD,
     &   FREQ, R, NR, DELTAR, PLTTYP, XS, YS, THETA,
     &   SD, NSD, RD, NRD, TITLE )

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

C     Read in pressure field and convert to transmission loss

      DO ISR = 1, NSD * NRD
         IREC =  ISR + 6
         READ ( SHDFIL, REC = IREC ) ( P( J ), J = 1, NR )

C        ------ Convert to probability of detection
         DO J = 1, NR
            PSQ = P( J ) * CONJG( P( J ) )
            TL( J ) = 200.0
            IF ( PSQ .GT. 1.0E-20 ) TL( J ) = -10.0 * ALOG10( PSQ )
            P( J ) = TRANSIT( FOM - TL( J ), SIGMA )
         END DO

C        ------ Write out the POD
         WRITE( PODFIL, REC = IREC ) ( P( J ), J = 1, NR )
      END DO

      STOP
      END
