C........................................................Jun 2023
C Produce catalog AE-peak / month, Apomax(month) 1995-2017
C
C
      PROGRAM extpeakaemn
C
C----------------------------------------------------------------
C
C
      CHARACTER*128 INFILE,outfile  !
		 CHARACTER*2 AMN,ADY,AUT
	CHARACTER*4 AYEAR
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	DIMENSION IAE(0:23),IM(12)
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
      ICALLS=0
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
C
	infile='d:\Apkp\AE\AEYEAR' ! annual files for 1995-2017 Apo(tauy6)
	outfile='cataepeakmn.txt'
C
C Start 
C
C
C+    7	OPEN(11,FILE=OUTFILE)
    7	OPEN(11,FILE=OUTFILE,access='APPEND')
C
   28 format(1X,F8.3,3(1X,I2),3(1X,F6.0))
   29 format(A20,1X,I4,3(1X,I2),1X,F5.0)
   38 format(48(1X,I4))
C++   36 format(1X,F9.4,3(1X,I2),2X,F5.0,2X,F6.2)	 ! hourly Apo,Apo(tau_6)
C--   36 format(1X,I4,3(1X,I2),2X,F5.0,2X,F6.2)	 ! hourly Apo(tau_6),
   36 format(3X,I2,I2,1X,I2,10X,24(I4))	 ! hourly Apo
C
	nn=0
    1	CONTINUE
Cnoem      DO 177 kyear=1995,2017
      kyear=2018
	call blet4(kyear,AYEAR)
	infile(14:17)=AYEAR
	open(10,file=infile,action='READ')
			year1=float(kyear)
 	if(int(year1/4.)*4.eq.kyear) THEN 
	IM(2)=29
	dnyr=366.
	                          ELSE
	IM(2)=28
	dnyr=365.
	ENDIF
        del=1./dnyr
C
         kyr=kyear-kyear/100*100
C Monthly cycle
        DO 201 kmn=1,12
        iaemax=0
C       
C Daily cycle
       kdymn=im(kmn)
        DO 202 kdy=1,kdymn
C
    2 CONTINUE
      read(10,36,end=102) iyr,iMN,iDY,(IAE(k),k=0,23)
	DO iut=0,23
	    if (iae(iut).gt.iaemax) then
	iaemax=iae(iut)
	imnmax=kmn
	idymax=kdy
	iutmax=iut
	    endif
	enddo
C
  202	CONTINUE
C
	lda=ndoy(iyr,imnmax,idymax) ! 
       call blet2(imnmax,AMN)
	call blet2(idymax,ADY)
	call blet2(iutmax,AUT)
	ryearmax=year1+(lda-1)*del
C Output Catalog
  205	nn=nn+1
      write(*,37) ryearmax,lda,AMN,ADY,AUT,iaemax,nn
      write(11,37) ryearmax,lda,AMN,ADY,AUT,iaemax,nn
C
 201	continue
  102 close(unit=10)
C
  177	CONTINUE
      close(unit=11)
C
   37	format(1X,F8.3,1X,I3,3(1X,A2),1X,I5,1X,I4)
C
   35      write(*,*) infile
      pause ' ' 
      STOP
       END

C***********************************************************
