/** * @brief Read in files with arrays and join them into a single file * @param argc * @param argv[] * @return */ int main (int argc, char *argv[]) { AnyOption opt; opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */ opt.setOption ("verbose", 'v'); opt.setOption ("random", 'r'); opt.addUsage ("OA: unittest: Perform some checks on the code"); opt.addUsage ("Usage: unittest [OPTIONS]"); opt.addUsage (""); opt.addUsage (" -v --verbose Print documentation"); opt.addUsage (" -r --random Seed for random number generator"); opt.processCommandArgs (argc, argv); int verbose = opt.getIntValue ('v', 1); int random = opt.getIntValue ('r', 0); if (opt.getFlag ("help") || opt.getFlag ('h')) { opt.printUsage (); exit (0); } if (verbose) { print_copyright (); } if (verbose >= 2) { print_options (std::cout); } oaunittest (verbose, 1, random); return 0; }
/** * @brief Read in files with arrays and join them into a single file * @param argc * @param argv[] * @return */ int main (int argc, char *argv[]) { AnyOption opt; /* parse command line options */ opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */ opt.setOption ("output", 'o'); opt.setOption ("format", 'f'); opt.setOption ("verbose", 'v'); opt.addUsage ("Orthonal Array Convert: convert array file into a different format"); opt.addUsage ("Usage: oaconvert [OPTIONS] [INPUTFILE] [OUTPUTFILE]"); opt.addUsage (""); opt.addUsage (" -h --help Prints this help "); opt.addUsage (" -f [FORMAT] Output format (default: TEXT, or BINARY) "); opt.processCommandArgs (argc, argv); int verbose = opt.getIntValue ("verbose", 2); if (verbose > 0) print_copyright (); /* parse options */ if (opt.getFlag ("help") || opt.getFlag ('h') || opt.getArgc () == 0) { opt.printUsage (); exit (0); } const std::string outputprefix = opt.getStringValue ('o', ""); std::string format = opt.getStringValue ('f', "BINARY"); arrayfile::arrayfilemode_t mode = arrayfile_t::parseModeString (format); if (opt.getArgc () != 2) { opt.printUsage (); exit (0); } std::string infile = opt.getArgv (0); std::string outfile = opt.getArgv (1); convert_array_file(infile, outfile, mode, verbose); return 0; }
void readoption(int argc, char *argv[], bool *convertDir, QString *filename, QString *dir, QString *path) { /* 1. CREATE AN OBJECT */ AnyOption *opt = new AnyOption(); /* 2. SET PREFERENCES */ //opt->noPOSIX(); /* do not check for POSIX style character options */ //opt->setVerbose(); /* print warnings about unknown options */ //opt->autoUsagePrint(true); /* print usage for bad options */ /* 3. SET THE USAGE/HELP */ opt->addUsage( "" ); opt->addUsage( "Usage: " ); opt->addUsage( "" ); opt->addUsage( " -h --help Prints this help " ); opt->addUsage( " -f --filename FILENAME Filename to be converted " ); opt->addUsage( " -d --dir DIRECTORY File dir to be converted " ); opt->addUsage( " -p --path PATH Path where converted file saves " ); opt->addUsage( "" ); /* 4. SET THE OPTION STRINGS/CHARACTERS */ /* by default all options will be checked on the command line and from option/resource file */ opt->setFlag( "help", 'h' ); /* a flag (takes no argument), supporting long and short form */ opt->setOption( "filename", 'f' ); /* an option (takes an argument), supporting long and short form */ opt->setOption( "dir", 'd' ); /* an option (takes an argument), supporting long and short form */ opt->setOption( "path", 'p' ); /* an option (takes an argument), supporting long and short form */ /* 5. PROCESS THE COMMANDLINE AND RESOURCE FILE */ /* go through the command line and get the options */ opt->processCommandArgs( argc, argv ); if( ! opt->hasOptions()) { /* print usage if no options */ opt->printUsage(); delete opt; return; } /* 6. GET THE VALUES */ if( opt->getFlag( "help" ) || opt->getFlag( 'h' ) ) opt->printUsage(); if( opt->getValue( 'f' ) != NULL || opt->getValue( "filename" ) != NULL ) { *convertDir = false; filename->append(QString(opt->getValue( 'f' ))); } if( opt->getValue( 'd' ) != NULL || opt->getValue( "dir" ) != NULL ) { *convertDir = true; dir->append(QString(opt->getValue( 'd' ))); } if( opt->getValue( 'p' ) != NULL || opt->getValue( "path" ) != NULL ) { path->append(QString(opt->getValue( 'p' ))); } /* 8. DONE */ delete opt; }
int main(int argc, char* argv[]) { AnyOption opt; // Usage opt.addUsage( "Example: " ); opt.addUsage( " cppbitmessage -p 8444" ); opt.addUsage( " " ); opt.addUsage( "Usage: " ); opt.addUsage( "" ); opt.addUsage( " -p --port Port to listen on"); opt.addUsage( " -V --version Show version number"); opt.addUsage( " --help Show help"); opt.addUsage( "" ); opt.setOption( "port", 'p' ); opt.setFlag( "version", 'V' ); opt.setFlag( "help" ); opt.processCommandArgs(argc, argv); if ((!opt.hasOptions()) || (opt.getFlag( "help" ))) { // print usage if no options opt.printUsage(); return 0; } if ((opt.getFlag("version")) || (opt.getFlag('V'))) { std::cout << "Version " << VERSION << std::endl; return 0; } int port = 8444; if ((opt.getValue("port") != NULL) || (opt.getValue('p'))) { std::stringstream ss; ss << opt.getValue("port"); ss >> port; }
int main(int argc, char **argv) { AnyOption *opt = new AnyOption(); opt->addUsage(""); opt->addUsage("Usage: "); opt->addUsage(""); opt->addUsage(" -h --help Print usage "); opt->addUsage(" -L --subsecLet Letter of Subsector (A-P) to generate, if omitted will generate entire sector "); opt->addUsage(" -d --detail %|zero|rift|sparse|scattered|dense "); opt->addUsage(" -m --maturity Tech level, backwater|frontier|mature|cluster "); opt->addUsage(" -a --ac Two-letter system alignment code "); opt->addUsage(" -s --secName Name of sector. For default output file name and sectorName_names.txt file"); opt->addUsage(" -p --path Path to sectorName_names.txt file "); opt->addUsage(" -o --outFormat 1|2|3|4|5|6 : v1.0, v2.0, v2.1 v2.1b, v2.2, v2.5 "); opt->addUsage(" -u --outPath Path and name of output file "); opt->addUsage(""); opt->setCommandFlag("main", 'm'); opt->setCommandFlag("system", 'S'); opt->setCommandFlag("sector", 's'); opt->setCommandFlag("subsector", 'u'); opt->setCommandFlag("help", 'h'); opt->setCommandOption("", 'x'); opt->setCommandOption("", 'y'); opt->setCommandOption("", 'z'); opt->setCommandOption("detail", 'd'); opt->setCommandOption("seed"); //opt->setVerbose(); /* print warnings about unknown options */ //opt->autoUsagePrint(true); /* print usage for bad options */ opt->processCommandArgs(argc, argv); #if 0 if(! opt->hasOptions()) { /* print usage if no options */ opt->printUsage(); delete opt; return 0; } #endif if(opt->getFlag("help") || opt->getFlag('h')) { opt->printUsage(); delete opt; return 0; } //long seed = 12345; long x = 0; long y = 10; long z = 0; int detail = 3; if(opt->getValue('x') != NULL) { x = atol(opt->getValue('x')); } if(opt->getValue('y') != NULL) { y = atol(opt->getValue('y')); } if(opt->getValue('z') != NULL) { z = atol(opt->getValue('z')); } if(opt->getValue("seed") != NULL) { //seed = atol(opt->getValue("seed")); } if(opt->getValue("detail") != NULL) { detail = atol(opt->getValue("detail")); } long startX, startY, startZ; long endX, endY, endZ; long sectorX = 8 * 4; long sectorY = 10 * 4; long sectorZ = 1; if(opt->getFlag("sector")) { startX = x / sectorX; endX = startX + sectorX - 1; startY = y / sectorY; endY = startY + sectorY - 1; startZ = z / sectorZ; endZ = startZ + sectorZ - 1; } else { startX = x; endX = x; startY = y; endY = y; startZ = z; endZ = z; } for(int i = startX; i <= endX; i++) { for(int j = startY; j <= endY; j++) { for(int k = startZ; k <= endZ; k++) { printSystem(x, y, z, detail); } } } }
//+----------------------------------------------------------------------------+ //| main() | //-----------------------------------------------------------------------------+ int main(int argc, char** argv) { common::PathFileString pfs(argv[0]); ////////////////////////////////////////////////////////////////////////////// // User command line parser AnyOption *opt = new AnyOption(); opt->autoUsagePrint(true); opt->addUsage( "" ); opt->addUsage( "Usage: " ); char buff[256]; sprintf(buff, " Example: %s -r example1_noisy.cfg", pfs.getFileName().c_str()); opt->addUsage( buff ); opt->addUsage( " -h --help Prints this help" ); opt->addUsage( " -r --readfile <filename> Reads the polyhedra description file" ); opt->addUsage( " -t --gltopic <topic name> (opt) ROS Topic to send OpenGL commands " ); opt->addUsage( "" ); opt->setFlag( "help", 'h' ); opt->setOption( "readfile", 'r' ); opt->processCommandArgs( argc, argv ); if( opt->getFlag( "help" ) || opt->getFlag( 'h' ) ) {opt->printUsage(); delete opt; return(1);} std::string gltopic("OpenGLRosComTopic"); if( opt->getValue( 't' ) != NULL || opt->getValue( "gltopic" ) != NULL ) gltopic = opt->getValue( 't' ); std::cerr << "[OpenGL communication topic is set to : \"" << gltopic << "\"]\n"; std::string readfile; if( opt->getValue( 'r' ) != NULL || opt->getValue( "readfile" ) != NULL ) { readfile = opt->getValue( 'r' ); std::cerr << "[ World description is read from \"" << readfile << "\"]\n"; } else{opt->printUsage(); delete opt; return(-1);} delete opt; // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Initialize ROS and OpenGLRosCom node (visualization) std::cerr << "["<<pfs.getFileName()<<"]:" << "[Initializing ROS]"<< std::endl; ros::init(argc, argv, pfs.getFileName().c_str()); if(ros::isInitialized()) std::cerr << "["<<pfs.getFileName()<<"]:" << "[Initializing ROS]:[OK]\n"<< std::endl; else{ std::cerr << "["<<pfs.getFileName()<<"]:" << "[Initializing ROS]:[FAILED]\n"<< std::endl; return(1); } COpenGLRosCom glNode; glNode.CreateNode(gltopic); // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Reading the input file std::cerr << "Reading the input file..." << std::endl; ShapeVector shapes; PoseVector poses; IDVector ID; if(ReadPolyhedraConfigFile(readfile, shapes, poses, ID)==false) { std::cerr << "["<<pfs.getFileName()<<"]:" << "Error reading file \"" << readfile << "\"\n"; return(-1); } std::cerr << "Read " << poses.size() << " poses of " << shapes.size() << " shapes with " << ID.size() << " IDs.\n"; // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Visualizing the configuration of objects std::cerr << "Visualizing the configuration of objects..." << std::endl; for(unsigned int i=0; i<shapes.size(); i++) { for(size_t j=0; j<shapes[i].F.size(); j++) { glNode.LineWidth(1.0f); glNode.AddColor3(0.3f, 0.6f, 0.5f); glNode.AddBegin("LINE_LOOP"); for(size_t k=0; k<shapes[i].F[j].Idx.size(); k++) { int idx = shapes[i].F[j].Idx[k]; Eigen::Matrix<Real,3,1> Vt = poses[i]*shapes[i].V[ idx ]; glNode.AddVertex(Vt.x(), Vt.y(), Vt.z()); } glNode.AddEnd(); } } glNode.SendCMDbuffer(); ros::spinOnce(); common::PressEnterToContinue(); // ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// // Running PROMTS with A* search algorithm std::cerr << "Running PROMTS with Depth Limited search algorithm..." << std::endl; promts::ProblemDataStruct pds("Depth-Limited Search"); pds.m_glNodePtr = &glNode; PoseVector refined_poses(shapes.size()); refinePoses_DLSearch(shapes, poses, ID, refined_poses, pds); // ////////////////////////////////////////////////////////////////////////////// return(0); }
int main (int argc, char *argv[]) { AnyOption opt; /* parse command line options */ opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */ opt.setOption ("output", 'o'); opt.setOption ("input", 'I'); opt.setOption ("rand", 'r'); opt.setOption ("verbose", 'v'); opt.setOption ("ii", 'i'); opt.setOption ("jj"); opt.setOption ("xx", 'x'); opt.setOption ("dverbose", 'd'); opt.setOption ("rows"); opt.setOption ("cols"); opt.setOption ("nrestarts"); opt.setOption ("niter"); opt.setOption ("mdebug", 'm'); opt.setOption ("oaconfig", 'c'); /* file that specifies the design */ opt.addUsage ("Orthonal Array: oatest: testing platform"); opt.addUsage ("Usage: oatest [OPTIONS] [FILE]"); opt.addUsage (""); opt.addUsage (" -h --help Prints this help "); opt.processCommandArgs (argc, argv); double t0 = get_time_ms (), dt = 0; int randvalseed = opt.getIntValue ('r', 1); int ix = opt.getIntValue ('i', 1); int r = opt.getIntValue ('r', 1); int jj = opt.getIntValue ("jj", 5); int xx = opt.getIntValue ('x', 0); int niter = opt.getIntValue ("niter", 10); int verbose = opt.getIntValue ("verbose", 1); const char *input = opt.getValue ('I'); if (input == 0) input = "test.oa"; srand (randvalseed); if (randvalseed == -1) { randvalseed = time (NULL); printf ("random seed %d\n", randvalseed); srand (randvalseed); } array_link array = exampleArray(0); lmc_t lmc_type = LMCcheck(array); array = array.randomperm(); array.showarray(); array_link reduced_array = reduceLMCform(array); reduced_array.showarray(); exit(0); try { array_link al = exampleArray(r); al.show(); al.showarray(); std::vector<int> sizes = array2modelmatrix_sizes(al); display_vector(sizes); myprintf("\n"); MatrixFloat modelmatrix = array2modelmatrix(al, "i", 1); array_link modelmatrixx = modelmatrix; modelmatrixx.show(); modelmatrixx.showarray(); modelmatrix = array2modelmatrix(al, "main", 1); modelmatrixx = modelmatrix; modelmatrixx.show(); modelmatrixx.showarray(); exit(0); } catch (const std::exception &e) { std::cerr << e.what() << std::endl; throw; } { array_link al = exampleArray (r); array_transformation_t tt = reduceOAnauty (al); array_link alx = tt.apply (al); exit (0); } return 0; }
AnyOption *parseInputOptions( int argc, char **argv ) { // parse input options AnyOption *opt = new AnyOption(); opt->addUsage( "----------------------------------------------------------------------------" ); opt->addUsage( "| NCPA Infrasound |" ); opt->addUsage( "| Normal Modes Broadband |" ); opt->addUsage( "| Based on either: Effective Sound Speed Approximation - see ModESS |" ); opt->addUsage( "| Wide_Angle High-Mach code - see WMod |" ); opt->addUsage( "----------------------------------------------------------------------------" ); opt->addUsage( "Usage: " ); opt->addUsage( "" ); opt->addUsage( "The options below can be specified in a colon-separated file \"ModBB.options\""); opt->addUsage( "or at the command line. Command-line options override file options." ); opt->addUsage( "Be sure to precede all options with two minuses (--)." ); opt->addUsage( " --help -h Print this message and exit" ); opt->addUsage( "" ); opt->addUsage( "One of two algorithms can be used to perform pulse propagation." ); opt->addUsage( "The first is based on the Effective Sound Speed Approximation (as in ModESS);" ); opt->addUsage( "the second is based on the the Wide_Angle High-Mach solution "); opt->addUsage( "of the wave equation (see implementation in WMod)." ); opt->addUsage( "ModESS is faster but it is accurate for (launch) angles less than 30 deg and" ); opt->addUsage( "low wind speeds. WMod extends the validity to higher angles" ); opt->addUsage( "and high Mach numbers but it runs slower." ); opt->addUsage( "Options --use_modess and --use_wmod allow the user to choose"); opt->addUsage( "the desired algorithm when computing the dispersion data (see step 1 below)." ); opt->addUsage( "" ); opt->addUsage( "To propagate a pulse, 2 steps must be completed:"); opt->addUsage( " 1. A dispersion file must be available or computed" ); opt->addUsage( " using the option --out_disp_src2rcv_file ." ); // opt->addUsage( " use either option --out_dispersion_files or --out_disp_src2rcv_file" ); opt->addUsage( " 2. Perform pulse propagation for one of several scenarios:"); opt->addUsage( " a. source-to-receiver at one range (option --pulse_prop_src2rcv)"); opt->addUsage( " b. source-to-receiver at several equally spaced ranges " ); opt->addUsage( " (option --pulse_prop_src2rcv_grid)"); // opt->addUsage( " c. computing the whole 2D pressure field " ); // opt->addUsage( " (most expensive - option --pulse_prop_grid)" ); opt->addUsage( " The source type can be one of the following:" ); opt->addUsage( " delta function -> see option --get_impulse_resp" ); opt->addUsage( " built-in pulse choice 1 -> see option --use_builtin_pulse1" ); opt->addUsage( " built-in pulse choice 2 -> see option --use_builtin_pulse2" ); opt->addUsage( " user-provided spectrum file -> see option --src_spectrum_file" ); opt->addUsage( " user-provided waveform file -> see option --src_waveform_file" ); opt->addUsage( "" ); // opt->addUsage( "To compute a dispersion file: one of the following 2 options is REQUIRED:" ); opt->addUsage( "To compute a dispersion file: the following option is REQUIRED:" ); opt->addUsage( " --out_disp_src2rcv_file <dispersion filename>"); opt->addUsage( " Output dispersion curves and modal values for" ); opt->addUsage( " source-to-receiver propagation to the specified file." ); // opt->addUsage( " --out_dispersion_files <dispersion filename stub>"); // opt->addUsage( " Output dispersion curves and modal values on a 2D grid" ); // opt->addUsage( " to binary files at each frequency. The resulting filenames" ); // opt->addUsage( " have the stub and frequency appended: " ); // opt->addUsage( " e.g. <stub><freq>_nm.bin." ); // opt->addUsage( " This option is computationally expensive." ); opt->addUsage( "" ); // opt->addUsage( " Examples (run in the 'samples' directory):" ); // opt->addUsage( "" ); // opt->addUsage( " a. Compute dispersion file that will be used to compute the pressure pulse at 1 receiver. Assume that we want to end up with a pulse having a spectrum with a maximum frequency of f_max=0.5 Hz. Also assume that we want the pulse represented on a time record of T=512 seconds. The number of positive frequencies necessary for the calculation is T*f_max = 256 i.e.256 frequencies between 0 and 0.5 Hz. Thus we know f_max=0.5 Hz and f_step=f_max/256=0.001953125 Hz. The corresponding run command is:" ); opt->addUsage( " Example (run in the 'samples' directory):" ); opt->addUsage( "" ); opt->addUsage( " Example to obtain a dispersion file that will be used to compute" ); opt->addUsage( " the propagated pressure pulse at a distant receiver. " ); opt->addUsage( " Assume that we want to end up with a pulse having a spectrum" ); opt->addUsage( " with a maximum frequency of f_max=0.5 Hz. " ); opt->addUsage( " Also assume that we want the pulse represented on a time record " ); opt->addUsage( " of T=512 seconds. The number of positive frequencies necessary " ); opt->addUsage( " for the calculation is T*f_max = 256 i.e.256 frequencies " ); opt->addUsage( " between f_min=f_step and 0.5 Hz. The step in frequency is " ); opt->addUsage( " f_step=f_max/256=0.001953125 Hz." ); opt->addUsage( " The corresponding run command is:" ); opt->addUsage( "" ); opt->addUsage( " >> ../bin/ModBB --out_disp_src2rcv_file myDispersionFile.dat " ); opt->addUsage( " --atmosfile NCPA_canonical_profile_zuvwtdp.dat --atmosfileorder zuvwtdp " ); opt->addUsage( " --skiplines 0 --azimuth 90 --f_step 0.001953125 --f_max 0.5 --use_modess" ); opt->addUsage( "" ); opt->addUsage( " Each line in this dispersion file has (4 + 4*n_modes) entries" ); opt->addUsage( " in the following format:" ); opt->addUsage( " freq n_modes rho_src rho_rcv Re(k_pert_m) Im(k_pert_m) V_m(z_src) V_m(z_rcv)" ); opt->addUsage( " where m varies from 1 to n_modes. k_pert_m, and V_m are" ); opt->addUsage( " the m_th wavenumber and mode amplitude respectively." ); opt->addUsage( " z_src and z_rcv stand for source and receiver height respectively." ); opt->addUsage( "" ); // opt->addUsage( " b. Compute dispersion files for propagation to all receivers on a 2D grid: for 256 frequencies from 0 to 0.5 Hz in steps of 0.5/256 Hz:" ); // opt->addUsage( "" ); // opt->addUsage( " >> ../bin/ModBB --out_dispersion_files disprs --atmosfile NCPA_canonical_profile_zuvwtdp.dat --atmosfileorder zuvwtdp --skiplines 0 --azimuth 90 --f_step 0.001953125 --f_max 0.5 --use_modess" ); opt->addUsage( "" ); opt->addUsage( "In addition the following options are REQUIRED:" ); opt->addUsage( " --use_modess Prompts the use of ModESS algorithm." ); opt->addUsage( " --use_wmod Prompts the use of WMod algorithm." ); opt->addUsage( " Note that --use_modess and --use_wmod are mutually exclusive." ); opt->addUsage( " --atmosfile <filename> Uses an ASCII atmosphere file" ); opt->addUsage( " referenced to Mean Sea Level (MSL)." ); opt->addUsage( " --atmosfileorder The order of the (z,t,u,v,w,p,d) fields in " ); opt->addUsage( " the ASCII file (Ex: 'ztuvpd')" ); opt->addUsage( " --skiplines Lines at the beginning of the ASCII file to skip" ); opt->addUsage( " --azimuth Value in range [0,360), clockwise from North" ); opt->addUsage( " --f_step The frequency step" ); opt->addUsage( " --f_max Maximum frequency to propagate" ); opt->addUsage( " Note that in this case the array of frequencies is [f_step:f_step:f_max]." ); opt->addUsage( "" ); opt->addUsage( "OPTIONAL [defaults]:" ); opt->addUsage( " --f_min Minimum frequency [f_step Hz] " ); opt->addUsage( " --maxheight_km Calculation grid height in km above MSL [150 km]" ); opt->addUsage( " --zground_km Height of the ground level above MSL [0 km]" ); opt->addUsage( " --Nz_grid Number of points on the z-grid from the ground" ); opt->addUsage( " to maxheight [20000]" ); opt->addUsage( " --sourceheight_km Source height in km Above Ground Level (AGL) [0]" ); opt->addUsage( " --receiverheight_km Receiver height in km AGL [0]" ); opt->addUsage( " --maxrange_km Maximum horizontal distance from origin to propagate" ); opt->addUsage( " [1000 km]" ); opt->addUsage( " --ground_impedance_model Name of the ground impedance models to be employed:" ); opt->addUsage( " [rigid], TBD" ); opt->addUsage( " --Lamb_wave_BC For a rigid ground: if ==1 it sets" ); opt->addUsage( " admittance= = -1/2*dln(rho)/dz; [ 0 ]" ); opt->addUsage( " --wind_units Use it to specify 'kmpersec' if the winds are given" ); opt->addUsage( " in km/s [ mpersec ]" ); opt->addUsage( " --use_attn_file Option to specify a file name containing" ); opt->addUsage( " user-provided attenuation coefficients " ); opt->addUsage( " to be loaded instead of the default" ); opt->addUsage( " Sutherland-Bass attenuation. " ); opt->addUsage( " The text file should contain two columns: " ); opt->addUsage( " height (km AGL) and " ); opt->addUsage( " attenuation coefficients in np/m." ); opt->addUsage( " --c_min Specify the minimum phase speed (in m/sec)." ); opt->addUsage( " This is used in conjunction with the --wvnum_filter" ); opt->addUsage( " flag which turns on wavenumber filtering by" ); opt->addUsage( " phase speed. See also the --wvnum_filter flag" ); opt->addUsage( " and the --c_max option." ); opt->addUsage( " --c_max Specify the maximum phase speed (in m/sec)." ); opt->addUsage( "" ); opt->addUsage( "FLAGS (no value required after the flag itself):" ); opt->addUsage( " --turnoff_WKB Turn off the WKB least phase speed estimation," ); opt->addUsage( " an approximation that speeds-up ground-to-ground" ); opt->addUsage( " propagation. If either or both the source and " ); opt->addUsage( " receiver are not on the ground [height=0] " ); opt->addUsage( " the approximation is turned off by default" ); opt->addUsage( " regardless whether the flag is mentioned" ); opt->addUsage( " in the command line or not." ); opt->addUsage( " --use_zero_attn Set attenuation to zero."); opt->addUsage( " Reads the dispersion file and sets the"); opt->addUsage( " imaginary part of the wavenumber to zero."); opt->addUsage( " --wvnum_filter Applies wavenumber filtering by phase speed" ); opt->addUsage( " and should be followed by specification of" ); opt->addUsage( " the parameters:" ); opt->addUsage( " --c_min minimum phase speed (in m/sec)." ); opt->addUsage( " --c_max maximum phase speed (in m/sec)." ); opt->addUsage( "" ); opt->addUsage( "" ); opt->addUsage( "Options for PULSE PROPAGATION:" ); opt->addUsage( " --pulse_prop_src2rcv <dispersion filename> "); opt->addUsage( " Propagate pulse from source to 1 receiver"); opt->addUsage( " at a distance specified by option --range_R_km; " ); opt->addUsage( " --range_R_km Propagate pulse to this range [km]" ); opt->addUsage( " --waveform_out_file <waveform filename> Name of the waveform output file" ); opt->addUsage( "" ); opt->addUsage( " --pulse_prop_src2rcv_grid <dispersion filename> "); opt->addUsage( " Propagate pulse from source to array of "); opt->addUsage( " horizontally equally-spaced receivers" ); opt->addUsage( "" ); opt->addUsage( " REQUIRED additional options:" ); opt->addUsage( " --f_center The center frequency of the built-in pulse choices 1 and 2" ); opt->addUsage( " (f_center<=f_max/5)" ); opt->addUsage( " --R_start_km Propagation from this range to R_end_km in DR_km steps." ); opt->addUsage( " --R_end_km Pulse is propagated from R_start_km to this range." ); opt->addUsage( " --DR_km Range step to propagate from R_start_km to R_end_km." ); opt->addUsage( " --waveform_out_file <waveform filename> "); opt->addUsage( " Name of the waveform output file." ); opt->addUsage( "" ); opt->addUsage( " OPTIONAL [defaults]:" ); opt->addUsage( " --max_celerity Maximum celerity [340 m/s]." ); opt->addUsage( " --nfft Number of points used in the FFT computation. "); opt->addUsage( " Defaults to [4*f_max/f_step]." ); opt->addUsage( "" ); opt->addUsage( "" ); opt->addUsage( "SOURCE TYPE input options: Use one of the following 4 options" ); opt->addUsage( " to specify the source type:" ); opt->addUsage( " --get_impulse_resp Flag to use a delta function as source and" ); opt->addUsage( " to output the impulse response." ); opt->addUsage( " --use_builtin_pulse1 Flag to request the use of the built-in source pulse." ); opt->addUsage( " Note: Use --f_center to request the central frequency" ); opt->addUsage( " of the pulse. f_center is restricted to a maximum" ); opt->addUsage( " value of fmax/5 where fmax is the maximum frequency" ); opt->addUsage( " defined by the dispersion file." ); opt->addUsage( " The input waveform and spectrum are also saved for the" ); opt->addUsage( " user's reference such that:" ); opt->addUsage( " The built-in source spectrum is outputted in the file." ); opt->addUsage( " 'source_spectrum_input.dat' with the format." ); opt->addUsage( " | Freq (Hz) | Re(S) | Imag(S) |." ); opt->addUsage( " The input source waveform is outputted in the file." ); opt->addUsage( " 'source_waveform_input.dat' with the format." ); opt->addUsage( " | Time [s] | Amplitude |." ); opt->addUsage( " --use_builtin_pulse2 Flag to request a second shape of built-in source pulse." ); opt->addUsage( " The input waveform and spectrum are also saved for the" ); opt->addUsage( " user's reference such that:" ); opt->addUsage( " The built-in source spectrum is outputted in the file." ); opt->addUsage( " 'source_spectrum_input.dat' with the format." ); opt->addUsage( " | Freq (Hz) | Re(S) | Imag(S) |." ); opt->addUsage( " The input source waveform is outputted in the file." ); opt->addUsage( " 'source_waveform_input.dat' with the format." ); opt->addUsage( " | Time [s] | Amplitude |." ); opt->addUsage( " --src_spectrum_file Specify the file name of the source spectrum"); opt->addUsage( " at positive frequencies. The file must have 3 columns" ); opt->addUsage( " | Freq | Real(Spectrum) | Imag(Spectrum) |" ); opt->addUsage( " Note that the frequencies provided in the file" ); opt->addUsage( " must match the frequencies in the dispersion file." ); opt->addUsage( " --src_waveform_file Specify the file name of the user-provided " ); opt->addUsage( " source waveform. The file must have 2 columns" ); opt->addUsage( " |Time | Amplitude |" ); opt->addUsage( " If none of then source type options are specified the delta function source"); opt->addUsage( " is the default i.e. the output is the impulse response." ); opt->addUsage( "" ); opt->addUsage( " Example: Pulse propagation to a point on the ground at range_R_km" ); opt->addUsage( " and output the impulse response:" ); opt->addUsage( "" ); opt->addUsage( " ../bin/ModBB --pulse_prop_src2rcv myDispersionFile.dat --range_R_km 240 " ); opt->addUsage( " --waveform_out_file mywavf.dat --get_impulse_resp" ); opt->addUsage( "" ); opt->addUsage( " Example: Pulse propagation to a point on the ground at range_R_km" ); opt->addUsage( " and employ the user-provided source spectrum:" ); opt->addUsage( "" ); opt->addUsage( " ../bin/ModBB --pulse_prop_src2rcv myDispersionFile.dat --range_R_km 240 " ); opt->addUsage( " --waveform_out_file mywavf.dat --max_celerity 300 " ); opt->addUsage( " --src_spectrum_file source_spectrum_example.dat" ); opt->addUsage( "" ); opt->addUsage( " Example: Pulse propagation to several points on the ground 20 km apart" ); opt->addUsage( " and employ the user-provided source waveform:" ); opt->addUsage( "" ); opt->addUsage( " ../bin/ModBB --pulse_prop_src2rcv_grid myDispersionFile.dat " ); opt->addUsage( " --R_start_km 240 --DR_km 20 --R_end_km 300 --waveform_out_file mywavf.dat " ); opt->addUsage( " --src_waveform_file source_waveform_input_example.dat" ); opt->addUsage( "" ); opt->addUsage( "" ); /* // This functionality works but was disabled because of too long computation times. opt->addUsage( " To compute a 2D field:" ); opt->addUsage( " --pulse_prop_grid <dispersion directory name> "); opt->addUsage( " Compute/view pulse on the 2D spatial x-z grid of 'height_km'"); opt->addUsage( " and 'width_km' starting at 'R_start_km" ); opt->addUsage( "" ); opt->addUsage( " --------------------------------------------------------------" ); opt->addUsage( " height_km | |" ); opt->addUsage( " | Pressure field computed within |" ); opt->addUsage( " | a 2D (width_km x height_km) grid |" ); opt->addUsage( " | 'ntsteps' times |" ); opt->addUsage( " | every 'tmstep' seconds |" ); opt->addUsage( " | |" ); opt->addUsage( " | |" ); opt->addUsage( " -------------x------------------------------------------------" ); opt->addUsage( " R_start_km" ); opt->addUsage( "" ); opt->addUsage(" Additional parameters:" ); opt->addUsage( " --R_start_km The grid (viewing window) starts at R_start_km" ); opt->addUsage( " --width_km Grid width" ); opt->addUsage( " --max_celerity Reference speed [m/s]; in conjunction with R_start_km"); opt->addUsage( " it is determining where inside the grid the field is at"); opt->addUsage( " a time step; a value smaller than the speed of sound"); opt->addUsage( " at the ground is suggested." ); opt->addUsage( " --tmstep 2D pressure field is calculated at this specified time step." ); opt->addUsage( " --ntsteps Number of times the 2D pressure field is calculated"); opt->addUsage( " 'tmstep' seconds apart." ); opt->addUsage( "" ); opt->addUsage( " OPTIONAL [defaults]:" ); opt->addUsage( " --height_km The height of the 2D grid. [maximum height]" ); opt->addUsage( " --frame_file_stub Each 2D grid is saved into a file with the name"); opt->addUsage( " frame_file_stub_<time_of_start>; Default:[Pressure2D]." ); opt->addUsage( "" ); opt->addUsage( " Example: >> ../bin/ModBB --pulse_prop_grid mydispersionFolder --R_start_km 220 --width_km 50 --height_km 25 --max_celerity 300 --tmstep 30 --ntsteps 5 --frame_file_stub myPressure --use_builtin_pulse" ); opt->addUsage( "" ); */ // Set up the actual flags, etc. opt->setFlag( "help", 'h' ); opt->setFlag( "use_modess" ); opt->setFlag( "use_wmod" ); opt->setFlag( "get_impulse_resp" ); opt->setFlag( "use_builtin_pulse1" ); opt->setFlag( "use_builtin_pulse2" ); opt->setFlag( "turnoff_WKB"); opt->setFlag( "plot"); opt->setFlag( "use_zero_attn"); opt->setFlag( "wvnum_filter"); opt->setOption( "atmosfile" ); opt->setOption( "atmosfileorder" ); opt->setOption( "wind_units" ); opt->setOption( "skiplines" ); opt->setOption( "azimuth" ); opt->setOption( "maxrange_km" ); opt->setOption( "sourceheight_km" ); opt->setOption( "receiverheight_km" ); opt->setOption( "maxheight_km" ); opt->setOption( "zground_km" ); opt->setOption( "stepsize" ); opt->setOption( "Nz_grid" ); opt->setOption( "Nrng_steps" ); opt->setOption( "out_TL_2D" ); opt->setOption( "ground_impedance_model" ); opt->setOption( "Lamb_wave_BC" ); opt->setOption( "f_min" ); opt->setOption( "f_step" ); opt->setOption( "f_max" ); opt->setOption( "f_center" ); opt->setOption( "pulse_prop_grid" ); opt->setOption( "pulse_prop_src2rcv" ); opt->setOption( "pulse_prop_src2rcv_grid" ); opt->setOption( "R_start_km" ); opt->setOption( "R_end_km" ); opt->setOption( "DR_km" ); opt->setOption( "max_celerity" ); opt->setOption( "range_R_km" ); opt->setOption( "out_dispersion_files" ); opt->setOption( "out_disp_src2rcv_file" ); opt->setOption( "waveform_out_file" ); opt->setOption( "width_km" ); opt->setOption( "height_km" ); opt->setOption( "tmstep" ); opt->setOption( "ntsteps" ); opt->setOption( "frame_file_stub" ); opt->setOption( "disp_dirname" ); opt->setOption( "src_spectrum_file" ); opt->setOption( "src_waveform_file" ); opt->setOption( "nfft" ); opt->setOption( "use_attn_file" ); opt->setOption( "c_min" ); opt->setOption( "c_max" ); // Process the command-line arguments opt->processFile( "./ModBB.options" ); opt->processCommandArgs( argc, argv ); if( ! opt->hasOptions()) { // print usage if no options opt->printUsage(); delete opt; exit( 1 ); } // Check to see if help text was requested if ( opt->getFlag( "help" ) || opt->getFlag( 'h' ) ) { opt->printUsage(); exit( 1 ); } return opt; }
void detailed( int argc, char* argv[] ) { /* 1. CREATE AN OBJECT */ AnyOption *opt = new AnyOption(); /* 2. SET PREFERENCES */ //opt->noPOSIX(); /* do not check for POSIX style character options */ //opt->setVerbose(); /* print warnings about unknown options */ //opt->noUsage(); /* stop printing Usage */ /* 3. SET THE USAGE/HELP */ opt->addUsage( "Usage: foo [OPTIONS]... [IMAGE FOLDER] " ); opt->addUsage( "Unknown options/arguments encountered " ); opt->addUsage( "Use -h or --help for a complete list of options" ); /* 4. SET THE OPTION STRINGS/CHARACTERS */ opt->setFlag( "help", 'h' ); /* for help */ opt->setOption( "width", 'w' ); opt->setOption( "height" ); opt->setFlag( "convert"); opt->setCommandOption( "name", 'n' ); opt->setCommandFlag( "help" ); opt->setFileOption( "title" ); /* 5. PROVIDE THE COMMANDLINE AND RESOURCE FILE */ if ( ! opt->processFile( "sample.txt" ) ) cout << "Failed processing the resource file" << endl ; opt->processCommandArgs( argc, argv ); /* 6. GET THE VALUES */ /* help */ if( opt->getFlag( "help" ) || opt->getFlag( 'h' ) ){ opt->printUsage(); /* print help here */ } cout << "THE OPTIONS : " << endl << endl ; if( opt->getValue( 'w' ) != NULL ) cout << "w : " << opt->getValue( 'w' ) << endl ; if( opt->getValue( "width" ) != NULL ) cout << "width : " << opt->getValue( "width" ) << endl ; if( opt->getValue( "height" ) != NULL ) cout << "height : " << opt->getValue( "height" ) << endl ; if( opt->getValue( "name" ) != NULL ) cout << "name : " << opt->getValue( "name" ) << endl ; if( opt->getValue( 'n' ) != NULL ) cout << "n : " << opt->getValue( 'n' ) << endl ; if( opt->getValue( "title" ) != NULL ) cout << "title : " << opt->getValue( "title" ) << endl ; if( opt->getFlag( "convert" ) ) cout << "convert : set " << endl ; cout << endl ; /* 7. GET THE ACTUAL ARGUMNETS AFTER THE OPTIONS */ cout << "THE ARGUMENTS : " << endl << endl ; for( int i = 0 ; i < opt->getArgc() ; i++ ){ cout << opt->getArgv( i ) << endl ; } cout << endl; /* 7. DONE */ delete opt; }
int main(int argc, char** argv) #endif /* #else int WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #endif */ { string datapath; AnyOption *opt = new AnyOption(); opt->addUsage( "" ); opt->addUsage( "Usage: " ); opt->addUsage( "" ); opt->addUsage( " -h --help Prints this help " ); opt->addUsage( " -d --data-path /dir Data files path " ); opt->addUsage( "" ); opt->setFlag( "help", 'h' ); opt->setOption( "data-path", 'd' ); opt->processCommandArgs( argc, argv ); if( opt->getFlag( "help" ) || opt->getFlag( 'h' ) ) { GWDBG_OUTPUT("Usage") opt->printUsage(); delete opt; return 0; } if( opt->getValue( 'd' ) != NULL || opt->getValue( "data-size" ) != NULL ) datapath = opt->getValue('d'); delete opt; try { #ifdef GP2X GW_PlatformGP2X platform; #elif defined(GW_PLAT_PANDORA) GW_PlatformPandora platform; #elif defined(GW_PLAT_S60) GW_PlatformS60 platform; #elif defined(GW_PLAT_WIZ) GW_PlatformWIZ platform; #elif defined(GW_PLAT_ANDROID) GW_PlatformAndroid platform; #elif defined(GW_PLAT_IOS) GW_PlatformIOS platform; #else GW_PlatformSDL platform(640, 480); #endif if (!datapath.empty()) platform.datapath_set(datapath); platform.initialize(); GW_GameList gamelist(&platform); GW_Menu menu(&platform, &gamelist); menu.Run(); platform.finalize(); } catch (GW_Exception &e) { GWDBG_OUTPUT(e.what().c_str()) fprintf(stderr, "%s\n", e.what().c_str()); return 1; } return 0; }
int process_option(int argc, char* argv[]){ AnyOption *opt = new AnyOption(); opt->setVerbose(); opt->addUsage( "" ); opt->addUsage( "Usage: " ); opt->addUsage( "" ); opt->addUsage( "--S0" ); opt->addUsage( "--G0" ); opt->addUsage( "--RhoGEF0" ); opt->addUsage( "--RhoA0" ); opt->addUsage( "--Inhibitor0" ); opt->addUsage( "--kg1" ); opt->addUsage( "--kg2" ); opt->addUsage( "--kf1" ); opt->addUsage( "--kfd" ); opt->addUsage( "--kg3" ); opt->addUsage( "--kgd" ); opt->addUsage( "--kf2" ); opt->addUsage( "--ka1" ); opt->addUsage( "--ka2" ); opt->addUsage( "--ki1" ); opt->addUsage( "--kid" ); opt->addUsage( "" ); opt->setOption( "S0" ); opt->setOption( "G0" ); opt->setOption( "RhoGEF0" ); opt->setOption( "RhoA0" ); opt->setOption( "Inhibitor0" ); opt->setOption( "kg1" ); opt->setOption( "kg2" ); opt->setOption( "kf1" ); opt->setOption( "kfd" ); opt->setOption( "kg3" ); opt->setOption( "kgd" ); opt->setOption( "kf2" ); opt->setOption( "ka1" ); opt->setOption( "ka2" ); opt->setOption( "ki1" ); opt->setOption( "kid" ); opt->processCommandArgs( argc, argv ); if( opt->getValue( "S0" ) != NULL ){ S0 = atof(opt->getValue( "S0" )); } if( opt->getValue( "G0" ) != NULL ){ G0 = atof(opt->getValue( "G0" )); } if( opt->getValue( "RhoGEF0" ) != NULL ){ RhoGEF0 = atof(opt->getValue( "RhoGEF0" )); } if( opt->getValue( "RhoA0" ) != NULL ){ RhoA0 = atof(opt->getValue( "RhoA0" )); } if( opt->getValue( "Inhibitor0" ) != NULL ){ Inhibitor0 = atof(opt->getValue( "Inhibitor0" )); } if( opt->getValue( "kg1" ) != NULL ){ kg1 = atof(opt->getValue( "kg1" )); } if( opt->getValue( "kg2" ) != NULL ){ kg2 = atof(opt->getValue( "kg2" )); } if( opt->getValue( "kf1" ) != NULL ){ kf1 = atof(opt->getValue( "kf1" )); } if( opt->getValue( "kfd" ) != NULL ){ kfd = atof(opt->getValue( "kfd" )); } if( opt->getValue( "kg3" ) != NULL ){ kg3 = atof(opt->getValue( "kg3" )); } if( opt->getValue( "kgd" ) != NULL ){ kgd = atof(opt->getValue( "kgd" )); } if( opt->getValue( "kf2" ) != NULL ){ kf2 = atof(opt->getValue( "kf2" )); } if( opt->getValue( "ka1" ) != NULL ){ ka1 = atof(opt->getValue( "ka1" )); } if( opt->getValue( "ka2" ) != NULL ){ ka2 = atof(opt->getValue( "ka2" )); } if( opt->getValue( "ki1" ) != NULL ){ ki1 = atof(opt->getValue( "ki1" )); } if( opt->getValue( "kid" ) != NULL ){ kid = atof(opt->getValue( "kid" )); } return 0; }
// // Function to parse the input options (both command lines and in the options file ModessRD.options) // AnyOption *parseInputOptions( int argc, char **argv ) { // parse input options AnyOption *opt = new AnyOption(); opt->addUsage( "----------------------------------------------------------------------------" ); opt->addUsage( "| NCPA Infrasound |" ); opt->addUsage( "| Normal Modes for Range-Dependent Environments |" ); opt->addUsage( "| Two-Way Coupled Mode Solution |" ); opt->addUsage( "| Single Frequency: Effective Sound Speed Approximation |" ); opt->addUsage( "----------------------------------------------------------------------------" ); opt->addUsage( "Usage: " ); opt->addUsage( "By default the program computes the 1D transmission loss (TL)" ); opt->addUsage( "at the ground or the specified receiver height and saves the data to 2 files:" ); opt->addUsage( " file tloss_rd2wcm_1d.nm - considering attenuation in the atmosphere" ); opt->addUsage( " file tloss_rd2wcm_1d.lossless.nm - no attenuation" ); opt->addUsage( "Additionally, if the flag --write_2D_TLoss is present on the command line the 2D TL is saved to file tloss_rd_2d.nm" ); opt->addUsage( "The options below can be specified in a colon-separated file \"Modess.options\" or at the command line. Command-line options override file options." ); opt->addUsage( " --help -h Print this message and exit" ); opt->addUsage( "" ); opt->addUsage( " The atmosphere can be specified from one of 2 different sources:"); opt->addUsage( " 1. An .env file containing the atmospheric specifications at certain ranges:" ); opt->addUsage( " use option --g2senvfile <filename>" ); opt->addUsage( " 2. Several ASCII files stored in a given directory:" ); opt->addUsage( " use option --use_1D_profiles_from_dir <mydirname>" ); //opt->addUsage( "The program requires an .env file containing the atmospheric specifications at certain ranges" ); opt->addUsage( "The following options apply:" ); opt->addUsage( "" ); opt->addUsage( "REQUIRED (no default values):" ); //opt->addUsage( " --atmosfile <filename> Uses an ASCII atmosphere file" ); opt->addUsage( " --g2senvfile <filename> Uses an .env binary file containing multiple 1D profiles" ); opt->addUsage( " --atmosfileorder The order of the (z,t,u,v,w,p,d) fields in the ASCII file (Ex: 'ztuvpd')" ); opt->addUsage( " --skiplines Lines at the beginning of the ASCII file to skip" ); opt->addUsage( " --azimuth Degrees in range [0,360), clockwise from North" ); opt->addUsage( " --freq Frequency [Hz]" ); opt->addUsage( "" ); opt->addUsage( "OPTIONAL [defaults]:" ); opt->addUsage( " --maxheight_km Calculation grid height in km above MSL [150 km]" ); opt->addUsage( " --zground_km Height of the ground level above MSL [0 km]" ); opt->addUsage( " --Nz_grid Number of points on the z-grid from ground to maxheight [20000]" ); opt->addUsage( " --sourceheight_km Source height in km Above Ground Level (AGL) [0]" ); opt->addUsage( " --receiverheight_km Receiver height in km AGL [0]" ); opt->addUsage( " --maxrange_km Maximum horizontal distance from origin to propagate [1000 km]" ); opt->addUsage( " --Nrng_steps Number of range steps to propagate [1000]" ); opt->addUsage( " --ground_impedance_model Name of the ground impedance models to be employed:" ); opt->addUsage( " [rigid], others TBD" ); opt->addUsage( " --Lamb_wave_BC If ==1 it sets admittance = -1/2*dln(rho)/dz; [ 0 ]" ); opt->addUsage( " --wind_units Use it to specify 'kmpersec' if the winds are given in km/s [mpersec]" ); opt->addUsage( " --use_attn_file Use it to specify a file name containing user-provided" ); opt->addUsage( " attenuation coefficients to be loaded instead of " ); opt->addUsage( " the default Sutherland-Bass attenuation. " ); opt->addUsage( " The text file should contain two columns: " ); opt->addUsage( " height (km AGL) and " ); opt->addUsage( " attenuation coefficients in np/m." ); opt->addUsage( "" ); opt->addUsage( " --use_profile_ranges_km" ); opt->addUsage( " e.g. --use_profile_ranges_km 0_20_50_80.5_300 " ); opt->addUsage( " The profiles at certain ranges specified by numbers" ); opt->addUsage( " (in km) in a string such as 0_20_50_80.5_300 are"); opt->addUsage( " requested in the propagation. Note that underscores" ); opt->addUsage( " are necessary to separate the numbers." ); opt->addUsage( " Note also that these are requested ranges;" ); opt->addUsage( " however the left-closest profile available" ); opt->addUsage( " in the .env file will actually be used; " ); opt->addUsage( " for instance we request the profile at 300 km " ); opt->addUsage( " but in the .env file the left-closest profile" ); opt->addUsage( " may be available at 290 km and it is the one used." ); opt->addUsage( " Example: >> ../bin/ModessRD2WCM --atmosfile g2sgcp2011012606L.jordan.env "); opt->addUsage( " --atmosfileorder zuvwtdp --azimuth 90 --freq 0.01 "); opt->addUsage( " --use_profiles_ranges_km 100_200_250 --maxrange_km 500 "); opt->addUsage( "" ); opt->addUsage( " --use_profiles_at_steps_km" ); opt->addUsage( " e.g. --use_profiles_at_steps_km 100" ); opt->addUsage( " The profiles are requested at equidistant intervals " ); opt->addUsage( " specified by this option [1000]" ); opt->addUsage( "" ); opt->addUsage( " --use_1D_profiles_from_dir" ); opt->addUsage( " e.g. --use_1D_profiles_from_dir myprofiles" ); opt->addUsage( " This option allows to use the ascii profiles stored in" ); opt->addUsage( " the specified directory. The profiles must have names" ); opt->addUsage( " 'profiles0001', 'profiles0002', etc. and will be" ); opt->addUsage( " used in alphabetical order at the provided ranges" ); opt->addUsage( " e.g. in conjunction with either" ); opt->addUsage( " option '--use_profile_ranges_km' " ); opt->addUsage( " or option '--use_profiles_at_steps_km'" ); opt->addUsage( " If there are more requested ranges than existing" ); opt->addUsage( " profiles then the last profile is used repeatedly" ); opt->addUsage( " as necessary." ); opt->addUsage( " Example: >> ../bin/ModessRD2WCM --atmosfileorder zuvwtdp --skiplines 1" ); opt->addUsage( " --azimuth 90 --freq 0.1 --use_1D_profiles_from_dir myprofiles" ); opt->addUsage( " --use_profile_ranges_km 0_100_300_500 " ); opt->addUsage( "" ); opt->addUsage( "FLAGS (no value required):" ); opt->addUsage( " --write_2D_TLoss Outputs the 2D transmission loss to" ); opt->addUsage( " default file: tloss_rd2wcm_2d.nm" ); opt->addUsage( "" ); opt->addUsage( "" ); opt->addUsage( " The format of the output files are as follows (column order):" ); opt->addUsage( " tloss_rd2wcm_1d.nm: r, 4*PI*Re(P), 4*PI*Im(P), (incoherent TL)" ); opt->addUsage( " tloss_rd2wcm_1d.lossless.nm:" ); opt->addUsage( " tloss_rd2wcm_2d.nm: r, z, 4*PI*Re(P), 4*PI*Im(P)" ); opt->addUsage( "" ); opt->addUsage( " Examples to run (in the 'samples' directory):" ); opt->addUsage( "" ); opt->addUsage( " ../bin/ModessRD2WCM --use_1D_profiles_from_dir profiles --atmosfileorder zuvwtdp --skiplines 1 --azimuth 90 --freq 0.1 --use_profile_ranges_km 0_100_200_300 --maxrange_km 500" ); opt->addUsage( "" ); opt->addUsage( " ../bin/ModessRD2WCM --g2senvfile g2sgcp2011012606L.jordan.env --atmosfileorder zuvwtdp --skiplines 1 --azimuth 90 --freq 0.1 --use_profile_ranges_km 0_100_200_250 --maxrange_km 500" ); opt->addUsage( "" ); opt->addUsage( " ../bin/ModessRD2WCM --use_1D_profiles_from_dir profiles --atmosfileorder zuvwtdp --skiplines 1 --azimuth 90 --freq 0.1 --maxrange_km 500" ); opt->addUsage( "" ); opt->addUsage( " Note: if options --use_profile_ranges_km/--use_profiles_at_steps_km are not used then we fall back on the range-independent case using the first available atm. profile." ); opt->addUsage( "" ); // Set up the actual flags, etc. opt->setFlag( "help", 'h' ); opt->setFlag( "write_2D_TLoss" ); opt->setFlag( "plot" ); opt->setOption( "atmosfile" ); opt->setOption( "atmosfileorder" ); opt->setOption( "g2senvfile" ); opt->setOption( "wind_units" ); opt->setOption( "use_1D_profiles_from_dir" ); opt->setOption( "slicefile" ); opt->setOption( "skiplines" ); opt->setOption( "azimuth" ); opt->setOption( "freq" ); opt->setOption( "maxrange_km" ); opt->setOption( "sourceheight_km" ); opt->setOption( "receiverheight_km" ); opt->setOption( "maxheight_km" ); opt->setOption( "zground_km" ); opt->setOption( "stepsize" ); opt->setOption( "Nz_grid" ); opt->setOption( "Nrng_steps" ); opt->setOption( "ground_impedance_model" ); opt->setOption( "Lamb_wave_BC" ); opt->setOption( "use_profile_ranges_km" ); opt->setOption( "use_profiles_at_steps_km" ); opt->setOption( "use_attn_file" ); // Process the command-line arguments opt->processFile( "./ModessRD2WCM.options" ); opt->processCommandArgs( argc, argv ); if( ! opt->hasOptions()) { // print usage if no options opt->printUsage(); delete opt; exit( 1 ); } // Check to see if help text was requested if ( opt->getFlag( "help" ) || opt->getFlag( 'h' ) ) { opt->printUsage(); exit( 1 ); } return opt; }
/** * @brief Filter arrays in a file and write filtered arrays to output file * @param argc Number of command line arguments * @param argv Command line arguments * @return */ int main (int argc, char *argv[]) { AnyOption opt; /* parse command line options */ opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */ opt.setOption ("output", 'o'); opt.setOption ("verbose", 'v'); opt.setOption ("na", 'a'); opt.setOption ("index", 'i'); opt.setOption ("format", 'f'); opt.addUsage ("Orthonal Array Filter: filter arrays"); opt.addUsage ("Usage: oaanalyse [OPTIONS] [INPUTFILE] [VALUESFILE] [THRESHOLD] [OUTPUTFILE]"); opt.addUsage (" The VALUESFILE is a binary file with k*N double values. Here N is the number of arrays"); opt.addUsage (" and k the number of analysis values."); opt.addUsage (""); opt.addUsage (" -h --help Prints this help "); opt.addUsage (" -v --verbose Verbose level (default: 1) "); opt.addUsage (" -a Number of values in analysis file (default: 1) "); opt.addUsage (" --index Index of value to compare (default: 0) "); opt.addUsage (" -f [FORMAT] Output format (default: TEXT, or BINARY; B) "); opt.processCommandArgs (argc, argv); print_copyright (); /* parse options */ if (opt.getFlag ("help") || opt.getFlag ('h') || opt.getArgc () < 4) { opt.printUsage (); exit (0); } int verbose = opt.getIntValue ('v', 1); int na = opt.getIntValue ('a', 1); int index = opt.getIntValue ("index", 0); std::string format = opt.getStringValue ('f', "BINARY"); arrayfile::arrayfilemode_t mode = arrayfile_t::parseModeString (format); /* read in the arrays */ std::string infile = opt.getArgv (0); std::string anafile = opt.getArgv (1); double threshold = atof (opt.getArgv (2)); std::string outfile = opt.getArgv (3); if (verbose) printf ("oafilter: input %s, threshold %f (analysisfile %d values, index %d)\n", infile.c_str (), threshold, na, index); arraylist_t *arraylist = new arraylist_t; int n = readarrayfile (opt.getArgv (0), arraylist); if (verbose) printf ("oafilter: filtering %d arrays\n", n); // read analysis file FILE *afid = fopen (anafile.c_str (), "rb"); if (afid == 0) { printf (" could not read analysisfile %s\n", anafile.c_str ()); exit (0); } double *a = new double[n * na]; fread (a, sizeof (double), n * na, afid); fclose (afid); std::vector< int > gidx; ; for (int jj = 0; jj < n; jj++) { double val = a[jj * na + index]; if (val >= threshold) gidx.push_back (jj); if (verbose >= 2) printf ("jj %d: val %f, threshold %f\n", val >= threshold, val, threshold); } // filter arraylist_t *filtered = new arraylist_t; selectArrays (*arraylist, gidx, *filtered); /* write arrays to file */ if (verbose) cout << "Writing " << filtered->size () << " arrays (input " << arraylist->size () << ") to file " << outfile << endl; writearrayfile (outfile.c_str (), *filtered, mode); /* free allocated structures */ delete[] a; delete arraylist; delete filtered; return 0; }
/** * @brief Read in a list of array and check for each of the arrays whether they are in LMC form or not * @param argc * @param argv[] * @return */ int main (int argc, char *argv[]) { char *fname; int correct = 0, wrong = 0; /* parse command line options */ AnyOption opt; opt.setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */ opt.setOption ("loglevel", 'l'); opt.setOption ("oaconfig", 'c'); opt.setOption ("check"); opt.setOption ("strength", 's'); opt.setOption ("prune", 'p'); opt.setOption ("output", 'o'); opt.setOption ("mode", 'm'); opt.addUsage ("oacheck: Check arrays for LMC form or reduce to LMC form"); opt.addUsage ("Usage: oacheck [OPTIONS] [ARRAYFILE]"); opt.addUsage (""); opt.addUsage (" -h --help Prints this help"); opt.addUsage (" -l [LEVEL] --loglevel [LEVEL] Set loglevel to number"); opt.addUsage (" -s [STRENGTH] --strength [STRENGTH] Set strength to use in checking"); std::string ss = " --check [MODE] Select mode: "; ss += printfstring ("%d (default: check ), %d (reduce to LMC form), %d (apply random transformation and reduce)", MODE_CHECK, MODE_REDUCE, MODE_REDUCERANDOM); // for (int i = 3; i < ncheckopts; ++i) ss += printfstring (", %d (%s)", static_cast< checkmode_t > (i), modeString ((checkmode_t)i).c_str ()); opt.addUsage (ss.c_str ()); opt.addUsage (" -o [OUTPUTFILE] Output file for LMC reduction"); opt.processCommandArgs (argc, argv); algorithm_t algmethod = (algorithm_t)opt.getIntValue ("mode", MODE_AUTOSELECT); int loglevel = NORMAL; if (opt.getValue ("loglevel") != NULL || opt.getValue ('l') != NULL) loglevel = atoi (opt.getValue ('l')); // set custom loglevel setloglevel (loglevel); if (checkloglevel (QUIET)) { print_copyright (); } if (opt.getFlag ("help") || opt.getFlag ('h') || opt.getArgc () == 0) { opt.printUsage (); return 0; } checkmode_t mode = MODE_CHECK; if (opt.getValue ("check") != NULL) mode = (checkmode_t)atoi (opt.getValue ("check")); // set custom loglevel if (mode >= ncheckopts) mode = MODE_CHECK; logstream (QUIET) << "#time start: " << currenttime () << std::endl; double t = get_time_ms (); t = 1e3 * (t - floor (t)); srand (t); int prune = opt.getIntValue ('p', 0); fname = opt.getArgv (0); setloglevel (loglevel); int strength = opt.getIntValue ('s', 2); if (strength < 1 || strength > 10) { printf ("Strength specfied (t=%d) is invalid\n", strength); exit (1); } else { log_print (NORMAL, "Using strength %d to increase speed of checking arrays\n", strength); } arraylist_t outputlist; char *outputfile = 0; bool writeoutput = false; if (opt.getValue ("output") != NULL) { writeoutput = true; outputfile = opt.getValue ('o'); } arrayfile_t *afile = new arrayfile_t (fname); if (!afile->isopen ()) { printf ("Problem opening %s\n", fname); exit (1); } logstream (NORMAL) << "Check mode: " << mode << " (" << modeString (mode) << ")" << endl; /* start checking */ double Tstart = get_time_ms (), dt; int index; array_link al (afile->nrows, afile->ncols, -1); for (int i = 0; i < afile->narrays; i++) { index = afile->read_array (al); array_t *array = al.array; arraydata_t arrayclass = arraylink2arraydata (al, 0, strength); arrayclass.lmc_overflow_check (); OAextend oaextend; lmc_t result = LMC_NONSENSE; LMCreduction_t *reduction = new LMCreduction_t (&arrayclass); LMCreduction_t *randtest = new LMCreduction_t (&arrayclass); array_link test_arraylink = al.clone(); array_t *testarray = test_arraylink.array; randtest->transformation->randomize (); reduction->setArray ( al); /* variables needed within the switch statement */ switch (mode) { case MODE_CHECK: { /* LMC test with reduction code */ reduction->mode = OA_TEST; result = LMCcheck(al, arrayclass, oaextend, *reduction); break; } case MODE_CHECKJ4: { /* LMC test with special code */ reduction->mode = OA_TEST; reduction->init_state = COPY; oaextend.setAlgorithm (MODE_J4, &arrayclass); result = LMCcheck (al, arrayclass, oaextend, *reduction); break; } case MODE_REDUCEJ4: { /* LMC test with special code */ reduction->mode = OA_REDUCE; reduction->setArray (al); result = LMCcheckj4 (al, arrayclass, *reduction, oaextend); break; } case MODE_CHECK_SYMMETRY: { myprintf("MODE_CHECK_SYMMETRY not supported any more"); exit(1); } case MODE_CHECKJ5X: { oaextend.setAlgorithm (MODE_J5ORDERX, &arrayclass); /* LMC test with special code */ reduction->mode = OA_TEST; reduction->init_state = COPY; result = LMCcheck (al, arrayclass, oaextend, *reduction); break; } case MODE_CHECKJ5XFAST: { oaextend.setAlgorithm (MODE_J5ORDERX, &arrayclass); /* LMC test with special code */ reduction->mode = OA_TEST; reduction->init_state = COPY; if (1) { array_link al (array, arrayclass.N, arrayclass.ncols, al.INDEX_NONE); reduction->updateSDpointer (al); } result = LMCcheck (al, arrayclass, oaextend, *reduction); break; } case MODE_REDUCEJ5X: { OAextend oaextend; oaextend.setAlgorithm (MODE_J5ORDERX, &arrayclass); /* LMC test with special code */ printf ("oacheck: WARNING: MODE_CHECKJ5X: untested code, not complete\n"); reduction->mode = OA_REDUCE; result = LMCcheck (al, arrayclass, oaextend, *reduction); break; } case MODE_REDUCE: /* LMC reduction */ { reduction->mode = OA_REDUCE; copy_array(array, reduction->array, arrayclass.N, arrayclass.ncols); dyndata_t dynd = dyndata_t(arrayclass.N); result = LMCreduction(array, array, &arrayclass, &dynd, reduction, oaextend); break; } case MODE_REDUCERANDOM: { /* random LMC reduction */ oaextend.setAlgorithm(MODE_ORIGINAL, &arrayclass); reduction->mode = OA_REDUCE; randtest->transformation->apply(array, testarray); copy_array(testarray, reduction->array, arrayclass.N, arrayclass.ncols); reduction->init_state = INIT; array_link alp = arrayclass.create_root(arrayclass.ncols, 1000); reduction->setArray(alp); dyndata_t dynd = dyndata_t(arrayclass.N); result = LMCreduction(testarray, testarray, &arrayclass, &dynd, reduction, oaextend); if (log_print(NORMAL, "")) { reduction->transformation->show(); } } break; case MODE_REDUCETRAIN: /* LMC reduction with train*/ reduction->mode = OA_REDUCE; result = LMCreduction_train (al, &arrayclass, reduction, oaextend); break; case MODE_REDUCETRAINRANDOM: /* random LMC reduction with train*/ reduction->mode = OA_REDUCE; randtest->transformation->apply (array, testarray); result = LMCreduction_train (test_arraylink, &arrayclass, reduction, oaextend); break; case MODE_HADAMARD: myprintf("MODE_HADAMARD not supported any more\n"); exit(1); default: result = LMC_NONSENSE; std::cout << "function " << __FUNCTION__ << "line " << __LINE__ << "Unknown mode" << std::endl; exit (1); break; } bool aequal; switch (mode) { case MODE_CHECK: if (result == LMC_LESS) { ++wrong; log_print (NORMAL, "Found array nr %i/%i NOT in lmc form:\n", i, afile->narrays); } else { ++correct; log_print (NORMAL, "Found array nr %i/%i in lmc form.\n", i, afile->narrays); } break; case MODE_CHECKJ4: case MODE_CHECKJ5X: case MODE_CHECKJ5XFAST: case MODE_CHECK_SYMMETRY: if (result == LMC_LESS) { ++wrong; log_print (NORMAL, "Found array nr %i/%i NOT in minimal form:\n", i, afile->narrays); } else { ++correct; log_print (NORMAL, "Found array nr %i/%i in minimal form.\n", i, afile->narrays); } break; case MODE_REDUCE: case MODE_REDUCEJ4: case MODE_REDUCEJ5X: case MODE_REDUCETRAIN: aequal = std::equal (array, array + arrayclass.N * arrayclass.ncols, reduction->array); if ((!aequal) || reduction->state == REDUCTION_CHANGED) { ++wrong; log_print (QUIET, "Reduced array %i/%i to lmc form.\n", i, afile->narrays); if (checkloglevel (NORMAL)) { log_print (QUIET, "Original:\n"); print_array (array, afile->nrows, afile->ncols); print_array ("Reduction:\n", reduction->array, afile->nrows, afile->ncols); printf ("---------------\n"); } if (checkloglevel (DEBUG)) { cout << "Transformation: " << endl; reduction->transformation->show (cout); rowindex_t row; colindex_t column; array_diff (array, reduction->array, arrayclass.N, arrayclass.ncols, row, column); cout << "Difference at: "; printf (" row %d, col %d\n", row, column); } } else { ++correct; log_print (QUIET, "Array %i/%i was already in lmc form:\n", i, afile->narrays); } break; case MODE_REDUCETRAINRANDOM: case MODE_REDUCERANDOM: case MODE_REDUCEJ4RANDOM: aequal = std::equal (array, array + arrayclass.N * arrayclass.ncols, reduction->array); if (!aequal) { ++wrong; log_print (SYSTEM, "Array %i/%i: reduced random transformation not equal to original (BUG!)\n", i, afile->narrays); if (checkloglevel (NORMAL)) { print_array ("Original:\n", array, afile->nrows, afile->ncols); print_array ("Randomized:\n", testarray, afile->nrows, afile->ncols); print_array ("Reduction:\n", reduction->array, afile->nrows, afile->ncols); printf ("---------------\n"); } } else { ++correct; log_print (QUIET, "Array %i/%i: reduced random transformation to original\n", i, afile->narrays); } break; case MODE_HADAMARD: break; default: std::cout << "function " << __FUNCTION__ << "line " << __LINE__ << "unknown mode" << std::endl; break; } array_link al = array_link ((carray_t *)reduction->array, afile->nrows, afile->ncols, -1); if (result == LMC_MORE || !prune) { outputlist.push_back (al); } delete randtest; delete reduction; destroy_array (testarray); } afile->closefile (); delete afile; if (writeoutput) { logstream (NORMAL) << "Writing output (" << outputlist.size () << " arrays)" << endl; writearrayfile (outputfile, outputlist); } logstream (QUIET) << "#time end: " << currenttime () << std::endl; return 0; }
/// parse the command line options for the program AnyOption *parseOptions (int argc, char *argv[], algorithm_t &algorithm) { AnyOption *opt = new AnyOption; /* parse command line options */ opt->setFlag ("help", 'h'); /* a flag (takes no argument), supporting long and short form */ opt->setOption ("loglevel", 'l'); opt->setOption ("sort", 's'); opt->setFlag ("x", 'x'); /* special debugging flag */ opt->setOption ("restart", 'r'); opt->setOption ("oaconfig", 'c'); /* file that specifies the design */ opt->setOption ("output", 'o'); /* prefix for output files */ opt->setFlag ("generate", 'g'); /* only generate extensions, do not perform LMC check */ opt->setFlag ("coptions"); /* print compile time options */ opt->setOption ("format", 'f'); /* format to write to */ opt->setOption ("mode", 'm'); /* algorithm method */ opt->setOption ("maxk", 'K'); /* max number of columns to extend to */ opt->setOption ("rowsymmetry", 'R'); /* max number of columns to extend to */ opt->setFlag ("streaming"); /* operate in streaming mode */ opt->setOption ("initcolprev", 'I'); /* algorithm method */ opt->addUsage ("Orthonal Arrays: extend orthogonal arrays"); #ifdef OAEXTEND_SINGLECORE opt->addUsage ("Usage: oaextendmpi [OPTIONS]"); #else opt->addUsage ("Usage: oaextendsingle [OPTIONS]"); #endif opt->addUsage (""); opt->addUsage (" -h --help Prints this help "); opt->addUsage (" --coptions Show compile time options used "); opt->addUsage (" -r [FILE] --restart [FILE] Restart with results file "); opt->addUsage (" -l [LEVEL] --loglevel [LEVEL] Set loglevel to number "); opt->addUsage (" -s [INTEGER] --sort [INTEGER] Sort input and output arrays (default: 1) "); opt->addUsage (" -c [FILE] --oaconfig [FILE] Set file with design specification"); opt->addUsage (" -g --generate [FILE] Only generate arrays, do not perform LMC check"); opt->addUsage (" --rowsymmetry [VALUE] Use row symmetry in generation"); opt->addUsage (" -o [STR] --output [FILE] Set prefix for output (default: result) "); opt->addUsage (" -f [FORMAT] Output format (default: TEXT, or BINARY, D, Z). Format D is " "binary difference, format Z is binary with zero-difference "); opt->addUsage (" --initcolprev [INTEGER] Initialization method of new column (default: 1)"); opt->addUsage ( " --maxk [INTEGER] Maximum number of columns to exten to (default: extracted from config file) "); opt->addUsage ( " --streaming Operate in streaming mode. Generated arrays will be written to disk " "immediately. "); std::string ss = printfstring (" -m [MODE] Algorithm (") + algorithm_t_list () + ")\n"; opt->addUsage (ss.c_str ()); // opt->printUsage(); opt->addUsage (""); opt->addUsage ("Example: ./oaextendsingle -l 2"); opt->processCommandArgs (argc, argv); if (opt->getValue ("mode") != NULL || opt->getValue ('m') != NULL) { int vv = atoi (opt->getValue ('m')); // set custom loglevel algorithm = (algorithm_t)vv; } else { algorithm = MODE_AUTOSELECT; } return opt; }
int main(int argc, char** argv) { QApplication app(argc, argv); AnyOption options; options.addUsage(QString("Usage: %1 --help | --console | [--output path --prefix prefixName --suffix suffixName --type typeName").arg(argv[0]).toAscii()); options.addUsage(""); options.addUsage("--help Displays this message."); options.addUsage("--console Run the gui version."); options.addUsage("--output [path] Output directory for the plugin skeleton."); options.addUsage("--prefix [prefixName] Prefix to use for the plugin."); options.addUsage("--suffix [suffixName] Suffix to use for the plugin."); options.addUsage("--type [typeName] Type to use for the plugin."); options.addUsage("--quiet Process quietly (non gui generation only)."); options.setFlag("help"); options.setFlag("console"); options.setOption("output"); options.setOption("prefix"); options.setOption("suffix"); options.setOption("type"); options.setOption("quiet"); options.processCommandArgs(argc, argv); if(options.getFlag("help")) { options.printUsage(); return 0; } if(options.getFlag("console")) { bool paramsOk = options.getValue("output") && options.getValue("prefix") && options.getValue("type") && options.getValue("suffix"); if( !paramsOk ) { options.printUsage(); return 1; } if(!options.getFlag("quiet")) { qDebug() << "output = " << options.getValue("output"); qDebug() << "prefix = " << options.getValue("prefix"); qDebug() << "suffix = " << options.getValue("suffix"); qDebug() << "type = " << options.getValue("type"); } dtkPluginGenerator generator; generator.setOutputDirectory(options.getValue("output")); generator.setPrefix(options.getValue("prefix")); generator.setSuffix(options.getValue("suffix")); generator.setType(options.getValue("type")); bool resultGenerator = generator.run(); if(!options.getFlag("quiet")) { if(resultGenerator) qDebug() << "Generation succeeded."; else qDebug() << "Plugin generation: Generation failed."; } } else { dtkPluginGeneratorMainWindow generator; generator.show(); generator.raise(); return app.exec(); } }
/** Utilizing AnyOption class, take the command line and parse it for valid options. Handle usage printout as well. @param argc argc from main() @param char**argv array of char* directly from main() @returns If an error occurs, return false. Currently no errors. Always returns true. */ bool parsecmd(int argc, char**argv) { stringstream str; // Setup all default values if not already set by simple strings and values above. if (getenv("WEBRTC_SERVER")) mainserver = xGetDefaultServerName(); if (getenv("WEBRTC_CONNECT")) { stunserver = "STUN "; stunserver += xGetPeerConnectionString(); } peername = xGetPeerName(); AnyOption *opt = new AnyOption(); opt->addUsage("Usage: "); opt->addUsage(""); opt->addUsage(" -h --help Prints this help "); opt->addUsage(" --server <servername|IP>[:<serverport>] Main sever and optional port."); opt->addUsage( " --stun <stunserver|IP>[:<port>] STUN server (and optionally port).\n Default is " STUNSERVER_DEFAULT); opt->addUsage( " --peername <Name> Use this name as my client/peer name online."); opt->addUsage(" --avopts <none|audio|video|audiovideo> Enable audio, video, or audiovideo."); opt->addUsage(""); opt->addUsage("Environment variables can be used as defaults as well."); opt->addUsage(" WEBRTC_SERVER - Main server name."); opt->addUsage(" WEBRTC_CONNECT - STUN server name with port."); opt->addUsage(" USERNAME - Peer user name."); opt->addUsage(""); opt->setFlag("help", 'h'); opt->setOption("server"); opt->setOption("stun"); opt->setOption("peername"); opt->setOption("avopts"); opt->processCommandArgs(argc, argv); /* 6. GET THE VALUES */ if (opt->getFlag("help") || opt->getFlag('h')) { opt->printUsage(); exit(1); } if (opt->getValue("server")) { cout << "New main server is " << opt->getValue("server") << endl; string serverloc = opt->getValue("server"); size_t colonpos = serverloc.find(':'); mainserver = serverloc.substr(0,colonpos); if(colonpos != string::npos) { stringstream sstrm; sstrm << serverloc.substr(colonpos+1); sstrm >> mainserver_port; }
AnyOption *parseInputOptions( int argc, char **argv ) { // parse input options AnyOption *opt = new AnyOption(); opt->addUsage( "Usage: " ); opt->addUsage( "" ); opt->addUsage( "The options below can be specified in a colon-separated file \"raytrace.2d.options\" or at the command line. Command-line options override file options." ); opt->addUsage( " --help -h Print this message and exit" ); //opt->addUsage( " --atmosout Output the atmosphere and all its derivatives to atmospheric_profile.out"); opt->addUsage( "" ); opt->addUsage( "To use an arbitrary 1-D atmospheric profile in ASCII format (space or comma-separated) the following options apply:" ); opt->addUsage( "REQUIRED (no default values):" ); opt->addUsage( " --atmosfile <filename> Uses an ASCII atmosphere file" ); opt->addUsage( " --atmosfileorder The order of the (z,t,u,v,w,p,d) fields in the ASCII file (Ex: 'ztuvpd')" ); opt->addUsage( " --elev Value in range (-90,90)" ); opt->addUsage( " --azimuth Value in range [0,360), clockwise from north" ); opt->addUsage( " --maxraylength Maximum ray length to calculate (km) [none]" ); opt->addUsage( "OPTIONAL [defaults]:" ); opt->addUsage( " --skiplines Lines at the beginning of the ASCII file to skip [0]" ); opt->addUsage( " --maxelev Maximum elevation angle to calculate [--elev value]" ); opt->addUsage( " --delev Elevation angle step [1]" ); opt->addUsage( " --maxazimuth Maximum azimuth to calculate [--azimuth value]" ); opt->addUsage( " --dazimuth Azimuth angle step [1]" ); opt->addUsage( " --sourceheight Height at which to begin raytrace [ground level]" ); opt->addUsage( " --maxheight Height at which to cut off calculation [150 km]" ); opt->addUsage( " --maxrange Maximum distance from origin to calculate (km) [no maximum]" ); opt->addUsage( " --stepsize Ray length step size for computation, km [0.01]" ); opt->addUsage( " --skips Maximum number of skips to allow. Use 0 for no limits. [0]" ); opt->addUsage( " --wind_units Specify 'kmpersec' if the winds are given in km/s [mpersec]" ); opt->addUsage( "FLAGS (no value required):" ); opt->addUsage( " --partial Report the final, incomplete raypath as well as the complete bounces." ); opt->addUsage( "" ); /* opt->addUsage( "To use a set of ASCII files that form a 2-D slice of the atmosphere the following options apply:" ); opt->addUsage( "REQUIRED (no default values):" ); opt->addUsage( " --slicefile <filename> The name of the summary file describing the path (see documentation)" ); opt->addUsage( " --elev Value in range (-90,90)" ); opt->addUsage( " --maxraylength Maximum ray length to calculate (km) [none]" ); opt->addUsage( "OPTIONAL [defaults]:" ); opt->addUsage( " --maxelev Maximum elevation angle to calculate [--elev value]" ); opt->addUsage( " --delev Elevation angle step [1]" ); opt->addUsage( " --maxazimuth Maximum azimuth to calculate [--azimuth value]" ); opt->addUsage( " --dazimuth Azimuth angle step [1]" ); opt->addUsage( " --sourceheight Height at which to begin raytrace [ground level]" ); opt->addUsage( " --maxheight Height at which to cut off calculation [150 km]" ); opt->addUsage( " --maxrange Maximum distance from origin to calculate (km) [no maximum]" ); opt->addUsage( " --stepsize Ray length step size for computation, km [0.01]" ); opt->addUsage( " --skips Maximum number of skips to allow. Use 0 for no limits. [0]" ); opt->addUsage( "FLAGS (no value required):" ); opt->addUsage( " --partial Report the final, incomplete raypath as well as the complete bounces." ); opt->addUsage( "" ); opt->addUsage( "To use an analytic profile with Gaussian wind jets the following options apply:" ); opt->addUsage( "REQUIRED (no default values):" ); opt->addUsage( " --jetfile <filename> The parameter file for the profile" ); opt->addUsage( " --elev Value in range (-90,90)" ); opt->addUsage( " --azimuth Value in range [0,360), clockwise from north (optional for --envfile)" ); opt->addUsage( " --maxraylength Maximum ray length to calculate (km) [none]" ); opt->addUsage( "OPTIONAL [defaults]:" ); opt->addUsage( " --maxelev Maximum elevation angle to calculate [--elev value]" ); opt->addUsage( " --delev Elevation angle step [1]" ); opt->addUsage( " --maxazimuth Maximum azimuth to calculate [--azimuth value]" ); opt->addUsage( " --dazimuth Azimuth angle step [1]" ); opt->addUsage( " --sourceheight Height at which to begin raytrace [ground level]" ); opt->addUsage( " --maxheight Height at which to cut off calculation [150 km]" ); opt->addUsage( " --maxrange Maximum distance from origin to calculate (km) [no maximum]" ); opt->addUsage( " --stepsize Ray length step size for computation, km [0.1]" ); opt->addUsage( " --skips Maximum number of skips to allow. Use 0 for no limits. [0]" ); opt->addUsage( "FLAGS (no value required):" ); opt->addUsage( " --partial Report the final, incomplete raypath as well as the complete bounces." ); */ opt->addUsage( "" ); opt->addUsage( "Examples (run from 'samples' directory):" ); opt->addUsage( "../bin/raytrace.2d --azimuth 90 --elev 1 --delev 1 --maxelev 45 --skips 1 --atmosfile NCPA_canonical_profile_zuvwtdp.dat --atmosfileorder zuvwtdp --maxraylength 800 --maxheight 140" ); opt->addUsage( "cat raypath_az090* > raypaths.2d.dat" ); opt->addUsage( "rm raypath_az090*" ); // Set up the actual flags and stuff opt->setFlag( "help", 'h' ); opt->setFlag( "norange" ); opt->setFlag( "atmosout" ); opt->setFlag( "partial" ); opt->setOption( "slicefile" ); opt->setOption( "atmosfile" ); opt->setOption( "jetfile" ); opt->setOption( "elev" ); opt->setOption( "azimuth" ); opt->setOption( "maxraylength" ); opt->setOption( "lat" ); opt->setOption( "lon" ); opt->setOption( "maxrange" ); opt->setOption( "maxelev" ); opt->setOption( "delev" ); opt->setOption( "maxazimuth" ); opt->setOption( "dazimuth" ); opt->setOption( "sourceheight" ); opt->setOption( "maxheight" ); opt->setOption( "stepsize" ); opt->setOption( "dZ" ); opt->setOption( "dR" ); opt->setOption( "atmosfileorder" ); opt->setOption( "skiplines" ); opt->setOption( "skips" ); opt->setOption( "wind_units" ); // Process the command-line arguments opt->processFile( "./raytrace.2d.options" ); opt->processCommandArgs( argc, argv ); if( ! opt->hasOptions()) { // print usage if no options opt->printUsage(); delete opt; exit( 1 ); } // Check to see if help text was requested if ( opt->getFlag( "help" ) || opt->getFlag( 'h' ) ) { opt->printUsage(); exit( 1 ); } return opt; }
int main(int argc, char **argv){ // nekonstantni nastaveni generatoru nahodnych cisel srand((unsigned int)time(0)); // server cast clock_t t1, t2; t1 = clock(); int NP = 50; double F = 0.7; double CR = 0.6; int Generations = 10; int pocet_neuronu = 5; char *nejlepsi_jedinec = "nejlepsi_jedinec.txt"; char *data = "data.txt"; int tichy = 0; // parsovani parametru AnyOption *opt = new AnyOption(); opt->setVerbose(); /* print warnings about unknown options */ opt->autoUsagePrint(true); /* print usage for bad options */ opt->addUsage( "" ); opt->addUsage( "NNSA (Neural Network Space Arcade) - Testovani rekuretni neuronove site na jednoduche arkade" ); opt->addUsage( "" ); opt->addUsage( "Pouziti: " ); opt->addUsage( "" ); opt->addUsage( " -h --help Zobrazi tuto napovedu " ); opt->addUsage( " -n jedinec.txt Nejlepsi jedinec " ); opt->addUsage( " -d data.txt Udaje o jednotlivych generacich " ); opt->addUsage( " " ); opt->addUsage( " --NP 60 Velikost populace " ); opt->addUsage( " --F 0.7 Mutacni konstanta " ); opt->addUsage( " --CR 0.8 Prah krizeni " ); opt->addUsage( " --generations 100 Pocet kol slechteni populace " ); opt->addUsage( " --neurons 4 Pocet neuronu v neuronove siti " ); opt->addUsage( " --quiet 1 Neukecany rezim " ); opt->addUsage( "" ); opt->setFlag( "help", 'h'); /* a flag (takes no argument), supporting long and short form */ opt->setOption('n'); opt->setOption('d'); opt->setOption("NP"); opt->setOption("F"); opt->setOption("CR"); opt->setOption("generations"); opt->setOption("neurons"); opt->setOption("quiet"); opt->processCommandArgs(argc, argv); NP = atoi(opt->getValue("NP")); F = atof(opt->getValue("F")); CR = atof(opt->getValue("CR")); Generations = atoi(opt->getValue("generations")); pocet_neuronu = atoi(opt->getValue("neurons")); nejlepsi_jedinec = opt->getValue('n'); data = opt->getValue('d'); tichy = atoi(opt->getValue("quiet")); cout << "Parametry diferencialni evoluce:" << endl; cout << " -> Velikost populace NP = " << NP << endl; cout << " -> Mutacni konstanta F = " << F << endl; cout << " -> Prah krizeni CR = " << CR << endl; cout << " -> Pocet generaci = " << Generations << endl; cout << " -> Pocet neuronu = " << pocet_neuronu << endl; DiferencialniEvoluce *d1 = new DiferencialniEvoluce(NP, F, CR, Generations, pocet_neuronu, &ohodnoceni, tichy, data); d1->UlozNejlepsiJedinec(nejlepsi_jedinec); // 32bit - pretece cca po 36 minutach t2 = clock(); cout << "Doba behu programu: " << ((double) (t2 - t1))/CLOCKS_PER_SEC << endl; return 0; }