ResInsight/Octave/OctavePlugin/riGetCaseGroups.cpp
Magne Sjaastad b050cac1d2
Make it possible to build Octave plugins independent to main build
The building of Octave plugins within main ResInsight build on RHEL8 cause the build to use gcc-12, and gcc-12 is extremely slow when building opm-common.

Adjust the CMake configuration so it is possible to build the Octave plugins as an independent build job. The plugin binaries can then be uploaded to an external server. The main ResInsight build  can download the binaries and include them in the install package for ResInsight.

Use the flag RESINSIGHT_USE_EXTERNAL_OCTAVE_PLUGINS to download external Octave plugin binaries.
2024-06-04 07:42:50 +02:00

141 lines
3.8 KiB
C++

#include <QtNetwork>
#include <octave/oct.h>
#include <octave/oct-map.h>
#include "riSettings.h"
void getCaseGroups(std::vector<QString>& groupNames, std::vector<int>& groupIds, const QString &hostName, quint16 port)
{
QString serverName = hostName;
quint16 serverPort = port;
QTcpSocket socket;
socket.connectToHost(serverName, serverPort);
if (!socket.waitForConnected(riOctavePlugin::connectTimeOutMilliSecs))
{
error("Connection: %s",socket.errorString().toLatin1().data());
return;
}
// Create command and send it:
QString command("GetCaseGroups");
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)(2*sizeof(quint64)))
{
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
{
error("Waiting for data: %s",socket.errorString().toLatin1().data());
return;
}
OCTAVE_QUIT;
}
quint64 byteCount;
socketStream >> byteCount;
quint64 groupCount;
socketStream >> groupCount;
// Get response. Read all data for command
while (socket.bytesAvailable() < (int)byteCount)
{
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
{
error("Waiting for data: %s",socket.errorString().toLatin1().data());
return;
}
OCTAVE_QUIT;
}
quint64 group = 0;
while (group < groupCount)
{
QString caseGroupName;
qint64 caseGroupId;
socketStream >> caseGroupName;
socketStream >> caseGroupId;
groupNames.push_back(caseGroupName);
groupIds.push_back(caseGroupId);
group++;
}
return;
}
DEFUN_DLD (riGetCaseGroups, args, nargout,
"Usage:\n"
"\n"
" riGetCaseGroups()\n"
"\n"
"This function returns a CaseGroupInfo Structure for each of the case groups in the current ResInsight project.\n"
"CaseGroupInfo = {\n"
" CaseGroupId = int # A project-unique integer used to address this particular CaseGroup\n"
" CaseGroupName = string # The name assigned to the CaseGroup in ResInsight\n"
"}\n"
)
{
int nargin = args.length ();
if (nargin > 0)
{
error("riGetCaseGroups: Too many arguments, this function does not take any arguments.\n");
print_usage();
}
else if (nargout != 1)
{
error("riGetCaseGroups: Wrong number of output arguments, expects one output argument.\n");
print_usage();
}
else
{
std::vector<QString> groupNames;
std::vector<int> groupIds;
getCaseGroups(groupNames, groupIds, "127.0.0.1", riOctavePlugin::portNumber());
size_t groupCount = groupNames.size();
if (groupCount != groupIds.size())
{
error("riGetCurrentCase: Inconsistent data received from ResInsight.\n");
}
else
{
// Create cells with N items for each field in the data structure
Cell cellValuesA(groupCount, 1);
Cell cellValuesB(groupCount, 1);
for (size_t i = 0; i < groupCount; i++)
{
cellValuesA(i) = groupIds[i];
cellValuesB(i) = groupNames[i].toLatin1().data();
}
// Build a map between the field name and field cell values
octave_map m;
m.assign(riOctavePlugin::caseGroupInfo_CaseGroupId, cellValuesA);
m.assign(riOctavePlugin::caseGroupInfo_CaseGroupName, cellValuesB);
return octave_value(m);
}
}
return octave_value();
}