      program extMgssn0
C...............................................................Sep 2021
C Extract MgII for SSN=0 1983-2021
C
	CHARACTER*2 AYR,AMN,ADY,BMN,BDY
	CHARACTER*64 outfile,infileMg
	+,infile
      CHARACTER*4 AYEAR,BYEAR
c-	CHARACTER*8 YYYYMMDD
C
      infileMg='MgII.dat'
	      OPEN(10,file=infileMg,action='READ')
		  infile='extf107ssn0.txt'  ! List of ~4000(SSN=0) days 1950-2021
	      OPEN(11,file=infile,action='READ')
	outfile='extMgssn0.txt'
       OPEN(12,file=outfile)
C
   31	format(1X,I4,1X,F8.3,2(1X,A2),2X,F9.7)
   32	format(1X,A4,2A2,2X,F9.7)
   30	format(2X,A4,7X,A2,1X,A2,1X,F7.5)
C cycle of SSN=0 days
      nn=0
	nout=0
         DO 150 iev=1,4000
    2	read(11,33,end=52) nn,ryear,amn,ady,f107 ! day of SSN=0
	iyear=int(ryear)
	if (iyear.lt.1983) goto 2  !+++++++++++++++++
C
      iyr=iyear-iyear/100*100
	call blet4(iyear,AYEAR)
	AYR=AYEAR(3:4)
C
    1	read(10,30,end=52) byear,bmn,bdy,alpha		   ! MgII
C    1	read(10,*,end=52) YYYYMMDD,alpha,icnt
c-      BYEAR=YYYYMMDD(1:4)
c-	BMN=YYYYMMDD(5:6)
c-	BDY=YYYYMMDD(7:8)
      if ((AYEAR.eq.BYEAR).and.(AMN.eq.BMN).and.(ADY.eq.BDY)) then
	GOTO 55
	                                   else
	GOTO 1
	                                  endif
   55 CONTINUE
      nout=nout+1
      write(*,31) nout,ryear,amn,ady,alpha
      write(12,31) nout,ryear,amn,ady,alpha
  150	continue
   52	close(unit=11)
      close(unit=10)
C
    3	close(unit=12)
	
   33	format(1X,I4,1X,F8.3,2(1X,A2),1X,F6.2)
      pause ' '
	STOP
	END
