	program delpchpeak1
c .......................................................Jan 2019
C Select peaks of delPch=Pchmax(3d)-Pchmin(-3d) for del > Thr(Fi)-model 
C Use DelPch(Solar Phase) model as threshold 
C movind 3day window, 
C if del_max > 100. during 3 days, output at pchmax during 3 days
C for 2011-2018
C
c
	DIMENSION del(1763),ryears(1763),pchm(1763),solfi(1763)
	CHARACTER(10) DD
      CHARACTER(10) TT
      CHARACTER(5) ZZ
	CHARACTER*64,infile,outfile
	CHARACTER*2 AMD(1763,2)
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='delpchpeak1.res'
	OPEN(11,FILE=OUTFILE)
C 2011.211 03 19    .413  446.21  210.27
   36	format(1X,F8.3,2(1X,A2),1X,F7.3,2(1X,F7.2))
   35	format(1X,F8.3,2(1X,A2),1X,F7.3,2(1X,F7.2),1X,I4)
   30	format(A64)

C	infile='delpch3d.txt'
      infile='solphasepcmax.txt'
		OPEN(10,FILE=infile,ACTION='READ')
c	read(10,30) txt !~ title line
c	write(11,30) txt
C
 	icntot=0 ! count of dPch
c-	do ii=1,1763
c-	read(10,36,end=102) RYEARS(ii),AMD(ii,1),AMD(ii,2),solfi(ii)
c-	+,pchm(ii),del(ii)
c-      icntot=icntot+1
c-	enddo      
c-  55  CLOSE(unit=10)
C start
C cycle on events	
	nres=0
	nout=0
	DO 101 ii=1,1760
	read(10,36,end=102) RYEARS(ii),AMD(ii,1),AMD(ii,2),solfi(ii)
	+,pchm(ii),del(ii)
      icntot=icntot+1
c     
	res=del(ii)
	peak=pchm(ii)
	fi=solfi(ii)
      thr=fi*(-92.3024*fi-31.0421)+160.075
	IF (res.lt.thr) THEN
C
	goto 101
	                    ELSE
C prepare output	
C Output results:
   99	nout=ii
      nres=nres+1
	write(*,35) RYEARS(nout),AMD(nout,1),AMD(nout,2),solfi(nout)
	+,pchm(nout),del(nout),nres
      write(11,35) RYEARS(nout),AMD(nout,1),AMD(nout,2),solfi(nout)
	+,pchm(nout),del(nout),nres
C
	                      ENDIF
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

