*
*cutted from gpdcspe by Nikolay Nikonov
*CMZ :  2.01/00 05/04/2000  14.35.18  by  Marialuigia Ambriola
*CMZ :  2.00/00 03/03/2000  15.39.06  by  Francesco Cafagna
*CMZ :  1.02/00 19/01/2000  15.50.14  by  Francesco Cafagna
*CMZ :  1.01/00 16/05/96  17.38.13  by  Francesco Cafagna
*CMZ :  1.00/02 27/03/96  18.35.42  by  Francesco Cafagna
*-- Author :    Francesco Cafagna   23/02/96
      SUBROUTINE GPDCSPE(XINSPE,YINSPE,ZINSPE,XOUTSPE,YOUTSPE,ZOUTSPE)
*************************************************************************
*                                                                       *
* To calculate XAVE,YAVE,ZAVE and NMULT, YMULT after each hit           *
*                                                                       *
*                                                                       *
*************************************************************************
*#include "gcunit.inc"
*#include "gpphit.inc"
      PARAMETER (RADDEG=57.295779)
#include "gpspe.inc"
*#include "gpsed.inc"
*#include "gpkey.inc"
*et. 04/11/2005
*#include "gpstripspe.inc"
*end et.
*               
*
* Data block for digitalization
*
      REAL XINSPE,YINSPE,ZINSPE,XOUTSPE,YOUTSPE,ZOUTSPE
      REAL VPOS(3),BMAGNET(3),ANGLEX,ANGLEY,XMULT,YMULT,DXPOS,DYPOS
*
*      DATA NTRA,LTRA/1,1/
      
c        PRINT*,XINSPE,' ',YINSPE,' ',ZINSPE,' ',XOUTSPE,' ',ZOUTSPE

         XAVSPE = (XINSPE+XOUTSPE)/2.
         YAVSPE = (YINSPE+YOUTSPE)/2.
         ZAVSPE = (ZINSPE+ZOUTSPE)/2.

         
C
C ADD RESOLUTION SIMULATION TO XAVSPE 
C	 
         ANGLEX=0.
         ANGLEY=0.
         IF(ZOUTSPE.NE.ZINSPE) THEN 
            ANGLEX=RADDEG*ATAN( ABS(XOUTSPE-XINSPE )/
     +           ABS(ZOUTSPE-ZINSPE ) ) 
            ANGLEY=RADDEG*ATAN( ABS(YOUTSPE-YINSPE )/
     +           ABS(ZOUTSPE-ZINSPE ) )           
         ENDIF
            
c        PRINT*,'ANGX=',ANGLEX,' ANGY=',ANGLEY
         
         VPOS(1)=XAVSPE
         VPOS(2)=YAVSPE
         VPOS(3)=ZAVSPE	 
         CALL GUFIELD(VPOS,BMAGNET)
       
         CALL GPRSPE(ANGLEX,ANGLEY,BMAGNET,XMULT,YMULT,DXPOS,DYPOS)

         NXMULT=INT(XMULT)
         NYMULT=INT(YMULT)
            
         XAVSPE = XAVSPE + DXPOS
         YAVSPE = YAVSPE + DYPOS

c         PRINT*,'<X>=',XAVSPE,' <Y>=',YAVSPE,' <Z>=',ZAVSPE
c         PRINT*,'NXMULT=',NXMULT,' NYMULT=',NYMULT

*
   20 RETURN
      END
