Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
ptwX_core.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include "ptwX.h"

Go to the source code of this file.

Functions

ptwXPointsptwX_new (statusMessageReporting *smr, int64_t size)
nfu_status ptwX_initialize (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t size)
ptwXPointsptwX_create (statusMessageReporting *smr, int64_t size, int64_t length, double const *xs)
ptwXPointsptwX_createLine (statusMessageReporting *smr, int64_t size, int64_t length, double slope, double offset)
nfu_status ptwX_copy (statusMessageReporting *smr, ptwXPoints *dest, ptwXPoints *src)
ptwXPointsptwX_clone (statusMessageReporting *smr, ptwXPoints *ptwX)
ptwXPointsptwX_slice (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t index1, int64_t index2)
nfu_status ptwX_reallocatePoints (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t size, int forceSmallerResize)
nfu_status ptwX_clear (statusMessageReporting *smr, ptwXPoints *ptwX)
nfu_status ptwX_release (statusMessageReporting *smr, ptwXPoints *ptwX)
ptwXPointsptwX_free (ptwXPoints *ptwX)
int64_t ptwX_length (statusMessageReporting *smr, ptwXPoints *ptwX)
nfu_status ptwX_setData (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t length, double const *xs)
nfu_status ptwX_deletePoints (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t i1, int64_t i2)
double * ptwX_getPointAtIndex (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t index)
double ptwX_getPointAtIndex_Unsafely (ptwXPoints *ptwX, int64_t index)
nfu_status ptwX_setPointAtIndex (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t index, double x)
nfu_status ptwX_insertPointsAtIndex (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t index, int64_t n1, double const *xs)
nfu_status ptwX_ascendingOrder (statusMessageReporting *smr, ptwXPoints *ptwX, int *order)
ptwXPointsptwX_fromString (statusMessageReporting *smr, char const *str, char sep, char **endCharacter)
int ptwX_countOccurrences (statusMessageReporting *smr, ptwXPoints *ptwX, double value)
nfu_status ptwX_reverse (statusMessageReporting *smr, ptwXPoints *ptwX)
nfu_status ptwX_sort (statusMessageReporting *smr, ptwXPoints *ptwX, enum ptwX_sort_order order)
nfu_status ptwX_closesDifference (statusMessageReporting *smr, ptwXPoints *ptwX, double value, int64_t *index, double *difference)
nfu_status ptwX_closesDifferenceInRange (statusMessageReporting *smr, ptwXPoints *ptwX, int64_t i1, int64_t i2, double value, int64_t *index, double *difference)
ptwXPointsptwX_unique (statusMessageReporting *smr, ptwXPoints *ptwX, int order)
nfu_status ptwX_abs (statusMessageReporting *smr, ptwXPoints *ptwX)
nfu_status ptwX_neg (statusMessageReporting *smr, ptwXPoints *ptwX)
nfu_status ptwX_add_double (statusMessageReporting *smr, ptwXPoints *ptwX, double value)
nfu_status ptwX_mul_double (statusMessageReporting *smr, ptwXPoints *ptwX, double value)
nfu_status ptwX_slopeOffset (statusMessageReporting *smr, ptwXPoints *ptwX, double slope, double offset)
nfu_status ptwX_add_ptwX (statusMessageReporting *smr, ptwXPoints *ptwX1, ptwXPoints *ptwX2)
nfu_status ptwX_sub_ptwX (statusMessageReporting *smr, ptwXPoints *ptwX1, ptwXPoints *ptwX2)
nfu_status ptwX_range (statusMessageReporting *smr, ptwXPoints *ptwX, double *rangeMin, double *rangeMax)
nfu_status ptwX_compare (statusMessageReporting *smr, ptwXPoints *ptwX1, ptwXPoints *ptwX2, int *comparison)
nfu_status ptwX_close (statusMessageReporting *smr, ptwXPoints *ptwX1, ptwXPoints *ptwX2, int epsilonFactor, double epsilon, int *index)

Function Documentation

◆ ptwX_abs()

nfu_status ptwX_abs ( statusMessageReporting * smr,
ptwXPoints * ptwX )

Definition at line 588 of file ptwX_core.c.

588 {
589
590 int64_t i1;
591 double *p1;
592
593 if( ptwX->status != nfu_Okay ) {
594 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
595 return( nfu_badSelf );
596 }
597
598 for( i1 = 0, p1 = ptwX->points; i1 < ptwX->length; i1++, p1++ ) *p1 = fabs( *p1 );
599 return( nfu_Okay );
600}
@ nfu_Okay
@ nfu_badSelf
int nfu_SMR_libraryID
#define smr_setReportError2p(smr, libraryID, code, fmt)
nfu_status status
Definition ptwX.h:28
double * points
Definition ptwX.h:32

