logical function hec_nextevt_epio_runh(irecbuf,iepbuf) c c quick pass to get run header info c c c created: 29.04.97 Dugan O'Neil c mods : 22.11.99 Carla Sbarra move some functionalities to c hec_runh_epio c implicit none c c geometry common c include'hec_par.inc' include'hec_geo.inc' include'hec_datacard.inc' include'hec_epio.inc' include'hec_evth.inc' include'hec_online.inc' include'hec_runh.inc' include'hec_stats_epio.inc' c c set the maximum number of records to search for the first c record containing an event header bank c integer maxrecords parameter (maxrecords = 10) c c set the maximum number of banks expected in a record c integer maxsubl parameter (maxsubl = 10) c c local variable declarations c integer i, id, ierr, nw, len integer irecords c logical getmore c c dimension epio buffer arrays c integer*2 irecbuf, iepbuf dimension irecbuf(lrecbuf), iepbuf(lepbuf) c c we are looking for the run header bank. c It is the only bank in the corresponding logical record, so c loop over all logical records, until a record starting with a c run header bank is found c irecords = 0 getmore = .true. hec_nextevt_epio_runh = .true. do while ( getmore .and. irecords.le.maxrecords ) c c call epio reading c call epread(in_typ(2), 20, nw, irecbuf, iepbuf, ierr) if(ierr.eq.0)then call epfrd(in_typ(2), 11, nw, irecbuf, iepbuf, ierr) endif c c correct for bad run header in May 96 c if (irunpd .eq. 1 .and. irecbuf(3) .eq. id_runh) then irecbuf(1) = 14 irecbuf(2) = irecbuf(1) - 2 endif c if (ierr .eq. 1) then c c end of file c hec_nextevt_epio_runh = .false. eorflag = .true. print *, ' *** end of epio file reached' return elseif (ierr .ne. 0) then c c epread error: if online mode return instead of stopping c if ( onflag ) then hec_nextevt_epio_runh = .false. print *, ' *** epread error in hec_nextevt_epio_runh ' + , ierr, ' continuing...' return else print *, ' *** epread error in hec_nextevt_epio_runh', + ierr stop endif c else c c count number of records read c irecords = irecords + 1 c c get id of first bank c len = irecbuf(2) do i = 1, min(len + 1, lrecbuf) ibankbuf(i) = irecbuf(1 + i) enddo id = ibankbuf(2) c c if it is the run header bank, fill RUNH common c if (id .eq. id_runh) then stat_runh = stat_runh + 1 call hec_runh_epio hec_nextevt_epio_runh = .false. getmore =.false. endif c endif enddo c c check that we have found a run header, if not, stop c if (irecords .ge. maxrecords) then if (onflag) then print *, ' *** no run header record found in', + ' hec_nextevt_epio_runh' return else print *, ' *** no run header record found in ', + ' hec_nextevt_epio_runh',irecords,maxrecords stop endif endif c end