logical function hec_nextevt_epio_slow(irecbuf,iepbuf) c c quick pass to get run header info c c created: 22/11/99 Carla Sbarra c modified: c implicit none c c geometry common c include'hec_par.inc' include'hec_datacard.inc' include'hec_epio.inc' include'hec_stats_epio.inc' c c set the maximum number of records to search for a slow c control record 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, ib, id, ierr, nw, len integer irecords, nbank, lenrec c integer lbank(maxsubl) logical getmore, b_pc, b_sps, b_beam save b_pc, b_sps, b_beam data b_pc, b_sps, b_beam /.false.,.false.,.false./ c c dimension epio buffer arrays c integer*2 irecbuf, iepbuf dimension irecbuf(lrecbuf), iepbuf(lepbuf) c c initialise slow control common block c call hec_slow_ini c c loop over first 10 records, until a record starting with a c slow control header bank is found (we assume SC records are at the c beginning of the epio file, which is true in all tests done c up to now) c irecords = 0 getmore = .true. do while ( irecords.lt. maxrecords. and. getmore ) 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 if (ierr .eq. 1) then c c end of file c hec_nextevt_epio_slow = .false. c eorflag = .true. print *, ' *** end of epio file reached' return elseif (ierr .ne. 0) then c c epread error: write a warning, then return c hec_nextevt_epio_slow = .false. print *, ' *** epread error in hec_nextevt_epio_slow ' + , ierr return else c c count number of records c irecords = irecords +1 c c get first bank c len = irecbuf(2) do i = 1, min(len + 1, lrecbuf) ibankbuf(i) = irecbuf(1 + i) enddo c c get id and pointer of first bank in record c id = ibankbuf(2) c print *, '*** slow pass *** 1st block in record: ',id c c if it is a slow control header block, exit loop and fill slow control common c if (id .eq. id_slow_header) then getmore=.false. endif endif c enddo c c check that we have found a slow control bank, if not, stop c if ( irecords .ge. maxrecords ) then hec_nextevt_epio_slow=.false. return endif c c find pointers to banks in event record c getmore = .true. nbank = 0 ipointep = 2 do while (nbank .lt. maxsubl .and. getmore) len = irecbuf(ipointep) c if (len .lt. 1) then print *,' *** bad bank length in hec_nextevt_epio_slow', + len return endif c len = len + 1 nbank = nbank + 1 lbank(nbank)= ipointep ipointep = ipointep + len c c make sure not to go past end of record c fixes for particular run periods c lenrec = irecbuf(1) if (ipointep .lt. lenrec - 1) then getmore = .true. else getmore = .false. endif enddo c c for this event record, loop over banks and fill commons c do ib = 1, nbank c c get pointer to the beginning of current bank and copy it c ipointep = lbank(ib) len = irecbuf(ipointep) do i = 1, min(len + 1, lrecbuf) ibankbuf(i) = irecbuf(ipointep - 1 + i) enddo c c get bank id c id = ibankbuf(2) c c get slow control PC data data c if (id .eq. id_slow_pc) then c print *, ' pc' stat_slow_pc = stat_slow_pc + 1 call hec_slow_pc_epio b_pc = .true. c c get slow control SPS data data c elseif (id .eq. id_slow_sps) then c print *, ' sps' stat_slow_sps = stat_slow_sps + 1 call hec_slow_sps_epio b_sps = .true. c c get slow control BEAM data data c elseif (id .eq. id_slow_beam) then c print *, ' beam' stat_slow_beam = stat_slow_beam + 1 call hec_slow_beam_epio b_beam =.true. endif enddo c hec_nextevt_epio_slow = .not.( b_pc.and.b_sps.and.b_beam ) c end