bool XferChannel::mainUpdate() { if (mInternalStatus == _WaitingForRequests) { mCurrentRequest = mHost->getNextXferRequest(mSudo); if (mCurrentRequest == NULL) return false; else { mInternalStatus = _SendingRequestHeader; return true; } } if (mInternalStatus == _SendingRequestHeader) { // If uploading, make sure the data to be uploaded is encoded. if (mCurrentRequest->isUploadRequest() && mCurrentRequest->getEncodedData().isEmpty()) mCurrentRequest->setEncodedData(Tools::bin(mCurrentRequest->getData())); SendResponse r = sendData(mCurrentRequest->getRequestHeader()); if (r != SendSucceed) return (r == SendAgain); mInternalStatus = (mCurrentRequest->isUploadRequest() ? _WaitingForReady : _ReadingDownloadHeader); } if (mInternalStatus == _ReadingDownloadHeader) { ReadReply r = readUntil("\n"); if (r.readAgain) return false; if (r.data.isEmpty()) throw(tr("Invalid response to download header")); if (r.data.startsWith("Error: ")) { if(r.data.contains("File not found")) { mCurrentRequest->handleFailure(QString(mCurrentRequest->getFilename()) + " - " + tr("File not found"), 0); mInternalStatus = _WaitingForRequests; return true; } else { throw(QString(r.data)); } } if (r.data.endsWith('\r')) { SSHLOG_WARN(mHost) << "Warning: Stray carriage-return after xfer header"; r.data.chop(1); } QList<QByteArray> parts = r.data.split(','); mCurrentRequest->setDataSize(parts[0].toInt()); mCurrentRequest->setChecksum(parts[1]); mLeftoverEscape = false; mInternalStatus = _DownloadingBody; } if (mInternalStatus == _DownloadingBody) { ReadReply r = readBinaryData(mCurrentRequest->getDataSize()); if (r.readAgain) return false; // Check the checksum. QCryptographicHash hash(QCryptographicHash::Md5); hash.addData(r.data); QByteArray checksum = hash.result().toHex().toLower(); if (checksum != mCurrentRequest->getChecksum()) mCurrentRequest->handleFailure(tr("Checksum failure: %1 vs %2").arg(QString(checksum)).arg(QString(mCurrentRequest->getChecksum())), 0); else { mCurrentRequest->setData(r.data); mCurrentRequest->handleSuccess(); } mInternalStatus = _WaitingForOk; } if (mInternalStatus == _WaitingForReady) { ReadReply r = readUntil("\n"); if (r.readAgain) return true; if (r.data != "Ready") criticalError("Failed to upload file"); mInternalStatus = _UploadingBody; } if (mInternalStatus == _UploadingBody) { QByteArray encoded = mCurrentRequest->getEncodedData(); SendResponse r = sendData(encoded); if (r != SendSucceed) return (r == SendAgain); mCurrentRequest->handleSuccess(); mInternalStatus = _WaitingForOk; } if (mInternalStatus == _WaitingForOk) { ReadReply r = readUntil("\n"); if (r.readAgain) return true; if (r.data.endsWith('\r')) { SSHLOG_WARN(mHost) << "Warning: Stray carriage-return after xfer OK"; r.data.chop(1); } if (r.data != "OK") criticalError("Did not receive OK at the end of transmission. Got: " + r.data); mInternalStatus = _WaitingForRequests; return true; } return false; }
void ExporterVTK<MeshType>::readVTUFiles ( exporterData_Type& dvar ) { ASSERT ( this->M_numImportProc, "The number of pieces to be loaded was not specified." ); UInt numPoints, numCells; std::vector<Real> inputValues; std::vector<Real> globalIDs; const UInt start ( dvar.start() ); const UInt numGlobalDOF ( dvar.numDOF() ); // Each processor will read all the files, and fill just its own component of the vectors for ( UInt iProc = 0; iProc < this->M_numImportProc; ++iProc ) { std::string filename ( this->M_postDir + this->M_prefix + "_" + dvar.variableName() + this->M_postfix + "." + iProc + ".vtu" ); std::ifstream inputFile ( filename.c_str() ); if (this->M_procId == 0) { std::cout << "\tfile " << filename << std::endl; } ASSERT (inputFile.is_open(), "There is an error while opening " + filename ); // file parsing: line by line std::string line; size_t found; std::stringstream parseLine; while ( inputFile.good() && getline ( inputFile, line ) ) { // this is essentially a consistency check: the number of DOF is explicitly // written in the VTK files. We will check that the number of values read // from file matches this number found = line.find ( "NumberOfPoints" ); if ( found != std::string::npos ) { // place the get pointer at the first " after NumberOfPoints found = line.find ( "\"", found, 1 ); // after the " we'll find the number: parse the substring parseLine.str ( line.substr (found + 1) ); parseLine >> numPoints; // do the same for NumberOfCells found = line.find ( "NumberOfCells" ); found = line.find ( "\"", found, 1 ); parseLine.str ( line.substr (found + 1) ); parseLine >> numCells; } // load all PointData arrays if ( line.find ( "<PointData" ) != std::string::npos ) { while ( inputFile.good() && getline ( inputFile, line ) ) { if ( line.find ( dvar.variableName() ) != std::string::npos ) { inputValues.resize ( dvar.fieldDim() *numPoints ); if ( line.find ( "binary" ) != std::string::npos ) { UInt numBitsFloat; found = line.find ( "Float" ); parseLine.str ( line.substr (found + 5) ); parseLine >> numBitsFloat; ASSERT (inputFile.good(), "There is an error while opening " + filename ); getline ( inputFile, line ); readBinaryData ( line, inputValues, numBitsFloat ); } else { ASSERT (inputFile.good(), "There is an error while opening " + filename ); getline ( inputFile, line ); readASCIIData ( line, inputValues ); } } if ( line.find ( "GlobalId" ) != std::string::npos ) { globalIDs.resize ( numPoints ); ASSERT (inputFile.good(), "There is an error while opening " + filename ); getline ( inputFile, line ); readASCIIData ( line, globalIDs ); } }