*$ CREATE FLUSCW.FOR
*COPY FLUSCW
*                                                                      *
*=== fluscw ===========================================================*
*                                                                      *
      DOUBLE PRECISION FUNCTION FLUSCW ( IJ    , PLA   , TXX   , TYY   ,
     &                                   TZZ   , WEE   , XX    , YY    ,
     &                                   ZZ    , NREG  , IOLREG, LLO   ,
     &                                   NSURF )

      INCLUDE '(DBLPRC)'
      INCLUDE '(DIMPAR)'
      INCLUDE '(IOUNIT)'
*
*----------------------------------------------------------------------*
*                                                                      *
*     Copyright (C) 1989-2015      by    Alfredo Ferrari & Paola Sala  *
*     All Rights Reserved.                                             *
*                                                                      *
*     New version of Fluscw for FLUKA9x-FLUKA20xy:                     *
*                                                                      *
*     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     *
*     !!! This is a completely dummy routine for Fluka9x/200x. !!!     *
*     !!! The  name has been kept the same as for older  Fluka !!!     *
*     !!! versions for back-compatibility, even though  Fluscw !!!     *
*     !!! is applied only to estimators which didn't exist be- !!!     *
*     !!! fore Fluka89.                                        !!!     *
*     !!! User  developed versions  can be used for  weighting !!!     *
*     !!! flux-like quantities at runtime                      !!!     *
*     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     *
*                                                                      *
*     Input variables:                                                 *
*                                                                      *
*           Ij = (generalized) particle code (Paprop numbering)        *
*          Pla = particle laboratory momentum (GeV/c) (if > 0),        *
*                or kinetic energy (GeV) (if <0 )                      *
*    Txx,yy,zz = particle direction cosines                            *
*          Wee = particle weight                                       *
*     Xx,Yy,Zz = position                                              *
*         Nreg = (new) region number                                   *
*       Iolreg = (old) region number                                   *
*          Llo = particle generation                                   *
*        Nsurf = transport flag (ignore!)                              *
*                                                                      *
*     Output variables:                                                *
*                                                                      *
*       Fluscw = factor the scored amount will be multiplied by        *
*       Lsczer = logical flag, if true no amount will be scored        *
*                regardless of Fluscw                                  *
*                                                                      *
*     Useful variables (common SCOHLP):                                *
*                                                                      *
*     Flux like binnings/estimators (Fluscw):                          *
*          ISCRNG = 1 --> Boundary crossing estimator                  *
*          ISCRNG = 2 --> Track  length     binning                    *
*          ISCRNG = 3 --> Track  length     estimator                  *
*          ISCRNG = 4 --> Collision density estimator                  *
*          ISCRNG = 5 --> Yield             estimator                  *
*          JSCRNG = # of the binning/estimator                         *
*                                                                      *
*----------------------------------------------------------------------*
*
      INCLUDE '(SCOHLP)'
      INCLUDE '(TRACKR)'
      INCLUDE '(USRBDX)'
      INCLUDE 'EXTRST.inc'
*
      INTEGER LUN_FLUSCW
      DATA LUN_FLUSCW / -23 /

* N.B -> 
* N.B ->  the following scoring needs to be present in the input file
* N.B ->  USRBDX            1.  BEAMPART      -23.     Vac6e   AIR_017          bp1_ext
* N.B ->  USRBDX          400.      395.       20.                               &
* N.B ->
      
      LOGICAL LFIRST
      SAVE LFIRST
      DATA LFIRST / .TRUE. /
      IF ( LFIRST ) THEN
         LFIRST = .FALSE.

         WRITE ( LUNOUT,* ) ""
         WRITE ( LUNOUT,* ) "FLUSCW to count extracted protons"
         WRITE ( LUNOUT,* ) "FLUSCW logical unit", LUN_FLUSCW
         WRITE ( LUNOUT,* ) ""
         CALL FFLUSH(LUNOUT)

      END IF

*     set initial flag to scoring
      FLUSCW = ONEONE
      LSCZER = .FALSE.

*     check the unit number
      IF (IPUSBX(JSCRNG) .NE. LUN_FLUSCW) GOTO 100

*     check that the particle is a proton
      IF (JTRACK.NE.1) GOTO 100

*     at this point set initial flag to no scoring
      LSCZER = .TRUE.

*     compute TURN
      ITURN = MOD(ISPUSR(1), 10)

*     activate scoring if there is correspondence between
*     detector name and turn
      IF     (TITUSX(JSCRNG).EQ.'bp1_ext   ' .AND. ITURN.EQ.1 .AND.
     &     LTRACK.EQ.1 ) THEN
         LSCZER = .FALSE.
      END IF

 100  CONTINUE
      RETURN
*=== End of function Fluscw ===========================================*
      END
