      program extpchssn
C.......................................................Jan. 2018
C Extract Pch(SSN2) for median calculation at ranges of SSN2=0:50:250
C
C
      character*60 infile1,infile2,outfile,txt
	dimension pch(2849),issn(2849)
	+,cov(2849)

c	infile2='ssn2-part.txt'
	infile2='cov-part.txt'
	infile1='pchdata.dat'
	OPEN(11,file=infile1,action='READ')
	read(11,*) txt
	OPEN(12,file=infile2,action='READ')
	read(12,*) txt
c   30 format(2(1X,I4)) !SSN2
   30 format(2('%',1X,F5.0)) !cov
   31 format(8X,F7.2)
c   32 format(20X,I4)
   32 format(11X,F6.1)
c   33 format(1X,I4,1X,F7.2)
   33 format(1X,F6.1,1X,F7.2)
   34	format(1X,I4)
C	outfile='pchssn.txt'
	outfile='pchcov.txt'
	OPEN(10,file=outfile,access='APPEND')
C
	do ii=1,2849
	read(11,31,end=51) pch(ii)
c	read(12,32,end=52) issn(ii)
	read(12,32,end=52) cov(ii)
	enddo
   51	close(unit=11)
   52	close(unit=12)

c	ix0=0
c   1	ix1=ix0+50
	x0=50.
   1	x1=x0+50.
	write(*,30) x0,x1
	write(10,30) x0,x1
	nn=0
	DO 50 ii=1,2849
c	if ((issn(ii).ge.ix0).and.(issn(ii).lt.ix1)) then
	if ((cov(ii).ge.x0).and.(cov(ii).lt.x1)) then
	nn=nn+1
c	write(*,33) issn(ii),pch(ii)
c	write(10,33) issn(ii),pch(ii) 
	write(*,33) cov(ii),pch(ii)
	write(10,33) cov(ii),pch(ii) 
	else
	goto 50
	endif
   50	continue
      write(*,34) nn
	write(10,34) nn
      x0=x1
	if (x0.le.250) goto 1
	close(unit=10)
	pause ' '
	STOP
	END


