mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Updated to version 0.8.0
This commit is contained in:
114
OctavePlugin/riGetMainGridDimensions.cpp
Normal file
114
OctavePlugin/riGetMainGridDimensions.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#include <QtNetwork>
|
||||
#include <octave/oct.h>
|
||||
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
DEFUN_DLD (riGetMainGridDimensions, args, nargout,
|
||||
"Usage:\n"
|
||||
"\n"
|
||||
" riGetMainGridDimensions( [CaseName/CaseIndex])\n"
|
||||
"\n"
|
||||
"Returns a vector of size 3: [ICount, JCount, KCount] \n"
|
||||
"Containing the dimentions of the main grid in the requested case.\n"
|
||||
"If the Eclipse Case is not defined, the active View in ResInsight is used."
|
||||
)
|
||||
{
|
||||
int nargin = args.length ();
|
||||
if (nargin > 1)
|
||||
{
|
||||
error("riGetActiveCellInfo: Too many arguments. Only the name or index of the case is valid input.\n");
|
||||
print_usage();
|
||||
}
|
||||
else if (nargout < 1)
|
||||
{
|
||||
error("riGetActiveCellInfo: Missing output argument.\n");
|
||||
print_usage();
|
||||
}
|
||||
else
|
||||
{
|
||||
int32NDArray propertyFrames;
|
||||
|
||||
if (nargin > 0)
|
||||
getMainGridDimensions(propertyFrames, "127.0.0.1", 40001, args(0).char_matrix_value().row_as_string(0).c_str());
|
||||
else
|
||||
getMainGridDimensions(propertyFrames, "127.0.0.1", 40001, "");
|
||||
|
||||
return octave_value(propertyFrames);
|
||||
}
|
||||
|
||||
return octave_value_list ();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user