      program extpeakmon1
C
C............................................................Mar 2022
C Count N(moder),N(intens) from Catalogues Kp,Dst,Wp storms WNT (mon=1,2,11,12),EQN(3,4,9,10),SMR(5,6,7,8)
C
      CHARACTER*64 infile,outfile
C+	+,outkp
C	+,txt
      CHARACTER*1 kps
C	 CHARACTER*18 txt1 ! Wp
C-	 CHARACTER*14 txt1 ! Kp
C	CHARACTER*32 txt2	!Wp
		CHARACTER*20 txt1	!Dst
		CHARACTER*18 txt2	!Dst
C-      CHARACTER*4 AYEAR
	CHARACTER*2 AMN
C+	+,AYR !Kp
C	+,AYR1,AMN1,ADY1,AYR2,AMN2,ADY2,AYR3,AMN3,ADY3
C+	CHARACTER*6 YYMMDD1,YYMMDD2,YYMMDD3 !Kp
C
C      infile='tecstorm_geom.txt' !WP
C      infile='dststorm.txt'  ! Dst
      infile='dststorm94.txt'  ! Dst
CNORM       infile='kpstorm.txt'  !
C++       infile='kpstorm94.txt'  !
	outfile='extcatpeak.txt'
C++	outkp='kpstormfin.txt'
C   30 format(I4,A18,I2,7X,F5.1,A32,1X,I4)	  ! Wp
C   30 format(1X,I4,A21,I2,7X,F5.0,A20)	  ! Dst
C   30 format(1X,I4,A14,I2,6X,F4.1,A11)	  !Kp
	kps='1'
	OPEN(11,file=outfile,access='APPEND')
C++	OPEN(12,file=outkp)
   1	continue
	OPEN(10,file=infile,action='READ')
	if (kps.eq.'1') then
C	thr1=4.8   !WP
C	thr2=6.5   !WP
	thr1=-50.   !Dst
	thr2=-100.   !Dst
C+	thr1=5.0   !Kp
C+	thr2=7.0   !Kp
			else
C	thr1=6.5   !WP
C	thr2=15.0  !WP
	thr1=-100.   !Dst
	thr2=-1000.   !Dst
C+	thr1=7.0   !Kp
C+	thr2=9.1   !Kp
	endif
C	do k=1,8 ! Wp
C	do k=1,11 ! Dst
C-       do k=1,11 ! Kp
C-      read(10,*) txt !extra lines
C-	Ayear=txt(7:10)
C	if (AYEAR.eq.'1994') then	! TEC storms
C	if (AYEAR.eq.'DST5') then	! Dst storms
C	backspace(10)
C	exit
C	endif
C-	enddo
	nwnt=0
	neqn=0
	nsmr=0
	ntot=0
	nstr=0
	iyr_pre=0
C
   30	format(1X,I4,1X,A20,I2,7X,F5.0,2X,A18)  !Dst
C   30	format(1X,I4,1X,A6,1X,I2,2X,A6,1X,I2,1X,F4.1,2X,A6,1X,I2)  !Kp
   2	read(10,30,end=51)ninp,txt1,imn,peak,txt2 ! Wp, Dst
C+   2	read(10,*,end=51)ninp,yymmdd1,iut1,yymmdd2,iut,peak,yymmdd3,iut3 ! Kp
C   2	read(10,*,end=51)ninp,ryymmdd1,iut1,ryymmdd2,iut,peak,ryymmdd3
C     +,iut3
      nstr=nstr+1
CNORM	if (kps.eq.'1') then
CNORM	write(12,30) nstr,yymmdd1,iut1,yymmdd2,iut,peak,yymmdd3,iut3
CNORM	endif
C
C Select events from Jan. 1994:
C+        AYR=yymmdd1(1:2)
C+	read(AYR,*) ryr
C+	iyr=int(ryr)
C+	if ((iyr.gt.30).and.(iyr.lt.94)) then
C+	if (iyr_pre+1.ne.iyr) then
C+	iyr_pre=iyr-1
C+	endif
C+	goto 2
C+	endif
C End select
C+      IF ((peak.lt.thr1).or.(peak.ge.thr2)) GOTO 2  !Wp, Kp
      IF ((peak.gt.thr1).or.(peak.le.thr2)) GOTO 2  !Dst
      ntot=ntot+1
C+	AMN=yymmdd2(3:4) ! Kp
      call blet2(imn,AMN)	  !Dst
C+	read(AMN,*) rmn
C+	imn=int(rmn)

	if ((imn.eq.1).or.(imn.eq.2).or.(imn.eq.11).or.(imn.eq.12)) then
	nwnt=nwnt+1
C	write(*,30) txt1,imn,txt2,nwnt
C	write(11,30) txt1,imn,txt2,nwnt
	endif
	if ((imn.eq.3).or.(imn.eq.4).or.(imn.eq.9).or.(imn.eq.10)) then
	neqn=neqn+1
C	write(*,30) txt1,imn,txt2,neqn
C	write(12,30) txt1,imn,txt2,neqn
	endif
	if ((imn.eq.5).or.(imn.eq.6).or.(imn.eq.7).or.(imn.eq.8)) then
	nsmr=nsmr+1
C	write(*,30) txt1,imn,txt2,nsmr
C	write(13,30) txt1,imn,txt2,nsmr
	endif
	goto 2
   51 close(10)
      close(12)
      write(*,33) nwnt,neqn,nsmr,ntot,nstr,kps
	write(11,33) nwnt,neqn,nsmr,ntot,nstr,kps
C
   33	format(5(1X,I5),1X,A1)
      if (kps.eq.'1') then
	kps='2'
	goto 1
	endif
      close(11)
	pause ' '
	STOP
	END
