void FindFileDialog::findFiles() { QRegExp filePattern(fileNameComboBox->currentText() + "*"); filePattern.setPatternSyntax(QRegExp::Wildcard); QDir directory(directoryComboBox->currentText()); QStringList allFiles = directory.entryList(QDir::Files | QDir::NoSymLinks); QStringList matchingFiles; foreach (QString file, allFiles) { if (filePattern.exactMatch(file)) matchingFiles << file; } showFiles(matchingFiles); }
bool parseOptions( int argc, char** argv, ProgramOptions &options ) { // add help message std::stringstream desc_stream; desc_stream << "Usage splash2txt [options] <input-file>" << std::endl; po::options_description desc( desc_stream.str( ) ); std::string slice_string = ""; std::string filemode = "splash"; #if (ENABLE_ADIOS==1) const std::string filemodeOptions = "[splash,adios]"; #else const std::string filemodeOptions = "[splash]"; #endif // add possible options desc.add_options( ) ( "help,h", "print help message" ) ( "verbose,v", "verbose output, print status messages" ) ( "mode,m", po::value< std::string > ( &filemode )->default_value( filemode ), (std::string("File Mode ") + filemodeOptions).c_str() ) ( "list,l", "list the available datasets for an input file" ) ( "input-file", po::value< std::string > ( &options.inputFile ), "parallel input file" ) ( "output-file,o", po::value< std::string > ( &options.outputFile ), "output file (otherwise stdout)" ) ( "step,s", po::value<uint32_t > ( &options.step )->default_value( options.step ), "requested simulation step" ) ( "data,d", po::value<std::vector<std::string> > ( &options.data )->multitoken( ), "name of datasets to print" ) ( "slice", po::value< std::string > ( &slice_string )->default_value( "xy" ), "dimensions of slice for field data, e.g. xy" ) /// \todo if the standard offset value would be the MIDDLE of the global simulation area, it would be awesome ( "offset", po::value<size_t > ( &options.sliceOffset )->default_value( 0 ), "offset of slice in dataset" ) ( "delimiter", po::value<std::string>( &options.delimiter )->default_value( " " ), "select a delimiter for data elements. default is a single space character" ) ( "no-units", "no conversion of stored data elements with their respective unit" ) ; po::positional_options_description pos_options; pos_options.add( "input-file", -1 ); try { // parse command line options and store values in vm po::variables_map vm; po::store( po::command_line_parser( argc, argv ). options( desc ).positional( pos_options ).run( ), vm ); po::notify( vm ); // print help message and quit program if requested or if required parameters are missing if ( vm.count( "help" ) || !vm.count( "input-file" ) || ( !vm.count( "data" ) && !vm.count( "list" ) ) || !vm.count( "step" ) ) { errorStream << desc << "\n"; return false; } if (filemode == "splash" ) { options.fileMode = FM_SPLASH; } #if (ENABLE_ADIOS==1) else if(filemode == "adios") { options.fileMode = FM_ADIOS; } #endif // re-parse wrong typed input files to valid format, if possible // find _X.h5 with syntax at the end and delete it boost::regex filePattern( "_.*\\.h5", boost::regex_constants::icase | boost::regex_constants::perl ); options.inputFile = boost::regex_replace( options.inputFile, filePattern, "" ); // set various flags options.verbose = vm.count( "verbose" ) != 0; options.listDatasets = vm.count( "list" ) != 0; options.toFile = vm.count( "output-file" ) != 0; options.applyUnits = vm.count( "no-units" ) == 0; if ( vm.count( "slice" ) ^ vm.count( "offset" ) ) { errorStream << "Parameters 'slice' and 'offset' require each other." << std::endl; errorStream << desc << "\n"; return false; } if ( vm.count( "slice" ) ) { bool sliceFound = false; options.fieldDims.set( 0, 0, 0 ); for ( size_t i = 0; i < numAllowedSlices; ++i ) { if ( slice_string.compare( allowedSlices[i] ) == 0 ) { sliceFound = true; options.isReverseSlice = false; break; } if ( slice_string.compare( allowedReverseSlices[i] ) == 0 ) { sliceFound = true; options.isReverseSlice = true; break; } } if ( !sliceFound ) { errorStream << "Invalid input for parameter 'slice'. Accepted: xy, xz, yz, yx, zx, zy" << std::endl; errorStream << desc << "\n"; return false; } if ( slice_string.find( 'x' ) != std::string::npos ) options.fieldDims[0] = 1; if ( slice_string.find( 'y' ) != std::string::npos ) options.fieldDims[1] = 1; if ( slice_string.find( 'z' ) != std::string::npos ) options.fieldDims[2] = 1; } } catch ( const boost::program_options::error& ) { errorStream << desc << "\n"; throw std::runtime_error( "Error parsing command line options!" ); } return true; }