	program extpch3
c .......................................................Dec 2019
C Separate to 3 classes: Minor, Moderate, Intence storms
C
C for 2011-2019
C
c
c	DIMENSION ryears(303),del(303),ivsw(303),IAE(303),iaa(303)
c	+,iap(303),fx(500),fy(500),ifx(500),ify(500)
c     +,IDST(303),wp(303),iarn(303),iarp(303),iann(303),ianp(303)
c      INTEGER*2 lag(303,10)
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*128,infile,outfile1,outfile2,outfile3,txt
c	CHARACTER*2 AMD(303,2)
	CHARACTER*80 txt1
	CHARACTER*45 txt2
C
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
      outfile1='extpchdst1.res' !  Minor storms Dst [-30:-50)
	outfile2='extpchdst2.res' !  Moderate storms Dst [-50:-100)
	outfile3='extpchdst3.res' !  Intense storms Dst <=-100
      
	OPEN(11,FILE=OUTFILE1)		! 
	OPEN(12,FILE=OUTFILE2)		! 
	OPEN(13,FILE=OUTFILE3)		! 
C
C Year    MN DD  Pchmin  Pchmax  delPch  d Vswmax  d AEmax  d aamax  d apmax  d Dstmin d Wpmax nn  d ICME
C 2011.211  3 19  235.94  446.21  210.27  4   516  4   587  4    45  3    18  3   -17  4  3.7    1
   36	format(A80,I4,A45)
C Year     MN DD  Pchmin  Pchmax  delPch +d   ARn +d   ARp +d   ANn +d   ANp   nn
C 2011.211  3 19  235.94  446.21  210.27  5   159  1   119  3   240  4   265    1
   37	format(A80,I4,A45,1X,I3)
   30	format(A128)
C
      	infile='catpch1thr.res' ! Pch
		OPEN(10,FILE=infile,ACTION='READ')
	read(10,30) txt !~ title line
	write(11,30) txt
	write(12,30) txt
	write(13,30) txt
      icnt1=0
	icnt2=0
	icnt3=0
C
 	icntot=0 ! count of dPch
	do 101 ii=1,303
	read(10,36,end=102) txt1,idst,txt2
      icntot=icntot+1
	if ((idst.le.-30).and.(idst.gt.-50)) then
	icnt1=icnt1+1
	write(*,37)  txt1,idst,txt2,icnt1
	write(11,37)  txt1,idst,txt2,icnt1
	goto 101
	endif
	if ((idst.le.-50).and.(idst.gt.-100)) then
	icnt2=icnt2+1
	write(*,37)  txt1,idst,txt2,icnt2
	write(12,37)  txt1,idst,txt2,icnt2
	goto 101
	endif
	if (idst.le.-100) then
	icnt3=icnt3+1
	write(*,37)  txt1,idst,txt2,icnt3
	write(13,37)  txt1,idst,txt2,icnt3
	endif
  101	CONTINUE
  102  CLOSE(unit=10)
      CLOSE(unit=11)
      CLOSE(unit=12)
      close(unit=13)
  900 pause ' '
      STOP
      END

