      program laggecstar
C...........................................................Nov 2023
C -12:to:+11h GEC, to=0 at Starlink launch
C
       DIMENSION igec(0:23),idat(0:71),ires(0:23)
	CHARACTER*128 INFHSS,INFILE,OUTFILE,outgec,txt
	CHARACTER*2 AMN,ADY,AUT,AMM,AYR
	CHARACTER*4 AYEAR
C
       infhss='Starlink20192023.txt'
	infile='d:\web\dat0\YR\gecYEAR.txt'
C
	outfile='catgecstar.txt'	 ! GECmax,GECav(24h)
	outgec='gecprof24.txt'
	OPEN(11,file=infhss,action='READ')
C
	OPEN(10,file=outfile)
	OPEN(13,file=outgec)
C
   28 format(I3,1X,I4,4(1X,I2))
   29 format(3(I2),24(1X,I4))
C
C
C     DO 177 iev=1,122	  !Total
        DO 177 iev=1,118	  !before Nov. 2023
      read(11,28,end=127) nn,iyear,imn1,idy1,iut1,imm
	call blet4(iyear,AYEAR)
	if (iyear.eq.2020) then
	ndyr=366
	else
	ndyr=365
	endif
	del=1./ndyr
	nnut1=iut1+24 ! nn(iUT1) at 3-day set( nn=0:71)
	nnut0=nnut1-12
C
      iyr1=iyear-iyear/100*100
	 lda1=ndoy(iyr1,imn1,idy1)
	xyear=iyear+del*(lda1-1)
C
	lda0=lda1
	iut0=iut1-12
	if (iut0.lt.0) then
	lda0=lda1-1
	iut0=iut0+24
	endif
C
	infile(19:22)=AYEAR
	AYR=AYEAR(3:4)
	infile(13:14)=AYR
      OPEN(12,file=infile,action='READ')
	 read(12,*) txt ! title
	nut2=1
C
	DO ndy=1,lda0
    1	read(12,29,end=128) iyr2,imn2,idy2,igec	 !lda0
      ENDDO
	 do kk=0,23
	idat(kk)=igec(kk)
	 enddo
      read(12,29,end=128) iyr2,imn2,idy2,igec ! lda1
	 do kk=0,23
	idat(kk+24)=igec(kk)
	 enddo
      read(12,29,end=128) iyr2,imn2,idy2,igec ! lda2
	 do kk=0,23
	idat(kk+48)=igec(kk)
	 enddo
C
      sum=0.
	nut=0
	 ipeak=0
C       do kk=iut0,iut0+23
      do kk=nnut0,nnut0+23
	ires(nut)=idat(kk)
	sum=sum+ires(nut)
	if (ipeak.lt.idat(kk)) then
	ipeak=idat(kk)
	kdtmax=kk
	endif
	nut=nut+1
	 enddo
	gecav=sum/2400.
	gecmax=ipeak/100.
C
           ndeltmax=kdtmax-nnut1
C       ldamax=lda0
C	if (kdtmax.gt.24) then
C	  if (kdtmax.lt.47) then
C	ldamax=lda1
C	kdtmax=kdtmax-24
C	          else
C	ldamax=lda1+1
C	kdtmax=kdtmax-48
C	      endif
C	endif

C
    2	CONTINUE
      call blet2(imn1,AMN)
	call blet2(idy1,ADY)
	call blet2(iut1,AUT)
	call blet2(imm1,AMM)
C
      write(*,32) xyear,lda1,amn,ady,aut,amm,lda0,iut0,ndeltmax
	+,gecmax,gecav,iev
	write(10,32) xyear,lda1,amn,ady,aut,amm,lda0,iut0,ndeltmax
	+,gecmax,gecav,iev
	write(*,33) (ires(k),k=0,23)
	write(13,33) (ires(k),k=0,23)
  128 close(12)
C	
  177	CONTINUE
  127 close(11)
      close(10)
      close(13)
      close(14)
  32	FORMAT(1X,F8.3,1X,I3,4(1X,A2),1X,I3,1X,I2,1X,I3,2(1X,F6.2)
     +,1X,I3)
  33	FORMAT(24(1X,I4))
       pause ' '
	STOP
	END