Octave interface: Rebuilt the riSetActiveCellProperties command.

Accept the new arguments, refactored to new framework, improved error handling.
Still needs to support specified timesteps and Grid Coarsening
p4#: 21713
This commit is contained in:
Jacob Støren 2013-05-24 11:36:59 +02:00
parent 7ba9cef84b
commit 767c1d2409
5 changed files with 452 additions and 180 deletions

View File

@ -24,13 +24,14 @@
//////////////////////////////////////////////////////////////////////////
class RiaSocketServer;
class QTcpSocket;
class RiaSocketCommand
{
public:
virtual ~RiaSocketCommand() {}
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream) = 0;
virtual bool interpretMore(QDataStream& stream) { return true; }
virtual bool interpretMore(RiaSocketServer* server, QTcpSocket* currentClient) { return true; }
};
#include "cafFactory.h"

View File

@ -54,6 +54,261 @@
#include "cafFactory.h"
#include "RigGridBase.h"
#include "RiaSocketTools.h"
class RiaSetActiveCellProperty: public RiaSocketCommand
{
public:
RiaSetActiveCellProperty() :
m_currentReservoir(NULL),
m_scalarResultsToAdd(NULL),
m_currentScalarIndex(cvf::UNDEFINED_SIZE_T),
m_timeStepCountToRead(0),
m_bytesPerTimeStepToRead(0),
m_currentTimeStepToRead(0),
m_invalidActiveCellCountDetected(false),
m_porosityModelEnum(RifReaderInterface::MATRIX_RESULTS)
{}
static QString commandName () { return QString("SetActiveCellProperty"); }
virtual bool interpretCommand(RiaSocketServer* server, const QList<QByteArray>& args, QDataStream& socketStream)
{
RimCase* rimCase = RiaSocketTools::findCaseFromArgs(server, args);
QString propertyName = args[2];
QString porosityModelName = args[3];
if (porosityModelName == "Fracture")
{
m_porosityModelEnum = RifReaderInterface::FRACTURE_RESULTS;
}
// Find the requested data, Or create a set if we are setting data and it is not found
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
std::vector< std::vector<double> >* scalarResultFrames = NULL;
if (rimCase && rimCase->results(m_porosityModelEnum))
{
scalarResultIndex = rimCase->results(m_porosityModelEnum)->findOrLoadScalarResult(propertyName);
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T)
{
scalarResultIndex = rimCase->results(m_porosityModelEnum)->cellResults()->addEmptyScalarResult(RimDefines::GENERATED, propertyName, true);
}
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
{
scalarResultFrames = &(rimCase->results(m_porosityModelEnum)->cellResults()->cellScalarResults(scalarResultIndex));
m_currentScalarIndex = scalarResultIndex;
m_currentPropertyName = propertyName;
}
}
if (scalarResultFrames == NULL)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") + RiaSocketServer::tr("Could not find the %1 model property named: \"%2\"").arg(porosityModelName).arg(propertyName));
return true;
}
// Create a list of all the requested timesteps
m_requestedTimesteps.clear();
if (args.size() <= 4)
{
// Select all
for (size_t tsIdx = 0; tsIdx < scalarResultFrames->size(); ++tsIdx)
{
m_requestedTimesteps.push_back(tsIdx);
}
}
else
{
bool timeStepReadError = false;
for (int argIdx = 4; argIdx < args.size(); ++argIdx)
{
bool conversionOk = false;
int tsIdx = args[argIdx].toInt(&conversionOk);
if (conversionOk)
{
m_requestedTimesteps.push_back(tsIdx);
}
else
{
timeStepReadError = true;
}
}
if (timeStepReadError)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: riGetActiveCellProperty : \n") + RiaSocketServer::tr("An error occured while interpreting the requested timesteps."));
}
}
m_currentReservoir = rimCase;
m_scalarResultsToAdd = scalarResultFrames;
if (server->currentClient()->bytesAvailable())
{
return this->interpretMore(server, server->currentClient());
}
return false;
}
virtual bool interpretMore(RiaSocketServer* server, QTcpSocket* currentClient)
{
if (m_invalidActiveCellCountDetected) return true;
if (!currentClient->bytesAvailable()) return false;
QDataStream socketStream(currentClient);
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
// If we have not read the header and there are data enough: Read it.
// Do nothing if we have not enough data
if (m_timeStepCountToRead == 0 || m_bytesPerTimeStepToRead == 0)
{
if (currentClient->bytesAvailable() < (int)sizeof(quint64)*2) return false;
socketStream >> m_timeStepCountToRead;
socketStream >> m_bytesPerTimeStepToRead;
}
// If nothing should be read, or we already have read everything, do nothing
if ((m_timeStepCountToRead == 0) || (m_currentTimeStepToRead >= m_timeStepCountToRead) ) return true;
// Check if a complete timestep is available, return and whait for readyRead() if not
if (currentClient->bytesAvailable() < (int)m_bytesPerTimeStepToRead) return false;
size_t cellCountFromOctave = m_bytesPerTimeStepToRead / sizeof(double);
size_t gridActiveCellCount = m_currentReservoir->reservoirData()->activeCellInfo(m_porosityModelEnum)->globalActiveCellCount();
size_t gridTotalCellCount = m_currentReservoir->reservoirData()->mainGrid()->cellCount();
if (cellCountFromOctave != gridActiveCellCount && cellCountFromOctave != gridTotalCellCount)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") +
RiaSocketServer::tr("The number of cells in the data coming from octave does not match the case") + ":\"" + m_currentReservoir->caseUserDescription() + "\"\n"
" Octave: " + QString::number(cellCountFromOctave) + "\n"
" " + m_currentReservoir->caseUserDescription() + ": Active cell count: " + QString::number(gridActiveCellCount) + " Total cell count: " + QString::number(gridTotalCellCount)) ;
cellCountFromOctave = 0;
m_invalidActiveCellCountDetected = true;
currentClient->abort();
return true;
}
// Make sure the size of the retreiving container is correct.
// If it is, this is noops
m_scalarResultsToAdd->resize(m_timeStepCountToRead);
for (size_t tIdx = 0; tIdx < m_timeStepCountToRead; ++tIdx)
{
m_scalarResultsToAdd->at(tIdx).resize(cellCountFromOctave, HUGE_VAL);
}
// Read available complete timestepdata
while ((currentClient->bytesAvailable() >= (int)m_bytesPerTimeStepToRead) && (m_currentTimeStepToRead < m_timeStepCountToRead))
{
qint64 bytesRead = 0;
double * internalMatrixData = m_scalarResultsToAdd->at(m_currentTimeStepToRead).data();
#if 1 // Use raw data transfer. Faster.
bytesRead = currentClient->read((char*)(internalMatrixData), m_bytesPerTimeStepToRead);
#else
for (size_t cIdx = 0; cIdx < cellCountFromOctave; ++cIdx)
{
socketStream >> internalMatrixData[cIdx];
if (socketStream.status() == QDataStream::Ok) bytesRead += sizeof(double);
}
#endif
if ((int)m_bytesPerTimeStepToRead != bytesRead)
{
server->errorMessageDialog()->showMessage(RiaSocketServer::tr("ResInsight SocketServer: \n") +
RiaSocketServer::tr("Could not read binary double data properly from socket"));
}
++m_currentTimeStepToRead;
}
// If we have read all the data, refresh the views
if (m_currentTimeStepToRead == m_timeStepCountToRead)
{
if (m_currentReservoir != NULL)
{
// Create a new input property if we have an input reservoir
RimInputCase* inputRes = dynamic_cast<RimInputCase*>(m_currentReservoir);
if (inputRes)
{
RimInputProperty* inputProperty = NULL;
inputProperty = inputRes->m_inputPropertyCollection->findInputProperty(m_currentPropertyName);
if (!inputProperty)
{
inputProperty = new RimInputProperty;
inputProperty->resultName = m_currentPropertyName;
inputProperty->eclipseKeyword = "";
inputProperty->fileName = "";
inputRes->m_inputPropertyCollection->inputProperties.push_back(inputProperty);
RimUiTreeModelPdm* treeModel = RiuMainWindow::instance()->uiPdmModel();
treeModel->updateUiSubTree(inputRes->m_inputPropertyCollection());
}
inputProperty->resolvedState = RimInputProperty::RESOLVED_NOT_SAVED;
}
if( m_currentScalarIndex != cvf::UNDEFINED_SIZE_T &&
m_currentReservoir->reservoirData() &&
m_currentReservoir->reservoirData()->results(m_porosityModelEnum) )
{
m_currentReservoir->reservoirData()->results(m_porosityModelEnum)->recalculateMinMax(m_currentScalarIndex);
}
for (size_t i = 0; i < m_currentReservoir->reservoirViews.size(); ++i)
{
if (m_currentReservoir->reservoirViews[i])
{
m_currentReservoir->reservoirViews[i]->updateCurrentTimeStepAndRedraw();
}
}
}
return true;
}
return false;
}
private:
RimCase* m_currentReservoir;
std::vector< std::vector<double> >* m_scalarResultsToAdd;
size_t m_currentScalarIndex;
QString m_currentPropertyName;
std::vector<size_t> m_requestedTimesteps;
RifReaderInterface::PorosityModelResultType m_porosityModelEnum;
quint64 m_timeStepCountToRead;
quint64 m_bytesPerTimeStepToRead;
size_t m_currentTimeStepToRead;
bool m_invalidActiveCellCountDetected;
};
static bool RiaSetActiveCellProperty_init = RiaSocketCommandFactory::instance()->registerCreator<RiaSetActiveCellProperty>(RiaSetActiveCellProperty::commandName());
@ -65,12 +320,12 @@ RiaSocketServer::RiaSocketServer(QObject* parent)
m_tcpServer(NULL),
m_currentClient(NULL),
m_currentCommandSize(0),
m_scalarResultsToAdd(NULL),
m_currentTimeStepToRead(0),
m_currentReservoir(NULL),
m_currentScalarIndex(cvf::UNDEFINED_SIZE_T),
m_invalidActiveCellCountDetected(false),
m_readState(ReadingCommand),
// m_scalarResultsToAdd(NULL),
// m_currentTimeStepToRead(0),
// m_currentReservoir(NULL),
// m_currentScalarIndex(cvf::UNDEFINED_SIZE_T),
// m_invalidActiveCellCountDetected(false),
// m_readState(ReadingCommand),
m_currentCommand(NULL)
{
m_errorMessageDialog = new QErrorMessage(RiuMainWindow::instance());
@ -127,9 +382,15 @@ void RiaSocketServer::slotNewClientConnection()
}
else
{
if (m_readState == ReadingPropertyData)
if (m_currentCommand)
{
readPropertyDataFromOctave();
if (m_currentCommand->interpretMore(this, m_currentClient))
{
delete m_currentCommand;
m_currentCommand = NULL;
}
CVF_ASSERT(m_currentCommand == NULL);
}
terminateCurrentConnection();
@ -154,17 +415,17 @@ void RiaSocketServer::handleClientConnection(QTcpSocket* clientToHandle)
// Initialize state varianbles
m_currentCommandSize = 0;
m_scalarResultsToAdd = NULL;
// m_scalarResultsToAdd = NULL;
m_timeStepCountToRead = 0;
m_bytesPerTimeStepToRead = 0;
m_currentTimeStepToRead = 0;
m_currentReservoir = NULL;
m_currentScalarIndex = cvf::UNDEFINED_SIZE_T;
m_currentPropertyName = "";
// m_timeStepCountToRead = 0;
// m_bytesPerTimeStepToRead = 0;
// m_currentTimeStepToRead = 0;
// m_currentReservoir = NULL;
// m_currentScalarIndex = cvf::UNDEFINED_SIZE_T;
// m_currentPropertyName = "";
connect(m_currentClient, SIGNAL(disconnected()), this, SLOT(slotCurrentClientDisconnected()));
m_readState = ReadingCommand;
//m_readState = ReadingCommand;
m_currentCommand = NULL;
if (m_currentClient->bytesAvailable())
@ -242,7 +503,10 @@ void RiaSocketServer::readCommandFromOctave()
CVF_ASSERT(args.size() > 0);
std::cout << args[0].data() << std::endl;
m_currentCommand = RiaSocketCommandFactory::instance()->create(args[0]);
if (m_currentCommand)
{
bool finished = m_currentCommand->interpretCommand(this, args, socketStream);
@ -256,97 +520,12 @@ void RiaSocketServer::readCommandFromOctave()
{
// Todo: When all commands are into new shape, do the "unknown command" error output here.
bool isSetProperty = args[0] == "SetProperty"; // SetProperty [casename/index] PropertyName
if (!( isSetProperty ))
{
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Unknown command: %1").arg(args[0].data()));
terminateCurrentConnection();
return;
}
int caseId = -1;
QString propertyName;
RimCase* rimCase = NULL;
// Find the correct arguments
if (isSetProperty)
{
if (args.size() == 2)
{
propertyName = args[1];
}
else if (args.size() > 2)
{
caseId = args[1].toInt();
propertyName = args[2];
}
}
rimCase = this->findReservoir(caseId);
if (rimCase == NULL)
{
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Could not find the Case with CaseId : \"%1\"").arg(caseId));
return;
}
if (isSetProperty)
{
// Find the requested data, Or create a set if we are setting data and it is not found
size_t scalarResultIndex = cvf::UNDEFINED_SIZE_T;
std::vector< std::vector<double> >* scalarResultFrames = NULL;
if (rimCase && rimCase->results(RifReaderInterface::MATRIX_RESULTS))
{
scalarResultIndex = rimCase->results(RifReaderInterface::MATRIX_RESULTS)->findOrLoadScalarResult(propertyName);
if (scalarResultIndex == cvf::UNDEFINED_SIZE_T && isSetProperty)
{
scalarResultIndex = rimCase->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->addEmptyScalarResult(RimDefines::GENERATED, propertyName, true);
}
if (scalarResultIndex != cvf::UNDEFINED_SIZE_T)
{
scalarResultFrames = &(rimCase->results(RifReaderInterface::MATRIX_RESULTS)->cellResults()->cellScalarResults(scalarResultIndex));
m_currentScalarIndex = scalarResultIndex;
m_currentPropertyName = propertyName;
}
}
if (scalarResultFrames == NULL)
{
m_errorMessageDialog->showMessage(tr("ResInsight SocketServer: \n") + tr("Could not find the property named: \"%1\"").arg(propertyName));
}
// Set property
{
m_readState = ReadingPropertyData;
// Disconnect the socket from calling this slot again.
m_currentReservoir = rimCase;
if ( scalarResultFrames != NULL)
{
m_scalarResultsToAdd = scalarResultFrames;
if (m_currentClient->bytesAvailable())
{
this->readPropertyDataFromOctave();
}
}
}
}
}
}
#if 0
//--------------------------------------------------------------------------------------------------
/// This method reads data from octave and puts it into the resInsight Structures
//--------------------------------------------------------------------------------------------------
@ -466,12 +645,14 @@ void RiaSocketServer::readPropertyDataFromOctave()
}
}
}
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaSocketServer::slotCurrentClientDisconnected()
{
#if 0
if (m_timeStepCountToRead > 0
&& m_currentTimeStepToRead < m_timeStepCountToRead
&& m_currentClient->bytesAvailable()
@ -479,7 +660,21 @@ void RiaSocketServer::slotCurrentClientDisconnected()
{
this->readPropertyDataFromOctave();
}
#else
if (m_currentCommand)
{
if (m_currentCommand->interpretMore(this, m_currentClient))
{
delete m_currentCommand;
m_currentCommand = NULL;
}
/// What do we do here ?
CVF_ASSERT(m_currentCommand == NULL);
}
#endif
terminateCurrentConnection();
QTcpSocket *newClient = m_tcpServer->nextPendingConnection();
@ -505,17 +700,23 @@ void RiaSocketServer::terminateCurrentConnection()
// Clean up more state:
m_currentCommandSize = 0;
m_timeStepCountToRead = 0;
m_bytesPerTimeStepToRead = 0;
m_currentTimeStepToRead = 0;
m_scalarResultsToAdd = NULL;
m_currentReservoir = NULL;
m_currentScalarIndex = cvf::UNDEFINED_SIZE_T;
m_currentPropertyName = "";
m_invalidActiveCellCountDetected = false;
if (m_currentCommand)
{
delete m_currentCommand;
m_currentCommand = NULL;
}
m_readState = ReadingCommand;
m_currentCommandSize = 0;
// m_timeStepCountToRead = 0;
// m_bytesPerTimeStepToRead = 0;
// m_currentTimeStepToRead = 0;
// m_scalarResultsToAdd = NULL;
// m_currentReservoir = NULL;
// m_currentScalarIndex = cvf::UNDEFINED_SIZE_T;
// m_currentPropertyName = "";
// m_invalidActiveCellCountDetected = false;
// m_readState = ReadingCommand;
}
@ -524,6 +725,7 @@ void RiaSocketServer::terminateCurrentConnection()
//--------------------------------------------------------------------------------------------------
void RiaSocketServer::slotReadyRead()
{
#if 0
switch (m_readState)
{
case ReadingCommand :
@ -542,5 +744,19 @@ void RiaSocketServer::slotReadyRead()
CVF_ASSERT(false);
break;
}
#else
if (m_currentCommand)
{
if (m_currentCommand->interpretMore(this, m_currentClient))
{
delete m_currentCommand;
m_currentCommand = NULL;
}
}
else
{
readCommandFromOctave();
}
#endif
}

View File

@ -74,17 +74,17 @@ private:
// Vars used for reading data from octave and adding them to the available results
ReadState m_readState;
//ReadState m_readState;
RiaSocketCommand* m_currentCommand;
quint64 m_timeStepCountToRead;
quint64 m_bytesPerTimeStepToRead;
size_t m_currentTimeStepToRead;
std::vector< std::vector<double> >*
m_scalarResultsToAdd;
RimCase* m_currentReservoir;
size_t m_currentScalarIndex;
QString m_currentPropertyName;
bool m_invalidActiveCellCountDetected;
//quint64 m_timeStepCountToRead;
//quint64 m_bytesPerTimeStepToRead;
//size_t m_currentTimeStepToRead;
//std::vector< std::vector<double> >*
// m_scalarResultsToAdd;
//RimCase* m_currentReservoir;
//size_t m_currentScalarIndex;
//QString m_currentPropertyName;
//bool m_invalidActiveCellCountDetected;
};

