      subroutine user(eventType,numberOfWords,ev)

c...  we require that everything is declared
                       
      implicit none                                                     

c...  declarations                                                                   
      integer*4       eventType       ! not used with GS                
      integer*4       numberOfWords   ! 16 bit words in event           
                                      ! __excludes GS word count field  
      integer*2       ev(*)           ! event vector                    
                                      !   excludes GS word count field  

      integer*4       noev,i,j
      integer*2       nPEV,locev
      parameter       (nPEV=350)
      integer*2       pev(nPEV)

      integer*4       hitchan,dummy,ehichan,tgechan
      integer*4       esichan
      integer*4       h1CleanGe   
      integer*4       eg_eg                                      
      integer*4       status                                            
      integer*4       gsUnpack    

      character*10    str
                                                                   
c...  include common block interface between               
c     the user-function and "gsUnpack"                                
                                                                   
      include         'dapexe:gsUnpack.inc'                             
                                                                   
c...  include common block interface between              
c     the GammaSphere block handler and the user-function              
                                                                   
      include         'dapexe:gsRecords.inc'                            

c...  clear the pseudoeventvector

      do i=1,nPEV
        pev(i)=0
      end do

c...  unpack the event
                                          
      status=gsUnpack(numberOfWords,ev)                                 

      if (status .eq. 0) then                                 

c...    bin basic 1D signals (limit to 8K for space)

        do i=1,len_total-1
          if (gebit(i).and..not.bgohit(i)) then

            call h1Inc(id(i),ehi(i)/2)
            call h1Inc(ehichan,ehi(i)/2)

            call h1Inc(id(i)+110,tge(i)/2)
            call h1Inc(tgechan,tge(i)/2)

            call h1Inc(id(i)+220,eside(i))
            call h1Inc(esichan,eside(i))

            call h1Inc(hitchan,id(i))      

          end if
        end do

c...    ungated 2D matrix

        if (len_total.gt.2) then
          do i=1,len_total-1
            do j=i+1,len_total-1
              call h2Inc(eg_eg,ehi(i)/3,ehi(j)/3)       
            end do
          end do
        end if

      endif 

c...  done                                                            
                                                                   
      return   

c----------------------------------------------------------------------------
                                                
c...  userInit routine       
c                                                                   
      entry userInit                                                                                  
c...  pseudo event def

      call defPEV (pev(1),pev(nPEV))  

c.... common histograms
      
      call h1Number('hitpat',hitchan)
      call h1Number('ehiall',ehichan)
      call h1Number('tgeall',tgechan)
      call h1Number('esiall',esichan)

      call h2Number('eg_eg',eg_eg)

c...  individual detector histogram array setup

      do i=1,110
        j=1
        if (i.ge.10) j=2
        if (i.ge.100) j=3

        write(str,'(''ehi'',i<j>.<j>)') i
        call h1Number(str,dummy)

        write(str,'(''tge'',i<j>.<j>)') i
        call h1Number(str,dummy)

        write(str,'(''esi'',i<j>.<j>)') i
        call h1Number(str,dummy)

      end do

c...  done

      return                                                            

c-----------------------------------------------------------------
c...  userEx routine        
                                                                   
      entry userEx        
                                              
      write (6,*) 'UserEx: Finished processing:'    
      write (6,*) 'File:  ',the_file_header.FileNumber                  
      write (6,*) 'Run 1: ',the_file_header.run_title1                  
      write (6,*) 'Run 2: ',the_file_header.run_title2 

c...  done
                 
      return                                                            
c-----------------------------------------------------------------
c...  gsFileHeader routine  
                                                                   
      entry gsFileHeader   
                                             
      write (6,*) 'GS Tape/File Header:'                                
      write (6,*) 'Date:  ',the_tape_header.date                        
      write (6,*) 'Time:  ',the_tape_header.time                        
      write (6,*) 'Exp 1: ',the_tape_header.exp_title1                  
      write (6,*) 'Exp 2: ',the_tape_header.exp_title2                  
      write (6,*) 'Run:   ',the_file_header.RunNumber                   
      write (6,*) 'File:  ',the_file_header.FileNumber                  
      write (6,*) 'Run 1: ',the_file_header.run_title1                  
      write (6,*) 'Run 2: ',the_file_header.run_title2                  
      return                                                            
 
c...  done

      end                                                               