◆ ptwX_add_double()

nfu_status ptwX_add_double ( statusMessageReporting * smr,
ptwXPoints * ptwX,
double value )

Definition at line 613 of file ptwX_core.c.

613 {
614
615 if( ptwX_slopeOffset( smr, ptwX, 1, value ) != nfu_Okay )
617 return( ptwX->status );
618}
@ nfu_Error
nfu_status ptwX_slopeOffset(statusMessageReporting *smr, ptwXPoints *ptwX, double slope, double offset)
Definition ptwX_core.c:631

◆ ptwX_add_ptwX()

nfu_status ptwX_add_ptwX ( statusMessageReporting * smr,
ptwXPoints * ptwX1,
ptwXPoints * ptwX2 )

Definition at line 647 of file ptwX_core.c.

647 {
648
649 int64_t i1;
650 double *p1 = ptwX1->points, *p2 = ptwX2->points;
651
652 if( ptwX1->status != nfu_Okay ) {
653 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source1." );
654 return( nfu_badSelf );
655 }
656 if( ptwX2->status != nfu_Okay ) {
657 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source2." );
658 return( nfu_badSelf );
659 }
660
661 if( ptwX1->length != ptwX2->length ) {
663 "length of source1 = %d not the same as length of source2 = %d.", (int) ptwX1->length, (int) ptwX2->length );
664 return( nfu_domainsNotMutual );
665 }
666
667 for( i1 = 0; i1 < ptwX1->length; i1++, p1++, p2++ ) *p1 += *p2;
668 return( nfu_Okay );
669}
@ nfu_domainsNotMutual
#define smr_setReportError2(smr, libraryID, code, fmt,...)
int64_t length
Definition ptwX.h:29

◆ ptwX_ascendingOrder()

nfu_status ptwX_ascendingOrder ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int * order )

Definition at line 364 of file ptwX_core.c.

364 {
365/*
366* Returns -1 list is descending, 1 if ascending and 0 otherwise (i.e., mixed).
367*/
368 int64_t i1;
369 double x1, x2;
370
371 if( ptwX->status != nfu_Okay ) {
372 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
373 return( nfu_badSelf );
374 }
375
376 *order = 1;
377 if( ptwX->length < 2 ) return( nfu_Okay );
378
379 if( ( x1 = ptwX->points[0] ) < ( x2 = ptwX->points[1] ) ) { /* Check for ascending order. */
380 for( i1 = 2; i1 < ptwX->length; i1++ ) {
381 x1 = x2;
382 x2 = ptwX->points[i1];
383 if( x2 <= x1 ) {
384 *order = 0;
385 return( nfu_Okay );
386 }
387 } }
388 else {
389 *order = -1; /* Check for descending order. */
390 for( i1 = 1; i1 < ptwX->length; i1++ ) {
391 x2 = ptwX->points[i1];
392 if( x1 <= x2 ) {
393 *order = 0;
394 return( nfu_Okay );
395 }
396 x1 = x2;
397 }
398 }
399 return( nfu_Okay );
400}

◆ ptwX_clear()

nfu_status ptwX_clear ( statusMessageReporting * smr,
ptwXPoints * ptwX )

Definition at line 191 of file ptwX_core.c.

191 {
192
193 ptwX->length = 0;
194 ptwX->status = nfu_Okay;
195
196 return( ptwX->status );
197}

Referenced by ptwX_copy().

◆ ptwX_clone()

ptwXPoints * ptwX_clone ( statusMessageReporting * smr,
ptwXPoints * ptwX )

Definition at line 113 of file ptwX_core.c.

113 {
114
115 ptwXPoints *clone = ptwX_slice( smr, ptwX, 0, ptwX->length );
116
117 if( clone == NULL ) smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_Error, "Via." );
118 return( clone );
119}
struct ptwXPoints_s ptwXPoints
ptwXPoints * ptwX_slice(statusMessageReporting *smr, ptwXPoints *ptwX, int64_t index1, int64_t index2)
Definition ptwX_core.c:123

Referenced by ptwX_unique().

◆ ptwX_close()

nfu_status ptwX_close ( statusMessageReporting * smr,
ptwXPoints * ptwX1,
ptwXPoints * ptwX2,
int epsilonFactor,
double epsilon,
int * index )

Definition at line 754 of file ptwX_core.c.

