C***********************************************************************
C
	SUBROUTINE PKFIND( PANG1, DANG, DELPK, IFOUND)
C
C	PEAK LOCATOR ROUTINE
C
C		THIS ROUTINE PERFORMS A SEARCH FOR A PEAK NEAR
C	   THE EXPECTED POSITION.  THE SEARCH RANGE IS FROM THE
C	   EXPECTED PEAK POSITION (PANG1) MINUS DANG*25 TO THE EXPECTED
C	   POSITION PLUS DANG*24 GIVING A TOTAL OF 50 POINTS FOR
C	   EACH PEAK.  THE DATA IS THEN SMOOTHED AND SEARCHED FOR
C	   PEAK.
C
C  IFOUND is the returned status and will go in column 120 of record 7.
C		= 0  This routine not called.
C		= 1  Peak located within the smoothed region.
C		      in this case update DELPK, the latest peak
C		      shift from initial peak angle PANG1.
C		= 2  Peak located at extremes of search range,
C		      i.e., in the unsmoothed portion which is the
C		      first and last 6 points for the 13 pt smooth.
C		= 3  Peak not located.
C  	PASS0 stores IFOUND as the units digit of IPKFND(IPEAK)
C
C======================================================================
C
      INCLUDE 'COMMON.FTN'
C Uses ICOUNT, ICNT, IBUG
C Uses PANG1, as a dummy variables
C Calls SMTH13 to smooth the data;
C Calls IFSSCN with Subroutine STRCNT as an argument.
	EXTERNAL STRCNT
C
C======================================================================
C
C  COLLECT THE 50 DATA POINTS AT 1/2 SEC EACH POINT.
C
	BANG = PANG1 - 25.0*DANG
	ICOUNT = 0
	CALL IFSSCN(BANG,-50.0,DANG,0.0,0.5,0.0,STRCNT)
C
C  DATA COLLECTION IS NOW COMPLETED.  SMOOTH THE DATA.
C
	CALL SMTH13
C
C  SEARCH THE SMOOTHED DATA FOR THE LARGEST VALUE.  NOTE: THE FIRST 6
C  AND THE LAST 5 POINTS WERE NOT SMOOTHED.  IF THE PEAK LIES IN THESE
C  EXTREMES A FLAG IS RETURNED TO THE CALLING PROGRAM.
C
	IMAX = 0
	AMAX  = 0
	DO 210 I= 1,50
	IF(CNT(I).LT.AMAX) GOTO 210
	AMAX = CNT(I)
	IMAX= I
210	CONTINUE
C
C  WAS A PEAK FOUND ?
	IFOUND = 3
	IF (AMAX.LT.10) GOTO 9999
C
C  PEAK WAS FOUND. CALCULATE THE POSITION
C
	DEL = (IMAX - 26) * DANG
	PANG1 = PANG1 + DEL
C
C  IS THE PEAK AT EXTREMES WHERE NO SMOOTHING WAS PERFORMED ?
	IFOUND = 2
	IF ((IMAX.LT.7) .OR. (IMAX.GT.44)) GOTO 9999
C
C  PEAK LOCATED WITHIN SMOOTHED REGION,
C  UPDATE DELPK SINCE PEAK IS WELL DETERMINED
C
	IFOUND = 1
	DELPK = DEL
C
C======================================================================
C
C	DEBUG DISPLAY OF RESULTS WHEN RETURNING
C
9999	CONTINUE
D	IF(IBUG.NE.0) WRITE(IBUG,9994) PANG1,IFOUND,DEL,IMAX,AMAX,TIME
D9994	FORMAT(' >> DEBUG0 <<  PKFIND RESULTS: PANG1 = ',F9.4,
D    1	' IFOUND=',I3,/,' > PEAK DELTA=',F7.2,' PT #=',I3,
D    2	' PEAK CNTS=',F8.0,' TIME=',F7.2)
C
	RETURN
	END
                                                                                                                                    
C***********************************************************************
C
	SUBROUTINE STRCNT
C
C   THIS IS CALLED BY IFSSCN AT EACH STEP TO STORE COUNTS IN ARRAY CNT.
C
      INCLUDE 'COMMON.FTN'
C Uses COUNT, ISTEP, CNT, IERR
C
	IF(ISTEP.GT.50) GOTO 9000
	CNT(ISTEP) = COUNTS
	GOTO 9999
C
9000	WRITE(IERR,9004) ISTEP
9004	FORMAT(' >> PROGRAM ERROR IN PKFIND << ISTEP =',I5)
C
9999	RETURN
	END
