       SUBROUTINE SAX_ACC_LOOP(INCREMENT_ROUTINE) 
C
C----------------------------------------------------------------------
C
C.IDENTIFICATION: Subroutine SAX_ACC_LOOP
C.LIBRARY:        FOTLIB                     
C.AUTHOR:         L.Chiappetti - IFCTR Milano
C.VERSIONS:       0.0 - 10 May 93 - Original version
C                 0.1 - 03 Oct 93 - du field query anticipated to PRELOAD
C                 0.2 - 08 Nov 94 - added support to HK (bt=3)
C                 0.3 - 28 Mar 95 - missing RETURN for bt=2
C.PURPOSE:        Universal wrapper for main accumulation loop                 
C.METHOD:         switches according to packetcap preloaded information
C.SYNTAX:         CALL  SAX_ACC_LOOP(INCREMENT_ROUTINE) 
C.PARAMETERS:     EXTERNAL increment_routine : real accumulation routine        
C.RESTRICTIONS:   
C.NOTES:          INCREMENT_ROUTINE is an external routine usually found
C                 with the caller program, and is the work-horse of the
C                 accumulation (is specific of the kind of accumulation) 
C.FILES:          
C.REFERENCES      
C
C----------------------------------------------------------------------
C   
C
C      main switching routine for accumulations
C
       EXTERNAL   INCREMENT_ROUTINE
C      the argument is an external user written routine passed down to the various levels
C      to perform the accumulation over the wished data structure
C
C      this subroutine just calls the appropriate one according to the Basic Type
C      of packets ...
C-->   this means so far one does not handle observation CHAINS
C-->   and also cannot handle chains with separate observations in different modes 
C-->   in the future one should be able to switch back to here and support observations
C-->   in different modes
       INTEGER    ITYPE,IST,ID,I
       CHARACTER  DUMMY,UNITS*5
       LOGICAL    FOUND
       INCLUDE  'hcommon.inc'
       INCLUDE  'bincommon.inc'
       INCLUDE  'accumcommon.inc'
C
C      get packet primary and secondary types, and units in bytes or bits
C-->   all these should check if FOUND
C      CALL PKTCAP_LOOKUP('bt',ITYPE,IBT,DUMMY,FOUND) this is already in common
       CALL PKTCAP_LOOKUP('st',ITYPE,IST,DUMMY,FOUND)
*      CALL PKTCAP_LOOKUP('du',ITYPE,ID,UNITS,FOUND) moved to SAX_ACC_PRELOAD
       UNITS=ACCUMCOMMON_UNIT
C
C      call the appropriate routine, 
C-->   provisionally just return if bt is illegal
       GOTO (1,2,3)ACCUMCOMMON_IBT
       write(*,*)' illegal or unknown Basic Type'
       RETURN
C
C        DIRect modes (photon-by-photon) 
 1       CALL SAX_ACC_BT_1(IST,UNITS,INCREMENT_ROUTINE)  
         RETURN    
C        spectral indirect modes
  2      CALL SAX_ACC_BT_2(IST,UNITS,INCREMENT_ROUTINE)      
         RETURN
C        HK (housekeeping) data
C-->     I am not sure whether "units" are at all relevant
  3      CALL SAX_ACC_BT_3(IST,UNITS,INCREMENT_ROUTINE)      
         RETURN
       END