755 {
756/*
757* Returns the index where ptwX1 and ptwX2 differ significantly as determined by epsilonFactor and epsilon.
758*/
759
760 int64_t i1, n1 = ptwX1->length;
761 double larger;
762 double *p1 = ptwX1->points, *p2 = ptwX2->points;
763
764 *index = -1;
765 if( ptwX1->status != nfu_Okay ) {
766 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source1." );
767 return( nfu_badSelf );
768 }
769 if( ptwX2->status != nfu_Okay ) {
770 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source2." );
771 return( nfu_badSelf );
772 }
773
774 if( ptwX1->length != ptwX2->length ) {
776 "length of source1 = %d not the same as length of source2 = %d.", (int) ptwX1->length, (int) ptwX2->length );
777 return( nfu_domainsNotMutual );
778 }
779
780 epsilon = fabs( epsilon ) + abs( epsilonFactor ) * DBL_EPSILON;
781
782 for( i1 = 0; i1 < n1; i1++, p1++, p2++ ) {
783 larger = fabs( *p1 );
784 if( fabs( *p2 ) > larger ) larger = fabs( *p2 );
785 if( fabs( *p2 - *p1 ) > epsilon * larger ) break;
786 }
787 *index = (int) i1;
788 return( nfu_Okay );
789}
G4double epsilon(G4double density, G4double temperature)
#define DBL_EPSILON
Definition templates.hh:66

◆ ptwX_closesDifference()

nfu_status ptwX_closesDifference ( statusMessageReporting * smr,
ptwXPoints * ptwX,
double value,
int64_t * index,
double * difference )

Definition at line 489 of file ptwX_core.c.

489 {
490
491 return( ptwX_closesDifferenceInRange( smr, ptwX, 0, ptwX->length, value, index, difference ) );
492}
nfu_status ptwX_closesDifferenceInRange(statusMessageReporting *smr, ptwXPoints *ptwX, int64_t i1, int64_t i2, double value, int64_t *index, double *difference)
Definition ptwX_core.c:496

◆ ptwX_closesDifferenceInRange()

nfu_status ptwX_closesDifferenceInRange ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t i1,
int64_t i2,
double value,
int64_t * index,
double * difference )

Definition at line 496 of file ptwX_core.c.

497 {
498/*
499* Finds the closes datum to value. If *difference is zero, datum is same as value.
500*/
501 double d1;
502
503 if( ptwX->status != nfu_Okay ) {
504 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
505 return( nfu_badSelf );
506 }
507
508 if( i1 < 0 ) i1 = 0;
509 if( i2 > ptwX->length ) i2 = ptwX->length;
510 if( i1 >= i2 ) return( nfu_Okay );
511 *index = i1;
512 *difference = value - ptwX->points[i1];
513 for( i1++; i1 < i2; i1++ ) {
514 d1 = value - ptwX->points[i1];
515 if( fabs( *difference ) > fabs( d1 ) ) {
516 *index = i1;
517 *difference = d1;
518 }
519 }
520 return( nfu_Okay );
521}

Referenced by ptwX_closesDifference().

◆ ptwX_compare()

nfu_status ptwX_compare ( statusMessageReporting * smr,
ptwXPoints * ptwX1,
ptwXPoints * ptwX2,
int * comparison )

Definition at line 722 of file ptwX_core.c.

722 {
723
724 int64_t i1, n1 = ptwX1->length, n2 = ptwX2->length, nn = n1;
725 double *p1 = ptwX1->points, *p2 = ptwX2->points;
726
727 *comparison = 0;
728 if( ptwX1->status != nfu_Okay ) {
729 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source1." );
730 return( nfu_badSelf );
731 }
732 if( ptwX2->status != nfu_Okay ) {
733 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source2." );
734 return( nfu_badSelf );
735 }
736
737 if( nn > n2 ) nn = n2;
738 for( i1 = 0; i1 < nn; i1++, p1++, p2++ ) {
739 if( *p1 == *p2 ) continue;
740 *comparison = 1;
741 if( *p1 < *p2 ) *comparison = -1;
742 return( nfu_Okay );
743 }
744 if( n1 < n2 ) {
745 *comparison = -1; }
746 else if( n1 > n2 ) {
747 *comparison = 1;
748 }
749 return( nfu_Okay );
750}

◆ ptwX_copy()

nfu_status ptwX_copy ( statusMessageReporting * smr,
ptwXPoints * dest,
ptwXPoints * src )

Definition at line 89 of file ptwX_core.c.

