program main !*****************************************************************************80 ! !! MAIN is the main program for UNIFORM_DATASET. ! ! Discussion: ! ! UNIFORM_DATASET generates a uniform random dataset and writes it to a file. ! ! This program is meant to be used interactively. It's also ! possible to prepare a simple input file beforehand and use it ! in batch mode. ! ! The program requests input values from the user: ! ! * M, the spatial dimension, ! * N, the number of points to generate, ! * SEED, the seed, a positive integer. ! ! The program generates the data, writes it to the file ! ! uniform_M_N.txt ! ! where "M" and "N" are the numeric values specified by the user, ! and then asks the user for more input. To indicate that no further ! computations are desired, it is enough to input a nonsensical ! value, such as -1. ! ! Modified: ! ! 31 May 2007 ! ! Author: ! ! John Burkardt ! implicit none character ( len = 80 ) :: file_out_name integer ( kind = 4 ) ios integer ( kind = 4 ) m integer ( kind = 4 ) n real ( kind = 8 ), allocatable, dimension ( :, : ) :: r integer ( kind = 4 ) seed integer ( kind = 4 ) seed_init call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET' write ( *, '(a)' ) ' FORTRAN90 version' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Generate a uniform random dataset.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' This program is meant to be used interactively.' write ( *, '(a)' ) ' It is also possible to prepare a simple input' write ( *, '(a)' ) ' file beforehand and use it in batch mode.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The program requests input values from the user:' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' * M, the spatial dimension,' write ( *, '(a)' ) ' * N, the number of points to generate,' write ( *, '(a)' ) ' * SEED, a positive integer.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The program generates the data, ' write ( *, '(a)' ) ' writes it to the file' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' uniform_M_N.txt' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' where "M" and "N" are the numeric values specified' write ( *, '(a)' ) ' by the user, and then asks the user for more input.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' To indicate that no further computations are' write ( *, '(a)' ) ' desired, it is enough to input a nonsensical value,' write ( *, '(a)' ) ' such as -1.' do write ( *, '(a)' ) ' *' write ( *, '(a)' ) ' *' write ( *, '(a)' ) '* Ready to generate a new dataset:' write ( *, '(a)' ) ' *' write ( *, '(a)' ) ' *' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Enter M, the spatial dimension:' write ( *, '(a)' ) ' (Try "2" if you don''t have a preference.)' write ( *, '(a)' ) ' (0 or any negative value terminates execution.)' read ( *, *, iostat = ios ) m if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET - Fatal error!' write ( *, '(a)' ) ' An I/O error occurred while reading M.' exit end if if ( m <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET:' write ( *, '(a)' ) ' The value of M is interpreted as a request' write ( *, '(a)' ) ' for termination.' exit end if write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Enter N, the number of points to generate:' write ( *, '(a)' ) ' (Try "25" if you don''t have a preference.)' write ( *, '(a)' ) ' (0 or any negative value terminates execution).' read ( *, *, iostat = ios ) n if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET - Fatal error!' write ( *, '(a)' ) ' An I/O error occurred while reading N.' exit end if if ( n <= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET:' write ( *, '(a)' ) ' The value of N is interpreted as a request' write ( *, '(a)' ) ' for termination.' exit end if write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Enter SEED, the initial seed for UNIFORM,' write ( *, '(a)' ) ' a portable uniform random number generator:' write ( *, '(a)' ) ' (0 will cause the program to pick a value for you).' write ( *, '(a)' ) ' (a negative value terminates execution.)' read ( *, *, iostat = ios ) seed if ( ios /= 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET - Fatal error!' write ( *, '(a)' ) ' An I/O error occurred while reading IOS.' exit end if if ( seed < 0 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET:' write ( *, '(a)' ) ' The value of SEED is interpreted as a request' write ( *, '(a)' ) ' for termination.' exit end if if ( seed == 0 ) then call get_seed ( seed ) write ( *, '(a)' ) ' ' write ( *, '(a,i12)' ) ' Chosen value of SEED = ', seed end if allocate ( r(1:m,1:n) ) seed_init = seed call r8mat_uniform_01 ( m, n, seed, r ) ! write ( file_out_name, '(a,i2,a,i5,a)' ) 'uniform_', m, '_', n, '.txt' write ( file_out_name, '(a,i2.2,a,i5.5,a)' ) 'uniform_', m, '_', n, '.txt' call r8mat_uniform_write ( m, n, seed_init, seed, r, file_out_name ) deallocate ( r ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' The data was written to the file "' & // trim ( file_out_name ) // '".' end do write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'UNIFORM_DATASET' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop end