```    Program e02dafe

!     E02DAF Example Program Text

!     Mark 26.2 Release. NAG Copyright 2017.

!     .. Use Statements ..
Use nag_library, Only: e02daf, e02def, e02zaf, nag_wp
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nin = 5, nout = 6
Character (1), Parameter         :: label(2) = (/'X','Y'/)
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: eps, sigma, sum_nag, temp
Integer                          :: i, iadres, ifail, itemp, j, m,       &
nadres, nc, npoint, nws, px, py,     &
rank
!     .. Local Arrays ..
Real (Kind=nag_wp), Allocatable  :: c(:), dl(:), f(:), ff(:), lamda(:),  &
mu(:), w(:), wrk(:), ws(:), x(:),    &
y(:)
Integer, Allocatable             :: adres(:), iwrk(:), point(:)
!     .. Executable Statements ..
Write (nout,*) 'E02DAF Example Program Results'

!     Skip heading in data file

!     Read data, interchanging X and Y axes if PX < PY

If (px<py) Then
itemp = px
px = py
py = itemp
itemp = 1
Else
itemp = 0
End If

npoint = m + (px-7)*(py-7)
nc = (px-4)*(py-4)
nws = (2*nc+1)*(3*py-6) - 2
Allocate (lamda(px),mu(py),x(m),y(m),f(m),ff(m),w(m),dl(nc),c(nc),       &

If (itemp==1) Then

If (py>8) Then
End If

If (px>8) Then
End If

Else

If (px>8) Then
End If

If (py>8) Then
End If

End If

!     Sort points into panel order

ifail = 0

Write (nout,*)
Write (nout,99995) 'Interior ', label(itemp+1), '-knots'

If (px==8) Then
Write (nout,*) 'None'
Else

Do j = 5, px - 4
Write (nout,99996) lamda(j)
End Do

End If

Write (nout,*)
Write (nout,99995) 'Interior ', label(2-itemp), '-knots'

If (py==8) Then
Write (nout,*) 'None'
Else

Do j = 5, py - 4
Write (nout,99996) mu(j)
End Do

End If

!     Fit bicubic spline to data points

ifail = 0
Call e02daf(m,px,py,x,y,f,w,lamda,mu,point,npoint,dl,c,nc,ws,nws,eps,    &
sigma,rank,ifail)

Write (nout,*)
Write (nout,99999) 'Sum of squares of residual RHS', sigma
Write (nout,*)
Write (nout,99998) 'Rank', rank

!     Evaluate spline at the data points

ifail = 0
Call e02def(m,px,py,x,y,lamda,mu,c,ff,wrk,iwrk,ifail)

sum_nag = 0.0E0_nag_wp

If (itemp==1) Then
Write (nout,*)
Write (nout,*) 'X and Y have been interchanged'
End If

!     Output data points, fitted values and residuals

Write (nout,*)
Write (nout,*) '      X          Y          Data       Fit     Residual'

loop:   Do

Exit loop
End If

End Do loop

End Do

Write (nout,*)
Write (nout,99999) 'Sum of squared residuals', sum_nag
Write (nout,*)
Write (nout,*) 'Spline coefficients'

Do i = 1, px - 4
Write (nout,99996)(c((i-1)*(py-4)+j),j=1,py-4)
End Do

99999 Format (1X,A,1P,E16.2)
99998 Format (1X,A,I5)
99997 Format (1X,4F11.4,E11.2)
99996 Format (1X,6F11.4)
99995 Format (1X,A,A1,A)
End Program e02dafe
```