! D02PSF Example Program Text ! Mark 24 Release. NAG Copyright 2012. Module d02psfe_mod ! D02PSF Example Program Module: ! Parameters and User-defined Routines ! .. Use Statements .. Use nag_library, Only: nag_wp ! .. Implicit None Statement .. Implicit None ! .. Parameters .. Real (Kind=nag_wp), Parameter :: tol0 = 1.0E-3_nag_wp Integer, Parameter :: n = 2, nin = 5, nout = 6, & npts = 16, nwant = 1 Integer, Parameter :: lrwsav = 350 + 32*n Contains Subroutine f(t,n,y,yp,iuser,ruser) ! .. Scalar Arguments .. Real (Kind=nag_wp), Intent (In) :: t Integer, Intent (In) :: n ! .. Array Arguments .. Real (Kind=nag_wp), Intent (Inout) :: ruser(*) Real (Kind=nag_wp), Intent (In) :: y(n) Real (Kind=nag_wp), Intent (Out) :: yp(n) Integer, Intent (Inout) :: iuser(*) ! .. Executable Statements .. yp(1) = y(2) yp(2) = -y(1) Return End Subroutine f End Module d02psfe_mod Program d02psfe ! D02PSF Example Main Program ! .. Use Statements .. Use nag_library, Only: d02pff, d02pqf, d02psf, d02ptf, nag_wp Use d02psfe_mod, Only: f, lrwsav, n, nin, nout, npts, nwant, tol0 ! .. Implicit None Statement .. Implicit None ! .. Local Scalars .. Real (Kind=nag_wp) :: hnext, hstart, tend, tinc, tnow, & tol, tstart, twant, waste Integer :: fevals, i, ideriv, ifail, & lwcomm, method, stepcost, stepsok ! .. Local Arrays .. Real (Kind=nag_wp) :: ruser(1), thresh(n), yinit(n), & ynow(n), ypnow(n), & ypwant(nwant), ywant(nwant) Real (Kind=nag_wp), Allocatable :: rwsav(:), wcomm(:) Integer :: iuser(1), iwsav(130) ! .. Intrinsic Procedures .. Intrinsic :: real ! .. Executable Statements .. Write (nout,*) 'D02PSF Example Program Results' ! Skip heading in data file Read (nin,*) lwcomm = n + 5*nwant Allocate (rwsav(lrwsav),wcomm(lwcomm)) wcomm(1:lwcomm) = 0.0_nag_wp ! Set initial conditions and input for D02PQF Read (nin,*) method Read (nin,*) tstart, tend Read (nin,*) yinit(1:n) Read (nin,*) hstart Read (nin,*) thresh(1:n) ! Set output control tinc = (tend-tstart)/real(npts,kind=nag_wp) tol = tol0*10.0_nag_wp Do i = 1, 2 tol = tol*0.1_nag_wp ! Set up integration. ifail = 0 Call d02pqf(n,tstart,tend,yinit,tol,thresh,method,hstart,iwsav,rwsav, & ifail) Write (nout,99999) tol Write (nout,99998) Write (nout,99997) tstart, yinit(1:n) ! Set up first point at which solution is desired. twant = tstart + tinc tnow = tstart ! Integrate by steps until tend is reached or error is encountered. integ: Do While (tnow