/* * tgc_cfg.c * Creation Date : Nov 13 2000 * Author : Y.Nakaune */ #include #include #include #include "buf.h" #define D_CFG 1 #define T_CFG 2 #define HV_CFG 3 #define P_CFG 4 /*----------------------------------------------------- x,y,z conversion ---------------------------------------------------*/ static int x_conversion( int measurement_x ) { int standard_x; standard_x = CENTER_X + measurement_x - SCALE_ERROR_X - ( TGC_Xdown / 2 ); /*---CENTER_X is center X postion of TGC when stage is minimum. SCALE_ERROR_X is stage position when stage is minimum.---*/ return( standard_x ); } static int y_conversion( int measurement_y ) { int standard_y; standard_y = CENTER_Y + measurement_y - SCALE_ERROR_Y - ( TGC_Y / 2 ); /*---CENTER_Y is center Y postion of TGC when stage is minimum. SCALE_ERROR_Y is stage position when stage is minimum.---*/ return( standard_y ); } static int z_conversion( int measurement_z ) { int standard_z; standard_z = measurement_z; return( standard_z ); } /*----------------------------------------------------- Doublet ---------------------------------------------------*/ void Doublet( char *ptr ) { int x_pos, y_pos, z_pos; if ( sscanf( ptr, "%d %d %d \n", &x_pos, &y_pos, &z_pos ) != 3 ) { perror( "Doublet_CFG: find wrong format" ); return; } tgc_cfg.pre_doublet_x = x_pos; tgc_cfg.pre_doublet_y = y_pos; tgc_cfg.pre_doublet_z = z_pos; #ifdef F_DEBUG if ( Debug == 1 ) { printf("x_pos=%d y_pos=%d z_pos=%d\n",x_pos,y_pos,z_pos); printf("X_pos=%d Y_pos=%d Z_pos=%d\n", tgc_cfg.doublet_x,tgc_cfg.doublet_y,tgc_cfg.doublet_z); } #endif tgc_cfg.doublet_x = x_conversion( tgc_cfg.pre_doublet_x ); tgc_cfg.doublet_y = y_conversion( tgc_cfg.pre_doublet_y ); tgc_cfg.doublet_z = z_conversion( tgc_cfg.pre_doublet_z ); } /*----------------------------------------------------- Triplet ---------------------------------------------------*/ void Triplet( char *ptr ) { int x_pos, y_pos, z_pos; if ( sscanf( ptr, "%d %d %d \n", &x_pos, &y_pos, &z_pos ) != 3 ) { perror( "Triplet_CFG: find wrong format" ); return; } tgc_cfg.pre_triplet_x = x_pos; tgc_cfg.pre_triplet_y = y_pos; tgc_cfg.pre_triplet_z = z_pos; #ifdef F_DEBUG if ( Debug == 1 ) { printf("x_pos=%d y_pos=%d z_pos=%d\n",x_pos,y_pos,z_pos); printf("X_pos=%d Y_pos=%d Z_pos=%d\n", tgc_cfg.triplet_x,tgc_cfg.triplet_y,tgc_cfg.triplet_z); } #endif tgc_cfg.triplet_x = x_conversion( tgc_cfg.pre_triplet_x ); tgc_cfg.triplet_y = y_conversion( tgc_cfg.pre_triplet_y ); tgc_cfg.triplet_z = z_conversion( tgc_cfg.pre_triplet_z ); } /*----------------------------------------------------- HV ---------------------------------------------------*/ void HV( char *ptr ) { float lay0, lay1, lay2, lay3, lay4; if ( sscanf( ptr, "%f %f %f %f %f\n", &lay0, &lay1, &lay2, &lay3, &lay4 ) != 5 ) { perror( "HV_CFG: find wrong format" ); return; } tgc_cfg.HV[0] = lay0; tgc_cfg.HV[1] = lay1; tgc_cfg.HV[2] = lay2; tgc_cfg.HV[3] = lay3; tgc_cfg.HV[4] = lay4; #ifdef F_DEBUG if ( Debug == 1 ) { printf("H:0=%f 0=%f 2=%f 3=%f 4=%f\n",lay0,lay1,lay2,lay3,lay4); printf("H:0=%f 0=%f 2=%f 3=%f 4=%f\n", tgc_cfg.HV[0],tgc_cfg.HV[1],tgc_cfg.HV[2],tgc_cfg.HV[3],tgc_cfg.HV[4]); } #endif } /*----------------------------------------------------- Pressure ---------------------------------------------------*/ void Pressure( char *ptr ) { int lay0, lay1, lay2, lay3, lay4; if ( sscanf( ptr, "%d %d %d %d %d\n", &lay0, &lay1, &lay2, &lay3, &lay4 ) != 5 ) { perror( "Pressure_CFG: find wrong format" ); return; } tgc_cfg.Pressure[0] = lay0; tgc_cfg.Pressure[1] = lay1; tgc_cfg.Pressure[2] = lay2; tgc_cfg.Pressure[3] = lay3; tgc_cfg.Pressure[4] = lay4; #ifdef F_DEBUG if ( Debug == 1 ) { printf("P:0=%d 0=%d 2=%d 3=%d 4=%d\n",lay0,lay1,lay2,lay3,lay4); printf("P:0=%d 0=%d 2=%d 3=%d 4=%d\n", tgc_cfg.Pressure[0],tgc_cfg.Pressure[1], tgc_cfg.Pressure[2],tgc_cfg.Pressure[3],tgc_cfg.Pressure[4]); } #endif } /*--------------------------------------------------- ReadTGC_CFG Read TGC.cfg file ---------------------------------------------------*/ void ReadTGC_CFG( char *file ) { int id = 0; char buff[ BUFF_LENGTH ]; FILE *fp = NULL; if ( ( fp = fopen( file, "r" ) ) == NULL ) { fprintf( stderr, "File ( %s ) Not Found !\n", file ); exit(1); } while ( fgets( buff, BUFF_LENGTH, fp ) != NULL ) { if ( buff[0] == '#' || buff[0] == '\n' ) continue; else if ( strncmp( buff, "Doublet", 7 ) == 0 ) id = D_CFG; else if ( strncmp( buff, "Triplet", 7 ) == 0 ) id = T_CFG; else if ( strncmp( buff, "HV", 2 ) == 0 ) id = HV_CFG; else if ( strncmp( buff, "Pressure", 8 ) == 0 ) id = P_CFG; else switch ( id ) { case D_CFG: Doublet( buff ); break; case T_CFG: Triplet( buff ); break; case HV_CFG: HV( buff ); break; case P_CFG: Pressure( buff ); break; } } fclose( fp ); } /*----------EOF-------------------------------------*/