      program corstorm
C.......................................................Apr 2022
C
C Correction of Cat1(KP), Cat2(Kp) to t0(Dstmin)  	
      CHARACTER*128 OUTFILE1,OUTFILE2,INFIDST
C	+,INFILE
C	CHARACTER*1 kpx
	CHARACTER*24 txt1
C//   	infile='catkpstx.txt'  ! Kp storms 1 (Dst<-50) or 2 (Dst <-100)
	outfile1='catdst1.txt'
	outfile2='catdst2.txt'
C
   28 format(A24,2I2,2(1X,I2),1X,I4)
   29 format(1X,F8.3,1X,I3,3(1X,I2),1X,F3.1,1X,I3,1X,I3,2(1X,I4))
   30 format(1X,F8.3,1X,I3,3(1X,I2),1X,I4,1X,I3,3(1X,I2),1X,F3.1
     +,1X,I3,1X,I4)
C       kpx='1'		   !moderate storms
    1	CONTINUE
C      outfile(7:7)=kpx  !
C	infile(8:8)=kpx 
	INFIDST='dststorm94.txt'
C
    7	      OPEN(11,FILE=INFIDST,action='READ')
      OPEN(12,FILE=OUTFILE1)
	OPEN(13,FILE=OUTFILE2)
C	nev=460
C	if (kpx.eq.'2') nev=86
C	if (kpx.eq.'2') nev=107
C
        nout1=0
	nout2=0
	DO 177 iev=1,544
   2	read(11,28,end=26) txt1,kyr,kmn,kdy,kut,kdst
      klda=ndoy(kyr,kmn,kdy)
	if (kyr.lt.30) then
	kyear=2000+kyr
	                else
	kyear=1900+kyr
	endif
		xyear=float(kyear)
		if(int(xyear/4.)*4.eq.kyear) THEN 
 	 dnr=366
	                          ELSE
	dnr=365
	ENDIF
	del=1./dnr
      	ryear=kyear+(klda-1.)*del
C	IF (kpx.eq.'1') THEN 
	 if ((kdst.le.-50).and.(kdst.gt.-100)) then	  !++++++
	nout1=nout1+1

	write(*,30) ryear,klda,kmn,kdy,kut,kdst,nout1
	write(12,30) ryear,klda,kmn,kdy,kut,kdst,nout1
	GOTO 177
	                                   else				 !++++++
C	 if (kdst.le.-100) then	  
	nout2=nout2+1
	write(*,30) ryear,klda,kmn,kdy,kut,kdst,nout2
	write(13,30) ryear,klda,kmn,kdy,kut,kdst,nout2
	 GOTO 177
C	endif
			 	                               endif				 !++++++++
  177 continue
   26 close(11)
      close(12)
	close(13)
C        if (kpx.eq.'1') then
C	kpx='2'
C	goto 1
C	endif
	pause ' '
	STOP
	END
