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

NAG FL Interface Introduction
Example description
    Program g12abfe

!     G12ABF Example Program Text

!     Mark 30.2 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: g12abf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: p, ts
      Integer                          :: df, i, ifail, ldn, lfreq, lwt, n,    &
                                          nd, ngrp
      Character (1)                    :: freq, weight
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: expt(:), obsd(:), t(:), wt(:)
      Integer, Allocatable             :: di(:), grp(:), ic(:), ifreq(:),      &
                                          ni(:)
!     .. Executable Statements ..
      Write (nout,*) 'G12ABF Example Program Results'
      Write (nout,*)

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

!     Read in the problem size
      Read (nin,*) n, ngrp, freq, weight

      If (freq=='F' .Or. freq=='f') Then
        lfreq = n
      Else
        lfreq = 0
      End If
      If (weight=='W' .Or. weight=='w') Then
        lwt = n
      Else
        lwt = 0
      End If
      ldn = n
      Allocate (t(n),ic(n),grp(n),ifreq(lfreq),obsd(ngrp),expt(ngrp),di(ldn),  &
        ni(ldn),wt(lwt))

!     Read in data
      If (lfreq==0) Then
        Read (nin,*)(t(i),ic(i),grp(i),i=1,n)
      Else
        Read (nin,*)(t(i),ic(i),grp(i),ifreq(i),i=1,n)
      End If

!     Calculate the statistic
      ifail = 0
      Call g12abf(n,t,ic,grp,ngrp,freq,ifreq,weight,wt,ts,df,p,obsd,expt,nd,   &
        di,ni,ldn,ifail)

!     Display results
      Write (nout,99999) 'Observed', 'Expected'
      Write (nout,99998)('Group',i,obsd(i),expt(i),i=1,ngrp)
      Write (nout,*)
      Write (nout,99996) 'No. Unique Failure Times = ', nd
      Write (nout,*)
      Write (nout,99997) 'Test Statistic           = ', ts
      Write (nout,99996) 'Degrees of Freedom       = ', df
      Write (nout,99997) 'p-value                  = ', p

99999 Format (11X,A,2X,A)
99998 Format (1X,A,1X,I1,1X,F8.2,2X,F8.2)
99997 Format (1X,A,1X,F8.4)
99996 Format (1X,A,1X,I3)
    End Program g12abfe