	program histdelpch
c .......................................................Jan 2019
C Histogram of occurrence dPch=Pchmax(3d)-Pchmin(-3d)
C for 2011-2018
C
c
	DIMENSION THR(12),res(11),del(1763),pdp(11)
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*64,infile,outfile,txt
	CHARACTER*2 AMN,ADY
	DATA THR/0.,50.,100.,150.,200.,250.,300.,350.,400.,
	+500.,600.,700./ 
C
	CALL DATE_AND_TIME(DATE=DD,TIME=TT,ZONE=ZZ)
      TT(5:)='      '
      WRITE(*,*) 'PC Date: Year,Month,Day = ',DD,'Time = ',TT
C
  791 FORMAT(A10,1X,I4)
		  outfile='histdelpch.res'
	OPEN(11,FILE=OUTFILE,ACCESS='APPEND')
C
   36	format(1X,F8.3,2(1X,A2),17X,F7.2)

C	infile='delpch3d.txt'
	infile='delpchpos1.res'
		OPEN(10,FILE=infile,ACTION='READ')
	read(10,*) txt ! title line
C
 	icntot=0 ! count of dPch
	do ii=1,1435
	read(10,36,end=55) RYEAR,AMN,ADY,del(ii)
      icntot=icntot+1
	enddo      
  55  CLOSE(unit=10)
C start
	do i=1,11
	res(i)=0.
	enddo

C cycle on events	
	nres=0
	DO 101 ii=1,icntot
c     
	do j=1,11
	if ((del(ii).ge.thr(j)).and.(del(ii).lt.thr(j+1))) then
	res(j)=res(j)+1.
	goto 101
 	endif
	enddo
101	CONTINUE	   
	do ii=1,11
	pdp(ii)=res(ii)/icntot*100.
	enddo
      write(*,*) icntot
	write(11,*) icntot
	do k=1,11
	avth=(thr(k)+thr(k+1))/2.
	write(*,790) k,avth,res(k),pdp(k)
	write(11,790)  k,avth,res(k),pdp(k)
	enddo
 105	CONTINUE
 790  format(1X,I2,1X,F5.0,1X,F6.0,1X,F6.2)
C  %
c   

  800 CONTINUE             

	CLOSE(unit=11)
	goto 900
    2 CONTINUE
           write(*,*) 'INPUT FILE IS NOT IN YOUR DIRECTORY '
  900 pause ' '
      STOP
      END

