void Level::load_file_fail(std::ifstream &file, std::string s){ debug(s); file.close(); }
void seek_end(int pos) { in.seekg(pos,std::ios::end); }
operator bool() const {return in.good();}
int ESMReaderAll::processNextRecord(std::ifstream& in_File) { uint32_t RecordName = 0; //normally should be 4 char, but char is not eligible for switch int lastResult = 0; //read record name in_File.read((char*) &RecordName, 4); switch(RecordName) { case cACTI: lastResult = Activators::getSingleton().readNextRecord(in_File); break; case cALCH: lastResult = AlchemyPotions::getSingleton().readNextRecord(in_File); break; case cAPPA: lastResult = Apparatuses::getSingleton().readNextRecord(in_File); break; case cARMO: lastResult = Armours::getSingleton().readNextRecord(in_File); break; case cBODY: lastResult = BodyParts::getSingleton().readNextRecord(in_File); break; case cBOOK: lastResult = Books::getSingleton().readNextRecord(in_File); break; case cBSGN: lastResult = BirthSigns::getSingleton().readNextRecord(in_File); break; case cCELL: lastResult = Cells::getSingleton().readRecordCELL(in_File); break; case cCLAS: lastResult = Classes::getSingleton().readNextRecord(in_File); break; case cCLOT: lastResult = Clothings::getSingleton().readNextRecord(in_File); break; case cCONT: lastResult = Containers::getSingleton().readNextRecord(in_File); break; case cCREA: lastResult = Creatures::getSingleton().readNextRecord(in_File); break; case cDIAL: lastResult = DialogueTopics::getSingleton().readRecordDIAL(in_File); break; case cDOOR: lastResult = Doors::getSingleton().readNextRecord(in_File); break; case cENCH: lastResult = Enchantings::getSingleton().readNextRecord(in_File); break; case cFACT: lastResult = Factions::getSingleton().readNextRecord(in_File); break; case cGLOB: lastResult = Globals::getSingleton().readNextRecord(in_File); break; case cGMST: lastResult = GameSettings::getSingleton().readRecordGMST(in_File); break; case cINFO: lastResult = DialogueInfos::getSingleton().readNextRecord(in_File); break; case cINGR: lastResult = Ingredients::getSingleton().readNextRecord(in_File); break; case cLAND: lastResult = Landscape::getSingleton().readRecordLAND(in_File); break; case cLEVC: lastResult = LeveledCreatures::getSingleton().readNextRecord(in_File); break; case cLEVI: lastResult = LeveledItems::getSingleton().readNextRecord(in_File); break; case cLIGH: lastResult = Lights::getSingleton().readNextRecord(in_File); break; case cLOCK: lastResult = Lockpicks::getSingleton().readNextRecord(in_File); break; case cLTEX: lastResult = LandscapeTextures::getSingleton().readNextRecord(in_File); break; case cMGEF: lastResult = MagicEffects::getSingleton().readRecordMGEF(in_File); break; case cMISC: lastResult = MiscItems::getSingleton().readNextRecord(in_File); break; case cNPC_: lastResult = NPCs::getSingleton().readNextRecord(in_File); break; case cPGRD: lastResult = PathGrids::getSingleton().readRecordPGRD(in_File); break; case cPROB: lastResult = Probes::getSingleton().readNextRecord(in_File); break; case cRACE: lastResult = Races::getSingleton().readNextRecord(in_File); break; case cREGN: lastResult = Regions::getSingleton().readNextRecord(in_File); break; case cREPA: lastResult = RepairItems::getSingleton().readNextRecord(in_File); break; case cSCPT: lastResult = Scripts::getSingleton().readNextRecord(in_File); break; case cSKIL: lastResult = Skills::getSingleton().readRecordSKIL(in_File); break; case cSNDG: lastResult = SoundGenerators::getSingleton().readNextRecord(in_File); break; case cSOUN: lastResult = Sounds::getSingleton().readNextRecord(in_File); break; case cSPEL: lastResult = Spells::getSingleton().readNextRecord(in_File); break; case cSSCR: lastResult = StartScripts::getSingleton().readNextRecord(in_File); break; case cSTAT: lastResult = Statics::getSingleton().readNextRecord(in_File); break; case cWEAP: lastResult = Weapons::getSingleton().readNextRecord(in_File); break; default: std::cout << "processNextRecord: ERROR: unknown record type found: \"" <<IntTo4Char(RecordName)<<"\".\n" << "Current file position: "<<in_File.tellg()<< " bytes.\n"; lastResult = -1; break; }//swi return lastResult; }//processNextRecord of ESMReaderAll class
bool read(void* buf,size_t size) { return in.read((char*)buf,size).good(); }
void get_line(std::ifstream fin, char *buff, int buff_len, int &read_len) { fin.getline(buff, buff_len); read_len = fin.gcount(); buff[INPUT_LINE_SIZE - 1] = '\0'; }
std::unique_ptr<TorchStage> SpatialDropout::loadFromFile(std::ifstream& file) { float p; file.read((char*)(&p), sizeof(p)); return std::unique_ptr<TorchStage>(new SpatialDropout(p)); }
bool CameraPathRecord::loadFromStream(std::ifstream& in_File, const bool localized, const StringTable& table) { uint32_t readSize = 0; if (!loadSizeAndUnknownValues(in_File, readSize)) return false; uint32_t subRecName; uint16_t subLength; subRecName = subLength = 0; uint32_t bytesRead = 0; //read EDID char buffer[512]; if (!loadString512FromStream(in_File, editorID, buffer, cEDID, true, bytesRead)) return false; conditions.clear(); CTDA_CIS1_compound tempCC; bool hasCTDA = false; bool hasReadANAM = false; bool hasReadDATA = false; camShotList.clear(); uint32_t tempUint32; while (bytesRead<readSize) { //read next subrecord's name in_File.read((char*) &subRecName, 4); bytesRead += 4; switch(subRecName) { case cCTDA: if (hasCTDA) { conditions.push_back(tempCC); } //load CTDA if (!tempCC.unknownCTDA.loadFromStream(in_File, bytesRead)) return false; hasCTDA = true; tempCC.unknownCISx.clear(); break; case cCIS1: if (!hasCTDA) { std::cout << "Error: CPTH has CIS1 subrecord without prior CTDA!\n"; return false; } if (!tempCC.unknownCISx.empty()) { std::cout << "Error: CPTH seems to have more than one CIS1 per CTDA!\n"; return false; } //load CIS1 if (!loadString512FromStream(in_File, tempCC.unknownCISx, buffer, cCIS1, false, bytesRead)) return false; //check content if (tempCC.unknownCISx.empty()) { std::cout << "Error: subrecord CIS1 of CPTH is empty!\n"; return false; } conditions.push_back(tempCC); hasCTDA = false; break; case cANAM: if (hasReadANAM) { std::cout << "Error: CPTH seems to have more than one ANAM subrecord!\n"; return false; } //ANAM's length in_File.read((char*) &subLength, 2); bytesRead += 2; if (subLength!=8) { std::cout <<"Error: subrecord ANAM of CPTH has invalid length (" <<subLength <<" bytes). Should be eight bytes!\n"; return false; } //read ANAM's stuff in_File.read((char*) &cameraPathLinks.parentFormID, 4); in_File.read((char*) &cameraPathLinks.nextFormID, 4); bytesRead += 8; if (!in_File.good()) { std::cout << "Error while reading subrecord ANAM of CPTH!\n"; return false; }//if hasReadANAM = true; break; case cDATA: if (hasReadDATA) { std::cout << "Error: CPTH seems to have more than one DATA subrecord!\n"; return false; } //DATA's length in_File.read((char*) &subLength, 2); bytesRead += 2; if (subLength!=1) { std::cout <<"Error: subrecord DATA of CPTH has invalid length (" <<subLength <<" bytes). Should be one byte!\n"; return false; } //read DATA's stuff in_File.read((char*) &unknownDATA, 1); bytesRead += 1; if (!in_File.good()) { std::cout << "Error while reading subrecord DATA of CPTH!\n"; return false; }//if hasReadDATA = true; break; case cSNAM: //load SNAM if (!loadUint32SubRecordFromStream(in_File, cSNAM, tempUint32, false)) return false; bytesRead += 6; //check content if (tempUint32==0) { std::cout << "Error: subrecord SNAM of CPTH is zero!\n"; return false; } camShotList.push_back(tempUint32); break; default: std::cout << "Error: unexpected record type \""<<IntTo4Char(subRecName) << "\" found, but only CTDA, CIS1, ANAM, DATA or SNAM are allowed here!\n"; return false; break; }//swi }//while //push leftover CTDA/CIS1 if (hasCTDA) { conditions.push_back(tempCC); } //presence checks if (!(hasReadANAM and hasReadDATA)) { std::cout << "Error: At least one subrecord of CPTH is missing!\n"; return false; } return in_File.good(); }
bool DestructionData::loadFromStream(std::ifstream& in_File, const uint32_t recordType, char * buffer, uint32_t& bytesRead) { //DEST's length uint16_t subLength = 0; in_File.read((char*) &subLength, 2); bytesRead += 2; if (subLength!=8) { std::cout << "Error: subrecord DEST of "<<IntTo4Char(recordType)<<" has invalid length (" << subLength << " bytes). Should be eight bytes.\n"; return false; } //read DEST in_File.read((char*) &health, 4); in_File.read((char*) &stageCount, 1); in_File.read((char*) &unknownTwo, 1); in_File.read((char*) &unknownThreeFour, 2); bytesRead += 8; if (!in_File.good()) { std::cout << "Error while reading subrecord DEST of "<<IntTo4Char(recordType)<<"!\n"; return false; } isPresent = true; stages.clear(); DestructionStage tempStage; while (stages.size()<stageCount) { //read next record uint32_t innerRecordName = 0; in_File.read((char*) &innerRecordName, 4); bytesRead += 4; switch (innerRecordName) { case cDSTD: if (tempStage.unknownDSTD.isPresent()) { std::cout << "Error: "<<IntTo4Char(recordType)<<" seems to have more than one DSTD subrecord per stage!\n"; return false; }//if //read DSTD if (!tempStage.unknownDSTD.loadFromStream(in_File, cDSTD, false)) return false; bytesRead += (2+tempStage.unknownDSTD.getSize()); break; case cDMDL: if (!tempStage.replacementModel.empty()) { std::cout << "Error: "<<IntTo4Char(recordType)<<" seems to have more than one DMDL subrecord per stage!\n"; return false; }//if //DMDL's length in_File.read((char*) &subLength, 2); bytesRead += 2; if (subLength>511) { std::cout <<"Error: sub record DMDL of "<<IntTo4Char(recordType)<<" is longer than 511 characters!\n"; return false; } //read string memset(buffer, 0, 512); in_File.read(buffer, subLength); bytesRead += subLength; if (!in_File.good()) { std::cout << "Error while reading subrecord DMDL of "<<IntTo4Char(recordType)<<"!\n"; return false; } tempStage.replacementModel = std::string(buffer); //check content if (tempStage.replacementModel.empty()) { std::cout << "Error: subrecord DMDL of "<<IntTo4Char(recordType)<<" is empty!\n"; return false; } break; case cDMDT: if (tempStage.unknownDMDT.isPresent()) { std::cout << "Error: "<<IntTo4Char(recordType) << " seems to have more than one DMDT subrecord per stage!\n"; return false; }//if //read DMDT if (!tempStage.unknownDMDT.loadFromStream(in_File, cDMDT, false)) return false; bytesRead += (2+tempStage.unknownDMDT.getSize()); break; case cDSTF: //DSTF's length in_File.read((char*) &subLength, 2); bytesRead += 2; if (subLength!=0) { std::cout << "Error: subrecord DSTF of "<<IntTo4Char(recordType) << " has invalid length (" << subLength << " bytes). Should be zero bytes.\n"; return false; } //push it, if not empty if (tempStage.isReset()) { std::cout << "Error: "<<IntTo4Char(recordType)<<" seems to have an empty destruction stage!\n"; return false; } stages.push_back(tempStage); tempStage.reset(); break; default: std::cout << "Error: found unexpected subrecord \""<<IntTo4Char(innerRecordName) << "\", but only DSTD, DMDL, DMDT or DSTF are allowed here!\n"; return false; }//swi }//while return in_File.good(); }
void Q3BSPLoad::LoadBSPData(std::ifstream& aFile) { //Load leaves //Calculate number of leaves int numLeaves=m_header.m_directoryEntries[bspLeaves].m_length/sizeof(BSP_LOAD_LEAF); //Create space for this many BSP_LOAD_LEAFS m_loadLeaves.resize(numLeaves); //Load leaves aFile.seekg(m_header.m_directoryEntries[bspLeaves].m_offset,std::ios::beg); aFile.read((char*)&m_loadLeaves[0], m_header.m_directoryEntries[bspLeaves].m_length); //Load leaf faces array int num_leaf_faces=m_header.m_directoryEntries[bspLeafFaces].m_length/sizeof(int); //Create space for this many leaf faces m_loadLeafFaces.resize(num_leaf_faces); //Load leaf faces aFile.seekg(m_header.m_directoryEntries[bspLeafFaces].m_offset,std::ios::beg); aFile.read((char*)&m_loadLeafFaces[0], m_header.m_directoryEntries[bspLeafFaces].m_length); //Load Planes int num_planes=m_header.m_directoryEntries[bspPlanes].m_length/sizeof(BSP_LoadPlane); //Create space for this many planes m_loadPlanes.resize(num_planes); aFile.seekg(m_header.m_directoryEntries[bspPlanes].m_offset,std::ios::beg); aFile.read((char*)&m_loadPlanes[0], m_header.m_directoryEntries[bspPlanes].m_length); //Load nodes int num_nodes=m_header.m_directoryEntries[bspNodes].m_length/sizeof(BSP_NODE); //Create space for this many nodes m_loadNodes.resize(num_nodes); aFile.seekg(m_header.m_directoryEntries[bspNodes].m_offset,std::ios::beg); aFile.read((char*)&m_loadNodes[0], m_header.m_directoryEntries[bspNodes].m_length); //Load visibility data //load numClusters and bytesPerCluster aFile.seekg(m_header.m_directoryEntries[bspVisData].m_offset,std::ios::beg); aFile.read((char*)&m_loadVisibilityData, 2 * sizeof(int)); //Calculate the size of the bitset int bitsetSize=m_loadVisibilityData.m_numClusters*m_loadVisibilityData.m_bytesPerCluster; //Create space for bitset m_loadVisibilityData.m_bitset.resize(bitsetSize); //read bitset aFile.read((char*)&m_loadVisibilityData.m_bitset[0], bitsetSize); }
bool ApparatusRecord::loadFromStream(std::ifstream& in_File) { uint32_t Size; in_File.read((char*) &Size, 4); in_File.read((char*) &HeaderOne, 4); in_File.read((char*) &HeaderFlags, 4); /*Alchemy Apparatus: NAME = Item ID, required MODL = Model Name, required FNAM = Item Name, required AADT = Alchemy Data (16 bytes), required long Type (0=Mortar and Pestle,1=Albemic,2=Calcinator,3=Retort) float Quality float Weight long Value ITEX = Inventory Icon SCRI = Script Name (optional) */ uint32_t SubRecName; uint32_t SubLength, BytesRead; SubRecName = SubLength = 0; //read NAME in_File.read((char*) &SubRecName, 4); BytesRead = 4; if (SubRecName!=cNAME) { UnexpectedRecord(cNAME, SubRecName); return false; } //NAME's length in_File.read((char*) &SubLength, 4); BytesRead += 4; if (SubLength>255) { std::cout << "Subrecord NAME of APPA is longer than 255 characters!\n"; return false; } char Buffer[256]; memset(Buffer, '\0', 256); //read apparatus ID in_File.read(Buffer, SubLength); BytesRead += SubLength; if (!in_File.good()) { std::cout << "Error while reading subrecord NAME of APPA!\n"; return false; } recordID = std::string(Buffer); Model.clear(); ItemName.clear(); bool hasReadAADT = false; InventoryIcon.clear(); ScriptName.clear(); while (BytesRead<Size) { //read sub record's name in_File.read((char*) &SubRecName, 4); BytesRead += 4; switch (SubRecName) { case cMODL: if (!Model.empty()) { std::cout << "Error: APPA seems to have more than one MODL subrecord!\n"; return false; } //MODL's length in_File.read((char*) &SubLength, 4); BytesRead += 4; if (SubLength>255) { std::cout << "Subrecord MODL of APPA is longer than 255 characters!\n"; return false; } //read model path memset(Buffer, '\0', 256); in_File.read(Buffer, SubLength); BytesRead += SubLength; if (!in_File.good()) { std::cout << "Error while reading subrecord MODL of APPA!\n"; return false; } Model = std::string(Buffer); if (Model.empty()) { std::cout << "Error: subrecord MODL of APPA is empty!\n"; return false; } break; case cFNAM: if (!ItemName.empty()) { std::cout << "Error: APPA seems to have more than one FNAM subrecord!\n"; return false; } //FNAM's length in_File.read((char*) &SubLength, 4); BytesRead += 4; if (SubLength>255) { std::cout << "Subrecord FNAM of APPA is longer than 255 characters!\n"; return false; } //read apparatus name memset(Buffer, '\0', 256); in_File.read(Buffer, SubLength); BytesRead += SubLength; if (!in_File.good()) { std::cout << "Error while reading subrecord FNAM of APPA!\n"; return false; } ItemName = std::string(Buffer); if (ItemName.empty()) { std::cout << "Error: subrecord FNAM of APPA is empty!\n"; return false; } break; case cAADT: if (hasReadAADT) { std::cout << "Error: APPA seems to have more than one AADT subrecord!\n"; return false; } //AADT's length in_File.read((char*) &SubLength, 4); BytesRead += 4; if (SubLength!=16) { std::cout << "Error: sub record AADT of APPA has invalid length (" << SubLength << " bytes). Should be 16 bytes.\n"; return false; } //read apparatus data in_File.read((char*) &Type, 4); in_File.read((char*) &Quality, 4); in_File.read((char*) &Weight, 4); in_File.read((char*) &Value, 4); BytesRead += 16; if (!in_File.good()) { std::cout << "Error while reading subrecord AADT of APPA!\n"; return false; } hasReadAADT = true; break; case cITEX: if (!InventoryIcon.empty()) { std::cout << "Error: APPA seems to have more than one ITEX subrecord!\n"; return false; } //ITEX's length in_File.read((char*) &SubLength, 4); BytesRead += 4; //read apparatus icon path memset(Buffer, '\0', 256); in_File.read(Buffer, SubLength); BytesRead += SubLength; if (!in_File.good()) { std::cout << "Error while reading subrecord ITEX of APPA!\n"; return false; } InventoryIcon = std::string(Buffer); if (InventoryIcon.empty()) { std::cout << "Error: subrecord ITEX of APPA is empty!\n"; return false; } break; case cSCRI: if (!ScriptName.empty()) { std::cout << "Error: APPA seems to have more than one SCRI subrecord!\n"; return false; } //SCRI's length in_File.read((char*) &SubLength, 4); BytesRead += 4; if (SubLength>255) { std::cout << "Subrecord SCRI of APPA is longer than 255 characters!\n"; return false; } //read apparatus script ID memset(Buffer, '\0', 256); in_File.read(Buffer, SubLength); BytesRead += SubLength; if (!in_File.good()) { std::cout << "Error while reading subrecord SCRI of APPA!\n"; return false; } ScriptName = std::string(Buffer); if (ScriptName.empty()) { std::cout << "Error: subrecord SCRI of APPA is empty!\n"; return false; } break; default: std::cout << "Error: unexpected record type \""<<IntTo4Char(SubRecName) << "\" found, but only MODL, FNAM, AADT or ITEX are allowed here!\n"; return false; break; }//swi }//while //presence checks if (Model.empty() or ItemName.empty() or !hasReadAADT or InventoryIcon.empty()) { std::cout << "Error: At least one required subrecord of APPA is missing!\n"; return false; } return in_File.good(); }
static inline void eat_blankspace(std::ifstream &f) { while (isblank(f.peek())) { f.get(); } }
static inline void eat_whitespace(std::ifstream &f) { while (isspace(f.peek())) { f.get(); } }
bool PerkRecord::loadFromStream(std::ifstream& in_File, const bool localized, const StringTable& table) { uint32_t readSize = 0; if (!loadSizeAndUnknownValues(in_File, readSize)) return false; uint32_t subRecName; uint16_t subLength; subRecName = subLength = 0; uint32_t bytesRead; //read EDID in_File.read((char*) &subRecName, 4); bytesRead = 4; if (subRecName!=cEDID) { UnexpectedRecord(cEDID, subRecName); return false; } //EDID's length in_File.read((char*) &subLength, 2); bytesRead += 2; if (subLength>511) { std::cout <<"Error: sub record EDID of PERK is longer than 511 characters!\n"; return false; } //read EDID's stuff char buffer[512]; memset(buffer, 0, 512); in_File.read(buffer, subLength); bytesRead += subLength; if (!in_File.good()) { std::cout << "Error while reading subrecord EDID of PERK!\n"; return false; } editorID = std::string(buffer); //now read the rest unknownVMAD.setPresence(false); name.reset(); description.reset(); subBlocks.clear(); SubBlock temp; while (bytesRead<readSize) { //read next subrecord's name in_File.read((char*) &subRecName, 4); bytesRead += 4; switch (subRecName) { case cVMAD: if (unknownVMAD.isPresent()) { std::cout << "Error: record PERK seems to have more than one VMAD subrecord.\n"; return false; } if (!unknownVMAD.loadFromStream(in_File, cVMAD, false)) return false; bytesRead += (2 +unknownVMAD.getSize()); break; case cFULL: if (name.isPresent()) { std::cout << "Error: record PERK seems to have more than one FULL subrecord.\n"; return false; } //read FULL if (!name.loadFromStream(in_File, cFULL, false, bytesRead, localized, table, buffer)) return false; break; case cDESC: if (description.isPresent()) { std::cout << "Error: record PERK seems to have more than one DESC subrecord.\n"; return false; } //read DESC if (!description.loadFromStream(in_File, cDESC, false, bytesRead, localized, table, buffer)) return false; break; default: temp.subType = subRecName; if (!temp.subData.loadFromStream(in_File, subRecName, false)) { std::cout << "Error while reading subrecord "<<IntTo4Char(subRecName) << " of PERK!\n"; return false; } bytesRead += (2 +temp.subData.getSize()); subBlocks.push_back(temp); break; }//swi }//while if (!description.isPresent()) { std::cout << "Error: subrecord DESC of PERK is missing!\n"; return false; } return in_File.good(); }
void GamessukOut::readOptimisedCoordinates(std::ifstream &ifs) { //std::cout << "readOptimisedCoordinates\n"; double x,y,z; // Nuke the old coordinates gukBasis.atomLabels.clear(); gukBasis.coordinates.clear(); ifs.getline(buffer, BUFF_SIZE); while( ! ifs.eof() ) { // This for some optimize runtypes if ( strstr(buffer," x y z chg tag") != NULL ) { //std::cout << "start of opt coord\n"; // Skip 2 lines - should then be at the coordinates ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE); while( ! ifs.eof() ) { // End of geometry block if ( strstr(buffer, " ============================================================") != NULL) return; tokenize(tokens, buffer, " \t\n"); from_string<double>(x, tokens.at(0), std::dec); from_string<double>(y, tokens.at(1), std::dec); from_string<double>(z, tokens.at(2), std::dec); gukBasis.coordinates.push_back( Eigen::Vector3d( x, y, z )); gukBasis.atomLabels.push_back(tokens.at(4)); ifs.getline(buffer, BUFF_SIZE); } // end while } else if ( strstr(buffer,"atom znuc x y z") != NULL ) { // print "start of opt coord 2" // Skip 3 lines - should then be at the coordinates ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE); while( ! ifs.eof() ) { // End of geometry block if ( strstr(buffer, "*************************") != NULL) return; tokenize(tokens, buffer, " \t\n"); gukBasis.atomLabels.push_back(tokens.at(0)); from_string<double>(x, tokens.at(3), std::dec); from_string<double>(y, tokens.at(4), std::dec); from_string<double>(z, tokens.at(5), std::dec); gukBasis.coordinates.push_back( Eigen::Vector3d( x, y, z )); ifs.getline(buffer, BUFF_SIZE); } // end of while } ifs.getline(buffer, BUFF_SIZE); } // end of read loop } // end readOptimisedCoordinates
int main (int argc, char* argv[]) { int start, end; std::stringstream buffer; cout << "start main" << endl; if(argc < 6){ cout << "Please enter your input" << endl; return -1; } if (argc >= 6){ start = atoi(argv[3]); end = atoi(argv[4]); var = atof(argv[5]); } std::string indirname = argv[1]; buffer.str(""); buffer << indirname << "/simPattern.txt"; truePatternFile.open( buffer.str().c_str() ); buffer.str(""); buffer << indirname << "/patterns.tsv"; estimatedPatternFile.open( buffer.str().c_str() ); buffer.str(""); buffer << indirname << "/shortRead.txt"; shortReadFile.open( buffer.str().c_str() ); std::string outdirname = argv[2]; buffer.str(""); buffer << outdirname << "/eval.txt"; evalFile.open( buffer.str().c_str() ,std::ios_base::app); buffer.str(""); buffer << outdirname << "/mcf.txt"; MCFFile.open( buffer.str().c_str(), std::ios_base::app); buffer.str(""); buffer << outdirname << "/match.txt"; matchFile.open( buffer.str().c_str()); buffer.str(""); buffer << outdirname << "/matchApp.txt"; matchAppFile.open( buffer.str().c_str(), std::ios_base::app); buffer.str(""); buffer << outdirname << "/weight.txt"; weightFile.open( buffer.str().c_str()); buffer.str(""); buffer << indirname << "/match.txt"; mFile.open( buffer.str().c_str() ); buffer.str(""); buffer << outdirname << "/methylPercentageTrue.txt"; mTruePercentageFile.open( buffer.str().c_str() ); buffer.str(""); buffer << outdirname << "/methylPercentageEstimated.txt"; mEstimatedPercentageFile.open( buffer.str().c_str() ); buffer.str(""); buffer << outdirname << "/methylPercentageRead.txt"; mReadPercentageFile.open( buffer.str().c_str() ); //truePatternFile.open(argv[1]); //estimatedPatternFile.open(argv[2]); //evalFile.open(argv[3],std::ios_base::app); //MCFFile.open(argv[4],std::ios_base::app); //################ read the input .tsv data to the "line" number cout << "reading true patterns " << start << " " << end << endl; readTruePattern(start , end); cout << "reading estimated patterns " << start << " " << end << endl; readEstimatedPattern(start , end); cout << "reading short read " << endl; readShortRead(start, end); cout << "compute methyl Percentage " << endl; computeMethylPercentage(); cout << "write methyl Percentage " << endl; writeMethylPercentageMatrix(); cout << "build Graph " << start << endl; buildGraph(); //########### write the weight of edges and corresponding matches for every true pattern ######## /// the ffirst line is #truePattern , #estimated Pattern /// then each line is true Pattern id , abundance of pattern /// then each line is estimated pattern id , abundance of pattern // then the weight information of edges and matching information is seen in the rest of file //minCostFlowErr = computeMinCostFlowError(); //MCFFile << var << "\t" << minCostFlowErr << endl; //cout << "min cost flow error " << minCostFlowErr << endl; writeMatchMatrix(); minCostFlowErr = computeMinCostFlowError(); MCFFile << var << "\t" << minCostFlowErr << endl; cout << "min cost flow error " << minCostFlowErr << endl; readMatchMatrix(); //// computing Error Metric //////// for (double thresh=0.1; thresh<1; thresh +=0.1) computeErrorMatrix(thresh); //} /* cout << "Solve LP " << start << endl; ////////////LP////////////////////// lemon::Lp lp; lp.max(); //Graph::ArcMap<lemon::Lp::Col> x; std::map<Edge, lemon::Lp::Row> x; std::map<RedNode, lemon::Lp::Col> alpha; // std::map<Graph::BlueNode, lemon::Lp::Col> beta; lemon::Lp::Expr obj; for (RedNodeIt r(g); r != INVALID; ++r) { alpha[r] = lp.addCol(); //lp.colLowerBound(alpha[r], 0.0); obj += alpha[r]; } for (EdgeIt e(g); e != INVALID; ++e) { // x[e] = lp.addRow(); RedNode r = g.source(e); BlueNode b = g.target(e); x[e] = lp.addRow(alpha[r] + alpha[b] - length[e] <= 0); } lp.obj(obj); lp.solve(); float v = lp.primal(); //cout << "dual : " << v << endl; float abndncError = 0; float methylCallError = 0; int match = 0; for (EdgeIt e(g); e != INVALID; ++e) { lemon::Lp::Row row = x[e]; float dual = lp.dual(row); cout << " X(" << g.id(g.source(e)) <<", " << g.id(g.target(e)) << ") = " << dual<< endl; cout << " W(" << g.id(g.source(e)) <<", " << g.id(g.target(e)) << ") = " << length[e]<< endl; if (dual){ abndncError += pow(double(abundance_map[g.target(e)] - abundance_map[g.source(e)]),2) / 10000; methylCallError += length[e]; match++; } else{ abndncError += pow(double(abundance_map[g.target(e)]),2) /10000 + pow(double(abundance_map[g.source(e)]),2) /10000; methylCallError +=1; } } int TP = match; int FN = trueMethylData.size() - match; int FP = estimatedMethylData.size() - match; methylCallError = methylCallError/(match + FN +FP); //evalFile.open("/cbcb/project-scratch/fdorri/Code/methylFlow/testing/eval.txt", std::ios_base::app); //evalFile << "abndncError " << "\t" << "methylCall Error " << "\t" << "TP "<< "\t" << "FN " << "\t" << "FP " << endl; evalFile << abndncError << "\t" << methylCallError << "\t" << TP << "\t" << FN << "\t" << FP << std::endl; //std:cout << abndncError << "\t" << methylCallError << "\t" << TP << "\t" << FN << "\t" << FP << std::endl; */ }
int GamessukOut::readMOVectors(std::ifstream &ifs) { /* Loop through a series of columns of printed MO vectors & return the number of orbitals read in */ unsigned int norbitals, norbitalsRead; double energy; ifs.getline(buffer, BUFF_SIZE); //std::cout << "HeaderLine " << buffer << std::endl; // Check we're not at the end if ( strstr(buffer, "end of")!=0 ) return 0; tokenize(tokens, buffer, " \t\n"); // How many orbital columns: norbitals = static_cast<unsigned int>(tokens.size()); for ( unsigned int i=0; i < tokens.size() ; i++ ) { from_string<double>(energy, tokens.at(i), std::dec); //std::cout << "adding e " << energy << std::endl; gukBasis.moEnergies.push_back(energy); } // Add the lists to hold this set of coefficients // How many were read in previously: norbitalsRead = static_cast<unsigned int>(gukBasis.moVectors.size()); // Create the arrays to hold the coefficients for each orbital for ( unsigned int i=0; i < norbitals ; i++ ) gukBasis.moVectors.push_back( std::vector<double>() ); //skip 5 lines to just before where first set of orbitals are printed ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE); // loop nBasisFunctions times to read in up to norbitals coefficients for (int i=0; i < gukBasis.nBasisFunctions ; i++ ) { ifs.getline( buffer, BUFF_SIZE ); //std::cout << "MO line " << buffer << std::endl; tokenize(tokens, buffer, " \t\n"); for (unsigned int j=0; j < norbitals ; j++ ) { // reuse variable energy to hold coefficient from_string<double>(energy, tokens.at(j+4), std::dec); gukBasis.moVectors.at(norbitalsRead+j).push_back(energy); //std::cout << "Adding " << energy << " to vector " << norbitalsRead+j << std::endl; } } // skip 2 lines to where the next set of headers are printed ifs.getline(buffer, BUFF_SIZE); ifs.getline(buffer, BUFF_SIZE); // If we are printed out after an optimisation under the control of "iprint vectors", // the next line with be filled with " =================" if we've finished if ( strstr(buffer, " ===============================")!=0 ) return 0; return norbitals; } // end readMOVectors
/** * Parses an .idx file. */ std::vector<Reference> parse(std::ifstream& fs) { uint32_t size; uint32_t hash; fs >> le >> size; fs >> le >> hash; uint32_t headerHash{ 0 }; if ((hash != (headerHash = Crypto::lookup3(fs, size, 0)))) { throw Exceptions::InvalidHashException(hash, headerHash, ""); } uint16_t version; uint16_t bucket; uint8_t lengthFieldSize; uint8_t locationFieldSize; uint8_t keyFieldSize; uint8_t segmentBits; fs >> le >> version; fs >> le >> bucket; fs >> lengthFieldSize; fs >> locationFieldSize; fs >> keyFieldSize; fs >> segmentBits; this->versions_[bucket] = version; this->keySize_[bucket] = keyFieldSize; for (unsigned int i = 0; i < (size - 8); i += 8) { uint32_t dataBeg; uint32_t dataEnd; fs >> be >> dataBeg; fs >> be >> dataEnd; } fs.seekg(16 - ((8 + size) % 16), std::ios_base::cur); fs >> le >> size; fs >> le >> hash; std::pair<uint32_t, uint32_t> dataHash{ 0, 0 }; std::vector<char> data(size); fs.read(data.data(), data.size()); std::vector<Reference> files(size / 18); files.reserve(size / 18); for (auto i = 0U; i < (size / 18); ++i) { auto begin = data.begin() + 18 * i; auto end = begin + 18; files.emplace_back(begin, end, keyFieldSize, locationFieldSize, lengthFieldSize, segmentBits); dataHash = Crypto::lookup3(begin, end, dataHash); } if (hash != dataHash.first) { throw Exceptions::InvalidHashException(hash, dataHash.first, ""); } fs.seekg(0xE000 - ((8 + size) % 0xD000), std::ios_base::cur); return files; }
void Toggle::load(std::ifstream& ifs) { int data = 0; ifs.read((char*)&data, sizeof(int)); value = (data == 1); needsRedraw(); }
bool XAnimationKey::ParseFromFStream(std::ifstream& in) { std::streampos pos; char separator; if (!in.good()) { return false; } in.clear(); pos = in.tellg(); if (!KeyType.ParseFromFStream(in)) { in.clear(); in.seekg(pos); return false; } in >> separator; if (!in.good() || separator != ';') { in.clear(); in.seekg(pos); return false; } if (!NKeys.ParseFromFStream(in)) { in.clear(); in.seekg(pos); return false; } in >> separator; if (!in.good() || separator != ';') { in.clear(); in.seekg(pos); return false; } if (!Keys.ParseFromFStream(in, NKeys)) { in.clear(); in.seekg(pos); return false; } in >> separator; if (!in.good() || separator != ';') { in.clear(); in.seekg(pos); return false; } return true; }
void MSG_data::read_from( std::ifstream &in, MSG_header &header ) { size_t dsize; size_t dpos; unsigned char_1 *dbuff = 0; unsigned char_1 *dpnt = 0; typecode = header.f_typecode; switch (typecode) { case MSG_FILE_IMAGE_DATA: image = new MSG_data_image; dsize = header.data_field_length / 8; dbuff = new unsigned char_1[dsize]; in.read((char *) dbuff, dsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Data field." << std::endl; throw; } if (header.image_structure->compression_flag == MSG_NO_COMPRESSION) { image->len = dsize; image->data = (MSG_SAMPLE *) ( new char[dsize] ); memcpy(image->data, dbuff, dsize); } else { MSG_data_image_encoded encoded; encoded.data = dbuff; encoded.len = dsize; encoded.bpp = header.image_structure->number_of_bits_per_pixel; encoded.nx = header.image_structure->number_of_columns; encoded.ny = header.image_structure->number_of_lines; encoded.format = header.segment_id->data_field_format; encoded.decode( image ); } break; case MSG_FILE_GTS_MESSAGE: dsize = header.data_field_length / 8; dbuff = new unsigned char_1[dsize]; in.read((char *) dbuff, dsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Data field." << std::endl; throw; } gts_message = new MSG_data_gts; dpos = gts_message->read_from(dbuff, dsize); { std::string outname; outname = header.annotation->annotation; outname += ".bin"; gts_message->dump(outname); } break; case MSG_FILE_ALPHANUMERIC_TEXT: dsize = header.data_field_length / 8; dbuff = new unsigned char_1[dsize]; in.read((char *) dbuff, dsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Data field." << std::endl; throw; } text_message = new MSG_data_text; dpos = text_message->read_from(dbuff, dsize); break; case MSG_FILE_ENCRYPTION_KEY_MESSAGE: dsize = header.data_field_length / 8; dbuff = new unsigned char_1[dsize]; in.read((char *) dbuff, dsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Data field." << std::endl; throw; } key_message = new MSG_data_key; dpos = key_message->read_from(dbuff, dsize); break; case MSG_FILE_REPEAT_CYCLE_PROLOGUE: dsize = header.data_field_length / 8; dbuff = new unsigned char_1[dsize]; in.read((char *) dbuff, dsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Data field." << std::endl; throw; } if (header.annotation->product_id_1.find("MSG") != std::string::npos) { prologue = new MSG_data_level_15_header; dpnt = dbuff; dpos = prologue->sat_status.read_from(dpnt); dpnt += dpos; dpos = prologue->image_acquisition.read_from(dpnt); dpnt += dpos; dpos = prologue->celestial_events.read_from(dpnt); dpnt += dpos; dpos = prologue->image_description.read_from(dpnt); dpnt += dpos; dpos = prologue->radiometric_proc.read_from(dpnt); dpnt += dpos; dpos = prologue->geometric_proc.read_from(dpnt); dpnt += dpos; } else if (header.annotation->product_id_1.find("GOES") != std::string::npos || header.annotation->product_id_1.find("GMS") != std::string::npos || header.annotation->product_id_1.find("MTSAT") != std::string::npos || header.annotation->product_id_1.find("NOAA") != std::string::npos || header.annotation->product_id_1.find("METOP") != std::string::npos) { dpnt = dbuff; sdsprologue = new MSG_data_SGS_header; dpos = sdsprologue->read_from(dpnt); dpnt += dpos; } else if (header.annotation->product_id_1.find("MET5") != std::string::npos) { dpnt = dbuff; std::cout << "I have no info on MET5 file format !!!!" << std::endl; } else std::cout << "Unknown Image prologue file content" << std::endl; break; case MSG_FILE_REPEAT_CYCLE_EPILOGUE: dsize = header.data_field_length / 8; dbuff = new unsigned char_1[dsize]; in.read((char *) dbuff, dsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Data field." << std::endl; throw; } if (header.annotation->product_id_1.find("MSG") != std::string::npos) { epilogue = new MSG_data_level_15_trailer; dpnt = dbuff+1; dpos = 1; dpos = epilogue->product_stats.read_from(dpnt); dpnt += dpos; dpos = epilogue->navig_result.read_from(dpnt); dpnt += dpos; dpos = epilogue->radiometric_qlty.read_from(dpnt); dpnt += dpos; dpos = epilogue->geometric_qlty.read_from(dpnt); dpnt += dpos; dpos = epilogue->timelin_comple.read_from(dpnt); dpnt += dpos; } else std::cout << "Unknown Image epilogue file content" << std::endl; break; case MSG_FILE_DCP_MESSAGE: break; case MSG_FILE_BINARY_MESSAGE: dsize = header.data_field_length / 8; dbuff = new unsigned char_1[dsize]; in.read((char *) dbuff, dsize); if (in.fail( )) { std::cerr << "Read error from HRIT file: Data field." << std::endl; throw; } { std::ofstream os; std::string outname; outname = header.annotation->annotation; outname += ".bin"; os.open(outname.c_str( )); if (!os.good()) throw; os.write((char *) dbuff, (size_t) dsize); os.close( ); } break; default: std::cerr << "Unknown MSG file type " << header.f_typecode << std::endl; throw; break; } if (dbuff) delete [ ] dbuff; return; }
void ScriptLoader::_nextToken(std::ifstream &stream) { //EOF token if (!stream.good()) { mToken = TOKEN_EOF; return; } //(Get next character) int ch = stream.get(); while ((ch == ' ' || ch == 9) && !stream.eof()) { //Skip leading spaces / tabs ch = stream.get(); } if (!stream.good()) { mToken = TOKEN_EOF; return; } //Newline token if (ch == '\r' || ch == '\n') { do { ch = stream.get(); } while ((ch == '\r' || ch == '\n') && !stream.eof()); stream.unget(); mToken = TOKEN_NewLine; return; } //Open brace token else if (ch == '{') { mToken = TOKEN_OpenBrace; return; } //Close brace token else if (ch == '}') { mToken = TOKEN_CloseBrace; return; } //Text token if (ch < 32 || ch > 122) //Verify valid char { throw std::runtime_error("Parse Error: Invalid character, ConfigLoader::load()"); } mTokenValue = ""; mToken = TOKEN_Text; do { //Skip comments if (ch == '/') { int ch2 = stream.peek(); //C++ style comment (//) if (ch2 == '/') { stream.get(); do { ch = stream.get(); } while (ch != '\r' && ch != '\n' && !stream.eof()); mToken = TOKEN_NewLine; return; } } //Add valid char to tokVal mTokenValue += (char)ch; //Next char ch = stream.get(); } while (ch > 32 && ch <= 122 && !stream.eof()); stream.unget(); return; }
//Linearly read chunks void ReadChunk() { //because 3DS file stores data with a tree topology, so i do have considered //recursive/tree-like reading...but there is some mysterious chunks which might vary //from time to time... ehh...linear reading will be clearer??? const UINT c_chunkHeadByteLength = 6; //2 numbers at the head of every chunk uint16_t chunkID = 0; uint32_t chunkLength = 0; BINARY_READ(chunkID); BINARY_READ(chunkLength); //if chunk length corrupted , length data might be invalid if (chunkLength > static_fileSize) { static_currentChunkFileEndPos = static_fileSize - 1; fileIn.seekg(0, std::ios::end); DEBUG_MSG1("Load 3ds File : chunk is too long ! 3ds file might be damaged!!!"); return; } uint64_t tmpFilePos = fileIn.tellg(); static_currentChunkFileEndPos = tmpFilePos + chunkLength - c_chunkHeadByteLength; //in CURRENT chunk, there can be several sub-chunks to read switch (chunkID) { case NOISE_3DS_CHUNKID_MAIN3D: ParseMainChunk();//level1 break; case NOISE_3DS_CHUNKID_3D_EDITOR_CHUNK: Parse3DEditorChunk();//level2 break; case NOISE_3DS_CHUNKID_OBJECT_BLOCK: ParseObjectBlock();//level3 break; case NOISE_3DS_CHUNKID_TRIANGULAR_MESH: ParseTriangularMeshChunk();//level4 break; case NOISE_3DS_CHUNKID_VERTICES_LIST: ParseVerticesChunk();//level5 break; case NOISE_3DS_CHUNKID_FACES_DESCRIPTION: ParseFaceDescAndIndices();//level5 break; case NOISE_3DS_CHUNKID_FACES_MATERIAL: ParseFacesAndMatName();//level 6 break; case NOISE_3DS_CHUNKID_MAPPING_COORDINATES_LIST: ParseTextureCoordinate();//level5 break; case NOISE_3DS_CHUNKID_MATERIAL_BLOCK: ParseMaterialBlock();//level 3 break; case NOISE_3DS_CHUNKID_MATERIAL_NAME: ParseMaterialName();//level 4 break; case NOISE_3DS_CHUNKID_AMBIENT_COLOR: ParseAmbientColor();//level 4 break; case NOISE_3DS_CHUNKID_DIFFUSE_COLOR: ParseDiffuseColor();//level 4 break; case NOISE_3DS_CHUNKID_SPECULAR_COLOR: ParseSpecularColor();//level 4 break; case NOISE_3DS_CHUNKID_TEXTURE_MAP: ParseDiffuseMap();//level 4 break; case NOISE_3DS_CHUNKID_BUMP_MAP: ParseBumpMap();//level 4 break; case NOISE_3DS_CHUNKID_SPECULAR_MAP: ParseSpecularMap();//level 4 break; /*case NOISE_3DS_CHUNKID_REFLECTION_MAP: ParseReflectionMap();//4 break;*/ default: //not interested chunks , skip SkipCurrentChunk(); break; } }
void ParticleComponent::DoDeserialization(std::ifstream &loadStream) { loadStream.read((char*)&isEmittedFromHero, sizeof(isEmittedFromHero)); }
void seek(size_t pos) { in.seekg(pos,std::ios::beg); }
int CGait::InitGait(Aris::RT_CONTROL::CSysInitParameters& param) { int Line_Num; double temp; std::cout << "Start Reading File" << std::endl; std::cout<<"reading file data..."<<std::endl; fin.open("./gait/TL.txt"); for(int i=0;i<GAIT_TURN_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitTurnLeft[i][j]=-(int)temp; } } fin.close(); fin.open("./gait/TR.txt"); for(int i=0;i<GAIT_TURN_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitTurnRight[i][j]=-(int)temp; } } fin.close(); fin.open("./gait/start.txt"); for(int i=0;i<GAIT_HOME2START_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitHome2Start[i][j]=-(int)temp; } } fin.close(); //FOWARD fin.open("./gait/acc.txt"); for(int i=0; i<GAIT_ACC_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitMove_Acc[i][j]=-(int)temp; } } fin.close(); fin.open("./gait/cons.txt"); for(int i=0+GAIT_ACC_LEN; i<GAIT_ACC_LEN+GAIT_CON_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitMove_Cons[i-GAIT_ACC_LEN][j]=-(int)temp; } } fin.close(); fin.open("./gait/dec.txt"); for(int i=0+GAIT_ACC_LEN+GAIT_CON_LEN; i<GAIT_ACC_LEN+GAIT_CON_LEN+GAIT_DEC_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitMove_Dec[i-GAIT_ACC_LEN-GAIT_CON_LEN][j]=-(int)temp; } } fin.close(); //BACKWARD fin.open("./gait/back_acc.txt"); for(int i=0; i<GAIT_ACC_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitMoveBack_Acc[i][j]=-(int)temp; } } fin.close(); fin.open("./gait/back_cons.txt"); for(int i=0+GAIT_ACC_LEN; i<GAIT_ACC_LEN+GAIT_CON_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitMoveBack_Cons[i-GAIT_ACC_LEN][j]=-(int)temp; } } fin.close(); fin.open("./gait/back_dec.txt"); for(int i=0+GAIT_ACC_LEN+GAIT_CON_LEN; i<GAIT_ACC_LEN+GAIT_CON_LEN+GAIT_DEC_LEN;i++) { fin>>Line_Num; for(int j=0;j<GAIT_WIDTH;j++) { fin>>temp; GaitMoveBack_Dec[i-GAIT_ACC_LEN-GAIT_CON_LEN][j]=-(int)temp; } } fin.close(); return 0; }
size_t cur(void) { return in.tellg(); }
void GamessukOut::readBasisSet(std::ifstream &ifs) { //std::cout << "readBasisSet\n"; bool newAtom=true, gotAtom=false, firstAtom=true; std::string atomLabel; double exponent,coefficient; orbital stype; int nshell=-1; int lastNshell=-1; // the last shell number - is same as nshell when looping through a shell int lastStype=-1; // need to keep track of sp shells as we split into s & p // For separating sp-shells std::vector<double> s_coeff; std::vector<double> p_coeff; std::vector<double> sp_exponents; // skip 2 lines to be just before the first atom label ifs.getline(buffer, BUFF_SIZE) && ifs.getline(buffer, BUFF_SIZE); // now loop through the basis sets till we hit the end while ( ! ifs.eof() ) { ifs.getline(buffer, BUFF_SIZE); line=buffer; if ( line.compare(0,10," =========") == 0 ) { // End of basis - add indicies of where the coffecients and exponents of the GTOs for the last shell end gukBasis.gtoIndicies.at( gukBasis.shellLabels.size()-1 ).push_back( static_cast<unsigned int>(gukBasis.gtoExponents.size())); break; } // Remove blank space line=Trim(line); // skip blank lines if ( line.size() == 0 ) continue; // Separate into tokens if ( ! tokenize(tokens, line.c_str(), " \t\n") || tokens.size() == 0 ) { // If the string couldn't be tokenised, set tokens[0] to the entire string tokens.clear(); tokens.push_back( line ); } if ( tokens.size() == 1 ) { // This means a new atomLabel newAtom=true; if ( firstAtom ) firstAtom=false; else { // Check if the last shell was sp - if so add the temp sp data structures // to the main ones if (lastStype == SP ) { addSpBasis(s_coeff, p_coeff, sp_exponents); // Clear the temp data structures for separating out sp into s & p s_coeff.clear(); p_coeff.clear(); sp_exponents.clear(); lastStype=-1; } else { // Add the index for where the GTO coffecients and exponents for the previous shell start gukBasis.gtoIndicies.at( gukBasis.shellLabels.size()-1 ).push_back( static_cast<unsigned int>(gukBasis.gtoExponents.size())); } } // end firstAtom // Check if we've already processed an atom of this type if ( ! gukBasis.labelIndex( tokens.at(0) ) ) { //std::cout << "Processing atom label: " << tokens.at(0) << std::endl; gotAtom=false;// we'll be processing this atom gukBasis.shellLabels.push_back( tokens.at(0) ); gukBasis.shells.push_back( std::vector< orbital >() ); gukBasis.gtoIndicies.push_back( std::vector< unsigned int>() ); } else gotAtom=true; continue; } // End new atomLabel // if we're not processing an atom we can skip this line if ( gotAtom ) continue; /* Here we are reading in a line of the format: shell type prim exponents contraction coefficients 1 1s 3 5.533350 1.801737 ( 0.700713 ) or 2 2sp 4 3.664980 -0.747384 ( -0.395897 ) 1.709178 ( 0.236460 ) */ from_string<int>(nshell, tokens.at(0), std::dec); if ( nshell != lastNshell ) { // Reading a new shell if (! newAtom ) { // Add the data for the last shell processed //First check if last shell was sp & we need to add the data we've gathered to the main structures if ( lastStype == SP ) { addSpBasis(s_coeff, p_coeff, sp_exponents); // Clear the temp data structures for separating out sp into s & p s_coeff.clear(); p_coeff.clear(); sp_exponents.clear(); } else { // Add the index for where the primitives for the last shell finish gukBasis.gtoIndicies.at( gukBasis.shellLabels.size()-1 ).push_back( static_cast<unsigned int>(gukBasis.gtoExponents.size())); } // end sp shell } // end newAtom // need to determine type stype = gukBasis.shellTypeFromString(tokens.at(1)); //std::cout << "Reading new shell of type " << stype << std::endl; if ( stype != SP ) { // Add shell to symmetry list and AtomToShellIndex if not sp shell as we do that separately gukBasis.shells.at( gukBasis.shellLabels.size()-1 ).push_back( stype ); } } // end new shell // Now check for coefficients - we take the second lot to match Gaussian from_string<double>(exponent, tokens.at(3), std::dec); if ( stype == SP) { if ( tokens.size() != 12 ) std::cerr << "PROBLEM READING SP LINE!\n"; from_string<double>(coefficient, tokens.at(6), std::dec); s_coeff.push_back(coefficient); from_string<double>(coefficient, tokens.at(10), std::dec); p_coeff.push_back(coefficient); sp_exponents.push_back(exponent); } else { //std::cout << "Adding exponent " << exponent << std::endl; gukBasis.gtoExponents.push_back(exponent); from_string<double>(coefficient, tokens.at(6), std::dec); gukBasis.gtoCoefficients.push_back(coefficient); } // end type == SP lastNshell = nshell; lastStype = stype; newAtom=false; } // end while // Finished reading the basis data - now just collect some data from the summary - mainly for checking ifs.getline(buffer, BUFF_SIZE); //blank // nShell ifs.getline(buffer, BUFF_SIZE); if (strstr(buffer," total number of shells")==NULL) std::cerr << "Error reading nShell!: " << line << std::endl; // reuse nshell from above as temporary variable tokenize(tokens, buffer, " \t\n"); from_string<int>(nshell, tokens.at(4), std::dec); gukBasis.nShell=nshell; // nBasisFunctions ifs.getline(buffer, BUFF_SIZE); if (strstr(buffer," total number of basis")==NULL) std::cerr << "Error reading nBasisFunctions!: " << line << std::endl; tokenize(tokens, buffer, " \t\n"); // reuse nshell from above as temporary variable from_string<int>(nshell, tokens.at(5), std::dec); gukBasis.nBasisFunctions=nshell; // nElectrons ifs.getline(buffer, BUFF_SIZE); if (strstr(buffer," number of electrons")==NULL) std::cerr << "Error reading nElectrons!: " << line << std::endl; tokenize(tokens, buffer, " \t\n"); // reuse nshell from above as temporary variable from_string<int>(nshell, tokens.at(3), std::dec); gukBasis.nElectrons=nshell; } // end readBasisSet
bool operator!() const {return !in.good();}
REQUIRE(test_npc->get_skill_level(skill_id("dodge")) == 4); REQUIRE(test_npc->pos() == tripoint(72, 54, 0)); } else { // Unrecognized NPC, fail. REQUIRE(false); } } } TEST_CASE("Reading a legacy overmap save.") { std::string legacy_save_name = "tests/data/legacy_0.C_overmap.sav"; std::string new_save_name = "tests/data/jsionized_overmap.sav"; overmap test_map; std::ifstream fin; fin.open( legacy_save_name.c_str(), std::ifstream::binary ); REQUIRE( fin.is_open() ); test_map.unserialize( fin ); fin.close(); check_test_overmap_data( test_map ); std::ofstream fout; fout.open( new_save_name.c_str(), std::ofstream::binary ); REQUIRE( fout.is_open() ); test_map.serialize(fout); fout.close(); overmap test_map_2;