      program readeq
C.....................................................May 2022
C Read Obninsk EQ-catalog
C output: daily N(EQ_, Mmax, Mave 1995-2020
C
      CHARACTER*68 infile,outfile,txt
      CHARACTER*4 AYEAR, nrec,rec4,recor,recinp
	  CHARACTER*2 AMN,ADY,rec2
	CHARACTER*3 rec3
	CHARACTER*1 LAT,LON,rec1
	DIMENSION IM(12)
C+	+,eqs(100) ! read EQs/day
C+	INTEGER IIDEX
	DATA IM/31,28,31,30,31,30,31,31,30,31,30,31/
C +     EXTERNAL IIDEX
C
      infile='d:\Apkp\Equak\Obninsk\eqYEARMN.txt'
	outfile='d:\Apkp\Equak\Obninsk\eqYEAR.txt'
C
C     DO 100 iyear=1995,2021
      write(*,*) ' Enter iyear:'
	read(*,*) iyear
	call blet4(iyear,AYEAR)
	infile(25:28)=AYEAR
	outfile(25:28)=AYEAR
	OPEN(10,file=outfile,access='APPEND')
C
	iyr=iyear-iyear/100*100
      		z1=iyear/4.0
      jz=int(z1)*4
      IF(jz.EQ.iyear) THEN
	IM(2)=29
	dnr=366.
		  ELSE
	IM(2)=28
                dnr=365.
		       ENDIF
	del=1./dnr
C
       neqyr=0
      nread=1
	nrec='   1'
	imn1=1
	if (iyear.eq.2021) imn1=12
        DO 101 imn=imn1,12
	call blet2(imn,AMN)
	infile(29:30)=AMN
	OPEN(11,file=infile,action='READ')
C-	DO kk=1,11
C-	read(11,*) txt ! title line
C-	ENDDO
	ndmn=im(imn)
C
   30 format(9X,I4,2X,I2,2X,F8.1,1X,F6.2,1X,A1,2X,F6.2,1X,A1,1X,I4
     +,1X,F4.1)
C   30 format(9X,I4,2X,I2,37X,F4.1)
C      DO 102 idy=1,ndmn
C++	lda=ndoy(iyr,imn,idy) 
C++        ryear=iyear+(lda-1)*del
C
C      
C++    1	read(11,30,end=50) ninp,kdy,str,glat,LAT,glon,LON,kmh,eq ! Data
    1	read(11,*,end=50) ninp,kdy,rtime,glat,lat,glon,lon,ihei,eq ! Data
	recor='    '
      ninp_nex=ninp+1
	if (ninp_nex.gt.999) goto 5
	if (ninp_nex.lt.10) then 
	call blet1(ninp_nex,rec1)
	recor(1:1)=rec1
	goto 2
	endif
	if (ninp_nex.lt.100) then 
	call blet2(ninp_nex,rec2)
	recor(1:2)=rec2
	goto 2
	endif
   5	if (ninp_nex.lt.1000) then 
	call blet3(ninp_nex,rec3)
	recor(1:3)=rec3
	goto 2
	                else
	call blet4(ninp_nex,rec4)
	recor=rec4
	goto 2
	endif
    2	read(11,*,end=3) txt ! Data
      recinp=txt(1:4)
	if (recinp.eq.recor) then
	backspace(11)
	goto 3
      else
	      goto 2
	endif
    3  nkey=index(nrec,txt)
      if (lat.eq.'S') glat=-glat
	if (lon.eq.'W') glon=360.-glon
      call blet2(kdy,ADY)
      write(*,31) AYEAR,AMN,ADY,rtime,glat,glon,ihei,eq,ninp
	write(10,31) AYEAR,AMN,ADY,rtime,glat,glon,ihei,eq,ninp
	if (nkey.eq.0) goto 1
C	goto 50 !temp
C
C  102	CONTINUE
   50	close(11)
C      	goto 55 !temp
  101	CONTINUE
      close(10)
  100	CONTINUE
   31 format(1X,A4,2(1X,A2),1X,F9.1,2(1X,F6.2),2X,I4,1X,F4.1,1X,I4)

   55 pause ' '
      STOP
	END  