      SUBROUTINE DENS(X,NX,XG,NXG,H,K,DG)  
      
      IMPLICIT NONE
c     Kerndichteschaetzer

      INTEGER NX, NXG, K
      DOUBLE PRECISION X(*), XG(*), H, DG(*)

      DOUBLE PRECISION KERN

      INTEGER I,J

      DO 10 I=1,NXG
         DG(I)=0.0D0
         DO 20 J=1,NX
            DG(I)=DG(I)+KERN(K,XG(I),X(J),H)
 20      CONTINUE
         DG(I)=DG(I)/(NX*H)
 10   CONTINUE
      

      RETURN
      END


      DOUBLE PRECISION FUNCTION KERN(K,X,XJ,H)
      INTEGER K
      DOUBLE PRECISION X, XJ, H, PI
      
      PI=3.141592654D0
      

      IF ( (-1.0D0 .LE. ((X-XJ)/H)) .AND. 
     $     (((X-XJ)/H) .LE. 1.0D0) ) THEN 
         
         IF (K.EQ.1) THEN
            KERN=3.0D0/4.0D0 *(1-(X-XJ)/H*(X-XJ)/H)
         ELSE IF (K.EQ.2) THEN
            KERN=15.0D0/16.0D0 *(1-(X-XJ)/H*(X-XJ)/H)*
     $           (1-(X-XJ)/H*(X-XJ)/H)
         END IF
      ELSE
         KERN=0.0D0
      END IF

      RETURN
      END
