	program delpchef100
c .......................................................Oct 2019
C Select peaks of delPch=Pchmax(3d)-Pchmin(-3d) for del > 100 i.u.
C movind 3day window, 
C Select all Del >0: output => 'delpchpos.res'
C for 2011-2018
C
c
	DIMENSION del(1930),ryears(1930),pchm(1930)
	+,pmin(1930),MD(1930,2)
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*64,infile,outfile,txt
	CHARACTER*2 BMN,BDY
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='delpchef100.res' ! All Del >T(PCH, PHI) (using fittting curve)
	OPEN(11,FILE=OUTFILE)
C
   36	format(1X,F8.3,2(1X,I2),3(1X,F7.2),1X,I4)
   37	format(1X,F8.3,2(1X,A2),3(1X,F7.2),1X,I4,1X,F6.3)
   30	format(A64)

	infile='delpch3d.txt'
		OPEN(10,FILE=infile,ACTION='READ')
	read(10,30) txt !~ title line
	write(11,30) txt
C
 	icntot=0 ! count of dPch
	do ii=1,1930
	read(10,36,end=102) RYEARS(ii),MD(ii,1),MD(ii,2),pmin(ii)
	+,pchm(ii),del(ii),knum
      icntot=icntot+1
	enddo      
  55  CLOSE(unit=10)
C start
C cycle on events	
	nres=0
	nout=0
	nout_pre=0
	DO 101 ii=1,icntot
c     
      	IF (del(ii).le.0.) goto 101
C prepare output	
C
      ASTR=ryears(ii)
	call subsolphase(ASTR,phi)
C-	TPCH=phi*(-91.5+phi-32.43)+160.5
      tpch=100.
	IF (del(ii).ge.tpch) THEN
	GOTO 99
	          ELSE
	GOTO 101
	ENDIF
C
C Output results:
 99     nout=ii
        nout_pre=nout
      nres=nres+1
	call blet2(MD(nout,1),BMN)
	call blet2(MD(nout,2),BDY)
	write(*,37) RYEARS(nout),BMN,BDY,pmin(nout)
	+,pchm(nout),del(nout),nres,phi
      write(11,37) RYEARS(nout),BMN,BDY,pmin(nout)
	+,pchm(nout),del(nout),nres,phi
C

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

