C ========================================================
C 
      subroutine SUBIONKA2ac(cday,if2,im3,ih2)
C..........................................................Aug. 2018
C include CBK map
C..........................................................Jan. 2012
C----------------------------------------------------------------
C outfile1='c:/web/graf/2011/ns11f.br'
C outfile2='c:/web/graf/2011/ns11h.br'
C outfile3='c:/web/graf/2011/ns11m.br'
C
C program for extracting foF2, M3000F2 and hmF2=0 from IONKA daily files 
C
C*********TEST
C 
	CHARACTER*128 OUTFILE1,OUTFILE3,XXX,INFILE,TXT
	+,OUTFILE2
	CHARACTER*2 AMN,AYR,DY1,DY2,DDD,M3,CYR,CMN,CDY,CDAY(0:31)
	+,ST,DD1,DD2,DY22,AUT
	CHARACTER*4 YEAR
	CHARACTER*3 AFF2,AMF3
	CHARACTER*30 STNAME
      CHARACTER(5) af2(0:23),am3(0:23),ah2(0:23),ZZ
      DIMENSION IF2(31,0:23),IM3(31,0:23),IH2(31,0:23)
	+,xf2(0:23),xm3(0:23),xhm(0:23)
	INTEGER*2 ID1,ID2,jd,iut
	CHARACTER*13 STAT
	CHARACTER(10) DD
	COMMON /BL1/ST,YEAR,AYR,AMN,DY1,DY2,DD1,DD2,ID1,ID2,JF,JH,JT,DY22
 	+,STNAME
		COMMON /BL2/ STAT,GLAT,GLON,DD,TTT,ZZ,R12
C
cc=	WRITE(*,*) 'Enter DY1, DY2 '
cc=	read(*,33) DY1,DY2
   33 format(A2)
	read(dy1,*) rdy1
	idy1=int(rdy1)
	read(dy2,*) rdy2
 	idy2=int(rdy2)

c	st='ns' ! Novosibirsk

cc=      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',ctime

C
  	infile='c:/web/grif/NS/yrmndy.txt'
	infile(16:17)=ayr
	infile(18:19)=amn
C
	ii=0
	outfile1='c:/web/graf/2011/ns11f.br'
	outfile1(15:16)=ayr
	outfile1(20:21)=ayr
	outfile2=outfile1
	outfile2(22:22)='h'
	outfile3=outfile1
	outfile3(22:22)='m'
C
	OPEN(21,FILE=OUTFILE1)  ! foF2
	OPEN(22,FILE=OUTFILE2)	! hmF2
	OPEN(23,FILE=OUTFILE3)	! M3000
C
C Add reading outfile1, 2, 3 prior given day
C
  333 FORMAT(A128)
      icount=0

   55 READ(21, 333, END=44) TXT		  ! foF2
       CYR=TXT(1:2)
	CMN=TXT(3:4)
	CDY=TXT(5:6)
	if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.dy1)) then
 	goto 44
	                  else
         icount=icount+1
      GOTO 55
      CONTINUE
                  	endif
   44 mf_strings = icount
C     print*,'Strings in m_file:',m_strings
      REWIND (21)
      icount=0
C
      do while (icount.lt.mf_strings)
         READ(21, 333, END=444) TXT 	  ! foF2
         icount=icount+1
      enddo
  444 print*,'YES!'
      ENDFILE 21
      close(UNIT=21)
CCC
C  M3000
	icount=0
  155 READ(23,333,END=144) txt
 	CYR=txt(1:2)
	CMN=txt(3:4)
	CDY=txt(5:6)
	if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.dy1)) then  
	goto 144
	                  else
		icount=icount+1
      GOTO 155
      CONTINUE
                  	endif
  144 mm_strings = icount
       REWIND (23)
c
      icount=0
	do while (icount.lt.mm_strings)
         READ(23, 333, END=248) TXT 		   ! M3F2
         icount=icount+1
      enddo
  248 print*,'YES!'
      ENDFILE 23
      close(UNIT=23)
