Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
nf_utilities.c
Go to the documentation of this file.
1/*
2# <<BEGIN-copyright>>
3# Copyright 2019, Lawrence Livermore National Security, LLC.
4# This file is part of the gidiplus package (https://github.com/LLNL/gidiplus).
5# gidiplus is licensed under the MIT license (see https://opensource.org/licenses/MIT).
6# SPDX-License-Identifier: MIT
7# <<END-copyright>>
8*/
9
10#include <stdio.h>
11#include <stdlib.h>
12
13#include "nf_utilities.h"
14
15#ifdef _WIN32
16#include <float.h>
17#endif
18
19static const char Okay_message[] = "all is okay";
20static const char Error_message[] = "generic numericalFunctions error";
21static const char mallocError_message[] = "could not allocate memory";
22static const char insufficientMemory_message[] = "user's memory is too small to handle data";
23static const char badIndex_message[] = "bad index";
24static const char XNotAscending_message[] = "x values are not ascending";
25static const char badIndexForX_message[] = "index not correct for x value";
26static const char XOutsideDomain_message[] = "x value not in domain";
27static const char invalidInterpolation_message[] = "bad x,y values for interpolation";
28static const char badSelf_message[] = "source object has bad status value";
29static const char divByZero_message[] = "division by zero";
30static const char unsupportedInterpolation_message[] = "unsupported interpolation";
31static const char unsupportedInterpolationConversion_message[] = "unsupported interpolation conversion";
32static const char empty_message[] = "empty instance";
33static const char tooFewPoints_message[] = "too few points in instance";
34static const char notMutualDomian_message[] = "domains are not mutual";
35static const char unknownStatus_message[] = "unknown (i.e., invalid) status value";
36static const char badInput_message[] = "bad input to function";
37static const char badNorm_message[] = "bad norm";
38static const char badIntegrationInput_message[] = "bad integration input";
39static const char otherInterpolation_message[] = "other interpolation not supported";
40static const char flatInterpolation_message[] = "flat interpolation not supported";
41static const char failedToConverge_message[] = "failed to converge";
42static const char oddNumberOfValues_message[] = "odd number of inputted values";
43static const char badLogValue_message[] = "log of 0 or negative value";
44
45static int nfu_debugging = 0;
47
48/*
49************************************************************
50*/
51int nfu_setup( void ) {
52
53 nfu_SMR_libraryID = smr_registerLibrary( "numericalFunctions" );
54
55 return( 0 );
56}
57/*
58************************************************************
59*/
60double nfu_getNAN( void ) {
61
62 return( NAN );
63}
64/*
65************************************************************
66*/
67int nfu_isNAN( double d ) {
68
69 return( isnan( d ) );
70}
71/*
72************************************************************
73*/
74double nfu_getInfinity( double sign ) {
75
76 if( sign < 0 ) return( -INFINITY );
77 return( INFINITY );
78}
79/*
80************************************************************
81*/
82const char *nfu_statusMessage( nfu_status status ) {
83
84printf( "status = %d\n", status );
85 switch( status ) {
86 case nfu_Okay : return( Okay_message );
87 case nfu_Error : return( Error_message );
88 case nfu_mallocError : return( mallocError_message );
89 case nfu_insufficientMemory : return( insufficientMemory_message );
90 case nfu_badIndex : return( badIndex_message );
91 case nfu_XNotAscending : return( XNotAscending_message );
92 case nfu_badIndexForX : return( badIndexForX_message );
93 case nfu_XOutsideDomain : return( XOutsideDomain_message );
94 case nfu_invalidInterpolation : return( invalidInterpolation_message );
95 case nfu_badSelf : return( badSelf_message );
96 case nfu_divByZero : return( divByZero_message );
97 case nfu_unsupportedInterpolation : return( unsupportedInterpolation_message );
98 case nfu_unsupportedInterpolationConversion : return( unsupportedInterpolationConversion_message );
99 case nfu_empty : return( empty_message );
100 case nfu_tooFewPoints : return( tooFewPoints_message );
101 case nfu_domainsNotMutual : return( notMutualDomian_message );
102 case nfu_badInput : return( badInput_message );
103 case nfu_badNorm : return( badNorm_message );
104 case nfu_badIntegrationInput : return( badIntegrationInput_message );
105 case nfu_otherInterpolation : return( otherInterpolation_message );
106 case nfu_flatInterpolation : return( flatInterpolation_message );
107 case nfu_failedToConverge : return( failedToConverge_message );
108 case nfu_oddNumberOfValues : return( oddNumberOfValues_message );
109 case nfu_badLogValue : return( badLogValue_message );
110 }
111 return( unknownStatus_message );
112}
113/*
114************************************************************
115*/
116void nfu_setMemoryDebugMode( int mode ) {
117
118 nfu_debugging = mode;
119}
120/*
121************************************************************
122*/
123void *nfu_malloc( size_t size ) {
124
125 void *p = malloc( size );
126
127 if( nfu_debugging ) printf( "nfu_malloc %12p size = %8llu\n", p, (long long unsigned) size );
128 return( p );
129}
130/*
131************************************************************
132*/
133void *nfu_calloc( size_t size, size_t n ) {
134
135 void *p = calloc( size, n );
136
137 if( nfu_debugging ) printf( "nfu_calloc %12p size = %8llu, n = %8llu\n", p, (long long unsigned) size, (long long unsigned) n );
138 return( p );
139}
140/*
141************************************************************
142*/
143void *nfu_realloc( size_t size, void *old ) {
144
145 void *p = realloc( old, size );
146
147 if( nfu_debugging ) printf( "nfu_realloc %12p size = %8llu, old = %12p\n", p, (long long unsigned) size, old );
148 return( p );
149}
150/*
151************************************************************
152*/
153void *nfu_free( void *p ) {
154
155 if( p != NULL ) {
156 if( nfu_debugging ) printf( "nfu_free %12p\n", p );
157 free( p );
158 }
159 return( NULL );
160}
161/*
162********************************************************
163*/
164void nfu_printMsg( char const *fmt, ... ) {
165
166 va_list args;
167
168 va_start( args, fmt );
169 vfprintf( stderr, fmt, args );
170 fprintf( stderr, "\n" );
171 va_end( args );
172}
173/*
174********************************************************
175*/
176void nfu_printErrorMsg( char const *fmt, ... ) {
177
178 va_list args;
179
180 va_start( args, fmt );
181 vfprintf( stderr, fmt, args );
182 fprintf( stderr, "\n" );
183 va_end( args );
184
185 exit( EXIT_FAILURE );
186}
void free(voidpf ptr)
voidp malloc(uInt size)
int nfu_isNAN(double d)
void nfu_setMemoryDebugMode(int mode)
void nfu_printMsg(char const *fmt,...)
void * nfu_free(void *p)
void * nfu_realloc(size_t size, void *old)
void * nfu_calloc(size_t size, size_t n)
double nfu_getInfinity(double sign)
void nfu_printErrorMsg(char const *fmt,...)
void * nfu_malloc(size_t size)
const char * nfu_statusMessage(nfu_status status)
double nfu_getNAN(void)
int nfu_setup(void)
@ nfu_unsupportedInterpolation
@ nfu_domainsNotMutual
@ nfu_XNotAscending
@ nfu_invalidInterpolation
@ nfu_Okay
@ nfu_badSelf
@ nfu_badLogValue
@ nfu_oddNumberOfValues
@ nfu_mallocError
@ nfu_insufficientMemory
@ nfu_flatInterpolation
@ nfu_badNorm
@ nfu_badIntegrationInput
@ nfu_XOutsideDomain
@ nfu_badIndex
@ nfu_failedToConverge
@ nfu_tooFewPoints
@ nfu_unsupportedInterpolationConversion
@ nfu_badInput
@ nfu_badIndexForX
@ nfu_Error
@ nfu_empty
@ nfu_divByZero
@ nfu_otherInterpolation
enum nfu_status_e nfu_status
int nfu_SMR_libraryID
int smr_registerLibrary(char const *libraryName)
#define smr_unknownID
voidp calloc(uInt items, uInt size)