00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <string.h>
00037 #include <ctype.h>
00038
00039 #include <tpia_target.h>
00040 #include <tpia_misc.h>
00041
00042 #if defined __cplusplus
00043 namespace GIDI {
00044 using namespace GIDI;
00045 #endif
00046
00047
00048
00049
00050 tpia_multiplicity *tpia_multiplicity_create( statusMessageReporting *smr ) {
00051
00052 tpia_multiplicity *multiplicity;
00053
00054
00055 if( ( multiplicity = (tpia_multiplicity*) xData_malloc2( smr, sizeof( tpia_multiplicity ), 0, "multiplicity" ) ) == NULL ) return( NULL );
00056 if( tpia_multiplicity_initialize( smr, multiplicity ) ) multiplicity = tpia_multiplicity_free( smr, multiplicity );
00057 return( multiplicity );
00058 }
00059
00060
00061
00062 int tpia_multiplicity_initialize( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
00063
00064 memset( multiplicity, 0, sizeof( tpia_multiplicity ) );
00065 if( tpia_frame_setFromString( smr, "", "", 0, &(multiplicity->frame) ) ) return( 1 );
00066 return( 0 );
00067 }
00068
00069
00070
00071 tpia_multiplicity *tpia_multiplicity_free( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
00072
00073 tpia_multiplicity_release( smr, multiplicity );
00074 xData_free( smr, multiplicity );
00075 return( NULL );
00076 }
00077
00078
00079
00080 int tpia_multiplicity_release( statusMessageReporting *smr, tpia_multiplicity *multiplicity ) {
00081
00082
00083 multiplicity->grouped.data = (double*) xData_free( smr, multiplicity->grouped.data );
00084
00085 multiplicity->pointwise = (double*) xData_free( smr, multiplicity->pointwise );
00086 tpia_multiplicity_initialize( smr, multiplicity );
00087 return( 0 );
00088 }
00089
00090
00091
00092 tpia_multiplicity *tpia_multiplicity_createGetFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, int nGroups ) {
00093
00094 tpia_multiplicity *multiplicity;
00095
00096 if( ( multiplicity = tpia_multiplicity_create( smr ) ) == NULL ) return( NULL );
00097 if( tpia_multiplicity_getFromElement( smr, multiplicityElement, multiplicity, nGroups ) != 0 ) multiplicity = tpia_multiplicity_free( smr, multiplicity );
00098 return( multiplicity );
00099 }
00100
00101
00102
00103
00104 int tpia_multiplicity_getFromElement( statusMessageReporting *smr, xData_element *multiplicityElement, tpia_multiplicity *multiplicity, int ) {
00105
00106 const char *timeScale;
00107 int isDelayedNeutrons;
00108 xData_element *data;
00109
00110 xData_addToAccessed( smr, multiplicityElement, 1 );
00111 if( ( tpia_frame_setFromElement( smr, multiplicityElement, 2, &(multiplicity->frame) ) ) != 0 ) return( 1 );
00112 if( tpia_multiplicity_getTimeScaleFromElement( smr, multiplicityElement, &timeScale, &isDelayedNeutrons, &(multiplicity->timeScale) ) ) return( 1 );
00113 for( data = xData_getFirstElement( multiplicityElement ); data != NULL; data = xData_getNextElement( data ) ) {
00114 if( strcmp( data->name, "grouped" ) == 0 ) {
00115 if( tpia_misc_get2d_xShared_yHistogram_data_Grouped( smr, data, &(multiplicity->grouped) ) ) return( 1 ); }
00116 else if( strcmp( data->name, "pointwise" ) == 0 ) {
00117 if( ( multiplicity->pointwise = tpia_misc_get2dx_y_data( smr, data, &multiplicity->numberOfPointwise ) ) == NULL ) return( 1 ); }
00118 else {
00119 tpia_misc_setMessageError_Element( smr, NULL, multiplicityElement, __FILE__, __LINE__, 1, "unsupported multiplicity type = %s", data->name );
00120 return( 1 );
00121 }
00122 }
00123 return( 0 );
00124 }
00125
00126
00127
00128 int tpia_multiplicity_getTimeScaleFromElement( statusMessageReporting *smr, xData_element *element, const char **timeScale, int *isDelayedNeutrons,
00129 double *dTimeScale ) {
00130
00131 const char *p;
00132 char *e;
00133
00134 *isDelayedNeutrons = 0;
00135 *dTimeScale = 0.;
00136 *timeScale = xData_getAttributesValue( &(element->attributes), "timeScale" );
00137 if( *timeScale != NULL ) {
00138 if( strcmp( *timeScale, "prompt" ) ) {
00139 if( strncmp( *timeScale, "delayed", 7 ) ) {
00140 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "invalid timeScale attribute = %s", *timeScale );
00141 return( 1 ); }
00142 else {
00143 for( p = &((*timeScale)[7]); *p; p++ ) if( !isspace( *p ) ) break;
00144 if( *p != '=' ) {
00145 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "timeScale attribute '%s' missing '='", *timeScale );
00146 return( 1 );
00147 }
00148 p++;
00149 *dTimeScale = strtod( p, &e );
00150 if( *e != 0 ) {
00151 tpia_misc_setMessageError_Element( smr, NULL, element, __FILE__, __LINE__, 1, "could not convert timeScale attribute '%s' to double",
00152 *timeScale );
00153 return( 1 );
00154 }
00155 *isDelayedNeutrons = 1;
00156 }
00157 }
00158 }
00159 return( 0 );
00160 }
00161
00162 #if defined __cplusplus
00163 }
00164 #endif