2013-05-16 07:44:34 -05:00
|
|
|
|
#include <QtNetwork>
|
|
|
|
|
#include <octave/oct.h>
|
|
|
|
|
|
|
|
|
|
#include "riSettings.h"
|
|
|
|
|
|
|
|
|
|
void getTimeStepDates( std::vector<double>& decimalDays,
|
|
|
|
|
const qint64& caseId,
|
|
|
|
|
const QString& hostName,
|
|
|
|
|
quint16 port)
|
|
|
|
|
{
|
|
|
|
|
QString serverName = hostName;
|
|
|
|
|
quint16 serverPort = port;
|
|
|
|
|
|
|
|
|
|
QTcpSocket socket;
|
|
|
|
|
socket.connectToHost(serverName, serverPort);
|
|
|
|
|
|
2013-09-30 13:54:31 -05:00
|
|
|
|
if (!socket.waitForConnected(riOctavePlugin::connectTimeOutMilliSecs))
|
2013-05-16 07:44:34 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Connection: %s",socket.errorString().toLatin1().data());
|
2013-05-16 07:44:34 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create command and send it:
|
|
|
|
|
|
|
|
|
|
QString command = QString("GetTimeStepDays %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 07:44:34 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Waiting for header: %s",socket.errorString().toLatin1().data());
|
2013-05-16 07:44:34 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quint64 byteCount;
|
|
|
|
|
socketStream >> byteCount;
|
|
|
|
|
|
|
|
|
|
while (socket.bytesAvailable() < (int)(byteCount))
|
|
|
|
|
{
|
2013-09-30 13:54:31 -05:00
|
|
|
|
if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs))
|
2013-05-16 07:44:34 -05:00
|
|
|
|
{
|
2020-11-03 05:25:15 -06:00
|
|
|
|
error("Waiting for data: %s",socket.errorString().toLatin1().data());
|
2013-05-16 07:44:34 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
OCTAVE_QUIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quint64 timeStepCount;
|
|
|
|
|
socketStream >> timeStepCount;
|
|
|
|
|
|
|
|
|
|
octave_stdout << "byte count: " << byteCount << ", Timesteps: " << timeStepCount << std::endl;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < timeStepCount; i++)
|
|
|
|
|
{
|
|
|
|
|
double doubleValue;
|
|
|
|
|
|
|
|
|
|
socketStream >> doubleValue;
|
|
|
|
|
decimalDays.push_back(doubleValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFUN_DLD (riGetTimeStepDays, args, nargout,
|
|
|
|
|
"Usage:\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" riGetTimeStepDays()\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"This function returns the time from the simulation start\n"
|
|
|
|
|
"as decimal days for all the time steps as a Vector of doubles.\n"
|
|
|
|
|
"If the CaseId is not defined, ResInsight<68>s Current Case is used.\n"
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
int nargin = args.length ();
|
|
|
|
|
if (nargin > 1)
|
|
|
|
|
{
|
|
|
|
|
error("riGetTimeStepDays: Too many arguments, this function takes one optional argument.\n");
|
|
|
|
|
print_usage();
|
|
|
|
|
}
|
|
|
|
|
else if (nargout != 1)
|
|
|
|
|
{
|
|
|
|
|
error("riGetTimeStepDays: Wrong number of output arguments, this function requires one 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 07:44:34 -05:00
|
|
|
|
{
|
|
|
|
|
unsigned int argCaseId = args(0).uint_value();
|
|
|
|
|
caseId = argCaseId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<double> decimalDays;
|
|
|
|
|
|
|
|
|
|
getTimeStepDates(decimalDays, caseId, "127.0.0.1", 40001);
|
|
|
|
|
|
2015-06-30 14:38:33 -05:00
|
|
|
|
dim_vector dv(2, 1);
|
2013-05-16 07:44:34 -05:00
|
|
|
|
dv(0) = decimalDays.size();
|
|
|
|
|
dv(1) = 1;
|
|
|
|
|
NDArray oct_decimalDays(dv);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < decimalDays.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
oct_decimalDays(i) = decimalDays[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return octave_value(oct_decimalDays);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return octave_value();
|
|
|
|
|
}
|
|
|
|
|
|