13static int initialSizeOfList = 1000, incrementalSizeOfList = 1000;
14static int numberOfParticles = 0, sizeOfParticleSortedList = 0;
24 if( particle == NULL )
return( NULL );
44 for( i = 0, p = particleSortedList; i < numberOfParticles; i++, p++ ) {
45 if( *p == particle ) {
47 for( j = i; j < numberOfParticles; j++, p++ ) *p = p[1];
51 if( particle == particleListEnd ) particleListEnd = particle->
prior;
52 if( particle == particleList ) particleList = particle->
next;
81 int i, iCmp, min, mid, max,
Z,
A, m, level;
87 max = numberOfParticles;
89 mid = ( min + max ) / 2;
90 iCmp = strcmp( name, particleSortedList[mid]->name );
91 if( iCmp == 0 )
return( particleSortedList[mid] );
94 if( mid == 0 ) max = 0; }
97 if( min > max ) min = max;
101 if( numberOfParticles > 0 ) {
102 iCmp = strcmp( name, particleSortedList[mid]->name );
103 if( iCmp == 0 )
return( particleSortedList[mid] );
104 if( ( iCmp < 0 ) && ( mid != 0 ) ) {
106 iCmp = strcmp( name, particleSortedList[mid]->name );
111 if( ( particle->
name =
smr_allocateCopyString( smr, name,
"particle->name", __FILE__, __LINE__, __func__ ) ) == NULL )
goto err;
113 particle->
prior = NULL;
114 particle->
next = NULL;
125 if( sizeOfParticleSortedList < ( numberOfParticles + 1 ) ) {
126 if( sizeOfParticleSortedList == 0 ) {
127 sizeOfParticleSortedList = initialSizeOfList; }
129 sizeOfParticleSortedList += incrementalSizeOfList;
132 "particleSortedList" ) ) == NULL )
goto err;
135 if( particleList == NULL ) {
137 particleListEnd = particleList = particle; }
140 particle->
prior = particleListEnd;
141 particleListEnd->
next = particle;
142 particleListEnd = particle;
145 if( ( mid != 0 ) || ( iCmp > 0 ) ) mid++;
146 for( i = numberOfParticles; i > mid; i-- ) particleSortedList[i] = particleSortedList[i-1];
147 particleSortedList[mid] = particle;
163 for( i = 0; i < numberOfParticles; i++ ) printf(
"%s\n", particleSortedList[i]->name );
167#if defined __cplusplus
int MCGIDI_miscNameToZAm(statusMessageReporting *smr, const char *name, int *Z, int *A, int *m, int *level)
MCGIDI_POP * MCGIDI_POPs_findParticle(MCGIDI_POPs *pops, char const *name)
MCGIDI_particle * MCGIDI_particle_free(statusMessageReporting *smr, MCGIDI_particle *particle)
int MCGIDI_particle_release(statusMessageReporting *smr, MCGIDI_particle *particle)
int MCGIDI_particle_printInternalSortedList(statusMessageReporting *smr)
MCGIDI_particle * MCGIDI_particle_getInternalID(statusMessageReporting *smr, const char *const name, MCGIDI_POPs *pops)
int MCGIDI_particle_initialize(statusMessageReporting *smr, MCGIDI_particle *particle)
int MCGIDI_particle_freeInternalList(statusMessageReporting *smr)
MCGIDI_particle * MCGIDI_particle_new(statusMessageReporting *smr)
double MCGIDI_particleMass_AMU(statusMessageReporting *smr, const char *name)
char * smr_allocateCopyString(statusMessageReporting *smr, char const *s, char const *forItem, char const *file, int line, char const *function)
#define smr_realloc2(smr, old, size, forItem)
void * smr_freeMemory(void **p)
int smr_isOk(statusMessageReporting *smr)
#define smr_malloc2(smr, size, zero, forItem)