# include # include # include # include # include # include # include using namespace std; # include "uniform.H" int main ( void ); //****************************************************************************80 int main ( void ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for UNIFORM_DATASET. // // Discussion: // // UNIFORM_DATASET generates a uniform pseudorandom 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: // // 12 April 2007 // // Author: // // John Burkardt // { char command[255]; char file_out_name[255]; int i; int m; int n; double *r; int seed; int seed_init; char *string; timestamp ( ); cout << "\n"; cout << "UNIFORM_DATASET\n"; cout << " C++ version\n"; cout << "\n"; cout << " Compiled on " << __DATE__ << " at " << __TIME__ << ".\n"; cout << "\n"; cout << " Generate a uniform pseudorandom dataset.\n"; cout << "\n"; cout << " This program is meant to be used interactively.\n"; cout << " It is also possible to prepare a simple input\n"; cout << " file beforehand and use it in batch mode.\n"; cout << "\n"; cout << " The program requests input values from the user:\n"; cout << "\n"; cout << " * M, the spatial dimension,\n"; cout << " * N, the number of points to generate,\n"; cout << " * SEED, a positive integer.\n"; cout << "\n"; cout << " The program generates the data, writes it to the file\n"; cout << "\n"; cout << " uniform_M_N.txt\n"; cout << "\n"; cout << " where ""M"" and ""N"" are the numeric values specified\n"; cout << " by the user, and then asks the user for more input.\n"; cout << "\n"; cout << " To indicate that no further computations are\n"; cout << " desired, it is enough to input a nonsensical value,\n"; cout << " such as -1.\n"; for ( ; ; ) { cout << " *\n"; cout << " *\n"; cout << "* Ready to generate a new dataset:\n"; cout << " *\n"; cout << " *\n"; cout << "\n"; cout << " Enter M, the spatial dimension:\n"; cout << " (Try '2' if you don't have a preference.)\n"; cout << " (0 or any negative value terminates execution).\n"; cin >> m; if ( cin.rdstate ( ) ) { cin.clear ( ); cout << "\n"; cout << "UNIFORM_DATASET - Fatal error!\n"; cout << " An I/O error occurred while trying to read M.\n"; cout << " Abnormal end of execution.\n"; break; } if ( m < 1 ) { cout << "\n"; cout << "UNIFORM_DATASET\n"; cout << " The input value of M = " << m << "\n"; cout << " is interpreted as a request for termination.\n"; cout << " Normal end of execution.\n"; break; } cout << "\n"; cout << " Enter N, the number of points to generate:\n"; cout << " (Try '25' if you don't have a preference.)\n"; cout << " (0 or any negative value terminates execution).\n"; cin >> n; if ( cin.rdstate ( ) ) { cin.clear ( ); cout << "\n"; cout << "UNIFORM_DATASET - Fatal error!\n"; cout << " An I/O error occurred while trying to read N.\n"; cout << " Abnormal end of execution.\n"; break; } if ( n < 1 ) { cout << "\n"; cout << "UNIFORM_DATASET\n"; cout << " The input value of N = " << n << "\n"; cout << " is interpreted as a request for termination.\n"; cout << " Normal end of execution.\n"; break; } cout << "\n"; cout << " Enter SEED, which is 0 or a positive integer.\n"; cout << " ('0' will cause the program to pick a value for you.)\n"; cout << " (Try '0' or '123456789' if you don't have a preference.)\n"; cout << " (Any negative value terminates execution).\n"; cin >> seed; if ( cin.rdstate ( ) ) { cin.clear ( ); cout << "\n"; cout << "UNIFORM_DATASET - Fatal error!\n"; cout << " An I/O error occurred while trying to read SEED.\n"; cout << " Abnormal end of execution.\n"; break; } if ( seed < 0 ) { cout << "\n"; cout << "UNIFORM_DATASET\n"; cout << " The input value of SEED = " << seed << "\n"; cout << " is interpreted as a request for termination.\n"; cout << " Normal end of execution.\n"; break; } if ( seed == 0 ) { seed = get_seed ( ); cout << "\n"; cout << " The actual value of SEED will be = " << seed << "\n"; } seed_init = seed; r = r8mat_uniform_01 ( m, n, &seed ); sprintf ( file_out_name, "uniform_%d_%d.txt", m, n ); r8mat_uniform_write ( m, n, seed_init, r, file_out_name ); delete [] r; cout << "\n"; cout << " The data was written to the file \"" << file_out_name << "\".\n"; } cout << "\n"; timestamp ( ); return 0; }