      program extreuv2n
C........................................................Sep. 2016
C Extract EUV (1) 26 - 34 nm flux; (2) 0.1 - 50 nm flux 
C Add SSN1 and SSN2 excluding missed EUV (=0.0) days
C Filled gaps in EUV data by regressions with MgII index:
C   euv1=109.9796*mg2 -15.6095 input file:euvtot1mgn.txt   
C   euv2=229.4961*mg2 -32.7736 input file:euvtot2mgn.txt
	CHARACTER*90 OUTFILE,infile,infile1,infile2
	CHARACTER*4 AYEAR,CYEAR
	CHARACTER*2 AYR,AMN,ADY,cmn,cdy
	CHARACTER*1 OPT
	 dimension im(12)
	DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
  15	FORMAT(A4)
  16	FORMAT(A1)
C-  201	      WRITE(*,*)' ENTER year: '
C-		READ(*,15) AYEAR
C
C-	opt='1'			!TEMP
	opt='2'			!TEMP

	outfile='euvtot1n.txt'
	outfile(7:7)=opt
C-	outfile='euvtot2n.txt'

	OPEN(10,file=outfile,access='APPEND')
	infile1='ssn1.txt'
	infile2='ssn2.txt'
	OPEN(11,file=infile1,action='READ')
	OPEN(12,file=infile2,action='READ')
       infile='euvtot1mgn.txt'
	infile(7:7)=opt
COLD      infile(16:19)=AYEAR

	OPEN(13,file=infile,action='READ')
C  Cycle on years			   +++++++++++++++++++++++++++++++++
	DO 201 iyear=1996,2016
	call blet4(iyear,AYEAR)
      write(*,*) ayear
C
	AYR=AYEAR(3:4)
	read(ayr,*) ryr
	iyr=int(ryr)
	if(int(ryr/4.)*4.eq.iyr) THEN 
	im(2)=29
	ndnr=366
	                          ELSE
	IM(2)=28
	ndnr=365
	ENDIF
C
CREM	infile='d:\apkp\euv\euvYEAR-1.txt'	! or -1.txt
COLD	infile='d:\apkp\euv\euvYEAR-2.txt'	! or -2.txt
C
C day-to-day cycle
      DO 222 lda=1,ndnr  !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	call submmdd(lda,iyr,imn,idy)
	call blet2(imn,AMN)
	call blet2(idy,ADY)

	read(13,17,end=223) CYEAR,CMN,CDY,res
	read(11,18,end=224) CYEAR,JMN,JDY,issn1
	goto 225
  224	issn1=-1
  225	read(12,19,end=226) CYEAR,KMN,KDY,issn2
      goto 227
  226	issn2=-1
  227 continue
	if (issn1.eq.-1) then
	issn1=nint(0.6926*issn2-0.2452)
	if (issn1.lt.0) issn1=0
	endif
	if (res.eq.0.0) then
	GOTO 222
	                else
	write(*,20) CYEAR,CMN,CDY,res,issn1,issn2
	write(10,20) CYEAR,CMN,CDY,res,issn1,issn2
	endif
  222	continue	!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
201	continue           ! next year
  223 close(unit=13)
   17	format(1X,A4,2A2,1X,F9.5)
   18	format(A4,2I2,10X,I4)
   19	format(A4,2(1X,I2),10X,I4)
   20	format(1X,A4,2A2,1X,F9.5,2(1X,I4))
      pause ' '
	stop
	END
