      subroutine subdatngdcfhc(st,AYEAR,AMN,ADY)
C Keep only hourly data for output (0 = missed)
C.....................................................................Aug. 2022
C GIRO foF2 M3F2 scaled
C AMN = mn-for-cnt, AMNI = input_mn
C produce result = (Xave(UT-30m)+Xave(ut+30m))/2
C
c	DIMENSION im(12)
      character*128 infilef,infileh,outfilef,outfileh,txt,m_data
C	+,outfileb  !TEMPPPPPPPPPP
      character*3 DDD
	character*2 AYR,AMN,ADY,st,CYR,CMN,CDY,ADY1
	character*4 AYEAR,BYEAR
      integer count,f_strings,h_strings
     	dimension ifc(0:23),ihc(0:23)
	+,fc30(0:23,2),hc30(0:23,2)
	+,fi(0:23),hi(0:23)
C
C
C
   1	continue
      read(AMN,*) rmn
	imn=int(rmn)
C
C
      read(ADY,*) rdy
	idy1=int(rdy)
	idy2=idy1
	idy=idy1
	 call blet2(idy1,ADY1)
	call blet2(idy2,ADY)
C
       AYR=AYEAR(3:4)
      read(AYR,*) ryr
	iyr=int(ryr)

      infilef='c:\web\graf\ngdc\stYRMNf.txt' ! NEW /ngdc/
c	infileh='c:\web\graf\ngdc\stYRMNh.txt' ! NEW /ngdc/
	infilef(18:19)=ST
	infilef(20:21)=AYR
	infilef(22:23)=AMN
	infileh=infilef
	infileh(24:24)='h'

C
	outfilef='c:\web\graf\2020\stYRf.br'
      outfilef(18:19)=st
	outfilef(13:16)=AYEAR
	outfilef(15:16)=AYR
	outfilef(20:21)=AYR
	outfileh=outfilef
	outfileh(22:22)='h'
C
   30 format(A110)
c#          UT_Time      foF2      hmF2      foF1      hmF1      foE       zmE       foEs      fxI       TEC       
c#          Columns       4       5       6       7       8       9      10      11      12
c 2020 050 00:00:00       3.787   189.110     0.000     0.000     0.000     0.000     0.000     0.000     0.944
c   31 format(3X,A2,1X,I3,2(1X,I2),9X,F6.3,3X,F7.3)
C+++++++++++++++++++++++++
  333 FORMAT(A128)
      count=0
      OPEN(88,FILE=outfilef)
  255 READ(88, 333, END=244) m_data 
	CYR=m_data(1:2)
	CMN=m_data(3:4)
	CDY=m_data(5:6)
	if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.ady)) then	
	goto 244
	                  else
         count=count+1
      GOTO 255
      CONTINUE
                  	endif
  244 f_strings = count
      REWIND (88)
      count=0
      do while (count.lt.f_strings)
         READ(88, 333, END=248) m_data 
         count=count+1
      enddo
  248 print*,'YES!',st
      ENDFILE 88
      close(UNIT=88)
C TLG ADD!
CCC
      count=0
      OPEN(56,FILE=outfileh)
  355 READ(56, 333, END=344) m_data 
	CYR=m_data(1:2)
	CMN=m_data(3:4)
	CDY=m_data(5:6)
	if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.ady)) then  
	goto 344
	                  else
         count=count+1
      GOTO 355
      CONTINUE
                  	endif
  344 h_strings = count
      REWIND (56)
      count=0
      do while (count.lt.h_strings)
         READ(56, 333, END=348) m_data 
         count=count+1
      enddo
  348 print*,'YES!',st
      ENDFILE 56
      close(UNIT=56)
C      enddo
C=============================================================== 
	OPEN(15,file=outfilef,access='APPEND')
	OPEN(16,file=outfileh,access='APPEND')
          do k=0,23
	do i=1,2
	fc30(k,i)=0.
	hc30(k,i)=0.
	enddo
	enddo
	f30_pre=0. ! last 30min for prec day
	h30_pre=0. ! last 30min for prec day
