C .......................................................Mar 2014
C Extract fcF2, hcF2 from hcF2 map and hcF2 map at given sites
C 3 days in Sep. 2002, 3 days in Oct. 2003; 31 stations
C
C T.L.Gulyaeva...........................................Dec 2010
C hcF2 
C
C Input files stYRMN.txt $ 
C                          stYRMNg.txt (fcF2// from TECgps)
C & styrf.br(from IDCE) 	????????????????
C
C <<< to replace only line(s) for given day(s)
C 
C Output: annual file stYRf.br for Conver & /dat8/10/styrmn.txt
C
      PROGRAM DECODHF
C---------------------------------------------------------------
C data for 24 UT=0,1,2,...23hUT daily
C
C
C*********TEST
	CHARACTER*128 OUTFILE,infilest
	character*2 ayr,amn,ST,sts(31)
	+,DY1,DY2,ADY,stinp,AUT
	INTEGER*2 IDY,idy1,idy2,iut
	dimension glats(31),glons(31),ires(0:23)
	character*1 fm
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*6	YYMMDD
	CHARACTER*4 STAT,STATS(31)
	dimension im(12)
      COMMON /BLM/ STAT,GLAT,GLON
	DATA  IM/31,28,31,30,31,30,31,31,30,31,30,31/
	DATA STS
	+/'at','ch','co','ds','eg','ga','gs','jr','kk','ld'
     +,'mg','mh','mm','mo','nq','ok','pa','ro','rv','sd'
     +,'sf','so','ss','tk','tq','tr','tz','vt','wk','wp'
     +,'yg'/


C
	IRUN=1	 ! 1 for foF2, 2 for hmF2
c
	      CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
C read stations coordinates
	infilest='inputs1.inp'
  76	format(1X,I2,1X,F5.1,1X,F5.1,1X,A4,1X,A2)
   77	format(30X,F5.1,1X,F5.1,40X,A4,9X,A2)
		    OPEN(109,FILE=INFILEST,action='READ')
	do i=1,31
	read(109,77,end=78) glat,glon,stat,stinp
	if (stinp.eq.sts(i)) then
	write(*,76) i,glat,glon,stat,stinp
	glats(i)=glat
	glons(i)=glon
	stats(i)=stat
	 endif
	enddo
   78	close(unit=109)

C
  201	      WRITE(*,*)' ENTER yr,mn :'
		READ(*,15) AYR,AMN
   15	FORMAT(A2)
  202	      WRITE(*,*)' ENTER DY1,DY2 :'
		READ(*,15) DY1,DY2
	read(ayr,*) yr
	iyr=int(yr)
	if(int(yr/4.)*4.eq.iyr) THEN 
	im(2)=29
	ndnr=366
	                          ELSE
	IM(2)=28
	ndnr=365
	ENDIF
	read(amn,*) xmn
	mn=int(xmn)
		read(dy1,*) xdy1
 	idy1=int(xdy1)
		read(dy2,*) xdy2
 	idy2=int(xdy2)


C start foF2, hmF2 or TEC

  199	nds=idy2
C    
  	if (irun.eq.1) then
	fm='f'
	outfile='d:\web\graf\2010\styrf.txt'	! Extract foF2 from map
	endif 
	if (irun.eq.2) then
	fm='h'
	outfile='d:\web\graf\2010\styrh.txt'	! Extract hmF2 from map
	endif
	if (irun.eq.3) then
	fm='t'
	outfile='d:\web\graf\2010\styrt.txt'	! Extract TEC from map
	endif
	outfile(15:16)=ayr
	outfile(20:21)=ayr

C
C start cycle on stations
   79 format(1X,A4)

	DO 88 jj=1,31
	st=sts(jj)
	stat=stats(jj)
	write(*,79) stat
c	if (jj.lt.65) goto 88   ! last station only
	outfile(18:19)=st
c
	glat=glats(jj)
	glon=glons(jj)

c
c	
	OPEN(110,FILE=outfile,access='APPEND')
C
c ***************************************************************
C
   17 format(A128)
   18	format(A6,2X,A120)
  107	FORMAT(3A2,2X,24(A3,2X))
  108	FORMAT(3A2,2X,24(A3,A2))

C
C++
   	do 80 idy=idy1,idy2     ! count day number					             !!
C 
	call blet2(idy,ady)
	YYMMDD(1:2)=AYR
	YYMMDD(3:4)=AMN
	YYMMDD(5:6)=ADY

C start cycle on UT
	do iut=0,23
	call blet2(iut,AUT)
	call subinterc(fm,ayr,amn,ady,aut,resm)
	ires(iut)=nint(resm)
	enddo
C output 
	write(*,111) YYMMDD,(ires(k),k=0,23)
      write(110,111) YYMMDD,(ires(k),k=0,23)
   80	continue
C
   81	close(unit=110)
   82	close(unit=112)
C
	close(unit=109)
	close(unit=110)
  88	continue								 !!
  111	format(A6,1X,24(I4,1X))
	irun=irun+1
	if (irun.lt.4) then
	goto 199
	               else
	GOTO 33
	endif
C
    2 CONTINUE
       write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
 	pause ' '
	goto 34

   33	continue
      write(*,*) outfile
      pause ' ' 
   34   STOP
       END

C***********************************************************
      subroutine blet2(ilet,alet2)
c     nn=1,2,3,4 

	CHARACTER*1 IN(0:9)
	INTEGER*2 ilet
	DATA IN/'0','1','2','3','4','5','6','7','8','9'/
	CHARACTER*2 alet2
CLjuba	a2='00'
	alet2='00'             !NEW+7
	j10=ilet/10
	j1=ilet-j10*10
    5	do i=0,9
	if (j10.eq.i) then
	alet2(1:1)=IN(i)
	endif
	enddo
   7	do i=0,9 
     	if (j1.eq.i) then
 	alet2(2:2)=IN(i)
	endif
	enddo 
	return
	end
C
      integer function ndoy(iyr,imn,idy)
C To define day-of-year
C
	       DIMENSION IM(12)
	integer*2 iyr,imn,idy
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
	z1=iyr/4.0
      jz1=int(z1)*4
      IF(jz1.EQ.iyr) THEN
               IM(2)=29
        ELSE
                IM(2)=28
	       ENDIF
C Day-of-year LDA1
		mosum=0
      if(imn.gt.1) then
         do 1234 i=1,imn-1
1234    mosum=mosum+im(i)
         endif
      ndoy=mosum+idy	
	END FUNCTION
C ===============================================================
