      program extdstmin
C.................................................July 2022
C Extract peak of Dst storms + SSN2 1995-2022
C
	CHARACTER*45 INFILE,infiles
	CHARACTER*25 OUTFILE
	CHARACTER*2 AMN,ADY
	infile='dststorms.txt'   ! Apmax >48 , Hpo >5.0
	infiles='SSN2d.txt'
	outfile='dststorms.dat'
C
	OPEN(10,file=infile,action='READ')
	OPEN(11,file=infiles,action='READ')
      OPEN(12,file=outfile)
C
  170	FORMAT(1X,I4,19X,2I2,2(1X,I2),1X,I4)
  171	FORMAT(I4,2(1X,I2),1X,F8.3,1X,I4)
  172	FORMAT(1X,F8.3,2(1X,A2),1X,I2,3(1X,I4))
C
       nout=0
       DO 101 iev=1,924
	read(10,170,end=50) ICNT,iyr,imn,idy,iut,IDST
	if (iyr.gt.40) then
	iyear=1900+iyr
	else
	iyear=2000+iyr
	endif
C
   1	read(11,171,end=51) kyear,kmn,kdy,ryear,issn
	IF((iyear.eq.kyear).and.(imn.eq.kmn).and.(idy.eq.kdy)) THEN
	call blet2(imn,AMN)
	call blet2(idy,ADY)
	nout=nout+1
      write(*,172) ryear,AMN,ADY,iut,IDST,issn,nout
	write(12,172) ryear,AMN,ADY,iut,IDST,issn,nout
        GOTO 101
	                         ELSE
	goto 1
	  ENDIF
  101	CONTINUE
  50  close(10)
  51  close(11)
      close(12)
	pause ' '
	STOP
	END