89 {
90
91 if( dest->status != nfu_Okay ) {
92 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid destination." );
93 return( nfu_badSelf );
94 }
95 if( src->status != nfu_Okay ) {
96 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
97 return( nfu_badSelf );
98 }
99
100 if( ptwX_clear( smr, dest ) ) {
102 return( src->status );
103 }
104 if( ptwX_setData( smr, dest, src->length, src->points ) ) {
106 return( src->status );
107 }
108 return( nfu_Okay );
109}
nfu_status ptwX_clear(statusMessageReporting *smr, ptwXPoints *ptwX)
Definition ptwX_core.c:191
nfu_status ptwX_setData(statusMessageReporting *smr, ptwXPoints *ptwX, int64_t length, double const *xs)
Definition ptwX_core.c:234

◆ ptwX_countOccurrences()

int ptwX_countOccurrences ( statusMessageReporting * smr,
ptwXPoints * ptwX,
double value )

Definition at line 422 of file ptwX_core.c.

422 {
423
424 int count;
425 int64_t i1;
426
427 if( ptwX->status != nfu_Okay ) {
428 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
429 return( -nfu_badSelf );
430 }
431
432 count = 0;
433 for( i1 = 0; i1 < ptwX->length; i1++ ) {
434 if( ptwX->points[i1] == value ) ++count;
435 }
436 return( count );
437}

◆ ptwX_create()

ptwXPoints * ptwX_create ( statusMessageReporting * smr,
int64_t size,
int64_t length,
double const * xs )

Definition at line 54 of file ptwX_core.c.

54 {
55
56 ptwXPoints *ptwX = ptwX_new( smr, size );
57
58 if( ptwX == NULL ) {
60 else {
61 if( ptwX_setData( smr, ptwX, length, xs ) != nfu_Okay ) {
63 ptwX = ptwX_free( ptwX );
64 }
65 }
66 return( ptwX );
67}
ptwXPoints * ptwX_free(ptwXPoints *ptwX)
Definition ptwX_core.c:213
ptwXPoints * ptwX_new(statusMessageReporting *smr, int64_t size)
Definition ptwX_core.c:22

Referenced by GIDI::multiGroupXYs1d(), GIDI::Transporting::Flux::process(), and ptwX_fromString().

◆ ptwX_createLine()

ptwXPoints * ptwX_createLine ( statusMessageReporting * smr,
int64_t size,
int64_t length,
double slope,
double offset )

Definition at line 71 of file ptwX_core.c.

71 {
72
73 int64_t i1;
74 double *p1;
75 ptwXPoints *ptwX;
76
77 if( size < length ) size = length;
78 if( ( ptwX = ptwX_new( smr, size ) ) == NULL ) {
80 else {
81 for( i1 = 0, p1 = ptwX->points; i1 < length; i1++, p1++ ) *p1 = slope * i1 + offset;
82 ptwX->length = length;
83 }
84 return( ptwX );
85}
G4ThreadLocal T * G4GeomSplitter< T >::offset

Referenced by ptwXY_groupOneFunction(), ptwXY_groupThreeFunctions(), and ptwXY_groupTwoFunctions().

◆ ptwX_deletePoints()

nfu_status ptwX_deletePoints ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t i1,
int64_t i2 )

Definition at line 257 of file ptwX_core.c.

257 {
258
259 if( ptwX->status != nfu_Okay ) {
260 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
261 return( nfu_badSelf );
262 }
263
264 if( ( i1 < 0 ) || ( i1 > i2 ) || ( i2 > ptwX->length ) ) {
265 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badIndex, "index1 = %d, index2 = %d and length = %d",
266 (int) i1, (int) i2, (int) ptwX->length );
267 return( nfu_badIndex );
268 }
269 if( i1 != i2 ) {
270 int64_t n1 = ptwX->length - ( i2 - i1 );
271
272 for( ; i2 < ptwX->length; i1++, i2++ ) ptwX->points[i1] = ptwX->points[i2];
273 ptwX->length = n1;
274 }
275 return( ptwX->status );
276}
@ nfu_badIndex

◆ ptwX_free()

◆ ptwX_fromString()

ptwXPoints * ptwX_fromString ( statusMessageReporting * smr,
char const * str,
char sep,
char ** endCharacter )

Definition at line 404 of file ptwX_core.c.

