NAG Library Manual, Mark 29.1
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program g01sdfe
!     G01SDF Example Program Text

!     Mark 29.1 Release. NAG Copyright 2023.

!     .. Use Statements ..
      Use nag_library, Only: g01sdf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, ldf1, ldf2, lf, lout,      &
                                          ltail
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: df1(:), df2(:), f(:), p(:)
      Integer, Allocatable             :: ivalid(:)
      Character (1), Allocatable       :: tail(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: max, mod, repeat
!     .. Executable Statements ..
      Write (nout,*) 'G01SDF Example Program Results'
      Write (nout,*)

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

!     Read in the input vectors
      Read (nin,*) ltail
      Allocate (tail(ltail))
      Read (nin,*) tail(1:ltail)

      Read (nin,*) lf
      Allocate (f(lf))
      Read (nin,*) f(1:lf)

      Read (nin,*) ldf1
      Allocate (df1(ldf1))
      Read (nin,*) df1(1:ldf1)

      Read (nin,*) ldf2
      Allocate (df2(ldf2))
      Read (nin,*) df2(1:ldf2)

!     Allocate memory for output
      lout = max(lf,ldf1,ldf2,ltail)
      Allocate (p(lout),ivalid(lout))

!     Calculate probability
      ifail = -1
      Call g01sdf(ltail,tail,lf,f,ldf1,df1,ldf2,df2,p,ivalid,ifail)

      If (ifail==0 .Or. ifail==1) Then
!       Display titles
        Write (nout,*)                                                         &
          '   TAIL      F        DF1       DF2       P      IVALID'
        Write (nout,*) repeat('-',56)

!       Display results
        Do i = 1, lout
          Write (nout,99999) tail(mod(i-1,ltail)+1), f(mod(i-1,lf)+1),         &
            df1(mod(i-1,ldf1)+1), df2(mod(i-1,ldf2)+1), p(i), ivalid(i)
        End Do
      End If

99999 Format (5X,A1,3(4X,F6.2),4X,F6.3,4X,I3)
    End Program g01sdfe