void getMainGridDimensions(int32NDArray& gridDimensions, const QString &hostName, quint16 port, QString caseName) { QString serverName = hostName; quint16 serverPort = port; const int Timeout = 5 * 1000; QTcpSocket socket; socket.connectToHost(serverName, serverPort); if (!socket.waitForConnected(Timeout)) { error((("Connection: ") + socket.errorString()).toLatin1().data()); return; } // Create command and send it: QString command("GetMainGridDimensions "); command += caseName; QByteArray cmdBytes = command.toLatin1(); QDataStream socketStream(&socket); socketStream.setVersion(QDataStream::Qt_4_0); socketStream << (qint64)(cmdBytes.size()); socket.write(cmdBytes); // Get response. First wait for the header while (socket.bytesAvailable() < (int)(3*sizeof(quint64))) { if (!socket.waitForReadyRead(Timeout)) { error((("Wating for header: ") + socket.errorString()).toLatin1().data()); return; } } // Read timestep count and blocksize quint64 iCount; quint64 jCount; quint64 kCount; socketStream >> iCount; socketStream >> jCount; socketStream >> kCount; dim_vector dv (1, 1); dv(0) = 3; gridDimensions.resize(dv); gridDimensions(0) = iCount; gridDimensions(1) = jCount; gridDimensions(2) = kCount; QString tmp = QString("riGetMainGridDimensions : Read main grid dimensions"); if (caseName.isEmpty()) { tmp += QString(" from active case."); } else { tmp += QString(" from %1.").arg(caseName); } octave_stdout << tmp.toStdString() << " Dimensions: " << iCount << ", " << jCount << ", " << kCount << std::endl; return; }
void getCoarseningInfo(int32NDArray& coarseningInfo, const QString &hostName, quint16 port, const qint64& caseId) { QString serverName = hostName; quint16 serverPort = port; QTcpSocket socket; socket.connectToHost(serverName, serverPort); if (!socket.waitForConnected(riOctavePlugin::connectTimeOutMilliSecs)) { error((("Connection: ") + socket.errorString()).toLatin1().data()); return; } // Create command and send it: QString command = QString("GetCoarseningInfo %1").arg(caseId); QByteArray cmdBytes = command.toLatin1(); QDataStream socketStream(&socket); socketStream.setVersion(riOctavePlugin::qtDataStreamVersion); socketStream << (qint64)(cmdBytes.size()); socket.write(cmdBytes); // Get response. First wait for the header while (socket.bytesAvailable() < (int)(sizeof(quint64))) { if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) { error((("Waiting for header: ") + socket.errorString()).toLatin1().data()); return; } } quint64 byteCount; socketStream >> byteCount; quint64 boxCount = byteCount / (6 * sizeof(qint32)); dim_vector dv (1, 1); dv(0) = boxCount; dv(1) = 6; coarseningInfo.resize(dv); for (size_t i = 0; i < boxCount; i++) { qint32 i1; qint32 i2; qint32 j1; qint32 j2; qint32 k1; qint32 k2; socketStream >> i1; socketStream >> i2; socketStream >> j1; socketStream >> j2; socketStream >> k1; socketStream >> k2; coarseningInfo(i, 0) = i1; coarseningInfo(i, 1) = i2; coarseningInfo(i, 2) = j1; coarseningInfo(i, 3) = j2; coarseningInfo(i, 4) = k1; coarseningInfo(i, 5) = k2; } return; }