program main !*****************************************************************************80 ! !! lcvt_test() tests lcvt(). ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 09 August 2005 ! ! Author: ! ! John Burkardt ! implicit none integer i integer sample_function_cvt call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'lcvt_test():' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' Test lcvt().' do i = -1, 2 sample_function_cvt = i call test01 ( sample_function_cvt ) end do call test02 ( ) ! ! Terminate. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'lcvt_test():' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop 0 end subroutine test01 ( sample_function_cvt ) !*****************************************************************************80 ! !! TEST01 tests CVT, R8MAT_LATINIZE. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 09 August 2005 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: dim_num = 2 integer, parameter :: n = 25 real ( kind = rk ) generator(dim_num,n) integer i integer, parameter :: latin_steps = 3 integer sample_function_cvt integer, parameter :: sample_function_init = 0 integer, parameter :: sample_num_cvt = 100000 integer, parameter :: sample_num_steps = 50 write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST01' write ( *, '(a)' ) ' CVT computes a Centroidal Voronoi Tessellation.' write ( *, '(a)' ) ' R8MAT_LATINIZE makes it a Latin Hypersquare.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' In this test, we vary the sampling used during the' write ( *, '(a)' ) ' CVT Latin iteration.' write ( *, '(a)' ) ' ' write ( *, '(a,i12)' ) ' Spatial dimension DIM_NUM = ', dim_num write ( *, '(a,i12)' ) ' Number of generators = ', n write ( *, '(a)' ) ' ' if ( sample_function_init == -1 ) then write ( *, '(a)' ) ' Initialize using RANDOM_NUMBER (Fortran90 intrinsic).' else if ( sample_function_init == 0 ) then write ( *, '(a)' ) ' Initialize using UNIFORM.' else if ( sample_function_init == 1 ) then write ( *, '(a)' ) ' Initialize using HALTON.' else if ( sample_function_init == 2 ) then write ( *, '(a)' ) ' Initialize using GRID.' else if ( sample_function_init == 3 ) then write ( *, '(a)' ) ' USER will initialize data.' end if if ( sample_function_cvt == -1 ) then write ( *, '(a)' ) ' Sample using RANDOM_NUMBER (Fortran90 intrinsic).' else if ( sample_function_cvt == 0 ) then write ( *, '(a)' ) ' Sample using UNIFORM.' else if ( sample_function_cvt == 1 ) then write ( *, '(a)' ) ' Sample using HALTON.' else if ( sample_function_cvt == 2 ) then write ( *, '(a)' ) ' Sample using GRID.' end if write ( *, '(a,i8)' ) ' Number of sample points = ', sample_num_cvt write ( *, '(a,i8)' ) ' Number of sample steps = ', sample_num_steps do i = 1, latin_steps call cvt ( dim_num, n, sample_function_init, sample_function_cvt, & sample_num_cvt, sample_num_steps, generator ) call r8mat_transpose_print ( dim_num, n, generator, ' After CVT steps:' ) call r8mat_latinize ( dim_num, n, generator ) call r8mat_transpose_print ( dim_num, n, generator, ' After Latin step:' ) end do return end subroutine test02 ( ) !*****************************************************************************80 ! !! TEST02 tests CVT, R8MAT_LATINIZE. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 09 August 2005 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: dim_num = 2 integer, parameter :: n = 25 real ( kind = rk ) generator(dim_num,n) integer i integer, parameter :: latin_steps = 3 integer ngrid integer rank integer, parameter :: sample_function_cvt = 0 integer, parameter :: sample_function_init = 3 integer, parameter :: sample_num_cvt = 100000 integer, parameter :: sample_num_steps = 50 integer tuple(dim_num) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'TEST02' write ( *, '(a)' ) ' CVT computes a Centroidal Voronoi Tessellation.' write ( *, '(a)' ) ' R8MAT_LATINIZE makes it a Latin Hypersquare.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' In this test, we initialize the generators to' write ( *, '(a)' ) ' grid points; this is an unstable CVT solution.' write ( *, '(a)' ) ' ' write ( *, '(a,i12)' ) ' Spatial dimension DIM_NUM = ', dim_num write ( *, '(a,i12)' ) ' Number of generators = ', n write ( *, '(a)' ) ' ' if ( sample_function_init == -1 ) then write ( *, '(a)' ) ' Initialize using RANDOM_NUMBER (Fortran90 intrinsic).' else if ( sample_function_init == 0 ) then write ( *, '(a)' ) ' Initialize using UNIFORM.' else if ( sample_function_init == 1 ) then write ( *, '(a)' ) ' Initialize using HALTON.' else if ( sample_function_init == 2 ) then write ( *, '(a)' ) ' Initialize using GRID.' else if ( sample_function_init == 3 ) then write ( *, '(a)' ) ' USER will initialize data.' end if if ( sample_function_init == -1 ) then write ( *, '(a)' ) ' Sample using RANDOM_NUMBER (Fortran90 intrinsic).' else if ( sample_function_cvt == 0 ) then write ( *, '(a)' ) ' Sample using UNIFORM.' else if ( sample_function_cvt == 1 ) then write ( *, '(a)' ) ' Sample using HALTON.' else if ( sample_function_cvt == 2 ) then write ( *, '(a)' ) ' Sample using GRID.' end if write ( *, '(a,i8)' ) ' Number of sample points = ', sample_num_cvt write ( *, '(a,i8)' ) ' Number of sample steps = ', sample_num_steps ngrid = 5 do rank = 0, n-1 call tuple_next_fast ( ngrid, dim_num, rank, tuple ) generator(1:dim_num,rank+1) = real ( 2 * tuple(1:dim_num) - 1, kind = rk ) & / real ( 2 * ngrid, kind = rk ) end do call r8mat_transpose_print ( dim_num, n, generator, & ' Initial generators (rows):' ) do i = 1, latin_steps call cvt ( dim_num, n, sample_function_init, sample_function_cvt, & sample_num_cvt, sample_num_steps, generator ) call r8mat_transpose_print ( dim_num, n, generator, & ' After CVT steps:' ) call r8mat_latinize ( dim_num, n, generator ) call r8mat_transpose_print ( dim_num, n, generator, & ' After Latin step:' ) end do return end subroutine timestamp ( ) !*****************************************************************************80 ! !! timestamp() prints the current YMDHMS date as a time stamp. ! ! Example: ! ! 31 May 2001 9:45:54.872 AM ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 18 May 2013 ! ! Author: ! ! John Burkardt ! implicit none character ( len = 8 ) ampm integer d integer h integer m integer mm character ( len = 9 ), parameter, dimension(12) :: month = (/ & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' /) integer n integer s integer values(8) integer y call date_and_time ( values = values ) y = values(1) m = values(2) d = values(3) h = values(5) n = values(6) s = values(7) mm = values(8) if ( h < 12 ) then ampm = 'AM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h < 12 ) then ampm = 'PM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, '(i2.2,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