#include #include #include #include #include "hit_sci.h" #include "hit_file_def.h" static Hit_Sci_List* the_Hit_Sci_List; /******************************************** hit_sci_list_init ********************************************/ void hit_sci_list_init () { the_Hit_Sci_List = NULL; } /******************************************** hit_sci_list_first ********************************************/ Hit_Sci_List* hit_sci_list_first () { return ( the_Hit_Sci_List ); } /******************************************** hit_sci_list_remove_all ********************************************/ void hit_sci_list_remove_all () { Hit_Sci_List *p, *pNext; p = the_Hit_Sci_List; while ( p != NULL ) { pNext = p->next; free ( p ); p = pNext; } the_Hit_Sci_List = NULL; } /******************************************** hit_sci_list_create ********************************************/ Hit_Sci_List* hit_sci_list_create () { Hit_Sci_List* p; p = ( Hit_Sci_List* ) malloc ( sizeof( Hit_Sci_List ) ); if ( p <= 0 ) exit ( 2 ); return ( p ); } /******************************************** hit_sci_list_last ********************************************/ Hit_Sci_List* hit_sci_list_last ( Hit_Sci_List* pList ) { Hit_Sci_List* p; if ( pList == NULL ) return ( NULL ); while ( 1 ) { /*---get next pointer---*/ p = pList->next; if ( p == NULL ) break; pList = p; } return ( pList ); } /******************************************** hit_sci_list_add ********************************************/ Hit_Sci_List* hit_sci_list_add ( int ctnb, double trigger_t ) { /*---create an element of Hit_Sci_List---*/ Hit_Sci_List *p, *pLast; p = hit_sci_list_create (); (p->hit_sci).ctnb = ctnb; (p->hit_sci).trigger_t = trigger_t; p->next = NULL; /*---search last element---*/ pLast = hit_sci_list_last ( the_Hit_Sci_List ); if ( pLast == NULL ) { /*---first element---*/ the_Hit_Sci_List = p; return ( p ); } else { pLast->next = p; return ( the_Hit_Sci_List ); } } /******************************************** hit_sci_list_read ********************************************/ int hit_sci_list_read ( FILE *fp, int read_line, int read_mode ) { int i; char buffer[BUF_SIZE]; int ctnb, evtnb; double trigger_t; for ( i = 0; i < read_line; i++ ) { if ( fgets( buffer, BUF_SIZE, fp ) == NULL ) { fprintf ( stderr, "READ FILE ERROR (EOF) in hit_sci_list_read ! \n" ); return ( ERROR ); } buffer[ strlen(buffer) - 1 ] = '\0'; if ( sscanf( buffer, "%d %lf %d\n", &ctnb, &trigger_t, &evtnb ) != 3 ) { /*---read error---*/ fprintf ( stderr, "READ FILE ERROR in hit_sci_list_read ! \n" ); fprintf ( stderr, "at list %d : %s \n", i, buffer ); return ( ERROR ); } #ifdef DEBUG printf("ctnb = %d trigger_t = %lf \n", ctnb, trigger_t ); #endif /*---add an element to the_Hit_Sci_List---*/ hit_sci_list_add ( ctnb, trigger_t ); } }