SUBROUTINE rd_tdcunp (inddat,lendat,tmin,tmax,mode,stat) C--------------------------------------------------------------------- C RD_TDCUNP : unpack RD TDC data C Author : Morgan Burke (TRIUMF) C Date : 2000-Nov-20 C C INTEGER*4 inddat : start of TDC data C INTEGER*4 lendat : length of TDC data C REAL*4 tmin,tmax : time window C CHARACTER mode*3 : 'CAL' or 'RAW' C INTEGER*4 stat : =0 if ok, =1 if too many pulses C C CAUTION! The RD TDC data format is different from other TDCs. C There is not enough room to store coordinate, time, and width in C a single word, due to the high dynamic range of the RD TDCs. C Instead the format is a header word for a channel, followed C by the data words for that channel, then a header word for a new C channel, followed by data words, and so on. The tdc_bit values C for coordinates refer to the header word, while the values for C time and width refer to the data words. C C See unpct.F for more information. C--------------------------------------------------------------------- IMPLICIT NONE #include #include #include #include #include #include #include #include INTEGER*4 inddat,lendat,stat INTEGER*4 time,wide,lay,sec,end,imod,hitnum,i REAL*4 tmin,tmax,e,ftime,fwide,twalkp LOGICAL*4 rd, head CHARACTER*3 mode SAVE stat = 0 C loop over TDC data words DO i = inddat,inddat + lendat - 1 head = IAND(ISHFT(ibank(i),-31),1) .GT. 0 IF (head) THEN C extract RD coords lay = IAND(ISHFT(ibank(i),-tdcbit(1,3,i_rd)), + mask(tdcbit(2,3,i_rd))) sec = IAND(ISHFT(ibank(i),-tdcbit(1,4,i_rd)), + mask(tdcbit(2,4,i_rd))) end = IAND(ISHFT(ibank(i),-tdcbit(1,5,i_rd)), + mask(tdcbit(2,5,i_rd))) + 1 imod = (sec - 1) * 21 + lay rd = (lay .LT. 20) ELSEIF (rd) THEN C extract time, width time = IAND(ISHFT(ibank(i),-tdcbit(1,1,i_rd)), + mask(tdcbit(2,1,i_rd))) wide = IAND(ISHFT(ibank(i),-tdcbit(1,2,i_rd)), + mask(tdcbit(2,2,i_rd))) fwide = FLOAT(wide) C calibrate, if requested IF (mode .EQ. 'CAL') THEN ftime = (strobe_time - FLOAT(time)) * 0.5 - & rdt0(end,lay,sec) e = rdped(end,lay,sec) ftime = twalkp(ftime,e,'RD') ELSE ftime = FLOAT(time) ENDIF IF (ftime .LT. tmin .OR. ftime .GT. tmax) GOTO 999 C record in arrays IF ((rdlhit(1,imod) + rdlhit(2,imod)) .EQ. 0) THEN rdhits = rdhits + 1 rdtmod(rdhits) = imod ENDIF hitnum = rdlhit(end,imod) + 1 IF (hitnum .GT. rdmhit) THEN stat = 1 GOTO 999 ENDIF rdlhit(end,imod) = hitnum rdtlin(end,imod,hitnum) = ftime rdwlin(end,imod,hitnum) = fwide 999 CONTINUE ENDIF ENDDO RETURN END