C
C
  131 format(A4,4(1X,I2),13X,F6.3)
  132 format(A4,4(1X,I2),13X,F6.1)
C Dayly cycle
C
C       DO 41 idy=idy1,idy2
	idy=idy1
	   do it=0,23
C     	do ii=0,59
	fi(it)=0.
	hi(it)=0.
C	    enddo
	enddo
	lda=ndoy(iyr,imn,idy)
	call blet2(idy,ADY)
	call blet3(lda,DDD)
C
C?      maxut=0
	OPEN(10,file=infilef,action='READ')  ! Open for every day
	OPEN(14,file=infileh,action='READ')	 ! Open for every day
	DO nn=1,20
	read(10,333) txt         ! title line
	read(14,333) txt         ! title line
	ENDDO
  155	read(10,30,end=34) m_data
	CYR=m_data(3:4)
	CMN=m_data(6:7)
	CDY=m_data(9:10)
      if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.ady)) then  
	backspace(10)
	goto 156
	           else
	goto 155
	endif
C
  156    read(14,30,end=34) m_data
	CYR=m_data(3:4)
	CMN=m_data(6:7)
	CDY=m_data(9:10)
      if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.ady)) then  
	backspace(14)
	goto 104
	           else
	goto 156
	endif
C//
  104	iut=0
    5	read(10,131,end=34) BYEAR,KMN,KDYf,MUTf,MINf,fof2
    	    if (KDYf.gt.IDY) THEN
			close(unit=10)
		GOTO 141
			endif
		IF ((KDYf.eq.IDY).and.(MUTf.lt.iut)) goto 5
	IF ((KDYf.eq.IDY).and.(MUTf.eq.iut).and.(MINf.eq.0)) THEN 
		fi(iut)=foF2
	ENDIF
C
   75	read(14,132,end=34) BYEAR,KMN,KDYh,MUTh,MINh,hmf2
	    if (KDYh.gt.IDY) THEN
      close(unit=14)
		GOTO 141
	endif

	IF ((KDYh.eq.IDY).and.(MUTh.lt.iut)) goto 75
CC
	IF ((KDYh.eq.IDY).and.(MUTh.eq.iut).and.(MINh.eq.0)) THEN 
c  105	fi(mut)=foF2
	hi(iut)=hmF2
	endif
  105	iut=iut+1
	if (iut.lt.24) then 
	goto 5
                                                     ENDIF
   34	close(unit=10)
  134 close(unit=14)
C	mutend=mut
CC
	GOTO 122
C
	DO 40 iut=0,23
C KEEP ONLY min=00 data:
C
C+++++++++++++++++++++++++++++++++++++++++++++++++++
	sum1f=0.
	sum2f=0.
	sum1h=0.
	sum2h=0.
	icnf1=0
	icnh1=0
	icnf2=0
	icnh2=0
C
C+           DO 240 imin=0,29
      imin=0            !+++
	foF2=fi(iut)
	hmF2=hi(iut)
      IF (imin.eq.0) THEN					  !6
	ifc(iut)=nint(foF2*10.)
	ihc(iut)=nint(hmF2)
	ENDIF									   !6
   	 if (fof2.gt.0.) then					  !8
	 icnf1=icnf1+1
	sum1f=sum1f+fof2
	endif									  !8
	 if (hmf2.gt.0.) then					  !9
	 icnh1=icnh1+1
	sum1h=sum1h+hmf2
	endif									  !9
240   CONTINUE
        GOTO 40       ! ONLY min=00
C
   3  CONTINUE
      DO imin=30,59
	foF2=fi(iut)
	hmF2=hi(iut)
	 if (fof2.gt.0.) then                      !11
	 icnf2=icnf2+1
	sum2f=sum2f+fof2
	endif									   !11
	 if (hmf2.gt.0.) then					   !12
	 icnh2=icnh2+1
	sum2h=sum2h+hmf2
	endif									   !12
          ENDDO
