```!   G02HFF Example Program Text
!   Mark 26.2 Release. NAG Copyright 2017.

Module g02hffe_mod

!     G02HFF 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                           :: psi, psp
!     .. Parameters ..
Real (Kind=nag_wp), Parameter    :: tc = 1.5_nag_wp
Integer, Parameter, Public       :: nin = 5, nout = 6
Contains
Function psi(t)

!       .. Function Return Value ..
Real (Kind=nag_wp)             :: psi
!       .. Scalar Arguments ..
Real (Kind=nag_wp), Intent (In) :: t
!       .. Intrinsic Procedures ..
Intrinsic                      :: abs
!       .. Executable Statements ..
If (t<=-tc) Then
psi = -tc
Else If (abs(t)<tc) Then
psi = t
Else
psi = tc
End If
Return
End Function psi

Function psp(t)

!       .. Function Return Value ..
Real (Kind=nag_wp)             :: psp
!       .. Scalar Arguments ..
Real (Kind=nag_wp), Intent (In) :: t
!       .. Intrinsic Procedures ..
Intrinsic                      :: abs
!       .. Executable Statements ..
psp = 0.0_nag_wp
If (abs(t)<tc) Then
psp = 1.0_nag_wp
End If
Return
End Function psp
End Module g02hffe_mod
Program g02hffe

!     G02HFF Example Main Program

!     .. Use Statements ..
Use g02hffe_mod, Only: nin, nout, psi, psp
Use nag_library, Only: g02hff, nag_wp, x04cbf
!     .. Implicit None Statement ..
Implicit None
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: sigma
Integer                          :: i, ifail, indc, indw, ldc, ldx, m, n
!     .. Local Arrays ..
Real (Kind=nag_wp), Allocatable  :: c(:,:), rs(:), wgt(:), wk(:), x(:,:)
Character (0)                    :: clabs(1), rlabs(1)
!     .. Executable Statements ..
Write (nout,*) 'G02HFF Example Program Results'
Write (nout,*)
Flush (nout)

!     Skip heading in data file

!     Read in the problem size

ldx = n
ldc = m
Allocate (x(ldx,m),wgt(n),rs(n),wk(m*(n+m+1)+2*n),c(ldc,m))

!     Read in weights and residuals