	program exticmessc
C....................................................May 2016
C Correct ICME Catalogue by including SSC events
C
c
	integer imn,kut1
	dimension IM(12)
	+,cmut(415)
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*65 infile1,infile2,outfile
	CHARACTER*2 AMN,AYR,ADY,AUT,BMN(415),BDY(415)
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/ 
	CHARACTER*4 AYEAR,BYEAR(415)
C
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C

	outfile='listicme2.txt'  !  ICME 1999
	OPEN(11,FILE=OUTFILE)
   36 format(1X,I4,A1)
	iev=0
C
      infile1='listicme1.txt'
	OPEN(20,file=infile1,action='READ')
C
      infile2='ssc1.dat'
	OPEN(10,file=infile2,action='READ')
C
  100	icntots=0

   34	format(I4,2(1X,I2),1X,2(I2))	 ! SSC
   35	format(A4,2(1X,A2),1X,F5.2)  !ICME
C
C+
	iev=0
	issc=0
	do jj=1,415
  	read(20,35,end=27,err=2) BYEAR(jj),BMN(jj),BDY(jj),CMUT(jj)
	enddo
   27	close(unit=20)
C
C Cycle on ICME events
C
	DO 399 jj=1,415
	 AYEAR=BYEAR(jj)
	read(AYEAR,*) ryear
	iyear=int(ryear)
	AMN=BMN(jj)
	ADY=BDY(jj)
	UT1=CMUT(jj)
C
	AYR=AYEAR(3:4)
	read(ayr,*) ryr
 	iyr=int(ryr)
	read(amn,*) rmn
 	imn=int(rmn)
	read(ady,*) rdy
 	idy=int(rdy)
		if(int(ryr/4.)*4.eq.iyr) THEN 
		 im(2)=29
	ndr=366
	                          ELSE
	IM(2)=28
	ndr=365
	ENDIF
C
C
       kut1=nint(ut2)
	call blet2(kut1,AUT)

C
  101	read(10,34,end=428,err=2) KYEAR,KMN,KDY,KUT,KMIN
	issc=issc+1
	utssc=kut+kmin/60.
	kyr=KYEAR-KYEAR/100*100
	delut=utssc-ut1
C
	if (kyear.lt.iyear) goto 101 
      if (kyear.gt.iyear) goto 399

      IF ((kyear.eq.iyear).and.(kmn.eq.imn).and.(kdy.eq.idy).and.
	+(delut.gt.-0.1)) then
	iev=iev+1
	write(*,33) AYEAR,AMN,ADY,UT1,UTSSC,DELUT
	write(11,33) AYEAR,AMN,ADY,UT1,UTSSC,DELUT
	goto 399
	          ELSE
      ldajj=ndoy(iyr,imn,idy)
	ldasc=ndoy(kyr,kmn,kdy)
	if (ldasc.le.ldajj) then 
	goto 101
	else
	backspace(10)
	issc=issc-1
	goto 399
	endif
	          ENDIF
C
C
  399 continue	! end of cycle on ICME events

  428	CONTINUE
C
c
      close(unit=11)
	close(unit=10)
C
   33 format(1X,A4,2A2,2(1X,F5.2),1X,F6.2)
C
C	
	write(*,*) AYEAR,iev,issc
	goto 900
    2 CONTINUE
           write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
  900 pause ' '
      STOP
      END

