program main c*********************************************************************72 c cc pwl_interp_2d_test() tests pwl_interp_2d(). c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 14 September 2012 c c Author: c c John Burkardt c implicit none integer n_test_num parameter ( n_test_num = 5 ) integer i integer n integer n_test(n_test_num) integer prob integer prob_num save n_test data n_test / 2, 3, 4, 5, 9 / call timestamp ( ) write ( *, '(a)' ) '' write ( *, '(a)' ) 'pwl_interp_2d_test():' write ( *, '(a)' ) ' FORTRAN77 version' write ( *, '(a)' ) ' Test pwl_interp_2d().' write ( *, '(a)' ) ' The R8LIB library is needed.' write ( *, '(a)' ) ' The test needs the TEST_INTERP_2D library.' call f00_num ( prob_num ) c c Numerical tests. c do prob = 1, prob_num do i = 1, n_test_num n = n_test(i) call test01 ( prob, n ) end do end do c c Terminate. c write ( *, '(a)' ) '' write ( *, '(a)' ) 'pwl_interp_2d_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) '' call timestamp ( ) return end subroutine test01 ( prob, n ) c*********************************************************************72 c cc PWL_INTERP_2D_TEST01 tests PWL_INTERP_2D. c c Licensing: c c This code is distributed under the MIT license. c c Modified: c c 14 October 2012 c c Author: c c John Burkardt c c Parameters: c c Input, integer PROB, the problem number. c c Input, integer N, the grid size in each dimension. c implicit none integer n double precision app_error integer i integer ij double precision int_error integer j integer nd integer ni integer nxd integer nyd integer prob double precision r8vec_norm_affine double precision xd(n*n) double precision xd_1d(n) double precision xi(n*n) double precision xi_1d(n-1) double precision yd(n*n) double precision yd_1d(n) double precision yi(n*n) double precision yi_1d(n-1) double precision zd(n*n) double precision zdm((n-1)*(n-1)) double precision zi(n*n) nxd = n nyd = n write ( *, '(a)' ) '' write ( *, '(a)' ) 'PWL_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 ', & nxd, ' x ', nyd nd = nxd * nyd write ( *, '(a,i6)' ) ' Number of data points = ', nd call r8vec_linspace ( nxd, 0.0D+00, 1.0D+00, xd_1d ) call r8vec_linspace ( nyd, 0.0D+00, 1.0D+00, yd_1d ) ij = 0 do j = 1, nyd do i = 1, nxd 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 pwl_interp_2d ( nxd, nyd, 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, n - 1 xi_1d(i) = 0.5D+00 * ( xd_1d(i) + xd_1d(i+1) ) yi_1d(i) = 0.5D+00 * ( yd_1d(i) + yd_1d(i+1) ) end do ni = ( nxd - 1 ) * ( nyd - 1 ) ij = 0 do j = 1, nyd - 1 do i = 1, nxd - 1 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 pwl_interp_2d ( nxd, nyd, xd_1d, yd_1d, zd, ni, xi, & yi, zi ) app_error = r8vec_norm_affine ( ni, zi, zdm ) / dble ( ni ) 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