      subroutine hec_io_ini
c
c data io initialization. hec_adc has to be able to initialize
c data input for ZEBRA or EPIO formats. Must be able to initialize epio 
c in either online or offline mode.
c
      implicit none      
c
      include'hec_par.inc'      !shared parameters
      include'hec_datacard.inc' !datacard values
      include'hec_epio.inc'     !epio common
      include'hec_maxepio.inc'  !set epio maximum buffer sizes
      include'hec_online.inc'   !online
      include'hec_zebra.inc'    !zebra 
c
c local variables
c
      character*18 fname
      integer ierr
c
c set end of run flag to false at start of run
c
      eorflag = .false.
c
c initialize zebra
c
      if (in_typ(1) .eq. 1) then
        call mzebra(-1)
        ixstor=0
        call mzstor(ixstor, '/zzz/', '.', ifence, lev, blvect(1),
     +  blvect(1), blvect(100000), blvect(1600001))
        if (ixstor .ne. 0) then
          print *, ' from mzstor: ixstor = ', ixstor
          stop
        endif
c
c open zebra file
c
        open(in_typ(2), file='bank.fz', form='unformatted', 
     +  status='old', err=1)
c
c initialize epio (if offline, use epioin as filename,
c if online mode do not initialize epio here, do it in 
c hec_online_io_ini. Necessary to get proper epio filename
c from user prompt)
c
      elseif (in_typ(1) .eq. 2) then
        if (irunpd .le. 5) then
          lrecbuf = 6144 
          lepbuf  = 6144
        elseif (irunpd .le. 8) then
          lrecbuf = 6120
          lepbuf  = 6120
        elseif (irunpd .le. 12) then
          lrecbuf = 20000
          lepbuf = 6120
        else
          lrecbuf = 40000
          lepbuf = 6120
        endif
c
c input data file is called epioin if it we are in offline mode
c it takes the value specified by the user (stored in online common)
c in online mode
c
        if (run_mode .eq. 1) then
          fname = 'epioin'
        elseif(run_mode .eq. 2) then 
          fname = infname
        endif
c
        call epinit
        call epsetw(in_typ(2), 1, lepbuf, ierr)
        if (ierr .ne. 0) then
          print *, ' ***error calling epsetw in hec_io_ini', ierr
          stop
        endif   
        call epdefu(in_typ(2), fname, ierr)
        if (ierr .ne. 0) then
          print *, ' ***error calling epdefu in hec_io_ini', ierr
          stop
        endif   
c 
      else
        print *, ' ***unknown input data file type ', in_typ(1)
        stop
      endif
      return
c
 1    continue
      print *, ' *** error opening zebra file on unit ', in_typ(2)
      stop
c
      end


