      program omnires
C.............................................................May 2016
	CHARACTER*65 infileb,infildb,infilbz,infilsv,infildv
 	+,infilnp,infiltp,infilbs,infildt,infile,outfile
	 	CHARACTER*4 AYEAR
	CHARACTER*2 AMN,ADY
	 dimension par(193),jhrs(193),dat(0:24),jchrs(0:24),jphist(17)
	+,thr(17),idat(0:24),ipar(193)
	data THR/0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,14.,16.,18.
	+,20./

	outfile='omnires.txt'
	OPEN(10,file=outfile,access='APPEND')

	infileb='icimfeb24.txt'  !  IMF B for ICME 1999- during 12 hrs 
	infilbs='icimfbs24.txt'  !  IMF Bstep3h  for ICME 1999- during 12 hrs 
	infildb='icimfdb24.txt'  ! DB/DT for ICME 1999- during 12 hrs 
	infilbz='icimfbz24.txt'  !  Bz for ICME 1999- during 12 hrs 
	infilsv='icimfsv24.txt'  !  Vsw for ICME 1999- during 12 hrs 
	infildv='icimfdv24.txt'  !  dVsw/dt for ICME 1999- during 12 hrs 
	infilnp='icimfnp24.txt'  ! Np for ICME 1999- during 12 hrs 
	infiltp='icimftp24.txt'  ! Tp for ICME 1999- during 12 hrs 
	infildt='icimfdt24.txt'  ! dTp/dt for ICME 1999- during 12 hrs 
C
   31 format(1X,A25)
   32 format(1X,A4,2A2,1X,F5.2,25(1X,F8.0))
   33 format(1X,A4,2A2,1X,F5.2,25(1X,F5.0))
   34 format(1X,A4,2A2,1X,F5.2,25(1X,F5.1))
   30 format(1X,A4,2A2,1X,F5.2,25(1X,I5))
   29 format(1X,A4,2A2,1X,F5.2,25(1X,I5),2X,I2,1X,I5)
C
C+	infile=infilbs         ! Bstep3h:
C++	infile='icmdst2.txt'	!Dst
	infile='icmaei2.txt'	!AE
	OPEN(11,FILE=infile,action='READ')
	write(*,31) infile
		write(10,31) infile
C
	istrm=0
      DO 110 jj=1,193
C	read(11,34,end=111) AYEAR,AMN,ADY,UT1,(dat(k),k=0,24)	!Bstep3h
	read(11,30,end=111) AYEAR,AMN,ADY,UT1,(idat(k),k=0,24)	! Dst, AE
	amax=0.0
C++       mindst=0
       maxae=0
	   do k=0,24
C+	if (amax.lt.dat(k)) then	  !Bstep3h
C++	if (idat(k).lt.mindst) then	  !min Dst
	if (maxae.lt.idat(k)) then	  !min Dst
C++	 mindst=idat(k)
      maxae=idat(k)
	kmax=k
	endif
	   enddo
C+	par(jj)=amax
C++	ipar(jj)=mindst
	ipar(jj)=maxae
	jhrs(jj)=kmax
C Dstmin <=-100
C++	if (mindst.gt.-100) then 
	if (maxae.lt.1000) then 
	GOTO 110
	else
	istrm=istrm+1
c++	write(*,29)  AYEAR,AMN,ADY,UT1,(idat(k),k=0,24),kmax,mindst ! Dst
c++	write(10,29)  AYEAR,AMN,ADY,UT1,(idat(k),k=0,24),kmax,mindst	! Dst
	write(*,29)  AYEAR,AMN,ADY,UT1,(idat(k),k=0,24),kmax,maxae ! AE
	write(10,29)  AYEAR,AMN,ADY,UT1,(idat(k),k=0,24),kmax,maxae	! AE
	jchrs(kmax)=jchrs(kmax)+1
	GOTO 110
	endif

	jchrs(kmax)=jchrs(kmax)+1
	if (amax.gt.thr(17)) jphist(17)=jphist(17)+1 
	do k=1,16
	if ((amax.ge.thr(k)).and.(amax.lt.thr(k+1))) jphist(k)=jphist(k)+1 
    	enddo
  110	continue
  111	close(unit=11)
C 
      do k=0,24
      write(*,35) k,jchrs(k)
	write(10,35) k,jchrs(k)
	enddo
   35	 format(2(1X,I2))
	goto 40
C
      do k=1,17
	write(*,36) thr(k),jphist(k)
	write(10,36) thr(k),jphist(k)
	enddo
   36	 format(2(1X,F4.0,1X,I2))
   40   close(unit=11)
 	write(*,*) istrm
	pause ' '
	stop
	END