Module skim_mod

module skim_mod

        ! Uses
    use precision_mod
    use namelist_mod
    use hists_mod, ONLY:IDH_SkimmedEvents

        ! Variables
    integer, private, DIMENSION(MAX_SKMOD) :: SkimCodes = -1
    integer, private :: numSkimCodes = 0
    integer, private, DIMENSION(MAX_SKMOD) :: NSkimmed = 0

        ! Subroutines and functions
    public subroutine ResetSkim ()
    public subroutine FillSkimN (icode, N)
    public subroutine FillSkim (icode)

end module skim_mod
 ====================================================================
  Author: B. Jamieson
  Date of Release: 31 Jan 2002
  Last Altered: 9 Jul 2002 (BJ)
                    Undocumented Changes 
                16 Jan 2003 (BJ)  
                    Add count of number skimmed to each channel. Add
                    a second fill skim routine that caps skim at a
                    specified number of events.
 --------------------------------------------------------------------
  Description: Keep track of and update multiskimming channels.
  This module contains two subroutines used to keep track of 
  multiskimming channels.  ResetSkim is called at the begining
  of dplot.f90 to resets the flags so that none of the skim channels 
  will be written to unless FillSkim is called during the event.
  
  To set up multifile skimming follow these instructions:
   1) From the o/s command line, set up environment variables 
      with the names of the skim files you want to output to.
       eg.  set up two files to skim to in linux csh:
            csh> setenv SKIM1 "skim1.dat"
            csh> setenv SKIM3 "skim3.dat"

   2) Edit your .kcm file to tell MOFIA which channels to skim to:
       eg. to write to the two files set up in 1), put the following
           lines into your .kcm file (see multiskim.kcm):
              skim/off
              skim/on
              ! Open the files for channels 1 and 3
              skim/open 1 SKIM1
              skim/open 3 SKIM3
              ! Set up which YBOS event types to write to skim
              skim/skip BEGIN_FILE
              skim/skip END_FILE
              skim/skip FILE
              skim/write BEGIN_RUN
              skim/skip END_RUN
              skim/write EVENT
              skim/write COMMENT
              skim/write UNKNOWN
              ! Enable skimming on channels 1 and 3
              name skim skimoncode(1) = T
              name skim skimoncode(3) = T
              ! Show me which channels are enabled
              show name skim

   3) Put in calls to FillSkim, with the stream number to write to
      as an argument somewhere in your code.  You will also need to 
      add a module USE statement to USE skim_mod.  The code added might
      look something like this for skimming to the SKIM1 file:
         !.
         !. header code in your module is here
         !.
         USE skim_mod
         !.
         !. more type definitions, subroutines in module
         !.
         if ( This_is_what_I_want_in_SKIM1 ) then
            call FillSkim(1)
         end if
         !.
         !. the rest of your code
         !.
 ====================================================================

Description of Variables

SkimCodes

integer, private, DIMENSION(MAX_SKMOD) :: SkimCodes = -1

numSkimCodes

integer, private :: numSkimCodes = 0

NSkimmed

integer, private, DIMENSION(MAX_SKMOD) :: NSkimmed = 0

Description of Subroutines and Functions

ResetSkim

public subroutine ResetSkim ()
    ! Calls: KMSkim_Bar
end subroutine ResetSkim

FillSkimN

public subroutine FillSkimN (icode, N)
    integer (kind=i4) :: icode
    integer (kind=i4) :: N
    ! Calls: FillSkim
end subroutine FillSkimN
 Subroutine FillSkimN( icode, N )
 ------------------------------------------------------
 Call this with the skim code number each time the skim
 condition you want is met, and only put in if less than
 N events have met this criteria.  If N is set to -1, then
 allow infinite number of events to be skimmed.

FillSkim

public subroutine FillSkim (icode)
    integer (kind=i4) :: icode
    ! Calls: KMSkim_Out, hf1
end subroutine FillSkim
 Subroutine FillSkim( icode )
 -------------------------------------------------------
 Call this with the skim code number each time the skim
 condition you want is met .