      program rewritehss1
C...................................................Jan 2020
C Correct date and time UT for HSS Vsw max
C
      CHARACTER*50 infhss,infile,outfile,txt
      CHARACTER*4 AYEAR
	DIMENSION IM(12),dat(0:47),vswdy(0:23)
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
C
      infile='d:\apkp\OMNI\swYEAR.txt'
	infhss='entrhss48.txt'
	outfile='cathss48m.txt'
	OPEN(10,file=infhss,action='READ')
	OPEN(11,file=outfile)
C
   28 format(1X,F8.3,3(1X,I2),1X,F6.0,1X,I2,2(1X,F6.0),6X,I4)
   30 FORMAT(A50)
   31	format(I4,1X,I3,1X,I2,28X,F5.0)
      nn=0
C
      	DO 177 iev=1,1697
      read(10,28,end=27) ryear,imn1,idy1,iutmin,v1,iutmax,v2,delv,lda1
	iyear=int(ryear)
	iyr=iyear-iyear/100*100
	ryear0=float(iyear)
		if(int(ryear0/4.)*4.eq.iyear) THEN 
	ndnyr=366
	dyr=1./366.
	im(2)=29
	                          ELSE
	ndnyr=365
	dyr=1./365.
	im(2)=28
	ENDIF
C  correct yr,mn,dy for next day if iut2 > 23h:
	lda2=lda1
	iutout=iutmax
      if (iutout.gt.23) then
	iutout=iutout-24
C+++
	lda2=lda1+1
	ryear=ryear+dyr
	if (lda2.gt.ndnyr) then
	lda2=1
      iyear=iyear+1
	iyr=iyr+1
	ryear=float(iyear)
	 endif
	endif
        call submmdd(lda2,iyr,imn2,idy2)
C
      	call blet4(iyear,AYEAR)
 	infile(16:19)=AYEAR
	OPEN(12,file=infile,action='READ')
	do i=1,13
	read(12,30) txt ! extra lines
	enddo
C
	DO 125 lda=1,lda2
C
		DO k=0,23
	dat(k)=dat(k+24)  ! prec. day
	ENDDO
C
	DO ii=0,23
	read(12,31,end=50) kyear,kday,kut,vswdy(ii)
	dat(ii+24)=vswdy(ii)
	ENDDO
C
  125	CONTINUE		!>>>>>>>>>>>>>>>>>>
   50	close(unit=12)
C Check time tmax:
      vmax=v2
        do 119 mm=0,47
	if (dat(mm).gt.9990.) goto 119
	if (dat(mm).lt.vmax) then
	goto 119
	         else
	iut48=mm
	exit
	endif
  119	continue
	 

C	find Vmin nearest to vmax before iutm
	vmin=v2 ! =vmax
	icn99=0
	iutmin=0
	iut1=0
	iut2=iut48-1
	dvup=vmax
C	if (iut2.lt.0) goto 124
C
 	do 120 iut=iut2,iut1,-1
	if (dat(iut).gt.9990.) then 
	icn99=icn99+1
	goto 120
	       else
	dv=dvup-dat(iut)
	iutdif=iut2-iut
	if ((dv.lt.0).and.(iutdif.gt.10)) exit
	if (dat(iut).lt.vmin) then
	vmin=dat(iut)
	dvup=vmin
	iutmin=iut
	endif
	       endif
  120	continue
      mutmin=iutmin-iut48
c     if (iutmin.gt.23) iutmin=iutmin-24
		dvmax=vmax-vmin
	if (dvmax.ge.50.) then
	nn=nn+1
	write(*,29) ryear,lda2,imn2,idy2,mutmin,vmin,iutout,vmax,dvmax,nn
	write(11,29) ryear,lda2,imn2,idy2,mutmin,vmin,iutout,vmax,dvmax,nn
	endif
C
  177 CONTINUE
   29 format(1X,F8.3,1X,I3,2(1X,I2),1X,I3,1X,F6.0,1X,I2,2(1X,F6.0),1X
     +,I4)
   27	close(unit=10)
      close(unit=11)
	pause ' '
	STOP
	end


