37 #include <tpia_target.h>
38 #include <tpia_misc.h>
40 #if defined __cplusplus
54 if( ( target = (tpia_target*) xData_malloc2( smr,
sizeof( tpia_target ), 0,
"target" ) ) == NULL )
return( NULL );
63 memset( target, 0,
sizeof( tpia_target ) );
82 int tpia_target_readFromMap( statusMessageReporting *smr, tpia_target *target, tpia_map *map,
const char *evaluation,
const char *projectileName,
83 const char *targetName ) {
87 if( ( targetPath =
tpia_map_findTarget( smr, map, evaluation, projectileName, targetName ) ) == NULL )
return( 1 );
94 const char *targetName ) {
100 if( targetPath == NULL )
return( NULL );
122 target->path = (
char*)
xData_free( smr, target->path );
124 target->absPath = (
char*)
xData_free( smr, target->absPath );
126 for( i = 0; i < target->nHeatedTargets; i++ ) {
128 target->heatedTargets[i].path = (
char*)
xData_free( smr, target->heatedTargets[i].path );
130 target->heatedTargets[i].contents = (
char*)
xData_free( smr, target->heatedTargets[i].contents );
131 if( target->heatedTargets[i].heatedTarget != NULL )
tpia_target_heated_free( smr, target->heatedTargets[i].heatedTarget );
134 target->heatedTargets = (tpia_target_heated_info*)
xData_free( smr, target->heatedTargets );
136 target->readHeatedTargets = (tpia_target_heated_info**)
xData_free( smr, target->readHeatedTargets );
143 int tpia_target_read( statusMessageReporting *smr, tpia_target *target,
const char *fileName ) {
149 xData_element *element, *child;
150 int i, iHeated, nHeated = 0, status = 1;
155 char const *contents;
158 if( ( target->path = xDataMisc_allocateCopyString2( smr, fileName,
"path" ) ) == NULL )
return( status );
162 if( strcmp( element->name,
"xTarget" ) != 0 ) {
168 name = tpia_misc_pointerToAttributeIfAllOk2( smr, element, 1, &(target->attributes),
"projectile" );
170 if(
smr_isOk( smr ) && ( name = tpia_misc_pointerToAttributeIfAllOk2( smr, element, 1, &(target->attributes),
"target" ) ) != NULL ) {
174 if( strcmp( child->name,
"target" ) != 0 ) {
183 if( ( target->heatedTargets = (tpia_target_heated_info*) xData_malloc2( smr, nHeated *
sizeof( tpia_target_heated_info ), 1,
"heatedTargets" ) ) == NULL ) {
187 if( ( target->readHeatedTargets = (tpia_target_heated_info**) xData_malloc2( smr, nHeated *
sizeof( tpia_target_heated_info * ), 1,
"heatedTargets" ) ) == NULL )
193 if( i > 0 )
smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"target does not have a temperature attribute" );
197 for( iHeated = 0; iHeated < nHeated; iHeated++ )
if( target->heatedTargets[iHeated].temperature > temperature )
break;
198 if( iHeated < nHeated )
for( i = nHeated; i >= iHeated; i-- ) target->heatedTargets[i+1] = target->heatedTargets[i];
199 target->heatedTargets[iHeated].temperature = temperature;
200 target->heatedTargets[iHeated].path = NULL;
201 target->heatedTargets[iHeated].contents = NULL;
202 target->heatedTargets[iHeated].heatedTarget = NULL;
204 if( ( target->heatedTargets[iHeated].contents = xDataMisc_allocateCopyString2( smr, contents,
"contents" ) ) == NULL ) {
214 if((target->heatedTargets[iHeated].path = (
char*) xData_malloc2(smr, strlen( target->absPath ) + strlen( contents ) + 2, 0,
"path")) == NULL) {
218 strcpy( target->heatedTargets[iHeated].path, target->absPath );
219 *strrchr( target->heatedTargets[iHeated].path,
'/' ) = 0;
220 strcat( target->heatedTargets[iHeated].path,
"/" );
221 strcat( target->heatedTargets[iHeated].path, contents );
222 target->nHeatedTargets++;
230 for( i = 0; i < nHeated; i++ ) target->heatedTargets[i].ordinal = i;
231 for( i = 0; i < nHeated; i++ )
if( target->heatedTargets[i].contents == NULL )
break;
232 if( i == nHeated ) i = 0;
234 target->baseHeatedTarget = target->heatedTargets[i].heatedTarget; }
260 if( temperatures != NULL )
for( i = 0; i < target->nHeatedTargets; i++ ) temperatures[i] = target->heatedTargets[i].temperature;
261 return( target->nHeatedTargets );
270 if( ( index < 0 ) || ( index >= target->nHeatedTargets ) ) {
271 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"temperature index = %d out of range (0 <= index < %d", index, target->nHeatedTargets );
274 if( target->heatedTargets[index].heatedTarget != NULL )
return( 1 );
276 if( target->heatedTargets[index].heatedTarget != NULL ) {
277 target->heatedTargets[index].heatedTarget->ordinal = target->heatedTargets[index].ordinal;
278 for( i = target->nReadHeatedTargets; i > 0; i-- ) {
279 if( target->readHeatedTargets[i-1]->temperature < target->heatedTargets[index].temperature )
break;
280 target->readHeatedTargets[i] = target->readHeatedTargets[i-1];
282 target->readHeatedTargets[i] = &(target->heatedTargets[i]);
283 target->nReadHeatedTargets++;
285 return( ( target->heatedTargets[index].heatedTarget == NULL ? -1 : 0 ) );
292 if( ( index < 0 ) || ( index >= target->nHeatedTargets ) ) {
293 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"temperature index = %d out of range (0 <= index < %d", index, target->nHeatedTargets );
297 return( target->heatedTargets[index].heatedTarget );
304 if( ( index < 0 ) || ( index >= target->nHeatedTargets ) ) {
305 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"temperature index = %d out of range (0 <= index < %d", index, target->nHeatedTargets );
308 if( target->heatedTargets[index].heatedTarget == NULL ) {
309 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"temperature index = %d not read in", index );
312 return( target->heatedTargets[index].heatedTarget );
335 if( !
smr_isOk( smr ) )
return( -1 );
345 if( !
smr_isOk( smr ) )
return( NULL );
346 if( crossSectionType == tpia_crossSectionType_grouped ) {
347 return( &(heated->totalCrossSectionGrouped) ); }
348 else if( crossSectionType == tpia_crossSectionType_pointwise ) {
349 return( &(heated->totalCrossSectionPointwise) );
351 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1,
"Invalue crossSectionType = %d", crossSectionType );
358 int crossSectionType ) {
361 double xsec = 0., xsec1, xsec2;
363 for( i = 0; i < target->nReadHeatedTargets; i++ )
if( target->readHeatedTargets[i]->temperature > T )
break;
366 else if( i == target->nReadHeatedTargets ) {
371 xsec = ( ( target->readHeatedTargets[i]->temperature - T ) * xsec1 + ( T - target->readHeatedTargets[i-1]->temperature ) * xsec2 ) /
372 ( target->readHeatedTargets[i]->temperature - target->readHeatedTargets[i-1]->temperature );
381 int crossSectionType ) {
384 double xsec = 0., xsec1, xsec2;
386 for( i = 0; i < target->nReadHeatedTargets; i++ )
if( target->readHeatedTargets[i]->temperature > T )
break;
389 else if( i == target->nReadHeatedTargets ) {
394 xsec = ( ( target->readHeatedTargets[i]->temperature - T ) * xsec1 + ( T - target->readHeatedTargets[i-1]->temperature ) * xsec2 ) /
395 ( target->readHeatedTargets[i]->temperature - target->readHeatedTargets[i-1]->temperature );
405 tpia_decaySamplingInfo *decaySamplingInfo,
int nProductData, tpia_productOutgoingData *productData ) {
408 nProductData, productData ) );
419 #if defined __cplusplus
int tpia_target_heated_numberOfChannels(statusMessageReporting *, tpia_target_heated *target)
double tpia_target_getIndexChannelCrossSectionAtE(statusMessageReporting *smr, tpia_target *target, int index, double T, xData_Int iEg, double e_in, int crossSectionType)
int tpia_target_read(statusMessageReporting *smr, tpia_target *target, const char *fileName)
double tpia_target_getTotalCrossSectionAtTAndE(statusMessageReporting *smr, tpia_target *target, double T, xData_Int iEg, double e_in, int crossSectionType)
char * tpia_map_findTarget(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName)
xData_Int tpia_target_heated_getEnergyGrid(statusMessageReporting *, tpia_target_heated *target, double **energyGrid)
xData_element * xData_getNextElement(xData_element *element)
xData_document * xData_parseReadFile(statusMessageReporting *smr, const char *fileName, xData_xDataTypeOk func, void *userData)
int tpia_target_initialize(statusMessageReporting *smr, tpia_target *target)
int tpia_misc_setMessageError_Element(statusMessageReporting *smr, void *userInterface, xData_element *element, const char *file, int line, int code, const char *fmt,...)
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int tpia_target_release(statusMessageReporting *smr, tpia_target *target)
tpia_target * tpia_target_createRead(statusMessageReporting *smr, const char *fileName)
const char * xData_getAttributesValueInElement(xData_element *element, const char *name)
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
tpia_target_heated * tpia_target_getHeatedTargetAtIndex_ReadIfNeeded(statusMessageReporting *smr, tpia_target *target, int index)
int tpia_target_heated_numberOfProductionChannels(statusMessageReporting *, tpia_target_heated *target)
char * xDataMisc_getAbsPath(statusMessageReporting *smr, const char *fileName)
tpia_target_heated * tpia_target_getHeatedTargetAtTIndex(statusMessageReporting *smr, tpia_target *target, int index)
xData_element * xData_getFirstElement(xData_element *element)
int tpia_target_readHeatedTarget(statusMessageReporting *smr, tpia_target *target, int index, int checkElememtsForAccess)
xData_element * xData_getDocumentsElement(xData_document *doc)
void * xData_parseFree(statusMessageReporting *smr, xData_document *doc)
int smr_isOk(statusMessageReporting *smr)
tpia_1dData * tpia_target_getTotalCrossSectionAtTIndex(statusMessageReporting *smr, tpia_target *target, int index, int crossSectionType)
double tpia_target_heated_getIndexChannelCrossSectionAtE(statusMessageReporting *smr, tpia_target_heated *target, int index, xData_Int iEg, double e_in, int crossSectionType)
xData_Int tpia_target_getEnergyGridAtTIndex(statusMessageReporting *smr, tpia_target *target, int index, double **energyGrid)
tpia_target * tpia_target_free(statusMessageReporting *smr, tpia_target *target)
int xData_releaseAttributionList(statusMessageReporting *smr, xData_attributionList *attributes)
double tpia_target_heated_getTotalCrossSectionAtE(statusMessageReporting *smr, tpia_target_heated *target, xData_Int, double e_in, int crossSectionType)
void * xData_free(statusMessageReporting *, void *p)
int tpia_target_getTemperatures(statusMessageReporting *, tpia_target *target, double *temperatures)
int tpia_samplingMethods_initialize(statusMessageReporting *, tpia_samplingMethods *samplingMethods)
static int _tpia_target_releaseAndReturnOne(statusMessageReporting *smr, tpia_target *target)
int tpia_target_heated_sampleIndexChannelProductsAtE(statusMessageReporting *smr, tpia_target_heated *target, int index, tpia_decaySamplingInfo *decaySamplingInfo, int nProductData, tpia_productOutgoingData *productDatas)
int xData_copyAttributionList(statusMessageReporting *smr, xData_attributionList *dest, xData_attributionList *src)
int xData_convertAttributeToDouble(statusMessageReporting *smr, xData_element *element, const char *name, double *d)
char * tpia_target_getAttributesValue(statusMessageReporting *, tpia_target *target, char const *name)
int tpia_target_numberOfProductionChannels(statusMessageReporting *smr, tpia_target *target)
int tpia_target_numberOfChannels(statusMessageReporting *smr, tpia_target *target)
int tpia_target_readFromMap(statusMessageReporting *smr, tpia_target *target, tpia_map *map, const char *evaluation, const char *projectileName, const char *targetName)
int tpia_target_sampleIndexChannelProductsAtE(statusMessageReporting *smr, tpia_target *target, int index, double, tpia_decaySamplingInfo *decaySamplingInfo, int nProductData, tpia_productOutgoingData *productData)
tpia_target_heated * tpia_target_heated_createRead(statusMessageReporting *smr, const char *fileName, int checkElememtsForAccess)
tpia_target_heated * tpia_target_heated_free(statusMessageReporting *smr, tpia_target_heated *target)
tpia_target * tpia_target_create(statusMessageReporting *smr)
tpia_particle * tpia_particle_getInternalID(statusMessageReporting *smr, const char *const name)
tpia_target * tpia_target_createReadFromMap(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectileName, const char *targetName)