      program lagApotau6sd
C..............................................................June 2023
C Input: Apotau6.txt
C Extract Cat-storms peaks with Apo(tau6) >= 100 nt
C
C
      CHARACTER*64 infile,outfile
	CHARACTER*2 AMN,ADY,AUT,AUT_max,ADY_max,AMN_max
     +,AMN_pre,ADY_pre,AUT_pre
C
C	
C	infile='Apotau6.txt'                ! read(10
       infile='Catapotau6st.txt'
	outfile='Catapotau6.txt'			   !
   30	format(1X,F8.3,1X,I3,3(1X,A2),2X,F7.2,1X,I4)
   31	format(1X,F9.4,3(1X,I2),2X,F5.0,2X,F6.2)
C
       OPEN(10,file=infile,action='READ')
       OPEN(14,file=outfile,access='APPEND')
C
C
C
	ndy=0	!norm
C
C++        DO iyear=1994,2023  ! years
C 
C Apo(tau6)
	iut_pre=-1
	aptaumax=0.
	AUT_max='  '
	ADY_max='  '
	AMN_max='  '
	AUT_pre='  '
	ADY_pre='  '
	AMN_pre='  '
	lda_pre=97
	aptau_pre=0.0
	lda_max=0
	RYEAR_pre=1995.0000
	RYEAR_max=1995.0000
C    1	read(10,31,end=50) ryear,imn,idy,iut,apo,aptau
    1	read(10,*,end=50) ryear,lda,imn,idy,iut,aptau
C-  101	continue
	iyear=int(ryear)
	iyr=iyear-iyear/100*100
	call blet2(imn,AMN)
	call blet2(idy,ADY)
	call blet2(iut,AUT)
C	
       IF (lda.ne.lda_pre) THEN       !+
	AUT_max=AUT_pre
	aptamax=aptau_pre
	AMN_max=AMN_pre
	ADY_max=ADY_pre
	lda_max=lda_pre
	RYEAR_max=RYEAR_pre
        GOTO 2
	ENDIF
C
	    IF (lda.eq.lda_pre) THEN       !+
              	IF (aptau.gt.aptaumax) THEN !++
	aptaumax=aptau
	AUT_max=AUT
	AMN_max=AMN
	ADY_max=ADY
	lda_max=lda
	RYEAR_max=RYEAR
           GOTO 3
	                                   ELSE	 !++
	AUT_max=AUT_pre
	aptamax=aptau_pre
	AMN_max=AMN_pre
	ADY_max=ADY_pre
	lda_max=lda_pre
	RYEAR_max=RYEAR_pre
	     GOTO 3
	               ENDIF				!++
	                               ELSE !+
	aptaumax=aptau
	AUT_max=AUT
	AMN_max=AMN
	ADY_max=ADY
      lda_max=lda
      RYEAR_max=RYEAR
	      GOTO 3
	ENDIF                         !+
C
C Output
C-   2  if (lda_max-lda_pre.gt.2) then 
   2   ndy=ndy+1
C-	endif
      write(*,30) ryear_max,lda_max,amn_max,ady_max,aut_max,aptaumax,ndy
	write(14,30) ryear_max,lda_max,amn_max,ady_max,aut_max,aptaumax
	+,ndy
	lda_pre=lda	  
		AMN_pre=AMN
			ADY_pre=ADY
				AUT_pre=AUT
	aptau_pre=aptau
	aptaumax=aptau
	RYEAR_max=RYEAR
	RYEAR_pre=RYEAR
	GOTO 1
	           
   3	lda_pre=lda_max
	AMN_pre=AMN_max
	ADY_pre=ADY_max
	AUT_pre=AUT_max
	aptau_pre=aptaumax
	RYEAR_pre=RYEAR_max
	goto 1
C
C
   50	close(10)
C
   	close(unit=14)
	pause ' '
	STOP
	END