404 {
405
406 int64_t numberConverted;
407 double *doublePtr;
408 ptwXPoints *ptwX = NULL;
409
410 if( ( doublePtr = nfu_stringToListOfDoubles( smr, str, sep, &numberConverted, endCharacter, 1 ) ) == NULL ) {
412 return( NULL );
413 }
414 if( ( ptwX = ptwX_create( smr, numberConverted, numberConverted, doublePtr ) ) == NULL )
416 smr_freeMemory2( doublePtr );
417 return( ptwX );
418}
double * nfu_stringToListOfDoubles(statusMessageReporting *smr, char const *str, char sep, int64_t *numberConverted, char **endCharacter, int useSystem_strtod)
ptwXPoints * ptwX_create(statusMessageReporting *smr, int64_t size, int64_t length, double const *xs)
Definition ptwX_core.c:54

◆ ptwX_getPointAtIndex()

double * ptwX_getPointAtIndex ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t index )

Definition at line 280 of file ptwX_core.c.

280 {
281
282 if( ptwX->status != nfu_Okay ) {
283 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
284 return( NULL );
285 }
286
287 if( ( index < 0 ) || ( index >= ptwX->length ) ) {
288 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badIndex, "Index = %d out of bounds: length = %d",
289 (int) index, (int) ptwX->length );
290 return( NULL );
291 }
292 return( &(ptwX->points[index]) );
293}

Referenced by GIDI::multiGroupTwoXYs1ds(), and GIDI::multiGroupXYs1d().

◆ ptwX_getPointAtIndex_Unsafely()

double ptwX_getPointAtIndex_Unsafely ( ptwXPoints * ptwX,
int64_t index )

Definition at line 297 of file ptwX_core.c.

297 {
298
299 return( ptwX->points[index] );
300}

Referenced by GIDI::Transporting::Flux::process().

◆ ptwX_initialize()

nfu_status ptwX_initialize ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t size )

Definition at line 40 of file ptwX_core.c.

40 {
41
42 ptwX->status = nfu_Okay;
43 ptwX->length = 0;
44 ptwX->allocatedSize = 0;
45 ptwX->mallocFailedSize = 0;
46 ptwX->points = NULL;
47 if( ptwX_reallocatePoints( smr, ptwX, size, 0 ) != nfu_Okay )
49 return( ptwX->status );
50}
nfu_status ptwX_reallocatePoints(statusMessageReporting *smr, ptwXPoints *ptwX, int64_t size, int forceSmallerResize)
Definition ptwX_core.c:161
int64_t mallocFailedSize
Definition ptwX.h:31
int64_t allocatedSize
Definition ptwX.h:30

Referenced by ptwX_new().

◆ ptwX_insertPointsAtIndex()

nfu_status ptwX_insertPointsAtIndex ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t index,
int64_t n1,
double const * xs )

Definition at line 330 of file ptwX_core.c.

330 {
331
332 int64_t i1, i2, n1p, size = n1 + ptwX->length;
333
334 if( ptwX->status != nfu_Okay ) {
335 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
336 return( nfu_badSelf );
337 }
338
339 if( n1 < 1 ) return( nfu_Okay ); /* No points to insert. */
340
341 if( ( index < 0 ) || ( index > ptwX->length ) ) {
342 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badIndex, "Index = %d out of bounds: length = %d",
343 (int) index, (int) ptwX->length );
344 return( ptwX->status = nfu_Error );
345 }
346
347 if( size > ptwX->allocatedSize ) {
348 if( ptwX_reallocatePoints( smr, ptwX, size, 0 ) != nfu_Okay ) {
350 return( ptwX->status );
351 }
352 }
353
354 for( i1 = ptwX->length - 1, i2 = size - 1, n1p = ptwX->length - index; n1p > 0; i1--, i2--, n1p-- )
355 ptwX->points[i2] = ptwX->points[i1];
356 for( i1 = 0, i2 = index; i1 < n1; i1++, i2++ ) ptwX->points[i2] = xs[i1];
357 ptwX->length += n1;
358
359 return( nfu_Okay );
360}

◆ ptwX_length()

int64_t ptwX_length ( statusMessageReporting * smr,
ptwXPoints * ptwX )

◆ ptwX_mul_double()

nfu_status ptwX_mul_double ( statusMessageReporting * smr,
ptwXPoints * ptwX,
double value )

Definition at line 622 of file ptwX_core.c.

622 {
623
624 if( ptwX_slopeOffset( smr, ptwX, value, 0 ) != nfu_Okay )
626 return( ptwX->status );
627}

◆ ptwX_neg()

nfu_status ptwX_neg ( statusMessageReporting * smr,
ptwXPoints * ptwX )

Definition at line 604 of file ptwX_core.c.

