	SUBROUTINE L15CT_PROV_EXTRACT_DEBUG ( NBANK, STATUS, MFP_EVENT)

C----------------------------------------------------------------------
C-
C-	Purpose and Methods: Extract DEBUG section from calorimeter L1.5
C-	section of TRGR bank
C-
C-	Inputs: NBANK to chose which bank to extract
C-              1 = most recent bank, 2 = older bank
C-
C-	Outputs: L15CAL_DEBUG_BLOCK   copy of DEBUG section (in 
C-                                    L15CALDBB_DATA_BLOCK common block
C-
C-               STATUS            exit code
C-
C-               MFP_EVENT         flag to indicate MFP Event
C-
C-	Controls:
C-
C-	Created 2-MAY-1994	Gregory Snow
C-
C-      Modified  8-NOV-1994    S. Gross
C-                              - added "STATUS" return code
C-                              - only verify that DeBug Section is
C-                                NOT LONGER THAN reserved Common Block
C-                                space (original version required exact
C-                                length match) 
C-                              - changed name to avoid confusion
C-                 9-NOV-1994   - added MFP_EVENT return code
C-
C----------------------------------------------------------------------
	IMPLICIT NONE

        INCLUDE 'D0$PARAMS:LEVEL1_LOOKUP.PARAMS'
	INCLUDE 'D0$INC:ZEBCOM.INC'
	INCLUDE 'D0$LINKS:IZTRGR.LINK'

C- L15_FRAMEWORK.PARAMS must be included because that's where NUM_DSPS
C- is (for no known reason), and L15_LOCAL_DSP.PARAMS requires NUM_DSPS.
      INCLUDE 'D0$PARAMS:L15_FRAMEWORK.PARAMS'
      INCLUDE 'D0$PARAMS:L15_LOCAL_DSP.PARAMS'
        
	INCLUDE 'L15CALDBB_DATA_BLOCK.PARAMS'
        INCLUDE 'D0$INC:L15CALDBB_DATA_BLOCK.INC'
C-
	INTEGER NBANK
	INTEGER LTRGR,GZTRGR		! pointers to TRGR bank	
	INTEGER GZFIND_CRATE		! pointers to TRGR bank
	INTEGER L15START,PNTR		! pointers to TRGR bank
        INTEGER L15CAL_FRAME_START      ! pointers to TRGR bank
        INTEGER L15CAL_FRAME_PARAM_START   ! pointers to TRGR bank
        INTEGER L15CAL_TOOL_PARAM_START    ! pointers to TRGR bank
        INTEGER L15CAL_LOCAL_DSP_START     ! pointers to TRGR bank
        INTEGER L15CAL_GLOBAL_DSP_START    ! pointers to TRGR bank
	INTEGER L15CAL_DEBUG_START         ! pointers to TRGR bank
        INTEGER HEADER_LWFOLLOW, FRAME_LWFOLLOW
        INTEGER FRAME_PARAM_LWFOLLOW, TOOL_PARAM_LWFOLLOW
        INTEGER LOCAL_DSP_LWFOLLOW, GLOBAL_DSP_LWFOLLOW
	INTEGER DEBUG_LWFOLLOW
C
C-
	INTEGER I			! do loop indices
        
        LOGICAL STATUS, MFP_EVENT
C-
C- Initialize outputs first
C-
        STATUS = .FALSE.

        MFP_EVENT = .FALSE.

        CALL VZERO ( L15CAL_DEBUG_BLOCK, L15CAL_DEBUG_LENGTH )
C-
	LTRGR = GZTRGR()

        IF ( NBANK .EQ. 2 ) LTRGR = LQ ( LTRGR )

	L15START = GZFIND_CRATE ( 'TRGR', LTRGR, L15CAL_CRATE_ID )
C-	
	IF (L15START. LE. 0 ) THEN

	  CALL ERRMSG ( 'GZFIND_CRATE CANT FIND CRATE 81',
     &    'L15EXTRACT_L15CAL_DEBUG',
     &    'GZFIND_CRATE CANT FIND CRATE 81','W' )

	  RETURN

	ENDIF
C-
C-  read through TRGR to find start of DEBUG section
C-
        HEADER_LWFOLLOW = IQ ( L15START )

        L15CAL_FRAME_START = L15START + HEADER_LWFOLLOW + 1

        FRAME_LWFOLLOW = IQ ( L15CAL_FRAME_START )

        L15CAL_FRAME_PARAM_START = L15CAL_FRAME_START +
     &                             FRAME_LWFOLLOW + 1

        FRAME_PARAM_LWFOLLOW = IQ ( L15CAL_FRAME_PARAM_START )

        L15CAL_TOOL_PARAM_START = L15CAL_FRAME_PARAM_START +
     &                            FRAME_PARAM_LWFOLLOW + 1

        TOOL_PARAM_LWFOLLOW = IQ ( L15CAL_TOOL_PARAM_START )

        L15CAL_LOCAL_DSP_START = L15CAL_TOOL_PARAM_START +
     &                           TOOL_PARAM_LWFOLLOW + 1

        LOCAL_DSP_LWFOLLOW = IQ ( L15CAL_LOCAL_DSP_START )

        L15CAL_GLOBAL_DSP_START = L15CAL_LOCAL_DSP_START +
     &                            LOCAL_DSP_LWFOLLOW + 1

        GLOBAL_DSP_LWFOLLOW = IQ ( L15CAL_GLOBAL_DSP_START )

	L15CAL_DEBUG_START = L15CAL_GLOBAL_DSP_START + 
     &                       GLOBAL_DSP_LWFOLLOW + 1

	DEBUG_LWFOLLOW = IQ ( L15CAL_DEBUG_START )
C-
        IF ( DEBUG_LWFOLLOW + 1 .GE. L15CAL_DEBUG_LENGTH 
     &        .OR.
     &       DEBUG_LWFOLLOW .LE. 0 ) THEN

          CALL ERRMSG ( 'UNEXPECTED L15CAL DEBUG LENGTH',
     &	  'L15EXTRACT_L15CAL_DEBUG',
     &    'UNEXPECTED L15CAL DEBUG LENGTH', 'W' )

          RETURN

        ENDIF
C-
C-  fill in L15_GDSP_PASS for output
C-

        PNTR = L15CAL_DEBUG_START

        DO I = 1, DEBUG_LWFOLLOW + 1

           L15CAL_DEBUG_BLOCK ( I ) = IQ ( PNTR )

           PNTR = PNTR + 1

        ENDDO

        IF ( L15CAL_DEBUG_BLOCK ( MFP_FLAG + 1 ) .NE. 0 ) 
     &  MFP_EVENT = .TRUE.

        STATUS = .TRUE.
C-
C-
999	RETURN
	END

