program main !*****************************************************************************80 ! !! MAIN is the main program for NIEDERREITER2_DATASET. ! ! Discussion: ! ! NIEDERREITER2_DATASET generates a Niederreiter2 dataset and writes it out. ! ! These program assumes that your computer's word length ! is 31 bits, excluding sign. If this is not the case, ! modify the parameter NBITS throughout accordingly. ! ! Modified: ! ! 14 April 2003 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! Paul Bratley, Bennett Fox, Harald Niederreiter, ! Algorithm 738: ! Programs to Generate Niederreiter's Low-Discrepancy Sequences, ! ACM Transactions on Mathematical Software, ! Volume 20, Number 4, pages 494-495, 1994. ! ! Local Parameters: ! ! Local, integer DIM_MAX, the maximum dimension that will be used. ! ! Local, integer POWER, is used in a possible warm-up formula. ! implicit none integer, parameter :: dim_max = 20 integer, parameter :: base = 2 integer dim_num character ( len = 80 ) :: file_out_name integer ios integer n integer, parameter :: power = 12 real, allocatable, dimension ( :, : ) :: r integer :: seed = 123456789 integer skip call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'NIEDERREITER2_DATASET' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Show a Niederreiter sequence for a given' write ( *, '(a)' ) ' spatial dimension.' write ( *, '(a)' ) ' ' do write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Enter the spatial dimension' write ( *, '(a,i6)' ) ' between 1 and ', dim_max write ( *, '(a)' ) ' (A 0 or negative value terminates execution.)' read ( *, *, iostat = ios ) dim_num if ( ios /= 0 ) then exit end if if ( dim_num <= 0 ) then exit end if if ( dim_max < dim_num ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'NIEDERREITER2_DATASET - Error!' write ( *, '(a,i6)' ) ' The dimension may not exceed ', dim_max cycle end if ! ! The sequence length is the number of quasi-random points used to ! estimate the integral, excluding warm-up. ! ! Some users may wish to rewrite the driver to test a [heuristic] ! "convergence" criterion, stopping the generation of points ! when it is passed or when a specified number of points have been ! generated, whichever occurs first. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Choose the sequence length:' ! ! Except when comparing results with other bases, we suggest taking ! N to be a power of 2. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' If you do not have a preference, we' write ( *, '(a)' ) ' suggest using a large power of two, such as:' write ( *, '(a)' ) ' ' write ( *, '(a,i12)' ) ' 2**10 = ', 2**10 write ( *, '(a,i12)' ) ' 2**15 = ', 2**15 write ( *, '(a,i12)' ) ' 2**20 = ', 2**20 write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Enter the sequence length:' read ( *, *, iostat = ios ) n if ( ios /= 0 ) then exit end if if ( n <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'NIEDERREITER2_DATASET - Error!' write ( *, '(a)' ) ' The sequence length must be strictly positive.' cycle end if write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Choose the number of values to skip:' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' There is reason to believe that BASE**E, ' write ( *, '(a)' ) ' where E is defined for example in ' write ( *, '(a)' ) ' Bratley, Fox, and Niederreiter [1991], ' write ( *, '(a)' ) ' would be a good choice. Our formula has ' write ( *, '(a)' ) ' has the form:' write ( *, '(a)' ) ' SKIP = 2 ** POWER,' write ( *, '(a)' ) ' where POWER is chosen so that SKIP comes nowhere ' write ( *, '(a)' ) ' near the largest possible machine-representable' write ( *, '(a)' ) ' integer. It does not hurt to choose ' write ( *, '(a)' ) ' POWER larger than E, because skipping is ' write ( *, '(a)' ) ' done implicitly in O(1) time. ' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The maximum value of E for a fixed dimension ' write ( *, '(a)' ) ' S grows like log S. We allow some "fat" for ' write ( *, '(a)' ) ' the implicit constant. ' write ( *, '(a)' ) ' ' write ( *, '(a,i12)' ) ' Numerically, 2**POWER = ', 2 ** power write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Enter SKIP (not necessarily the value above)' read ( *, *, iostat = ios ) skip if ( ios /= 0 ) then exit end if if ( skip < 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'NIEDERREITER2_DATASET - Error!' write ( *, '(a)' ) ' The skip value must be nonnegative.' cycle end if allocate ( r(1:dim_num,1:n) ) call niederreiter2_generate ( dim_num, n, seed, r ) write ( file_out_name, '(a,i2.2,a,i5.5,a)' ) & 'niederreiter2_', dim_num, '_', n, '.txt' call niederreiter_write ( dim_num, n, base, skip, r, file_out_name ) deallocate ( r ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'NIEDERREITER2_DATASET:' write ( *, '(a)' ) ' Output file name is ' // trim ( file_out_name ) end do write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'NIEDERREITER2_DATASET:' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end