604 {
605
606 if( ptwX_slopeOffset( smr, ptwX, -1, 0 ) != nfu_Okay )
608 return( ptwX->status );
609}

◆ ptwX_new()

ptwXPoints * ptwX_new ( statusMessageReporting * smr,
int64_t size )

Definition at line 22 of file ptwX_core.c.

22 {
23
24 ptwXPoints *ptwX = (ptwXPoints *) smr_malloc2( smr, sizeof( ptwXPoints ), 1, "ptwX" );
25
26 if( ptwX == NULL ) {
28 return( NULL );
29 }
30
31 if( ptwX_initialize( smr, ptwX, size ) != nfu_Okay ) {
33 smr_freeMemory2( ptwX );
34 }
35 return( ptwX );
36}
nfu_status ptwX_initialize(statusMessageReporting *smr, ptwXPoints *ptwX, int64_t size)
Definition ptwX_core.c:40
#define smr_malloc2(smr, size, zero, forItem)

Referenced by ptwX_create(), ptwX_createLine(), ptwX_slice(), ptwX_unique(), ptwXY_equalProbableBins(), ptwXY_getXArray(), ptwXY_groupOneFunction(), ptwXY_groupThreeFunctions(), ptwXY_groupTwoFunctions(), ptwXY_runningIntegral(), and ptwXY_ysMappedToXs().

◆ ptwX_range()

nfu_status ptwX_range ( statusMessageReporting * smr,
ptwXPoints * ptwX,
double * rangeMin,
double * rangeMax )

Definition at line 699 of file ptwX_core.c.

699 {
700
701 int64_t i1, n1 = ptwX->length;
702 *rangeMin = *rangeMax = 0;
703 double *p1 = ptwX->points;
704
705 if( ptwX->status != nfu_Okay ) {
706 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
707 return( nfu_badSelf );
708 }
709
710 if( n1 > 0 ) {
711 *rangeMin = *rangeMax = *(p1++);
712 for( i1 = 1; i1 < n1; ++i1, ++p1 ) {
713 if( *p1 < *rangeMin ) *rangeMin = *p1;
714 if( *p1 > *rangeMax ) *rangeMax = *p1;
715 }
716 }
717 return( nfu_Okay );
718}

◆ ptwX_reallocatePoints()

nfu_status ptwX_reallocatePoints ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t size,
int forceSmallerResize )

Definition at line 161 of file ptwX_core.c.

161 {
162
163 if( ptwX->status != nfu_Okay ) {
164 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
165 return( nfu_badSelf );
166 }
167
168 if( size < ptwX_minimumSize ) size = ptwX_minimumSize; /* ptwX_minimumSize must be > 0 for other routines to work properly. */
169 if( size < ptwX->length ) size = ptwX->length;
170 if( size != ptwX->allocatedSize ) {
171 if( size > ptwX->allocatedSize ) { /* Increase size of allocated points. */
172 ptwX->points = (double *) smr_realloc2( smr, ptwX->points, (size_t) size * sizeof( double ), "ptwX->points" );
173 if( ptwX->points == NULL ) smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_Error, "Via." ); }
174 else if( ( ptwX->allocatedSize > 2 * size ) || forceSmallerResize ) { /* Decrease size, if at least 1/2 size reduction or if forced to. */
175 ptwX->points = (double *) smr_realloc2( smr, ptwX->points, (size_t) size * sizeof( double ), "ptwX->points" );
176 if( ptwX->points == NULL ) smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_Error, "Via." );
177 }
178 if( ptwX->points == NULL ) {
179 ptwX->mallocFailedSize = size;
180 size = 0;
181 ptwX->status = nfu_mallocError;
182 }
183 ptwX->allocatedSize = size;
184 }
185
186 return( ptwX->status );
187}
@ nfu_mallocError
#define ptwX_minimumSize
Definition ptwX.h:22
#define smr_realloc2(smr, old, size, forItem)

Referenced by ptwX_initialize(), ptwX_insertPointsAtIndex(), ptwX_setData(), and ptwX_setPointAtIndex().

◆ ptwX_release()

nfu_status ptwX_release ( statusMessageReporting * smr,
ptwXPoints * ptwX )

Definition at line 201 of file ptwX_core.c.

201 {
202
203 ptwX->status = nfu_Okay;
204 ptwX->length = 0;
205 ptwX->allocatedSize = 0;
206 smr_freeMemory2( ptwX->points );
207
208 return( nfu_Okay );
209}

Referenced by ptwX_free().

◆ ptwX_reverse()

nfu_status ptwX_reverse ( statusMessageReporting * smr,
ptwXPoints * ptwX )

