program main c*********************************************************************72 c cc lagrange_interp_2d_test() tests lagrange_interp_2d(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 13 September 2012 c c Author: c c John Burkardt c implicit none integer m_test_num parameter ( m_test_num = 5 ) integer i integer m integer m_test(m_test_num) integer prob integer prob_num save m_test data m_test / 1, 2, 3, 4, 8 / call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'lagrange_interp_2d_test():' write ( *, '(a)' ) ' FORTRAN77 version' write ( *, '(a)' ) ' Test lagrange_interp_2d().' write ( *, '(a)' ) ' The R8LIB library is needed.' write ( *, '(a)' ) & ' This test also needs the TEST_INTERP_2D library.' call f00_num ( prob_num ) c c Numerical tests. c do prob = 1, prob_num do i = 1, m_test_num m = m_test(i) call test01 ( prob, m ) end do end do c c Terminate. c write ( *, '(a)' ) '' write ( *, '(a)' ) 'lagrange_interp_2d_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine test01 ( prob, m ) c*****************************************************************************80 c cc LAGRANGE_INTERP_2D_TEST01 tests LAGRANGE_INTERP_2D. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 13 September 2012 c c Author: c c John Burkardt c c Parameters: c c Input, integer PROB, the problem number. c c Input, integer M, the polynomial degree in each dimension. c implicit none integer m_max parameter ( m_max = 8 ) double precision app_error integer i integer ij double precision int_error integer j integer m integer mx integer my integer nd integer ni integer prob double precision r8vec_norm_affine double precision xd((m_max+1)*(m_max+1)) double precision xd_1d(m_max+1) double precision xi((m_max+1)*(m_max+1)) double precision xi_1d(m_max) double precision yd((m_max+1)*(m_max+1)) double precision yd_1d(m_max+1) double precision yi((m_max+1)*(m_max+1)) double precision yi_1d(m_max) double precision zd((m_max+1)*(m_max+1)) double precision zdm(m_max*m_max) double precision zi((m_max+1)*(m_max+1)) mx = m my = m write ( *, '(a)' ) '' write ( *, '(a)' ) 'LAGRANGE_INTERP_2D_TEST01:' write ( *, '(a,i2)' ) & ' Interpolate data from TEST_INTERP_2D problem #', prob write ( *, '(a,i2,a,i2)' ) & ' Using polynomial interpolant of product degree ', & mx, ' x ', my nd = ( mx + 1 ) * ( my + 1 ) write ( *, '(a,i6)' ) ' Number of data points = ', nd call r8vec_chebyspace ( mx + 1, 0.0D+00, 1.0D+00, xd_1d ) call r8vec_chebyspace ( my + 1, 0.0D+00, 1.0D+00, yd_1d ) ij = 0 do j = 1, my + 1 do i = 1, mx + 1 ij = ij + 1 xd(ij) = xd_1d(i) yd(ij) = yd_1d(j) end do end do call f00_f0 ( prob, nd, xd, yd, zd ) if ( nd .le. 20 ) then call r8vec3_print ( nd, xd, yd, zd, ' X, Y, Z data:' ) end if c c #1: Does interpolant match function at data points? c ni = nd do i = 1, ni xi(i) = xd(i) yi(i) = yd(i) end do call lagrange_interp_2d ( mx, my, xd_1d, yd_1d, zd, ni, xi, & yi, zi ) if ( ni .le. 20 ) then call r8vec3_print ( ni, xi, yi, zi, ' X, Y, Z interpolation:' ) end if int_error = r8vec_norm_affine ( ni, zi, zd ) / dble ( ni ) write ( *, '(a)' ) '' write ( *, '(a,g14.6)' ) & ' RMS data interpolation error = ', int_error c c #2: Does interpolant approximate data at midpoints? c if ( 1 .lt. nd ) then do i = 1, mx xi_1d(i) = 0.5D+00 * ( xd_1d(i) + xd_1d(i+1) ) end do do i = 1, my yi_1d(i) = 0.5D+00 * ( yd_1d(i) + yd_1d(i+1) ) end do ni = mx * my ij = 0 do j = 1, my do i = 1, mx ij = ij + 1 xi(ij) = xi_1d(i) yi(ij) = yi_1d(j) end do end do call f00_f0 ( prob, ni, xi, yi, zdm ) call lagrange_interp_2d ( mx, my, xd_1d, yd_1d, zd, ni, xi, & yi, zi ) app_error = r8vec_norm_affine ( ni, zi, zdm ) / dble ( ni ) write ( *, '(a)' ) '' write ( *, '(a,g14.6)' ) ' RMS data approximation error = ', & app_error end if return end subroutine timestamp ( ) c*********************************************************************72 c cc timestamp() prints the YMDHMS date as a timestamp. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 12 June 2014 c c Author: c c John Burkardt c implicit none character * ( 8 ) ampm integer d character * ( 8 ) date integer h integer m integer mm character * ( 9 ) month(12) integer n integer s character * ( 10 ) time integer y save month data month / & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' / call date_and_time ( date, time ) read ( date, '(i4,i2,i2)' ) y, m, d read ( time, '(i2,i2,i2,1x,i3)' ) h, n, s, mm if ( h .lt. 12 ) then ampm = 'AM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h .lt. 12 ) then ampm = 'PM' else if ( h .eq. 12 ) then if ( n .eq. 0 .and. s .eq. 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, & '(i2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, & trim ( ampm ) return end