!   G08CCF Example Program Text
!   Mark 25 Release. NAG Copyright 2014.

    Module g08ccfe_mod

!     G08CCF Example Program Module:
!            Parameters and User-defined Routines

!     .. Use Statements ..
      Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Accessibility Statements ..
      Private
      Public                               :: user_cdf
!     .. Parameters ..
      Real (Kind=nag_wp), Parameter        :: std = 0.5_nag_wp
      Real (Kind=nag_wp), Parameter        :: xmean = 0.75_nag_wp
      Integer, Parameter, Public           :: nin = 5, nout = 6
    Contains
      Function user_cdf(x)
!       Cumulative distribution function for the user supplied distribution.
!       In this example, the distribution is the normal distribution, with
!       mean = 0.75 and standard deviation = 0.5

!       .. Use Statements ..
        Use nag_library, Only: s15abf
!       .. Function Return Value ..
        Real (Kind=nag_wp)                   :: user_cdf
!       .. Scalar Arguments ..
        Real (Kind=nag_wp), Intent (In)      :: x
!       .. Local Scalars ..
        Real (Kind=nag_wp)                   :: z
        Integer                              :: ifail
!       .. Executable Statements ..
        z = (x-xmean)/std
        ifail = -1
        user_cdf = s15abf(z,ifail)
        Return
      End Function user_cdf
    End Module g08ccfe_mod
    Program g08ccfe

!     G08CCF Example Main Program

!     .. Use Statements ..
      Use nag_library, Only: g08ccf, nag_wp
      Use g08ccfe_mod, Only: nin, nout, user_cdf
!     .. Implicit None Statement ..
      Implicit None
!     .. Local Scalars ..
      Real (Kind=nag_wp)                   :: d, p, z
      Integer                              :: ifail, n, ntype
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable      :: sx(:), x(:)
!     .. Executable Statements ..
      Write (nout,*) 'G08CCF Example Program Results'
      Write (nout,*)

!     Skip heading in data file
      Read (nin,*)

!     Read in problem type and required statistic
      Read (nin,*) n, ntype

      Allocate (x(n),sx(n))

!     Read in data
      Read (nin,*) x(1:n)

!     Perform K-S test for user specified distribution
      ifail = 0
      Call g08ccf(n,x,user_cdf,ntype,d,z,p,sx,ifail)

!     Display results
      Write (nout,*) 'Test against normal distribution with mean = 0.75'
      Write (nout,*) 'and standard deviation = 0.5.'
      Write (nout,*)
      Write (nout,99999) 'Test statistic D = ', d
      Write (nout,99999) 'Z statistic      = ', z
      Write (nout,99999) 'Tail probability = ', p

99999 Format (1X,A,F8.4)
    End Program g08ccfe