      program aaapstrm
C...............................................Oct. 2019
C Extract days with aa>=50, ap >=18
C to select storm and sub-storm  days
C
      character*50 infile,outfilaa,outfilap
      character*2 AMN,ADY,AUT
	character*4 AYEAR

	infile='d:\apkp\AA\aaYEAR'  ! ap & aa
	outfilaa='aastrm.txt'	 ! 
	outfilap='apstrm.txt'	 ! 
C
   30	format(A50)
c2011 364  1   8.3  -0.5   12859.   4.9  406.
  31	format(I4,3(1X,I2),2(1X,I3))
	OPEN(11,file=outfilaa)
	OPEN(12,file=outfilap)
C
       icntaa=0
	icntap=0
	iaaout_pre=2
	iapout_pre=2
      DO 44 iyear=2011,2019
	call blet4(iyear,AYEAR)
	infile(14:17)=AYEAR
	iyr=iyear-iyear/100*100
C
	OPEN(10,file=infile,action='READ')
C
	ryear=float(iyear)
		if(int(ryear/4.)*4.eq.iyear) THEN 
	ndnr=366
	                          ELSE
	ndnr=365
	ENDIF
C
C day-to day cycle
C
	DO lda=1,ndnr		 !++++++++
	call submmdd(lda,iyr,imn,idy)
	call blet2(imn,AMN)
	call blet2(idy,ADY)
	iaamax=0
	iapmax=0
        do iut=0,23,3		   !==========	 3h intervals
	call blet2(iut,AUT)
	  read(10,31,end=50) kyear,kmn,kday,kut,iap,iaa
	if (iaamax.lt.iaa) iaamax=iaa
	if (iapmax.lt.iap) iapmax=iap
        enddo				  !==========
	if ((iaamax.ge.50).and.(iaamax.gt.iaaout_pre)) then
	icntaa=icntaa+1
	write(*,32) icntaa,iyr,AMN,ADY,iaamax
	write(11,32) icntaa,iyr,AMN,ADY,iaamax
	iaaout_pre=iaamax
	                     else
	iaaout_pre=iaamax
      endif
C
	if ((iapmax.ge.25).and.(iapmax.gt.iapout_pre)) then
	icntap=icntap+1
	write(*,32) icntap,iyr,AMN,ADY,iapmax
	write(12,32) icntap,iyr,AMN,ADY,iapmax
	iapout_pre=iapmax
	                     else
	iapout_pre=iapmax
      endif
   32 format(1X,I4,1X,I2,2(1X,A2),1X,I4)

	ENDDO	   !++++++++
C
   50 close(unit=10)
   44 CONTINUE
       close(unit=11)
	close(unit=12)
      pause ' '
	STOP
	END