// Load Species information from XYZ file bool Species::loadFromXYZ(const char* filename) { Messenger::print("Loading XYZ data from file '%s'\n", filename); // Open the specified file... LineParser parser; parser.openInput(filename); if (!parser.isFileGoodForReading()) { Messenger::error("Couldn't open XYZ file '%s'.\n", filename); return false; } // Clear any existing data clear(); // Simple format - first line is number of atoms, next line is title, then follow atoms/coordinates, one atom per line parser.getArgsDelim(LineParser::Defaults); int nAtoms = parser.argi(0); parser.readNextLine(LineParser::Defaults); name_ = parser.line(); int el, success; for (int n=0; n<nAtoms; ++n) { success = parser.getArgsDelim(LineParser::Defaults); if (success != 0) { parser.closeFiles(); Messenger::error("Couldn't read Atom %i from file '%s'\n", n+1, filename); return false; } el = PeriodicTable::find(parser.argc(0)); if (el == -1) el = 0; SpeciesAtom* i = addAtom(el, parser.argd(1), parser.argd(2),parser.argd(3)); if (parser.hasArg(4)) i->setCharge(parser.argd(4)); } Messenger::print("Succesfully loaded XYZ data from file '%s'.\n", filename); parser.closeFiles(); return true; }
void FileSelectorWidget::on_FilesEdit_textChanged(QString textChanged) { if (refreshing_) return; // Split current string into separate arguments LineParser parser; parser.getArgsDelim(Parser::UseQuotes, ui.FilesEdit->text()); selectedFilenames_.clear(); for (int n = 0; n < parser.nArgs(); ++n) selectedFilenames_ << parser.argc(n); // If we are updating filter/plugin based on the name, do it here bool formatOk = true; if (updatePluginFromFilename_ && (selectedFilenames_.count() > 0)) formatOk = updatePluginFromCurrentFilename() != NULL; emit(selectionValid((selectedFilenames_.count() > 0) && formatOk)); }
// Parse Simulation block bool SimulationBlock::parse(LineParser& parser, DUQ* duq) { Messenger::print("\nParsing %s block...\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock)); bool blockDone = false, error = false; while (!parser.eofOrBlank(duq->worldPool())) { // Read in a line, which should contain a keyword and a minimum number of arguments parser.getArgsDelim(duq->worldPool(), LineParser::SkipBlanks+LineParser::UseQuotes); SimulationBlock::SimulationKeyword simKeyword = SimulationBlock::keyword(parser.argc(0)); if ((simKeyword != SimulationBlock::nSimulationKeywords) && ((parser.nArgs()-1) < SimulationBlock::nArguments(simKeyword))) { Messenger::error("Not enough arguments given to '%s' keyword.\n", SimulationBlock::keyword(simKeyword)); error = true; break; } switch (simKeyword) { case (SimulationBlock::BoxNormalisationPointsKeyword): duq->setBoxNormalisationPoints(parser.argi(1)); break; case (SimulationBlock::EndSimulationKeyword): Messenger::print("Found end of %s block.\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock)); blockDone = true; break; case (SimulationBlock::MaxIterationsKeyword): duq->setMaxIterations(parser.argi(1)); break; case (SimulationBlock::ParallelStrategyKeyword): if (DUQ::parallelStrategy(parser.argc(1)) == DUQ::nParallelStrategies) { Messenger::error("Unrecognised parallel strategy '%s'.\n", parser.argc(1)); error = true; } else duq->setParallelStrategy(DUQ::parallelStrategy(parser.argc(1))); break; case (SimulationBlock::SeedKeyword): duq->setSeed(parser.argi(1)); break; case (SimulationBlock::WindowFunctionKeyword): if (Data2D::windowFunction(parser.argc(1)) == Data2D::nWindowFunctions) { Messenger::error("Unrecognised window function '%s'.\n", parser.argc(1)); error = true; } else duq->setWindowFunction(Data2D::windowFunction(parser.argc(1))); break; case (SimulationBlock::nSimulationKeywords): Messenger::print("Unrecognised %s block keyword found - '%s'\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock), parser.argc(0)); InputBlocks::printValidKeywords(InputBlocks::SimulationBlock); error = true; break; default: printf("DEV_OOPS - %s block keyword '%s' not accounted for.\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock), SimulationBlock::keyword(simKeyword)); error = true; break; } // Error encountered? if (error) break; // End of block? if (blockDone) break; } return (!error); }
ATEN_USING_NAMESPACE // Load includes void Aten::loadEncoderDefinitions() { Messenger::enter("Aten::loadEncoderDefinitions"); QString encoderDefsFile = dataDirectoryFile("external/encoders.txt"); Messenger::print(Messenger::Verbose, "Looking for encoder definitions (%s)...", qPrintable(encoderDefsFile)); LineParser parser; parser.openInput(encoderDefsFile); if (!parser.isFileGoodForReading()) { Messenger::print("Unable to open encoder definitions file.\n"); return; } // Read in encoder definitions from file QString keyword; EncoderDefinition::EncoderDefinitionKeyword edk; EncoderDefinition* encoder = NULL; ExternalCommand* command = NULL; while (!parser.eofOrBlank()) { // Read first argument from file, which is our keyword parser.getArgsDelim(Parser::SkipBlanks + Parser::StripComments + Parser::UseQuotes); keyword = parser.argc(0); edk = EncoderDefinition::encoderDefinitionKeyword(keyword); if (edk == EncoderDefinition::nEncoderDefinitionKeywords) { Messenger::print("Unrecognised encoder definition keyword '%s'. Ignoring...\n", qPrintable(keyword)); continue; } // Deal with remaining keywords switch (edk) { // Command Name case (EncoderDefinition::CommandNameKeyword): if (!encoder) { Messenger::error("No encoder definition yet created in which to set name data (use 'Name' keyword before all others).\n"); continue; } command = encoder->addCommand(); command->setName(parser.argc(1)); break; // Command case (EncoderDefinition::CommandKeyword): if (!command) { Messenger::error("No command definition yet created in which to set command data (use 'CommandName' keyword before its siblings).\n"); continue; } command->setExecutable(parser.argc(1)); break; // Command arguments case (EncoderDefinition::CommandArgumentsKeyword): if (!command) { Messenger::error("No command definition yet created in which to set argument data (use 'CommandName' keyword before its siblings).\n"); continue; } command->setArguments(parser.argc(1)); break; case (EncoderDefinition::CommandSearchPathsKeyword): if (!command) { Messenger::error("No command definition yet created in which to set searchpath data (use 'CommandName' keyword before its siblings).\n"); continue; } for (int n=1; n<parser.nArgs(); ++n) command->addSearchPath(parser.argc(n)); break; // Name (create new object) case (EncoderDefinition::NameKeyword): encoder = encoders_.add(); encoder->setName(parser.argc(1)); break; case (EncoderDefinition::NicknameKeyword): if (!encoder) { Messenger::error("No encoder definition yet created in which to set data (use 'Name' keyword before all others).\n"); continue; } encoder->setNickname(parser.argc(1)); break; default: break; } } parser.closeFiles(); Messenger::exit("Aten::loadEncoderDefinitions"); }