C........................................................Aug 2023
C SSN2_27, F107_27, Lyman-a_27, MgII_27 peak
C........................................................
C Produce catalog SSN2_27, COV_27, Ly-a_27, MgII_27
C
C........................................................Mar. 2023
C 
C t0 at Apo(tau6) >=90nT storm peak
C
C 
C Select period of 48hrs starting from t0-12h, ending t0+35h; 
C 
      PROGRAM extsn27cvlymg90
C Input HSSUT.txt 1995-2023...........................Jan 2020
C
C----------------------------------------------------------------
C
C
      CHARACTER*128 INFILES,INFILEF,INFILEL,INFILEM,INFHSS
	+,outfile  !
		 CHARACTER*2 AMN,ADY,AUT
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
C
      ICALLS=0
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
C
	infiles='ssn2d27tau.txt' !SSN2_27 total file for 1995-2023: 90 Apo(tau6)-storms 
	infilef='ssn1cv27tau.txt' !F10.7_27 total file for 1995-2023: 90 Apo(tau6)-storms 
	infilel='lyman27tau.txt' !Lymaqn-a_27 total file for 1995-2023: 90 Apo(tau6)-storms 
	infilem='MgIId27tau.txt' !MgII_27 total file for 1995-2023: 90 Apo(tau6)-storms 
  	infhss='catapo6mn90.txt'  ! Apo 90 storms Apo>=90 nT + GECav-pre-storm 24hrs
	outfile='catsn27cvlymg90.txt'
C
C Start 
C
    1	CONTINUE
C
    7	OPEN(11,FILE=OUTFILE)
C
   28 format(1X,F8.3,1X,I3,3(1X,I2),1X,F5.0,1X,I3)
   29 format(A20,1X,I4,3(1X,I2),1X,F5.0)
   30  format(I4,2I2,2(1X,F5.1))			  !ssn1,cov27
   31  format(I4,2I2,1X,F10.8)			  !Lyman-a_27
   32  format(I4,2I2,1X,F7.5)			  !MgII_27
C
	open(10,file=infhss,action='READ')
	open(12,file=infiles,action='READ') ! SSN
	open(13,file=infilef,action='READ') ! SSN
	open(14,file=infilel,action='READ') ! SSN
	open(15,file=infilem,action='READ') ! SSN
C
C
C Cycle on events ====================================================
C
       	nev=90 ! intense Apo(tau6)>=90 nT monthly peak storms	
C
	DO 177 iev=1,nev
      read(10,28,end=27) xyear,lda1,imn1,idy1,iut1,aep,ninp
	iyear=int(xyear)
   41	read(12,*,end=103) ryear,kmns,kdys,ssn2tau				   ! 
      kyears=int(ryear)
	if ((kyears.eq.iyear).and.(kmns.eq.imn1).and.(kdys.eq.idy1)) then
	goto 42
	else
	goto 41
	endif
   42 read(13,30,end=104) kyearf,kmnf,kdyf,ssn1,covtau				   ! 
	if ((kyearf.eq.iyear).and.(kmnf.eq.imn1).and.(kdyf.eq.idy1)) then
	goto 43
	else
	goto 42
	endif
   43	read(14,31,end=105) kyearl,kmnl,kdyl,alymtau				   ! 
   	if ((kyearl.eq.iyear).and.(kmnl.eq.imn1).and.(kdyl.eq.idy1)) then
		goto 44
			else
				goto 43
					endif
   44	read(15,32,end=106) kyearm,kmnm,kdym,amgtau				   ! 
   	if ((kyearm.eq.iyear).and.(kmnm.eq.imn1).and.(kdym.eq.idy1)) then
		goto 45
			else
				goto 44
					endif
C
   45    call blet2(imn1,AMN)
	call blet2(idy1,ADY)
	call blet2(iut1,AUT)
C
C
C Output catalog
C   
 333  write(*,37) ryear,lda1,AMN,ADY,AUT,aep,ssn2tau,covtau,alymtau
     +,amgtau,iev
      write(11,37) ryear,lda1,AMN,ADY,AUT,aep,ssn2tau,covtau,alymtau
	+,amgtau,iev
  177	CONTINUE
   27 close(unit=10)
  103    close(unit=12)
  104	close(unit=13)
  105	close(unit=14)
  106	close(unit=15)
    	close(unit=11)
C
   37	format(1X,F8.3,1X,I3,3(1X,A2),1X,F5.0,2(1X,F5.1),F10.8,F7.5
     +,1X,I3)
C
   35      write(*,*) infilef
      pause ' ' 
      STOP
       END

C***********************************************************
