      program catvispch
C..........................................................Feb 2020
C      add Pch and DelPch (Pch_max-3s_Pch_min) to CathssvisCCH1.txt
C 
      CHARACTER*41 infile1,infile2,outfile
	DIMENSION pch(4)
	CHARACTER*8 epoch
	CHARACTER*2 AYR,AMN,ADY,CYR,CMN,CDY
	CHARACTER*47 txthss
	infile1='cathssviscch1.txt'
	 infile2='pchdata.dat'
	outfile='catvispch1.txt'
C
      OPEN(11,file=infile1,action='READ')
C
	OPEN(10,file=outfile)
	icch=0
	nn=0
C
   29 format(A47,1X,A8,1X,I2,3(1X,F7.3))
   30 FORMAT(1X,3A2,1X,F7.2)
   31 FORMAT(A47,1X,A8,1X,I2,3(1X,F7.3),3(1X,F7.2),1X,I4)
	DO 70 ii=1,490
	read(11,29,end=50) txthss,epoch,ith,chper,comlat,smag
	nn=nn+1
	if (nn.lt.24) goto 70

	ayr=epoch(3:4)
	amn=epoch(5:6)
	ady=epoch(7:8)

C
    1 OPEN(12,file=infile2,action='READ')
    2 read(12,30,end=51) cyr,cmn,cdy,pch(4)
      if ((cyr.eq.ayr).and.(cmn.eq.amn).and.(cdy.eq.ady)) then
	goto 3
	else
	do k=1,3
	pch(k)=pch(k+1)
	enddo
	goto 2
	endif
    3	pchmax=pch(4)
	pchmin=2000.
	do k=1,3
	if (pch(k).lt.pchmin) pchmin=pch(k)
	enddo
	dpch=pchmax-pchmin
	if (dpch.gt.90.) then
		icch=icch+1
	write(*,31) txthss,epoch,ith,chper,comlat,smag,pchmin,pchmax,dpch
	+,icch
	write(10,31) txthss,epoch,ith,chper,comlat,smag,pchmin,pchmax,dpch
	+,icch
	endif
C
   51	close(unit=12)
   70 CONTINUE
C
   50     close(unit=11)
      close(unit=10)
	pause ' '
	STOP
	END




