// 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; }
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"); }