2013-05-23 04:02:10 -05:00
|
|
|
|
#include <QtNetwork>
|
2014-04-02 01:55:26 -05:00
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
2013-05-23 04:02:10 -05:00
|
|
|
|
#include <octave/oct.h>
|
|
|
|
|
|
|
|
|
|
#include "riSettings.h"
|
2014-04-15 07:16:35 -05:00
|
|
|
|
#include "RiaSocketDataTransfer.cpp" // NB! Include cpp-file to avoid linking of additional file in oct-compile configuration
|
2014-04-02 02:52:02 -05:00
|
|
|
|
|
|
|
|
|
|
2013-05-23 04:02:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex)
|
|
|
|
|
{
|
|
|
|
|
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-23 04:02:10 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Connection: %s",socket.errorString().toLatin1().data());
|
2013-05-23 04:02:10 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create command and send it:
|
|
|
|
|
|
|
|
|
|
QString command = QString("GetCellCorners %1 %2").arg(caseId).arg(gridIndex);
|
|
|
|
|
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)(5 * sizeof(quint64)))
|
|
|
|
|
{
|
2013-09-30 13:54:31 -05:00
|
|
|
|
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
|
2013-05-23 04:02:10 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Waiting for header: %s",socket.errorString().toLatin1().data());
|
2013-05-23 04:02:10 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quint64 cellCountI;
|
|
|
|
|
quint64 cellCountJ;
|
|
|
|
|
quint64 cellCountK;
|
|
|
|
|
quint64 cellCount;
|
|
|
|
|
quint64 byteCount;
|
|
|
|
|
|
|
|
|
|
socketStream >> cellCount;
|
|
|
|
|
socketStream >> cellCountI;
|
|
|
|
|
socketStream >> cellCountJ;
|
|
|
|
|
socketStream >> cellCountK;
|
|
|
|
|
socketStream >> byteCount;
|
|
|
|
|
|
|
|
|
|
if (!(byteCount && cellCount))
|
|
|
|
|
{
|
|
|
|
|
error ("Could not find the requested data in ResInsight");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 01:48:36 -05:00
|
|
|
|
dim_vector dv;
|
|
|
|
|
dv.resize(5);
|
|
|
|
|
dv(0) = cellCountI;
|
|
|
|
|
dv(1) = cellCountJ;
|
|
|
|
|
dv(2) = cellCountK;
|
|
|
|
|
dv(3) = 8;
|
|
|
|
|
dv(4) = 3;
|
|
|
|
|
cellCornerValues.resize(dv);
|
|
|
|
|
|
2014-04-02 01:55:26 -05:00
|
|
|
|
double* internalMatrixData = cellCornerValues.fortran_vec();
|
|
|
|
|
QStringList errorMessages;
|
2014-04-15 07:16:35 -05:00
|
|
|
|
if (!RiaSocketDataTransfer::readBlockDataFromSocket(&socket, (char*)(internalMatrixData), byteCount, errorMessages))
|
2014-04-02 01:55:26 -05:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < errorMessages.size(); i++)
|
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("%s",errorMessages[i].toLatin1().data());
|
2014-04-02 01:55:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OCTAVE_QUIT;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 04:02:10 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFUN_DLD (riGetCellCorners, args, nargout,
|
|
|
|
|
"Usage:\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" riGetCellCorners([CaseId], GridIndex )\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"This function returns the UTM coordinates (X, Y, Z) of the 8 corners of all the cells in the grid.\n"
|
|
|
|
|
"If the CaseId is not defined, ResInsight<68>s Current Case is used.\n"
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
int nargin = args.length ();
|
|
|
|
|
if (nargin > 2)
|
|
|
|
|
{
|
|
|
|
|
error("riGetCellCorners: Too many arguments. CaseId is optional input argument.\n");
|
|
|
|
|
print_usage();
|
|
|
|
|
}
|
|
|
|
|
else if (nargout < 1)
|
|
|
|
|
{
|
|
|
|
|
error("riGetCellCorners: Missing output argument.\n");
|
|
|
|
|
print_usage();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NDArray cellCornerValues;
|
|
|
|
|
|
|
|
|
|
qint32 caseId = -1;
|
|
|
|
|
quint32 gridIndex = 0;
|
|
|
|
|
|
|
|
|
|
if (nargin == 1)
|
|
|
|
|
{
|
|
|
|
|
gridIndex = args(0).uint_value();
|
|
|
|
|
}
|
|
|
|
|
else if (nargin == 2)
|
|
|
|
|
{
|
|
|
|
|
unsigned int argCaseId = args(0).uint_value();
|
|
|
|
|
caseId = argCaseId;
|
|
|
|
|
|
|
|
|
|
gridIndex = args(1).uint_value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getCellCorners(cellCornerValues, "127.0.0.1", 40001, caseId, gridIndex);
|
|
|
|
|
|
|
|
|
|
return octave_value(cellCornerValues);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return octave_value();
|
|
|
|
|
}
|
|
|
|
|
|