// Read up to line starting with cmd. Sets args to rest of line. // Returns true if found, false if stream is not good anymore. bool Foam::fileFormats::AC3DsurfaceFormatCore::cueTo ( IFstream& is, const string& cmd, string& args ) { while (is.good()) { string line; is.getLine(line); string::size_type space = line.find(' '); if (space != string::npos) { if (line.substr(0, space) == cmd) { args = line.substr(space+1); return true; } } } return false; }
// Reads past -1 and reads element type label readTag(IFstream& is) { string tag; do { if (!is.good()) { return -1; } string line; is.getLine(line); if (line.size() < 6) { return -1; } tag = line.substr(0, 6); } while (tag == SEPARATOR); return readLabel(IStringStream(tag)()); }
bool Foam::meshReaders::STARCD::readHeader(IFstream& is, word fileSignature) { if (!is.good()) { FatalErrorInFunction << abort(FatalError); } word header; label majorVersion; is >> header; is >> majorVersion; // skip the rest of the line readToNewline(is); // add other checks ... if (header != fileSignature) { Info<< "header mismatch " << fileSignature << " " << is.name() << endl; } return true; }
// Reads points section. Read region as well? void readPoints ( IFstream& is, DynamicList<point>& points, // coordinates DynamicList<label>& unvPointID // unv index ) { Sout<< "Starting reading points at line " << is.lineNumber() << '.' << endl; static bool hasWarned = false; while (true) { string line; is.getLine(line); label pointI = readLabel(IStringStream(line.substr(0, 10))()); if (pointI == -1) { break; } else if (pointI != points.size()+1 && !hasWarned) { hasWarned = true; IOWarningIn ( "readPoints(IFstream&, label&, DynamicList<point>" ", DynamicList<label>&)", is ) << "Points not in order starting at point " << pointI //<< " at line " << is.lineNumber() //<< abort(FatalError); << endl; } point pt; is.getLine(line); pt[0] = readUnvScalar(line.substr(0, 25)); pt[1] = readUnvScalar(line.substr(25, 25)); pt[2] = readUnvScalar(line.substr(50, 25)); unvPointID.append(pointI); points.append(pt); } points.shrink(); unvPointID.shrink(); Sout<< "Read " << points.size() << " points." << endl; }
Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment ( IFstream& is ) { string line; do { is.getLine(line); } while ((line.empty() || line[0] == '#') && is.good()); return line; }
// Skip void skipSection(IFstream& is) { Info<< "Skipping section at line " << is.lineNumber() << '.' << endl; string line; while (is.good()) { is.getLine(line); if (isSeparator(line)) { break; } } }
// Skips till end of section. Returns false if end of file. bool skipSection(IFstream& inFile) { string line; do { inFile.getLine(line); if (!inFile.good()) { return false; } } while (line.size() < 4 || line.substr(0, 4) != "$End"); return true; }
void starMesh::readToNl(IFstream& is) { char c; do { is.get(c); } while (is && c != '\n'); }
// Reads and prints header void readHeader(IFstream& is) { string line; while (is.good()) { is.getLine(line); if (isSeparator(line)) { break; } else { Sout<< line << endl; } } }
static bool readCmd(IFstream& ACfile, string& cmd, string& args) { if (ACfile.good()) { string line; ACfile.getLine(line); string::size_type space = line.find(' '); if (space != string::npos) { cmd = line.substr(0, space); args = line.substr(space+1); return true; } } return false; }
Foam::Istream* Foam::IOobject::objectStream(const fileName& fName) { if (fName.size()) { IFstream* isPtr = new IFstream(fName); if (isPtr->good()) { return isPtr; } else { delete isPtr; return NULL; } } else { return NULL; } }
// Reads unit section void readUnits ( IFstream& is, scalar& lengthScale, scalar& forceScale, scalar& tempScale, scalar& tempOffset ) { Sout<< "Starting reading units at line " << is.lineNumber() << '.' << endl; string line; is.getLine(line); label l = readLabel(IStringStream(line.substr(0, 10))()); Sout<< "l:" << l << endl; string units(line.substr(10, 20)); Sout<< "units:" << units << endl; label unitType = readLabel(IStringStream(line.substr(30, 10))()); Sout<< "unitType:" << unitType << endl; // Read lengthscales is.getLine(line); lengthScale = readUnvScalar(line.substr(0, 25)); forceScale = readUnvScalar(line.substr(25, 25)); tempScale = readUnvScalar(line.substr(50, 25)); is.getLine(line); tempOffset = readUnvScalar(line.substr(0, 25)); Sout<< "Unit factors:" << nl << " Length scale : " << lengthScale << nl << " Force scale : " << forceScale << nl << " Temperature scale : " << tempScale << nl << " Temperature offset : " << tempOffset << nl << endl; }
scalar starMesh::readVtxCmpt(IFstream& is) { char lcs[17]; for (int i=0; i<16; i++) { is.get(lcs[i]); } lcs[16] = '\0'; return scalar(atof(lcs)); }
label starMesh::readVtxLabel(IFstream& is) { char lcs[16]; for (int i=0; i<15; i++) { is.get(lcs[i]); } lcs[15] = '\0'; return atoi(lcs); }
// Read up to line starting with cmd. Sets args to rest of line. // Returns true if found, false if stream is not good anymore. static bool readUpto ( const string& cmd, IFstream& ACfile, string& args ) { while (ACfile.good()) { string line; ACfile.getLine(line); string::size_type space = line.find(' '); if (space != string::npos && line.substr(0, space) == cmd) { args = line.substr(space+1); return true; } } return false; }
Foam::Istream* Foam::IOobject::objectStream() { fileName fName = filePath(); if (fName.size()) { IFstream* isPtr = new IFstream(fName); if (isPtr->good()) { return isPtr; } else { delete isPtr; return NULL; } } else { return NULL; } }
bool Foam::fileFormats::AC3DsurfaceFormatCore::readCmd ( IFstream& is, string& cmd, string& args ) { if (is.good()) { string line; is.getLine(line); string::size_type space = line.find(' '); if (space != string::npos) { cmd = line.substr(0, space); args = line.substr(space+1); return true; } } return false; }
// Reads cells section. Read region as well? Not handled yet but should just // be a matter of reading corresponding to boundaryFaces the correct property // and sorting it later on. void readCells ( IFstream& is, DynamicList<cellShape>& cellVerts, DynamicList<label>& cellMaterial, DynamicList<label>& boundaryFaceIndices, DynamicList<face>& boundaryFaces, DynamicList<label>& cellCorrespondence, DynamicList<label>& unvPointID // unv index ) { Info<< "Starting reading cells at line " << is.lineNumber() << '.' << endl; // Invert point numbering. label maxUnvPoint = 0; forAll(unvPointID, pointi) { maxUnvPoint = max(maxUnvPoint, unvPointID[pointi]); }
// Reads cells section. Read region as well? Not handled yet but should just // be a matter of reading corresponding to boundaryFaces the correct property // and sorting it later on. void readCells ( IFstream& is, DynamicList<cellShape>& cellVerts, DynamicList<label>& cellMaterial, DynamicList<label>& boundaryFaceIndices, DynamicList<face>& boundaryFaces ) { Sout<< "Starting reading cells at line " << is.lineNumber() << '.' << endl; const cellModel& hex = *(cellModeller::lookup("hex")); const cellModel& prism = *(cellModeller::lookup("prism")); const cellModel& tet = *(cellModeller::lookup("tet")); labelHashSet skippedElements; labelHashSet foundFeType; while (true) { string line; is.getLine(line); if (isSeparator(line)) { break; } IStringStream lineStr(line); label cellI, feID, physProp, matProp, colour, nNodes; lineStr >> cellI >> feID >> physProp >> matProp >> colour >> nNodes; if (foundFeType.insert(feID)) { Info<< "First occurrence of element type " << feID << " for cell " << cellI << " at line " << is.lineNumber() << endl; } if (feID == 11) { // Rod. Skip. is.getLine(line); is.getLine(line); } else if (feID == 171) { // Rod. Skip. is.getLine(line); } else if (feID == 41 || feID == 91) { // Triangle. Save - used for patching later on. is.getLine(line); face cVerts(3); IStringStream lineStr(line); lineStr >> cVerts[0] >> cVerts[1] >> cVerts[2]; boundaryFaces.append(cVerts); boundaryFaceIndices.append(cellI); } else if (feID == 44 || feID == 94)