View File

@ -196,7 +196,8 @@ DEFUN_DLD (riGetActiveCellProperty, args, nargout,
return octave_value_list ();
}
// The actual values are
// Setup the argument list
Matrix propertyFrames;
int caseId = -1;
std::string propertyName = "UNDEFINED";

View File

@ -3,31 +3,35 @@
#include "riSettings.h"
void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, quint16 port, QString caseName, QString propertyName)
void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, quint16 port,
const qint64& caseId, QString propertyName, const int32NDArray& requestedTimeSteps, QString porosityModel)
{
QString serverName = hostName;
quint16 serverPort = port;
const int Timeout = 5 * 1000;
QTcpSocket socket;
socket.connectToHost(serverName, serverPort);
socket.connectToHost(hostName, port);
if (!socket.waitForConnected(Timeout))
if (!socket.waitForConnected(riOctavePlugin::timeOutMilliSecs))
{
error((("Connection: ") + socket.errorString()).toLatin1().data());
return;
}
// Create command and send it:
QString command("SetProperty ");
command += caseName + " " + propertyName;
QByteArray cmdBytes = command.toLatin1();
QDataStream socketStream(&socket);
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
// Create command as a string with arguments , and send it:
QString command;
command += "SetActiveCellProperty " + QString::number(caseId) + " " + propertyName + " " + porosityModel;
for (int i = 0; i < requestedTimeSteps.length(); ++i)
{
if (i == 0) command += " ";
command += QString::number(static_cast<int>(requestedTimeSteps.elem(i)) - 1); // To make the index 0-based
if (i != requestedTimeSteps.length() -1) command += " ";
}
QByteArray cmdBytes = command.toLatin1();
socketStream << (qint64)(cmdBytes.size());
socket.write(cmdBytes);
@ -49,29 +53,33 @@ void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, q
{
QString tmp = QString("riSetActiveCellProperty : Wrote %1").arg(propertyName);
if (caseName.isEmpty())
if (caseId == -1)
{
tmp += QString(" to active case.");
tmp += QString(" to current case.");
}
else
{
tmp += QString(" to %1.").arg(caseName);
tmp += QString(" to case with Id = %1.").arg(caseId);
}
octave_stdout << tmp.toStdString() << " Active Cells : " << cellCount << " Time steps : " << timeStepCount << std::endl;
}
else
{
error("Was not able to write the proper amount of data to ResInsight:");
error("riSetActiveCellProperty : Was not able to write the proper amount of data to ResInsight:");
octave_stdout << " Active Cells : " << cellCount << "Time steps : " << timeStepCount << " Data Written: " << dataWritten << " Should have written: " << timeStepCount * cellCount * sizeof(double) << std::endl;
}
while(socket.bytesToWrite())
while(socket.bytesToWrite() && socket.state() == QAbstractSocket::ConnectedState)
{
// octave_stdout << "Bytes to write: " << socket.bytesToWrite() << std::endl;
socket.waitForBytesWritten(Timeout);
socket.waitForBytesWritten(riOctavePlugin::timeOutMilliSecs);
OCTAVE_QUIT;
}
if (socket.bytesToWrite() && socket.state() != QAbstractSocket::ConnectedState)
{
error("riSetActiveCellProperty : ResInsight refused to accept the data. Maybe the dimentions or porosity model is wrong");
}
return;
}
@ -80,12 +88,11 @@ void setEclipseProperty(const Matrix& propertyFrames, const QString &hostName, q
DEFUN_DLD (riSetActiveCellProperty, args, nargout,
"Usage:\n"
"\n"
"\triSetActiveCellProperty( Matrix(nActiveCells, nTimesteps), [CaseName/CaseIndex], PropertyName )\n"
"\triSetActiveCellProperty( Matrix[numActiveCells][numTimeSteps], [CaseId], PropertyName, [TimeStepIndices], [PorosityModel = \"Matrix\"|\"Fracture\"] ) \n"
"\n"
"Interprets the supplied matrix as an eclipse property set, and puts the data into\n"
"ResInsight as a \"Generated\" property with the name \"PropertyName\". The property\n"
"is added to the active case if no case specification is given, or to the Eclipse Case\n"
"named \"CaseName\" or to the case number \"CaseIndex\". "
"Interprets the supplied matrix as a property set defined for the active cells in the case, "
"and puts the data into ResInsight as a \"Generated\" property with the name \"PropertyName\"."
"If the CaseId is not defined, ResInsights Current Case is used."
)
{
int nargin = args.length ();
@ -93,41 +100,88 @@ DEFUN_DLD (riSetActiveCellProperty, args, nargout,
{
error("riSetActiveCellProperty: Too few arguments. The data matrix and the name of the property requested is neccesary\n");
print_usage();
return octave_value_list ();
}
else
if (nargin > 5)
{
Matrix propertyFrames = args(0).matrix_value();
if (error_state)
{
error("riSetActiveCellProperty: The supplied first argument is not a valid Matrix");
return octave_value_list ();
}
charMatrix caseName;
charMatrix propertyName;
if (nargin > 2)
{
caseName = args(1).char_matrix_value();
propertyName = args(2).char_matrix_value();
}
else
{
propertyName = args(1).char_matrix_value();
}
if (error_state)
{
error("setEclipseProperty: The supplied Case / Property names are invalid");
return octave_value_list ();
}
if (nargin > 2)
setEclipseProperty(propertyFrames, "127.0.0.1", 40001, caseName.row_as_string(0).c_str(), propertyName.row_as_string(0).c_str());
else
setEclipseProperty(propertyFrames, "127.0.0.1", 40001, "", propertyName.row_as_string(0).c_str());
error("riGetActiveCellProperty: Too many arguments.\n");
print_usage();
return octave_value_list ();
}
Matrix propertyFrames = args(0).matrix_value();
if (error_state)
{
error("riSetActiveCellProperty: The supplied first argument is not a valid Matrix");
print_usage();
return octave_value_list ();
}
std::vector<int> argIndices;
argIndices.push_back(0);
argIndices.push_back(1);
argIndices.push_back(2);
argIndices.push_back(3);
argIndices.push_back(4);
// Check if we have a CaseId:
if (!args(argIndices[1]).is_numeric_type())
{
argIndices[1] = -1;
for (size_t aIdx = 2; aIdx < argIndices.size(); ++aIdx)
--argIndices[aIdx];
}
// Check if we have a Requested TimeSteps
if (!(nargin > argIndices[3] && args(argIndices[3]).is_matrix_type()))
{
argIndices[3] = -1;
for (size_t aIdx = 4; aIdx < argIndices.size(); ++aIdx)
--argIndices[aIdx];
}
// Check if we have a PorosityModel
int lastArgumentIndex = argIndices[4] ;
if (!(nargin > argIndices[4] && args(argIndices[4]).is_string()))
{
argIndices[4] = -1;
for (size_t aIdx = 5; aIdx < argIndices.size(); ++aIdx)
--argIndices[aIdx];
}
// Check if we have more arguments than we should
if (nargin > lastArgumentIndex + 1)
{
error("riGetActiveCellProperty: Unexpected argument after the PorosityModel.\n");
print_usage();
return octave_value_list ();
}
int caseId = -1;
std::string propertyName = "UNDEFINED";
int32NDArray requestedTimeSteps;
std::string porosityModel = "Matrix";
if (argIndices[1] >= 0) caseId = args(argIndices[1]).int_value();
if (argIndices[2] >= 0) propertyName = args(argIndices[2]).char_matrix_value().row_as_string(0);
if (argIndices[3] >= 0) requestedTimeSteps = args(argIndices[3]).int32_array_value();
if (argIndices[4] >= 0) porosityModel = args(argIndices[4]).string_value();
if (porosityModel != "Matrix" && porosityModel != "Fracture")
{
error("riGetActiveCellProperty: The value for \"PorosityModel\" is unknown. Please use either \"Matrix\" or \"Fracture\"\n");
print_usage();
return octave_value_list ();
}
setEclipseProperty(propertyFrames, "127.0.0.1", 40001, caseId, propertyName.c_str(), requestedTimeSteps, porosityModel.c_str());
return octave_value_list ();
}