Program h03adfe
! H03ADF Example Program Text
! Mark 30.1 Release. NAG Copyright 2024.
! .. Use Statements ..
Use nag_library, Only: f11zaf, h03adf, nag_wp
! .. Implicit None Statement ..
Implicit None
! .. Parameters ..
Integer, Parameter :: nin = 5, nout = 6
Character (1), Parameter :: dup = 'F', zero = 'R'
! .. Local Scalars ..
Real (Kind=nag_wp) :: splen
Integer :: ifail, j, lenc, n, ne, nnz, ns
Logical :: direct
! .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: d(:), work(:)
Integer, Allocatable :: icol(:), irow(:), iwork(:), path(:)
! .. Executable Statements ..
Write (nout,*) 'H03ADF Example Program Results'
! Skip heading in data file
Read (nin,*)
Read (nin,*) n, ns, ne, nnz, direct
Allocate (d(nnz),work(2*n),icol(nnz),irow(nnz),iwork(3*n+1),path(n))
Read (nin,*)(d(j),irow(j),icol(j),j=1,nnz)
! Reorder the elements of D into the form required by H03ADF.
ifail = 0
Call f11zaf(n,nnz,d,irow,icol,dup,zero,iwork,iwork(n+2),ifail)
! Find the shortest path between vertices NS and NE.
ifail = 0
Call h03adf(n,ns,ne,direct,nnz,d,irow,icol,splen,path,iwork,work,ifail)
! Print details of shortest path.
lenc = n
loop: Do j = 0, n - 1
If (path(j+1)==0) Then
lenc = j
Exit loop
End If
End Do loop
Write (nout,99999) 'Shortest path = ', (path(j),j=1,lenc)
Write (nout,99998) 'Length of shortest path = ', splen
99999 Format (/,1X,A,10(I2,:,' to '))
99998 Format (/,1X,A,G16.6)
End Program h03adfe