#include #include #include #include #include "hit_tgc.h" #include "hit_file_def.h" static Hit_TGC_List* the_Hit_TGC_List; /******************************************** hit_tgc_list_init ********************************************/ void hit_tgc_list_init () { the_Hit_TGC_List = NULL; } /******************************************** hit_tgc_list_first ********************************************/ Hit_TGC_List* hit_tgc_list_first () { return ( the_Hit_TGC_List ); } /******************************************** hit_tgc_list_remove_all ********************************************/ void hit_tgc_list_remove_all () { Hit_TGC_List *p, *pNext; p = the_Hit_TGC_List; while ( p != NULL ) { pNext = p->next; free ( p ); p = pNext; } the_Hit_TGC_List = NULL; } /******************************************** hit_tgc_list_creat ********************************************/ Hit_TGC_List* hit_tgc_list_create () { Hit_TGC_List* p; p = ( Hit_TGC_List* ) malloc ( sizeof( Hit_TGC_List ) ); if ( p <= 0 ) exit ( 2 ); return ( p ); } /******************************************** hit_tgc_list_last ********************************************/ Hit_TGC_List* hit_tgc_list_last ( Hit_TGC_List* pList ) { Hit_TGC_List* p; if ( pList == NULL ) return ( NULL ); while ( 1 ) { /*---get next pointer---*/ p = pList->next; if ( p == NULL ) break; pList = p; } return ( pList ); } /******************************************** hit_tgc_list_add ********************************************/ Hit_TGC_List* hit_tgc_list_add ( int layer, int ws, int tgch, double hit_t ) { /*---create an element of Hit_DT_List---*/ Hit_TGC_List *p, *pLast; p = hit_tgc_list_create (); (p->hit_tgc).layer = layer; (p->hit_tgc).ws = ws; (p->hit_tgc).tgch = tgch; (p->hit_tgc).hit_t = hit_t; p->next = NULL; /*---search last element---*/ pLast = hit_tgc_list_last ( the_Hit_TGC_List ); if ( pLast == NULL ) { /*---first element---*/ the_Hit_TGC_List = p; return ( p ); } else { pLast->next = p; return ( the_Hit_TGC_List ); } } /******************************************** hit_tgc_list_read ********************************************/ int hit_tgc_list_read ( FILE *fp, int read_line, int read_mode ) { int i; char buffer[BUF_SIZE]; int layer, ws, tgch, evtnb; double hit_t; for ( i = 0; i < read_line; i++ ) { if ( fgets( buffer, BUF_SIZE, fp ) == NULL ) { fprintf ( stderr, "READ FILE ERROR (EOF) in hit_tgc_list_read ! \n" ); return ( ERROR ); } buffer[ strlen(buffer) - 1 ] = '\0'; if ( sscanf( buffer, "%d %d %d %lf %d\n", &layer, &ws, &tgch, &hit_t, &evtnb ) != 5 ) { /*---read error---*/ fprintf ( stderr, "READ FILE ERROR in hit_tgc_list_read ! \n" ); fprintf ( stderr, "at list %d : %s \n", i, buffer ); return ( ERROR ); } #ifdef DEBUG printf("layer = %d ws = %d tgch = %d hit_t = %lf\n", layer, ws, tgch, hit_t ); #endif /*---add an element to the_Hit_TGC_List---*/ hit_tgc_list_add ( layer, ws, tgch, hit_t ); } }