C........................................................Oct 2023
C Produce catalog Apo-peak / at day&UT of AE peak month, Apomax(month) 1995-2023.06
C
C
      PROGRAM extpeakapomnal
C
C----------------------------------------------------------------
C
C
      CHARACTER*128 INFILE,outfile,infhssmn  !
		 CHARACTER*2 AMN,ADY,AUT
C	CHARACTER*4 AYEAR
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
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\Hpo\Hpo19952023.txt' ! total file for 1995-2023 Apo(tauy6)
	infhssmn='cataepeakmn.txt'		!288 values 
	outfile='catapopeakmnal.txt'
C
C Start 
C
C
    7	OPEN(11,FILE=OUTFILE)
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(I4,3(1X,I2),41X,F4.0)	 ! hourly Apo

C
	open(10,file=infile,action='READ')
	open(15,file=infhssmn,action='READ')
C
	nn=0
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
         DO 177 iev=1,288
	read(15,*,end=101) xyear,lda,kmn,kdy,kut,aemax,nae
	kyear=int(xyear)
        apmax=0.

c	mon=1
    1	CONTINUE
    2  read(10,36,end=102) iyear,iMN,iDY,iUT,apo
C?      ryear=float(iyear)
C
C Select monthly peak Apo(tau6)
	IF ((kyear.eq.iyear).and.(imn.eq.kmn).and.(idy.eq.kdy)) THEN   !+1
C	+.and.(iut.eq.kut)) THEN           !
C^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	    if (apo.gt.apmax) then			 !2
	apmax=apo
	iyearmax=iyear
	imnmax=imn
	idymax=idy
	iutmax=iut
	GOTO 1
		               else					  !2
	 GOTO 1
	               endif				  !2
Cvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
	                  ELSE						   !1
	IF (apmax.gt.0.) THEN                 !3
c	backspace(10)
c	mon=mon+1
c	if (mon.gt.12) mon=1
C
C        call blet4(iyearmax,AYEAR)
      call blet2(imnmax,AMN)
	call blet2(idymax,ADY)
	call blet2(iutmax,AUT)
C--	 iyear=int(ryearmax)
c	iyr=iyearmax-iyearmax/100*100
C
c	lda=ndoy(iyr,imnmax,idymax) ! 
c		year1=float(iyearmax)
c	if(int(year1/4.)*4.eq.iyearmax) THEN 
c	dnyr=366
c	                          ELSE
c	dnyr=365
c	ENDIF
c       del=1./dnyr
c	ryearmax=year1+(lda-1)*del
C
C Output Catalog
	nn=nn+1
      write(*,37) xyear,lda,AMN,ADY,AUT,apmax,nn
      write(11,37) xyear,lda,AMN,ADY,AUT,apmax,nn
		 apmax=0.
       GOTO 177
	                    ELSE                !3
	GOTO 1
	                  ENDIF					!3
	                                      ENDIF        !1
  177	CONTINUE
  101    close(unit=15)
  102 close(unit=10)
      close(unit=11)

C
   37	format(1X,F8.3,1X,I3,3(1X,A2),1X,F5.0,1X,I4)
C
   35      write(*,*) infile
      pause ' ' 
      STOP
       END

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