CCC
C hmF2
	icount=0
  255 READ(22,333,END=244) txt
 	CYR=txt(1:2)
	CMN=txt(3:4)
	CDY=txt(5:6)
	if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.dy1)) then  
	goto 244
	                  else
         icount=icount+1
      GOTO 255
      CONTINUE
                  	endif
  244 mh_strings = icount
       REWIND (22)
      icount=0
      do while (icount.lt.mh_strings)
         READ(22, 333, END=446) txt	! remenber prec_DY1 lime
         icount=icount+1
      enddo
  446 print*,'YES!'
      ENDFILE 22
      close(UNIT=22)

     	 	OPEN(21,FILE=OUTFILE1,access='APPEND')
	OPEN(22,FILE=OUTFILE2,access='APPEND')
	OPEN(23,FILE=OUTFILE3,access='APPEND')

C
 100	continue
		alat=54.6
 	along=83.2
c-	xmagbr=58.7

   1	do 77 jd=idy1,idy2               ! cycle day-by-day
     	do k=0,23
 	if2(jd,k)=0
	ih2(jd,k)=0
 	im3(jd,k)=0
	enddo

   	jdy=jd
	call blet2(jd,DDD)
		CDAY(JD)=DDD 
	infile(20:21)=DDD
C
	OPEN(20,FILE=INFILE)
	read(20,333) XXX			  ! title line
  35  format(1X,I2,3X,A3,3X,A2) 
C
	do k=0,23
	af2(k)=' 00  '
	ah2(k)='000  '
	am3(k)='000  '
	enddo
 		
c  200	jcnt1=0
c      jcnt2=0
       AFF2='000'
	 AMF3='000'
	ZZ='     '
	kk=0
      do 141 k=0,23
  198	READ (20,35,END=195,ERR=211) iut,AFF2,M3
C	if(AFF2(1:1).eq.'/') AFF2='000'
	if(AFF2(1:1).eq.'/') THEN
	call blet2(iut,AUT)
	call subintereuc(glat,glon,ayr,amn,ddd,aut,cbkf)
 	icbkf=nint(cbkf*10.)
 	call blet3(icbkf,AFF2)
      ZZ(1:3)=AFF2
	ZZ(4:4)='_'
	af2(k)=ZZ
	ENDIF
	if(M3(1:1).eq.'/') M3='00'
	AMF3(1:2)=M3
      IF(ZZ(4:4).ne.'_')	af2(k)=AFF2
	am3(k)=AMF3
	read(AFF2,*) rf
	xf2(k)=rf/10.
	if2(jd,k)=nint(rf)
C      IF(ZZ(4:4).eq.'_') if2(jd,k)=ZZ
	read(AMF3,*) rm
	xm3(k)=rm/100.
 	im3(jd,k)=nint(rm)
	xhm(k)=0.
	kk=kk+1
 141	continue
 195	close(unit=20)

C calculate hmF2
	call subhmf2(alat,along,jd,xf2,xm3,xhm)
	do k=0,23
	ihmf2=nint(xhm(k))
	IH2(jd,k)=ihmF2
	enddo
C  OUTPUT daily data:
C==
c==      do m=1,24

	write(21,37) ayr,amn,ddd,(if2(jd,k),k=0,23)
	write(*,37) ayr,amn,ddd,(if2(jd,k),k=0,23)
	write(22,37) ayr,amn,ddd,(ih2(jd,k),k=0,23)
	write(*,37) ayr,amn,ddd,(ih2(jd,k),k=0,23)
		write(23,37) ayr,amn,ddd,(im3(jd,k),k=0,23)
	write(*,37) ayr,amn,ddd,(im3(jd,k),k=0,23)

   37	format(3A2,2X,24(I3,2X))
C
C
C
  77  continue         ! end cycle day-to-day
	close(unit=21)
	close(unit=22)
	close(unit=23)
C
C
	goto 210
C
 211  write(*,*) 'Error in input datafile:',infile
      pause ' '
	goto 210
 210	CONTINUE
C	
C		pause ' '
C      STOP
       return
       END
