PROGRAM READDETECT

  IMPLICIT NONE

  INTEGER(4) :: U

  CHARACTER(80) :: RUNTIT, RUNTIM*32, CHNAME*10
  INTEGER(4)    :: I, NCASE, NDET, NBIN, IV(50000)
  REAL(4)       :: EMIN, EBIN, ECUT
  REAL(4)       :: WEIPRI

  OPEN(NEWUNIT=U,FILE="detect001_fort.17",STATUS="old",&
    FORM="unformatted")

  READ(U) RUNTIT, RUNTIM, WEIPRI, NCASE
  WRITE(*,*) "RUNTIT: ",TRIM(ADJUSTL(RUNTIT))
  WRITE(*,*) "RUNTIM: ",TRIM(ADJUSTL(RUNTIM))
  WRITE(*,*) "WEIPRI: ",WEIPRI
  WRITE(*,*) "NCASE:  ",NCASE

  READ(U) NDET, CHNAME, NBIN, EMIN, EBIN, ECUT
  WRITE(*,*) NDET,CHNAME,NBIN,EMIN,EBIN,ECUT
  IF (NBIN>SIZE(IV)) STOP "NBIN>SIZE(IV). Increase the latter."
  READ(U) (IV(I), I =1,NBIN)
  CLOSE(U)

  OPEN(NEWUNIT=U,FILE="histogram.dat")
  DO I=1,NBIN
    WRITE(U,*) I,IV(I)
  ENDDO
  CLOSE(U)

END PROGRAM READDETECT
