2013-05-16 08:16:51 -05:00
|
|
|
|
#include <QtNetwork>
|
|
|
|
|
#include <octave/oct.h>
|
|
|
|
|
|
|
|
|
|
#include "riSettings.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void getGridDimensions(int32NDArray& gridDimensions, const QString &hostName, quint16 port, const qint64& caseId)
|
|
|
|
|
{
|
|
|
|
|
QString serverName = hostName;
|
|
|
|
|
quint16 serverPort = port;
|
|
|
|
|
|
|
|
|
|
QTcpSocket socket;
|
|
|
|
|
socket.connectToHost(serverName, serverPort);
|
|
|
|
|
|
2013-08-12 04:38:09 -05:00
|
|
|
|
if (!socket.waitForConnected(riOctavePlugin::connectTimeOutMilliSecs))
|
2013-05-16 08:16:51 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Connection: %s",socket.errorString().toLatin1().data());
|
2013-05-16 08:16:51 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create command and send it:
|
|
|
|
|
|
|
|
|
|
QString command = QString("GetGridDimensions %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)))
|
|
|
|
|
{
|
2013-09-30 13:54:31 -05:00
|
|
|
|
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
|
2013-05-16 08:16:51 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Waiting for header: %s",socket.errorString().toLatin1().data());
|
2013-05-16 08:16:51 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quint64 byteCount;
|
|
|
|
|
socketStream >> byteCount;
|
|
|
|
|
|
|
|
|
|
quint64 gridCount = byteCount / (3 * sizeof(quint64));
|
|
|
|
|
|
|
|
|
|
dim_vector dv (1, 1);
|
2013-09-30 06:38:25 -05:00
|
|
|
|
dv(0) = gridCount;
|
|
|
|
|
dv(1) = 3;
|
2013-05-16 08:16:51 -05:00
|
|
|
|
|
|
|
|
|
gridDimensions.resize(dv);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < gridCount; i++)
|
|
|
|
|
{
|
|
|
|
|
quint64 iCount;
|
|
|
|
|
quint64 jCount;
|
|
|
|
|
quint64 kCount;
|
|
|
|
|
|
|
|
|
|
socketStream >> iCount;
|
|
|
|
|
socketStream >> jCount;
|
|
|
|
|
socketStream >> kCount;
|
|
|
|
|
|
2013-09-30 06:38:25 -05:00
|
|
|
|
gridDimensions(i, 0) = iCount;
|
|
|
|
|
gridDimensions(i, 1) = jCount;
|
|
|
|
|
gridDimensions(i, 2) = kCount;
|
2013-05-16 08:16:51 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString tmp = QString("riGetGridDimensions : Read grid dimensions");
|
|
|
|
|
if (caseId < 0)
|
|
|
|
|
{
|
|
|
|
|
tmp += QString(" from current case.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tmp += QString(" from caseID: %1.").arg(caseId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
octave_stdout << tmp.toStdString() << std::endl;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFUN_DLD (riGetGridDimensions, args, nargout,
|
|
|
|
|
"Usage:\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" riGetGridDimensions([CaseId])\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"This function returns a two dimensional matrix: One row for each grid, starting with the main grid.\n"
|
|
|
|
|
"NOTE: This means that the <20>normal<61> GridIndices where 0 means Main Grid does not work directly with this matrix. You have to add 1.\n"
|
|
|
|
|
"The columns contain the following information:\n"
|
|
|
|
|
"[NI, NJ, NK]: I, J, K dimensions of the grid.\n"
|
|
|
|
|
"If the CaseId is not defined, ResInsight<68>s Current Case is used.\n"
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
int nargin = args.length ();
|
|
|
|
|
if (nargin > 1)
|
|
|
|
|
{
|
|
|
|
|
error("riGetGridDimensions: Too many arguments. Only the name or index of the case is valid input.\n");
|
|
|
|
|
print_usage();
|
|
|
|
|
}
|
|
|
|
|
else if (nargout < 1)
|
|
|
|
|
{
|
|
|
|
|
error("riGetGridDimensions: Missing output argument.\n");
|
|
|
|
|
print_usage();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qint64 caseId = -1;
|
|
|
|
|
if (nargin > 0)
|
|
|
|
|
{
|
2019-01-15 00:28:50 -06:00
|
|
|
|
if (riOctavePlugin::isOctaveValueNumeric(args(0)))
|
2013-05-16 08:16:51 -05:00
|
|
|
|
{
|
|
|
|
|
unsigned int argCaseId = args(0).uint_value();
|
|
|
|
|
caseId = argCaseId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32NDArray gridDimensions;
|
|
|
|
|
getGridDimensions(gridDimensions, "127.0.0.1", 40001, caseId);
|
|
|
|
|
|
|
|
|
|
return octave_value(gridDimensions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return octave_value_list ();
|
|
|
|
|
}
|
|
|
|
|
|