c-	goto 1
C
	if (icnf1.gt.0) then 		!2
	fc30(iut,1)=sum1f/icnf1
	else						!2
	fc30(iut,1)=0.
	endif						!2
      if (icnf2.gt.0) then		!3
	fc30(iut,2)=sum2f/icnf2
	else						!3
	fc30(iut,2)=0.
	endif						!3
	if (icnh1.gt.0) then 		!4
	hc30(iut,1)=sum1h/icnh1
	else						!4
	hc30(iut,1)=0.
	endif						!4
      if (icnh2.gt.0) then		!5
	hc30(iut,2)=sum2h/icnh2
	else						!5
	hc30(iut,2)=0.
	endif						!5
C
   40 CONTINUE
C 
122	 	DO iut=0,23
C KEEP ONLY min=00 data:  
C			 
	fut=fi(iut)
	hut=hi(iut)
		ifc(iut)=nint(fut*10.0)
	ihc(iut)=nint(hut)
	enddo
	GOTO 123
C	do iut=0,maxut
	do iut=0,23
	fut=0.
      if ((f30_pre.gt.0.).and.(fc30(iut,1).gt.0.)) 
	+fut=(f30_pre+fc30(iut,1))/2.
	if ((f30_pre.gt.0.).and.(fc30(iut,1).eq.0.)) fut=f30_pre
	if ((f30_pre.eq.0.).and.(fc30(iut,1).gt.0.)) fut=fc30(iut,1)
	        if (ifc(iut).eq.0) then
 	ifc(iut)=nint(fut*10.)
	endif
	hut=0.
      if ((h30_pre.gt.0.).and.(hc30(iut,1).gt.0.)) 
	+hut=(h30_pre+hc30(iut,1))/2.
	if ((h30_pre.gt.0.).and.(hc30(iut,1).eq.0.)) hut=h30_pre
	if ((h30_pre.eq.0.).and.(hc30(iut,1).gt.0.)) hut=hc30(iut,1)
	        if (ihc(iut).eq.0) then
      ihc(iut)=nint(hut*100.)
	endif
	f30_pre=fc30(iut,2)
	h30_pre=hc30(iut,2)
	enddo
C
CC+ Correct nc ===> at		  
C        if (st.eq.'nc') then	   !TEMP!!!!!!!!!!!!!!!!!!!!!!!!!
        if (st.eq.'eb') then	   !TEMP!!!!!!!!!!!!!!!!!!!!!!!!!
C-	close(15)
C-	close(16)
C-	outfilef(18:19)='at'
C-	outfilem(18:19)='at'
      write(*,32) AYR,AMN,ADY,(ifc(k),k=0,23)
	write(17,32) AYR,AMN,ADY,(ifc(k),k=0,23)

C- 	OPEN(16,file=outfilem,access='APPEND')
C
       do k=0,23
	if (ifc(k).gt.0) then
C	 fcat=ifc(k)*0.8273+6.276  ! nc => at
       fcat=ifc(k)*0.7448+12.24  ! eb => at
	ifc(k)=nint(fcat)
	endif
	if (ihc(k).gt.0) then
C	xm3at=ihc(k)*0.5739+153.4  ! nc => at
	xm3at=ihc(k)*0.5035+178.2  ! eb => at
	ihc(k)=nint(xm3at)
	endif
	enddo
	  endif
 123      write(*,32) AYR,AMN,ADY,(ifc(k),k=0,23)
	write(15,32) AYR,AMN,ADY,(ifc(k),k=0,23)
	write(*,32) AYR,AMN,ADY,(ihc(k),k=0,23)
	write(16,32) AYR,AMN,ADY,(ihc(k),k=0,23)
   32 format(3A2,2X,24(I3,2X))
   41 CONTINUE
  141    close(unit=15)
      close(unit=16)
	      if (st.eq.'eb') close(unit=17)
   51	CONTINUE
      ifsum=0
      do k=0,23
	ifsum=ifsum+ifc(k)
	enddo
      RETURN  
	END