      program extpeakmon2
C
C............................................................Apr 2022
C
C Count N(moder),N(intens) from Catalogues Dst,Wp storms WNT (mon=1,2,11,12),EQN(3,4,9,10),SMR(5,6,7,8)
C
      CHARACTER*64 infile,outwnt,outeqn,outsmr
      CHARACTER*1 kps
C-      CHARACTER*4 AYEAR
C-	CHARACTER*2 AMN
C
      infile='catdstxa.res'  ! Dst
	outwnt='catwntxa.txt'
	outeqn='cateqnxa.txt'
	outsmr='catsmrxa.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'
   1	continue
      infile(7:7)=kps
	outwnt(7:7)=kps
	outeqn(7:7)=kps
	outsmr(7:7)=kps
	OPEN(10,file=infile,action='READ')
	OPEN(11,file=outwnt)
	OPEN(12,file=outeqn)
	OPEN(13,file=outsmr)
C
	nwnt=0
	neqn=0
	nsmr=0
	ntot=0
	nstr=0
	iyr_pre=0
C
  138 format(1X,F8.3,1X,I3,3(1X,I2),1X,I4,1X,I3,1X,F3.1		!Dst,Kp,ap,aa,Wp
     +,2(1X,I3,1X,I3),1X,I3,1X,F4.1,9(1X,I3,1X,F5.2),1X,I4) ! 3(WU,WL,WE)
    2	read(10,138,end=51) ryear1,lda1,imn,idy1,iut1,idstpeak
 	+,iutkp,xkpmax,iutap,iapmax,iutaa,iaamax,iutwp,wpmax
     +,iutwum,wumaxm,iutwlm,wlminm,iutwem,wemaxm
	+,iutwun,wumaxn,iutwln,wlminn,iutwen,wemaxn
	+,iutwus,wumaxs,iutwls,wlmins,iutwes,wemaxs
     +,ninp

      nstr=nstr+1
C
	if ((imn.eq.1).or.(imn.eq.2).or.(imn.eq.11).or.(imn.eq.12)) then
	nwnt=nwnt+1
	write(*,138)  ryear1,lda1,imn,idy1,iut1,idstpeak
 	+,iutkp,xkpmax,iutap,iapmax,iutaa,iaamax,iutwp,wpmax
     +,iutwum,wumaxm,iutwlm,wlminm,iutwem,wemaxm
	+,iutwun,wumaxn,iutwln,wlminn,iutwen,wemaxn
	+,iutwus,wumaxs,iutwls,wlmins,iutwes,wemaxs,nwnt
	write(11,138)  ryear1,lda1,imn,idy1,iut1,idstpeak
 	+,iutkp,xkpmax,iutap,iapmax,iutaa,iaamax,iutwp,wpmax
     +,iutwum,wumaxm,iutwlm,wlminm,iutwem,wemaxm
	+,iutwun,wumaxn,iutwln,wlminn,iutwen,wemaxn
	+,iutwus,wumaxs,iutwls,wlmins,iutwes,wemaxs,nwnt
     	endif
	if ((imn.eq.3).or.(imn.eq.4).or.(imn.eq.9).or.(imn.eq.10)) then
	neqn=neqn+1
	write(*,138)  ryear1,lda1,imn,idy1,iut1,idstpeak
 	+,iutkp,xkpmax,iutap,iapmax,iutaa,iaamax,iutwp,wpmax
     +,iutwum,wumaxm,iutwlm,wlminm,iutwem,wemaxm
	+,iutwun,wumaxn,iutwln,wlminn,iutwen,wemaxn
	+,iutwus,wumaxs,iutwls,wlmins,iutwes,wemaxs,neqn
	write(12,138)  ryear1,lda1,imn,idy1,iut1,idstpeak
 	+,iutkp,xkpmax,iutap,iapmax,iutaa,iaamax,iutwp,wpmax
     +,iutwum,wumaxm,iutwlm,wlminm,iutwem,wemaxm
	+,iutwun,wumaxn,iutwln,wlminn,iutwen,wemaxn
	+,iutwus,wumaxs,iutwls,wlmins,iutwes,wemaxs,neqn
     	endif
	if ((imn.eq.5).or.(imn.eq.6).or.(imn.eq.7).or.(imn.eq.8)) then
	nsmr=nsmr+1
	write(*,138)  ryear1,lda1,imn,idy1,iut1,idstpeak
 	+,iutkp,xkpmax,iutap,iapmax,iutaa,iaamax,iutwp,wpmax
     +,iutwum,wumaxm,iutwlm,wlminm,iutwem,wemaxm
	+,iutwun,wumaxn,iutwln,wlminn,iutwen,wemaxn
	+,iutwus,wumaxs,iutwls,wlmins,iutwes,wemaxs,nsmr
	write(13,138)  ryear1,lda1,imn,idy1,iut1,idstpeak
 	+,iutkp,xkpmax,iutap,iapmax,iutaa,iaamax,iutwp,wpmax
     +,iutwum,wumaxm,iutwlm,wlminm,iutwem,wemaxm
	+,iutwun,wumaxn,iutwln,wlminn,iutwen,wemaxn
	+,iutwus,wumaxs,iutwls,wlmins,iutwes,wemaxs,nsmr
	endif
	goto 2
   51 close(10)
      close(11)
	close(12)
	close(13)
      write(*,33) nwnt,neqn,nsmr,ntot,nstr,kps
C	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
c     close(11)
	pause ' '
	STOP
	END
