17#if defined __cplusplus
27 char const *toUnits[3] ) {
30 double norm, wUnitFactor;
31 char const *wFromUnit, *toUnitsXY[2] = { toUnits[1], toUnits[2] };
54 if( ( dists->
Ws = (
double *)
smr_malloc2( smr, W_XYs->
length *
sizeof(
double ), 1,
"dists->Ws" ) ) == NULL )
goto err;
57 for( i = 0; i < W_XYs->
length; i++ ) {
58 XYs = &(W_XYs->
XYs[i]);
59 dists->
Ws[i] = wUnitFactor * XYs->
value;
61 if( MCGIDI_fromTOM_pdfOfXGivenW( smr, pdfXY, dists, i, &norm ) )
goto err;
64 else if( std::fabs( 1. - norm ) > 0.99 ) {
101 if( ( dist->
Xs = (
double *)
smr_malloc2( smr, 3 * n1 *
sizeof(
double ), 0,
"dist->Xs" ) ) == NULL )
goto err;
102 dist->
pdf = &(dist->
Xs[n1]);
103 dist->
cdf = &(dist->
pdf[n1]);
105 for( j1 = 0; j1 < n1; j1++ ) {
107 dist->
Xs[j1] = point->
x;
108 dist->
pdf[j1] = point->
y;
117 double inv_norm, sum = 0;
119 inv_norm = 1.0 / ( dist->
Xs[n1-1] - dist->
Xs[0] );
120 for( j1 = 0; j1 < n1; ++j1 ) {
121 if( j1 > 0 ) sum += dist->
Xs[j1] - dist->
Xs[j1-1];
123 dist->
cdf[j1] = sum * inv_norm;
125 dist->
cdf[n1-1] = 1.; }
128 for( j1 = 0; j1 < n1; j1++ ) dist->
pdf[j1] /= *norm;
171#if defined __cplusplus
int MCGIDI_fromTOM_interpolation(statusMessageReporting *smr, xDataTOM_element *element, int index, enum ptwXY_interpolation_e *interpolation)
int MCGIDI_fromTOM_pdfsOfXGivenW(statusMessageReporting *smr, xDataTOM_element *element, MCGIDI_pdfsOfXGivenW *dists, ptwXYPoints *norms, char const *toUnits[3])
int MCGIDI_fromTOM_pdfOfX(statusMessageReporting *smr, ptwXYPoints *pdfXY, MCGIDI_pdfOfX *dist, double *norm)
ptwXYPoints * MCGIDI_misc_dataFromXYs2ptwXYPointsInUnitsOf(statusMessageReporting *smr, xDataTOM_XYs *XYs, ptwXY_interpolation interpolation, char const *units[2])
double MCGIDI_misc_getUnitConversionFactor(statusMessageReporting *smr, char const *fromUnit, char const *toUnit)
enum nfu_status_e nfu_status
const char * nfu_statusMessage(nfu_status status)
nfu_status ptwXY_setValueAtX(ptwXYPoints *ptwXY, double x, double y)
nfu_status ptwXY_simpleCoalescePoints(ptwXYPoints *ptwXY)
ptwXYPoint * ptwXY_getPointAtIndex_Unsafely(ptwXYPoints *ptwXY, int64_t index)
enum ptwXY_interpolation_e ptwXY_interpolation
@ ptwXY_interpolationFlat
@ ptwXY_interpolationLinLog
@ ptwXY_interpolationLogLog
@ ptwXY_interpolationLinLin
@ ptwXY_interpolationOther
@ ptwXY_interpolationLogLin
int64_t ptwXY_length(ptwXYPoints *ptwXY)
ptwXPoints * ptwXY_runningIntegral(ptwXYPoints *ptwXY, nfu_status *status)
ptwXYPoints * ptwXY_free(ptwXYPoints *ptwXY)
double ptwX_getPointAtIndex_Unsafely(ptwXPoints *ptwX, int64_t index)
ptwXPoints * ptwX_free(ptwXPoints *ptwX)
#define smr_setReportError2(smr, libraryID, code, fmt,...)
#define smr_setReportError2p(smr, libraryID, code, fmt)
void * smr_freeMemory(void **p)
int smr_isOk(statusMessageReporting *smr)
#define smr_malloc2(smr, size, zero, forItem)
ptwXY_interpolation interpolationXY
ptwXY_interpolation interpolationWY
xDataTOM_xDataInfo xDataInfo
char const * xDataTOM_axes_getUnit(statusMessageReporting *smr, xDataTOM_axes *axes, int index)
xDataTOM_interpolationFlag
@ xDataTOM_interpolationFlag_log
@ xDataTOM_interpolationFlag_linear
@ xDataTOM_interpolationFlag_flat
int xDataTOME_getInterpolation(statusMessageReporting *smr, xDataTOM_element *element, int index, enum xDataTOM_interpolationFlag *independent, enum xDataTOM_interpolationFlag *dependent, enum xDataTOM_interpolationQualifier *qualifier)
xDataTOM_interpolationQualifier
void * xDataTOME_getXDataIfID(statusMessageReporting *smr, xDataTOM_element *TE, char const *ID)