      program cnttau2
C..............................................................Mar. 2024
C
C..............................................................June 2018
C
C..............................................................July 2016
C add cycle on 80 stations for current month
c	
c	  count Tau=TEC/NmF2, rv
C Input: (1) styrmnt.txt
C        (2) styrmn.txt
C Output:(1) styrmns.txt	 !slab-thickness Tau
C	   
      DIMENSION IM(12),ff2(0:23),tec(0:23)
	INTEGER*4 JRES(0:23)
	CHARACTER*128 INFILE1,INFILE2,OUTFILE,TXT,INDATE
	CHARACTER*2 st(80),stcode,yy,amn                  !June 2018
	CHARACTER*6	YRMNDY
	CHARACTER*4	YEAR
	CHARACTER*40 put        ! LIUBA
	CHARACTER*20 outf,inf2  ! LIUBA 
	CHARACTER*19 inf1       ! LIUBA
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
	DATA ST/'as','at','bc','bp','br','cb','ch','cn','cq','cs'
     +,'cw','jb','db','dw','eg','eb','di','gr','gu','ha' ! jb > cr Mar 2020
     +,'he','ho','jj','jm','jr','kk','lm','ml','mo','mq'
     +,'mw','nd','ni','ok','pe','pq','sa','rm','ro','vt' ! sa > ps
     +,'sq','tv','tr','wk','wp','wz','mm','tk','kg','mg'	  ! Mar 2020
     +,'sd','rv','qn','ns','so','gm','ei','gg','if','tu'	!tu> nc	  !Mar 2024
     +,'pa','fz','ff','kh','au','al','ga','nc','yg','ic'	!fz> yk nc>di Sep 2019
     +,'ad','bb','bl','ea','mh','sj','sp','cj','er','ll'/			  !Mar.2024
C
C Test
C      indate='d:\web\graf\date'       ! Tamara
	indate='/var/www/izmiran/ionosphere/weather/graf/date' ! LIUBA 
	open(10,file=indate,action='READ')
	 read(10,14) YEAR,AMN
	close(unit=10)
C
C	outfile='d:\web\graf\dat9\15\styrmns.txt'  ! Tamara
C	infile1='d:\web\graf\dat1\15\styrmn.txt'   ! Tamara
C	infile2='d:\web\graf\dat7\15\styrmnt.txt'  ! Tamara

      put='/var/www/izmiran/ionosphere/weather/graf'	! LIUBA 

	outf='/dat9/15/styrmns.txt'  ! LIUBA
	inf1='/dat1/15/styrmn.txt'   ! LIUBA
	inf2='/dat7/15/styrmnt.txt'  ! LIUBA

C 
	YY=YEAR(3:4)
   14	FORMAT(A4,1X,A2,3X,A4,1X,A2)
   15	FORMAT(A4)
C	outfile(18:19)=yy      ! Tamara 
C	outfile(23:24)=yy      ! Tamara
C	outfile(25:26)=amn     ! Tamara
C	infile1(18:19)=yy      ! Tamara
C	infile1(23:24)=yy      ! Tamara
C	infile1(25:26)=amn     ! Tamara
C	infile2(18:19)=yy      ! Tamara
C	infile2(23:24)=yy      ! Tamara
C	infile2(25:26)=amn     ! Tamara


	outf(7:8)=yy        ! LIUBA 
	outf(12:13)=yy      ! LIUBA
	outf(14:15)=amn     ! LIUBA

	inf1(7:8)=yy        ! LIUBA
	inf1(12:13)=yy      ! LIUBA
	inf1(14:15)=amn     ! LIUBA

	inf2(7:8)=yy        ! LIUBA
	inf2(12:13)=yy      ! LIUBA
	inf2(14:15)=amn     ! LIUBA

      outfile=put//outf    ! LIUBA
	infile1=put//inf1    ! LIUBA
	infile2=put//inf2    ! LIUBA

  200 continue
  199	format(A2)
	do 300 jsta=1,80	  !June 2018
	stcode=st(jsta)
	ieof=0
	write(*,*) stcode
C	 OUTFILE(21:22)=stcode   ! Tamara
C	infile1(21:22)=stcode    ! Tamara
C	infile2(21:22)=stcode    ! Tamara

      OUTFILE(50:51)=stcode    ! LIUBA
	infile1(50:51)=stcode    ! LIUBA
	infile2(50:51)=stcode    ! LIUBA

	write(*,*) 'outfile = ', outfile
	write(*,*) 'infile1 = ', infile1
	write(*,*) 'infile2 = ', infile2
c     
	OPEN(11,FILE=INFILE1)				  ! file foF2
	OPEN(12,FILE=INFILE2)				  ! file TEC
	OPEN(13,FILE=OUTFILE)				  ! Tau
C
  201	continue
	read(amn,*) rmn
	mn=int(rmn)
	read(yy,*) yr
	iy=int(yr)
	z1=yr/4.
	jz=int(z1)*4
	IF(jz.EQ.iy) THEN
               IM(2)=29
					dnr=366.
        ELSE
                IM(2)=28
	  	dnr=365.
	       ENDIF

  220 L=0   
      JFL=0 
  159	format(A6,2X,24(F3.1,2X))
  160	format(A128)
  161	format(A6,24(1X,F4.1))
  162	format(A6,24(1X,I4))

C Read-write title lines:
	do k=1,4
	read (11,160,err=270,end=300) txt      ! title
	read (12,160,err=270,end=300) txt      ! title
	if (k.eq.1) txt(15:17)='Tau'
	write(*,160) txt
	write(13,160) txt
	enddo
	ndnr=im(mn)
C Day-to-day cycle:
	DO 260 idy=1,ndnr
   	read (11,159,err=270,end=300) YRMNDY,(ff2(k),k=0,23)      ! file foF2
      read (12,161,err=270,end=300) YRMNDY,(tec(k),k=0,23)      ! file foF2
	do 10 i=0,23
	 xnm=ff2(i)*ff2(i)*1.24
	if (xnm.eq.0.) then
	write(*,*) infile1,YRMNDY,i,' Enter missed foF2:'
	read(*,*) fof2
	 xnm=fof2*fof2*1.24
c	pause ' '

c	rtau=1000.
c	goto 11
	endif

      if (xnm.gt.0.) then
		rtau=tec(i)/xnm
	else
	rtau=0.999
	endif
   11	 jres(i)=nint(rtau*1000.)
   10	continue
	write(*,162) YRMNDY,(jres(k),k=0,23)
	write(13,162) YRMNDY,(jres(k),k=0,23)
  260	continue
	goto 300
  270	 write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY ',infile1,infile2

  300	CONTINUE
	goto 301

  301	close(unit=11)
	close(unit=12)
	close(unit=13)
C	pause ' '        ! Liuba
      STOP
	end