# include # include # include # include # include # include using namespace std; # include "van_der_corput.H" int main ( void ); //****************************************************************************80 int main ( void ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for VAN_DER_CORPUT_DATASET. // // Discussion: // // VAN_DER_CORPUT_DATASET generates a van der Corput dataset. // // 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: // // * BASE, the base of the sequence, // * SEED, the seed, a positive integer. // * N, the number of points to generate, // // The program generates the data, writes it to the file // // van_der_corput_BASE_SEED_N.txt // // where "BASE", "SEED", 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 // { int base; char command[255]; char file_out_name[255]; int i; int n; double *r; int seed; int seed_init; char *string; timestamp ( ); cout << "\n"; cout << "VAN_DER_CORPUT_DATASET\n"; cout << " C++ version\n"; cout << "\n"; cout << " Compiled on " << __DATE__ << " at " << __TIME__ << ".\n"; cout << "\n"; cout << " Generate a van der Corput 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 << " * BASE, the base,\n"; cout << " * SEED, a positive integer.\n"; cout << " * N, the number of points to generate,\n"; cout << "\n"; cout << " The program generates the data, writes it to the file\n"; cout << "\n"; cout << " van_der_corput_BASE_SEED_N.txt\n"; cout << "\n"; cout << " where ""BASE"", ""SEED"" and ""N"" are the numeric values\n"; cout << " specified 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 BASE, the van der Corput base,\n"; cout << " which is often a prime number:\n"; cout << " (Try '2' if you don't have a preference.)\n"; cout << " (Any value of 1 or less terminates execution).\n"; cin >> base; if ( cin.rdstate ( ) ) { cin.clear ( ); cout << "\n"; cout << "VAN_DER_CORPUT_DATASET - Fatal error!\n"; cout << " An I/O error occurred while trying to read BASE.\n"; cout << " Abnormal end of execution.\n"; break; } if ( base <= 1 ) { cout << "\n"; cout << "VAN_DER_CORPUT_DATASET\n"; cout << " The input value of BASE = " << base << "\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 << " (Try '0' or '1' 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 << "VAN_DER_CORPUT_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 << "VAN_DER_CORPUT_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; } 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 << "VAN_DER_CORPUT_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 << "VAN_DER_CORPUT_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; } seed_init = seed; r = new double[n]; i4_to_van_der_corput_sequence ( seed, base, n, r ); sprintf ( file_out_name, "van_der_corput_%d_%d_%d.txt", base, seed, n ); van_der_corput_write ( n, seed_init, base, 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; }