13#if defined __cplusplus
18#define incrementalSize 1000
22#define AMU2MeV 931.494028
23#define AMU2eV ( MeV2eV * 931.494028 )
24#define K2MeV 8.6173856922566752e-11
25#define K2eV ( MeV2eV * K2MeV )
36static int referenceCount = 0;
37static char versionStr[64] =
"";
42static unitsDB unitsRoot = { 0, 0, NULL };
43static PoPs popsRoot = { 0, 0, NULL, NULL };
49 {
"MeV",
"eV",
MeV2eV }, {
"MeV",
"keV",
MeV2keV }, {
"K",
"MeV",
K2MeV }, {
"K",
"eV",
K2eV } };
51static char const *PoPs_genreStrings[] = {
"invalid",
"unknown",
"alias",
"photon",
"lepton",
"quark",
"meson",
"baryon",
"nucleus",
"atom" };
53static int PoPs_particleProperIndex(
int index );
54static int PoPs_sortedParticleIndex(
char const *name );
55static int unitsDB_release(
void );
75 if( referenceCount < 0 )
return( -1 );
76 return( ++referenceCount );
91 if( referenceCount != 0 )
return( referenceCount );
118 int i, index = PoPs_sortedParticleIndex( pop->
name );
120 if( index >= 0 )
return( popsRoot.
pops[PoPs_particleProperIndex( popsRoot.
sorted[index]->
index )] );
125 if( pops == NULL )
return( NULL );
126 sorted = &(pops[size]);
128 pops[i] = popsRoot.
pops[i];
129 sorted[i] = popsRoot.
sorted[i];
132 popsRoot.
pops = pops;
139 popsRoot.
sorted[index] = pop;
163 if( index >= 0 )
return( popsRoot.
pops[index] );
165 if( ( newPoP = (
PoP *)
smr_malloc2( smr,
sizeof(
PoP ), 0,
"newPoP" ) ) == NULL )
return( NULL );
184 if( pop->
index < 0 ) {
208 int index = PoPs_sortedParticleIndex( name );
210 if( index >= 0 ) index = PoPs_particleProperIndex( popsRoot.
sorted[index]->
index );
227static int PoPs_particleProperIndex(
int index ) {
235static int PoPs_sortedParticleIndex(
char const *name ) {
242 if( high == 0 )
return( -1 );
243 while( ( high - low ) > 1 ) {
244 mid = ( low + high ) >> 1;
245 iCmp = strcmp( name, popsRoot.
sorted[mid]->
name );
246 if( iCmp == 0 )
return( mid );
254 if( !strcmp( name, popsRoot.
sorted[0]->
name ) )
return( 0 );
255 if( strcmp( name, popsRoot.
sorted[0]->
name ) < 0 )
return( -1 );
258 if( strcmp( name, popsRoot.
sorted[high]->
name ) == 0 )
return( high );
269 if( index < 0 )
return( -1. );
281 return( popsRoot.
pops[index]->
name );
329 if( index < 0 )
return( -1 );
341 *Z = popsRoot.
pops[index]->
Z;
342 *
A = popsRoot.
pops[index]->
A;
353 if( index < 0 )
return( -1 );
369 if( protonIsNucleus ) {
370 if( strcmp(
"p", popsRoot.
pops[index]->
name ) == 0 )
return( 1 );
381 if( index < 0 )
return( NULL );
391 if( atomIndex < 0 )
return( NULL );
392 return( popsRoot.
pops[atomIndex]->
name );
401 if( index < 0 )
return( index );
409 char const *p = NULL;
418 if( strcmp(
"p", popsRoot.
pops[index]->
name ) == 0 ) {
422 else if( strcmp(
"h2", popsRoot.
pops[index]->
name ) == 0 ) {
424 else if( strcmp(
"h3", popsRoot.
pops[index]->
name ) == 0 ) {
426 else if( strcmp(
"he3", popsRoot.
pops[index]->
name ) == 0 ) {
428 else if( strcmp(
"he4", popsRoot.
pops[index]->
name ) == 0 ) {
441 return( popsRoot.
pops[index] );
450 return( PoPs_genreStrings[genre] );
467 fprintf( f,
"Mass units: number of units = %d\n", unitsRoot.
numberOfUnits );
469 fprintf( f,
" %s", unitsRoot.
unsorted[i1] );
471 fprintf( f,
"\n\n" );
472 fprintf( f,
"Particles: number of particles = %d\n", popsRoot.
numberOfParticles );
473 fprintf( f,
" name index genre mass hasNucleus alias info\n" );
474 fprintf( f,
" Z A l\n" );
475 fprintf( f,
" --------------------------------------------------------------------------------------------\n" );
478 pop = popsRoot.
sorted[i1]; }
480 pop = popsRoot.
pops[i1];
482 properIndex = PoPs_particleProperIndex( pop->
index );
486 fprintf( f,
" T" ); }
491 fprintf( f,
" T" ); }
495 if( pop->
Z + pop->
A > 0 ) {
496 fprintf( f,
" %3d %3d", pop->
Z, pop->
A );
498 fprintf( f,
" %d", pop->
l ); }
506 fprintf( f,
" %s (%d)", popsRoot.
pops[properIndex]->
name, popsRoot.
pops[properIndex]->
index ); }
510 for( aliasIndex = pop->
aliasIndex; aliasIndex >= 0; aliasIndex = popsRoot.
pops[aliasIndex]->
aliasIndex ) fprintf( f,
" %d", aliasIndex );
526 if( ( pop = (
PoP *)
smr_malloc2( smr,
sizeof(
PoP ), 0,
"pop" ) ) == NULL )
return( NULL );
589 if( ( pop =
PoP_new( smr ) ) == NULL )
return( NULL );
614 return( pop->
index );
628 double mass = -1., ratio;
635 mass = pop->
mass * ratio;
652 if( properIndex < 0 ) {
656 if( aliasIndex >= 0 ) {
657 PoP *truePop = popsRoot.
pops[aliasIndex];
659 for( pop = truePop; strcmp( alias, pop->
name ); pop = popsRoot.
pops[aliasIndex] ) aliasIndex = pop->
aliasIndex;
666 alias, truePop->
name, name );
670 if( ( pop =
PoP_new( smr ) ) == NULL )
return( NULL );
687static int unitsDB_release(
void ) {
705 if( strcmp( unit, unitsRoot.
unsorted[i] ) == 0 )
return( unitsRoot.
unsorted[i] );
709 char const **unsorted = (
char const **)
smr_malloc2( smr, size *
sizeof(
char * ), 0,
"unsorted" );
711 if( unsorted == NULL )
return( NULL );
730 if( !strcmp( unit, unitsRoot.
unsorted[i] ) )
return( i );
739 if( ( index < 0 ) || ( index >= unitsRoot.
numberOfUnits ) ) {
743 return( unitsRoot.
unsorted[index] );
750 int i, n =
sizeof( conversions ) /
sizeof( conversions[0] );
753 if( strcmp( _from, _to ) == 0 )
return( 0 );
754 for( i = 0; i < n; i++ ) {
755 if( strcmp( conversions[i]._from, _from ) == 0 ) {
756 if( strcmp( conversions[i]._to, _to ) == 0 ) {
757 *ratio = conversions[i].
ratio;
760 else if( strcmp( conversions[i]._to, _from ) == 0 ) {
761 if( strcmp( conversions[i]._from, _to ) == 0 ) {
762 *ratio = 1. / conversions[i].
ratio;
776 return(
PoPs_Bcast2( smr, comm, rank, &unitsRoot, &popsRoot ) );
780#if defined __cplusplus
double A(double temperature)
#define POPS_VERSION_MAJOR
char const * PoPs_getAtomsName_atIndex(statusMessageReporting *smr, int index)
int PoPs_particleIndex_smr(statusMessageReporting *smr, char const *name, char const *file, int line, char const *func)
void PoPs_write(FILE *f, int sorted)
PoP * PoP_new(statusMessageReporting *smr)
int PoPs_getAtomsIndex_atIndex(statusMessageReporting *smr, int index)
int PoPs_getZ_A_l(statusMessageReporting *smr, char const *name, int *Z, int *A, int *l)
@ PoPs_errorToken_badIndex
@ PoPs_errorToken_badName
@ PoPs_errorToken_badUnitConversion
int PoP_getIndex(PoP *pop)
char const * PoPs_getName_atIndex(statusMessageReporting *smr, int index)
int PoPs_release(statusMessageReporting *smr)
int PoPs_particleIndex(char const *name)
int PoPs_versionMajor(void)
#define POPS_VERSION_MINOR
int PoP_release(PoP *pop)
char const * PoPs_genreTokenToString(enum PoPs_genre genre)
enum PoPs_genre PoPs_getGenre(statusMessageReporting *smr, char const *name)
int PoP_copyParticle(statusMessageReporting *smr, PoP *desc, PoP *src)
int PoPs_getAtomsIndex(statusMessageReporting *smr, char const *name)
double PoPs_getMassInUnitOf_atIndex(statusMessageReporting *smr, int index, char const *unit)
PoP * PoP_makeAlias(statusMessageReporting *smr, char const *name, char const *alias)
int PoPs_readDatabase(statusMessageReporting *smr, char const *fileName)
int PoP_setZ_A_l(statusMessageReporting *smr, PoP *pop, int Z, int A, int l)
int PoPs_versionMinor(void)
PoP * PoPs_addAliasIfNeeded(statusMessageReporting *smr, char const *name, char const *alias)
int PoPs_versionPatchLevel(void)
int PoPs_getZ_A_l_atIndex(statusMessageReporting *smr, int index, int *Z, int *A, int *l)
int PoPs_numberOfParticle(void)
char const * PoPs_getAtomsName(statusMessageReporting *smr, char const *name)
PoP * PoPs_copyAddParticleIfNeeded(statusMessageReporting *smr, PoP *pop)
int PoPs_hasNucleus(statusMessageReporting *smr, char const *name, int protonIsNucleus)
double PoP_getMassInUnitOf(statusMessageReporting *smr, PoP *pop, char const *unit)
int PoP_initialize(statusMessageReporting *smr, PoP *pop)
const char * PoPs_version(void)
int PoPs_particleReadDatabase(statusMessageReporting *smr, char const *name)
PoP * PoPs_addParticleIfNeeded(statusMessageReporting *smr, PoP *pop)
int PoPs_unitConversionRatio(char const *_from, char const *_to, double *ratio)
#define POPS_VERSION_PATCHLEVEL
enum PoPs_genre PoPs_getGenre_atIndex(statusMessageReporting *smr, int index)
PoP * PoPs_getParticle_atIndex(int index)
char const * PoP_getName(PoP *pop)
PoP * PoP_makeParticle(statusMessageReporting *smr, enum PoPs_genre genre, char const *name, double mass, char const *massUnit)
double PoPs_getMassInUnitOf(statusMessageReporting *smr, char const *name, char const *unit)
int PoPs_hasNucleus_atIndex(statusMessageReporting *smr, int index, int protonIsNucleus)
void PoPs_print(int sorted)
int PoPs_Bcast2(statusMessageReporting *smr, MPI_Comm comm, int bossRank, unitsDB *unitsRoot, PoPs *popsRoot)
int PoPs_releasePrivate(statusMessageReporting *smr)
char const * unitsDB_stringFromIndex(statusMessageReporting *smr, int index)
int unitsDB_index(statusMessageReporting *smr, char const *unit)
char const * unitsDB_addUnitIfNeeded(statusMessageReporting *smr, char const *unit)
void * MPI_Comm
to pass hd2mpi ////////////////////////////////////////////
#define smr_setReportError2(smr, libraryID, code, fmt,...)
#define smr_allocateCopyString2(smr, s, forItem)
void * smr_freeMemory(void **p)
int smr_setReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
#define smr_malloc2(smr, size, zero, forItem)