Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sources/Deltares.Probabilistic.CWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
file(GLOB cwrapper_files
"*.h"
"*.cpp"
)

Expand Down
51 changes: 36 additions & 15 deletions sources/Deltares.Probabilistic.CWrapper/calcdistributions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,65 @@
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
//
#include <memory>
#include "stringHelper.h"
#include "../Deltares.Probabilistic.CWrapper/createDistribution.h"

using namespace Deltares::Reliability;

/// <summary>
/// wrapper for getXFromU
/// </summary>
/// <param name="u"> the u input value </param>
/// <param name="type"> enum for distribution type </param>
/// <param name="p"> array with 4 parameters defining the type </param>
/// <param name="error_indication"> extra output for indication of an error situation </param>
/// <returns> the x-value </returns>
extern "C"
void calculatedistributioninverse_c(double *u, double *y, EnumDistributions *type, double p[], tError *ierr)
double calculateDistributionInverse(const double u, const EnumDistributions type, double p[], tError* error_indication)
{
double x = 0.0;
try
{
auto s = createDistribution::createValid(*type, p);
*y = s->getXFromU(*u);
ierr->errorCode = 0;
auto pValues = createDistribution::convertArrayToVector(p);
auto s = createDistribution::createValid(type, pValues);
x = s.getXFromU(u);
error_indication->errorCode = 0;
}
catch (const std::exception& e)
{
ierr->errorCode = -1;
std::string s = e.what();
fillErrorMessage(*ierr, s);
error_indication->errorCode = -1;
const std::string s = e.what();
*error_indication = fillErrorStruct(s);
}
return x;
}

/// <summary>
/// wrapper for getUFromX
/// </summary>
/// <param name="x"> the x input value </param>
/// <param name="type"> enum for distribution type </param>
/// <param name="p"> array with 4 parameters defining the type </param>
/// <param name="error_indication"> extra output for indication of an error situation </param>
/// <returns> the u-value </returns>
extern "C"
void calculatedistribution_c(double* x, double* u, EnumDistributions * type, double p[], tError * ierr)
double calculateDistribution(const double x, const EnumDistributions type, double p[], tError* error_indication)
{
double u = 0.0;
try
{
auto s = createDistribution::createValid(*type, p);
*u = s->getUFromX(*x);
ierr->errorCode = 0;
auto pValues = createDistribution::convertArrayToVector(p);
auto s = createDistribution::createValid(type, pValues);
u = s.getUFromX(x);
error_indication->errorCode = 0;
}
catch (const std::exception& e)
{
ierr->errorCode = -1;
std::string s = e.what();
fillErrorMessage(*ierr, s);
error_indication->errorCode = -1;
const std::string s = e.what();
*error_indication = fillErrorStruct(s);
}
return u;
}


Loading