Definition at line 441 of file ptwX_core.c.

441 {
442
443 int64_t i1, i2 = ptwX->length - 1, n1 = ptwX->length / 2;
444 double tmp;
445
446 if( ptwX->status != nfu_Okay ) {
447 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
448 return( nfu_badSelf );
449 }
450
451 for( i1 = 0; i1 < n1; i1++, i2-- ) {
452 tmp = ptwX->points[i1];
453 ptwX->points[i1] = ptwX->points[i2];
454 ptwX->points[i2] = tmp;
455 }
456 return( nfu_Okay );
457}

◆ ptwX_setData()

nfu_status ptwX_setData ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t length,
double const * xs )

Definition at line 234 of file ptwX_core.c.

234 {
235
236 int64_t i;
237
238 if( ptwX->status != nfu_Okay ) {
239 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
240 return( nfu_badSelf );
241 }
242
243 if( length > ptwX->allocatedSize ) {
244 if( ptwX_reallocatePoints( smr, ptwX, length, 0 ) != nfu_Okay ) {
246 return( ptwX->status );
247 }
248 }
249 for( i = 0; i < length; i++ ) ptwX->points[i] = xs[i];
250 ptwX->length = length;
251
252 return( ptwX->status );
253}

Referenced by ptwX_copy(), and ptwX_create().

◆ ptwX_setPointAtIndex()

nfu_status ptwX_setPointAtIndex ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t index,
double x )

Definition at line 304 of file ptwX_core.c.

304 {
305
306 if( ptwX->status != nfu_Okay ) {
307 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
308 return( nfu_badSelf );
309 }
310
311 if( ( index < 0 ) || ( index > ptwX->length ) ) {
312 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badIndex, "Index = %d out of bounds: length = %d",
313 (int) index, (int) ptwX->length );
314 return( nfu_badIndex );
315 }
316
317 if( index == ptwX->allocatedSize ) {
318 if( ptwX_reallocatePoints( smr, ptwX, ptwX->allocatedSize + 10, 0 ) != nfu_Okay ) {
320 return( ptwX->status );
321 }
322 }
323 ptwX->points[index] = x;
324 if( index == ptwX->length ) ptwX->length++;
325 return( nfu_Okay );
326}

Referenced by ptwXY_equalProbableBins(), ptwXY_runningIntegral(), and ptwXY_ysMappedToXs().

◆ ptwX_slice()

ptwXPoints * ptwX_slice ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int64_t index1,
int64_t index2 )

Definition at line 123 of file ptwX_core.c.

123 {
124
125 int64_t i1, i2, length;
126 ptwXPoints *n1;
127
128 if( ptwX->status != nfu_Okay ) {
129 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
130 return( NULL );
131 }
132
133 if( index1 < 0 ) {
134 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badIndex, "negative index1 = %d.", (int) index1 );
135 return( NULL );
136 }
137 if( index2 < index1 ) {
138 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badIndex, "index1 = %d greater than index2 = %d",
139 (int) index1, (int) index2 );
140 return( NULL );
141 }
142 if( index2 > ptwX->length ) {
143 smr_setReportError2( smr, nfu_SMR_libraryID, nfu_badIndex, "index2 = %d greater than length = %d.",
144 (int) index2, (int) ptwX->length );
145 return( NULL );
146 }
147
148 length = ( index2 - index1 );
149 if( ( n1 = ptwX_new( smr, length ) ) == NULL ) {
151 return( NULL );
152 }
153 for( i2 = 0, i1 = index1; i1 < index2; i1++, i2++ ) n1->points[i2] = ptwX->points[i1];
154 n1->length = length;
155
156 return( n1 );
157}

Referenced by ptwX_clone().

◆ ptwX_slopeOffset()

nfu_status ptwX_slopeOffset ( statusMessageReporting * smr,
ptwXPoints * ptwX,
double slope,
double offset )

Definition at line 631 of file ptwX_core.c.

631 {
632
633 int64_t i1;
634 double *p1;
635
636 if( ptwX->status != nfu_Okay ) {
637 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
638 return( nfu_badSelf );
639 }
640
641 for( i1 = 0, p1 = ptwX->points; i1 < ptwX->length; i1++, p1++ ) *p1 = slope * *p1 + offset;
642 return( nfu_Okay );
643}

Referenced by ptwX_add_double(), ptwX_mul_double(), and ptwX_neg().

◆ ptwX_sort()

nfu_status ptwX_sort ( statusMessageReporting * smr,
ptwXPoints * ptwX,
enum ptwX_sort_order order )

Definition at line 461 of file ptwX_core.c.

461 {
462
463 int (*cmp)( void const *, void const * ) = ptwX_sort_descending;
464
465 if( ptwX->status != nfu_Okay ) {
466 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
467 return( nfu_badSelf );
468 }
469
470 if( order == ptwX_sort_order_ascending ) cmp = ptwX_sort_ascending;
471 qsort( ptwX->points, (size_t) ptwX->length, sizeof( ptwX->points[0] ), cmp );
472 return( nfu_Okay );
473}
@ ptwX_sort_order_ascending
Definition ptwX.h:24

Referenced by ptwX_unique().

◆ ptwX_sub_ptwX()

nfu_status ptwX_sub_ptwX ( statusMessageReporting * smr,
ptwXPoints * ptwX1,
ptwXPoints * ptwX2 )

Definition at line 673 of file ptwX_core.c.

673 {
674
675 int64_t i1;
676 double *p1 = ptwX1->points, *p2 = ptwX2->points;
677
678 if( ptwX1->status != nfu_Okay ) {
679 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source1" );
680 return( nfu_badSelf );
681 }
682 if( ptwX2->status != nfu_Okay ) {
683 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source2." );
684 return( nfu_badSelf );
685 }
686
687 if( ptwX1->length != ptwX2->length ) {
689 "length of source1 = %d not the same as length of source2 = %d.", (int) ptwX1->length, (int) ptwX2->length );
690 return( nfu_domainsNotMutual );
691 }
692
693 for( i1 = 0; i1 < ptwX1->length; i1++, p1++, p2++ ) *p1 -= *p2;
694 return( nfu_Okay );
695}

◆ ptwX_unique()

ptwXPoints * ptwX_unique ( statusMessageReporting * smr,
ptwXPoints * ptwX,
int order )

Definition at line 525 of file ptwX_core.c.

525 {
526/*
527* Returns a new ptwXPoints instance that is a unique list of the values in ptwX.
528* If order < 0 order is descending, if order > 0 order is ascending, otherwise, order is the same as ptwX.
529*/
530 int64_t i1, i2, n1 = 0;
531 double x1, *p2;
532 ptwXPoints *ptwX2 = NULL;
533
534 if( ptwX->status != nfu_Okay ) {
535 smr_setReportError2p( smr, nfu_SMR_libraryID, nfu_badSelf, "Invalid source." );
536 return( NULL );
537 }
538
539 if( order == 0 ) {
540 if( ( ptwX2 = ptwX_new( smr, ptwX->length ) ) == NULL ) {
542 return( NULL );
543 }
544 for( i1 = 0; i1 < ptwX->length; i1++ ) {
545 x1 = ptwX->points[i1];
546 for( i2 = 0, p2 = ptwX2->points; i2 < ptwX2->length; i2++, p2++ ) {
547 if( *p2 == x1 ) break;
548 }
549 if( i2 == ptwX2->length ) {
550 ptwX2->points[ptwX2->length] = x1;
551 ptwX2->length++;
552 }
553 } }
554 else {
555 enum ptwX_sort_order sort_order = ( order > 0 ) ? ptwX_sort_order_ascending : ptwX_sort_order_descending;
556
557 if( ( ptwX2 = ptwX_clone( smr, ptwX ) ) == NULL ) {
559 return( NULL );
560 }
561 if( ptwX_sort( smr, ptwX2, sort_order ) != nfu_Okay ) {
563 goto err;
564 }
565
566 if( ptwX2->length > 1 ) {
567 x1 = ptwX2->points[n1]; /* n1 is initially 0. */
568 n1++;
569 for( i1 = 1; i1 < ptwX2->length; i1++ ) {
570 if( x1 != ptwX2->points[i1] ) {
571 x1 = ptwX2->points[i1];
572 ptwX2->points[n1] = x1;
573 n1++;
574 }
575 }
576 ptwX2->length = n1;
577 }
578 }
579 return( ptwX2 );
580
581err:
582 if( ptwX2 != NULL ) ptwX_free( ptwX2 );
583 return( NULL );
584}
ptwX_sort_order
Definition ptwX.h:24
@ ptwX_sort_order_descending
Definition ptwX.h:24
ptwXPoints * ptwX_clone(statusMessageReporting *smr, ptwXPoints *ptwX)
Definition ptwX_core.c:113
nfu_status ptwX_sort(statusMessageReporting *smr, ptwXPoints *ptwX, enum ptwX_sort_order order)
Definition ptwX_core.c:461