📄 trace_impl.c
字号:
if ( methods_len != Nmeths ) { fprintf( stderr, "TRACE_Peek_next_ycoordmap(): The number of methods " "defined is %d and number read is %d\n", Nmeths, methods_len ); return 61; } if ( methods_len > 0 ) { /* Assume 1 method ID */ ymap->methods[ 0 ] = atoi( str4methods ); } *num_rows = ymap->num_rows; *num_columns = ymap->num_columns; *max_column_name = max_colnames; *max_title_name = strlen( ymap->title_name ) + 1; *num_methods = methods_len; /* Free the previous allocated YCoordMap stored at TRACE_file */ YCoordMap_free( fp->ymap ); fp->ymap = ymap; return 0;}TRACE_EXPORTint TRACE_Get_next_ycoordmap( TRACE_file fp, char *title_name, char **column_names, int *coordmap_sz, int coordmap_base[], int *coordmap_pos, const int coordmap_max, int *num_methods, int method_base[], int *method_pos, const int method_max ){ DRAW_YCoordMap *ymap; int icol; if ( fp->ymap == NULL ) { fprintf( stderr, "TRACE_Get_next_ycoordmap(): Cannot locate " "YCoordMap in TRACE_file.\n" ); return 60; } ymap = fp->ymap; strcpy( title_name, ymap->title_name ); /* fprintf( stderr, "strlen(%s) = %d\n", title_name, strlen(title_name) ); fflush( stderr ); */ for ( icol = 0; icol < ymap->num_columns - 1; icol++ ) { /* fprintf( stderr, "strlen(%s) = %d\n", ymap->column_names[icol], strlen(ymap->column_names[icol]) ); fflush( stderr ); */ strcpy( column_names[icol], ymap->column_names[icol] ); } if ( *coordmap_pos >= coordmap_max ) return 63; memcpy( &(coordmap_base[ *coordmap_pos ]), ymap->elems, sizeof( int ) * ymap->num_rows * ymap->num_columns ); *coordmap_sz = ymap->num_rows * ymap->num_columns; *coordmap_pos += *coordmap_sz; if ( *coordmap_pos > coordmap_max ) return 64; if ( ymap->num_methods > 0 ) { if ( *method_pos >= method_max ) return 65; memcpy( &(method_base[ *method_pos ]), ymap->methods, sizeof( int ) * ymap->num_methods ); *num_methods = ymap->num_methods; *method_pos += *num_methods; if ( *method_pos > method_max ) return 66; } return 0;}#define MAX_VERTICES 10TRACE_EXPORTint TRACE_Peek_next_primitive( const TRACE_file fp, double *start_time, double *end_time, int *num_tcoords, int *num_ycoords, int *num_bytes ){ DRAW_Category *type; DRAW_Primitive *prime; DRAW_Composite *cmplx; char typename[10]; int type_idx; int line_pos; char *linebuf; char *newline; char *info_A, *info_B; char coord_format[] = "(%lf, %d) %n"; char primitive_format[] = "%s TimeBBox(%lf,%lf) Category=%d %n"; double starttime, endtime; double tcoords[ MAX_VERTICES ]; int ycoords[ MAX_VERTICES ]; int num_vertices; int infovals[2]; int idx; /* Check if this Primitive is part of the Composite */ if ( fp->cmplx != NULL ) { cmplx = fp->cmplx; if ( cmplx->idx2prime < cmplx->num_primes ) { linebuf = cmplx->lines[ cmplx->idx2prime ]; cmplx->idx2prime++; } else { /* Free the composite and set it to NULL to minimize the overhead */ Composite_free( fp->cmplx ); fp->cmplx = NULL; linebuf = fp->line; } } else linebuf = fp->line; sscanf( linebuf, primitive_format, typename, &starttime, &endtime, &type_idx, &line_pos );#if defined( DEBUG ) printf( "%s %lf %lf %d ", typename, starttime, endtime, type_idx );#endif newline = (char *) (linebuf+line_pos); num_vertices = 0; while ( newline[0] == '(' ) { sscanf( newline, coord_format, &tcoords[num_vertices], &ycoords[num_vertices], &line_pos );#if defined( DEBUG ) printf( "(%lf, %d) ", tcoords[num_vertices], ycoords[num_vertices] );#endif newline = (char *) (newline+line_pos); num_vertices++; } /* Search for the valid Category in the category table */ type = NULL; for ( idx = 0; idx < fp->num_types; idx++ ) { if ( fp->types[ idx ]->hdr->index == type_idx ) { type = fp->types[ idx ]; break; } }/* if ( type == NULL ) { fprintf( stderr, "TRACE_Peek_next_primitive(): Cannot locate " "CATEGORY in catgeory table.\n" ); return 20; }*/ *num_bytes = 0; info_A = NULL; info_B = NULL; if ( ( info_A = strstr( newline, "< " ) ) != NULL && ( info_B = strstr( info_A, " >" ) ) != NULL && type != NULL ) { info_A = (char *) (info_A + 2); sprintf( info_B, "%c", '\0' ); sscanf( info_A, type->label, &infovals[0], &infovals[1] );#if defined( DEBUG ) printf( "<[0]=%d [1]=%d>", infovals[0], infovals[1] );#endif *num_bytes = 8; }#if defined( DEBUG ) printf( "\n" );#endif *start_time = starttime; *end_time = endtime; *num_tcoords = num_vertices; *num_ycoords = num_vertices; /* Allocate a new Primitive */ prime = Primitive_alloc( num_vertices ); prime->starttime = *start_time; prime->endtime = *end_time; prime->type_idx = type_idx; if ( *num_bytes > 0 ) { prime->num_info = *num_bytes; prime->info = (char *) malloc( prime->num_info * sizeof(char) ); memcpy( prime->info, infovals, prime->num_info );#if ! defined( WORDS_BIGENDIAN ) bswp_byteswap( 2, sizeof( int ), prime->info );#endif } prime->num_tcoords = num_vertices; prime->num_ycoords = num_vertices; for ( idx = 0; idx < num_vertices; idx++ ) { prime->tcoords[ idx ] = tcoords[ idx ]; prime->ycoords[ idx ] = ycoords[ idx ]; } /* Free the previous allocated Primitive stored at TRACE_file */ Primitive_free( fp->prime ); fp->prime = prime; return 0;}TRACE_EXPORTint TRACE_Get_next_primitive( const TRACE_file fp, int *category_index, int *num_tcoords, double tcoord_base[], int *tcoord_pos, const int tcoord_max, int *num_ycoords, int ycoord_base[], int *ycoord_pos, const int ycoord_max, int *num_bytes, char byte_base[], int *byte_pos, const int byte_max ){ DRAW_Primitive *prime; if ( fp->prime == NULL ) { fprintf( stderr, "TRACE_Get_next_primitive(): Cannot locate " "Primitive in TRACE_file.\n" ); return 30; } prime = fp->prime; *category_index = prime->type_idx; if ( prime->num_info > 0 ) { if ( *byte_pos >= byte_max ) return 31; memcpy( &(byte_base[ *byte_pos ]), prime->info, sizeof( char ) * prime->num_info ); *num_bytes = prime->num_info; *byte_pos += *num_bytes; if ( *byte_pos > byte_max ) return 32; } if ( *tcoord_pos >= tcoord_max ) return 33; memcpy( &(tcoord_base[ *tcoord_pos ]), prime->tcoords, sizeof( double ) * prime->num_tcoords ); *num_tcoords = prime->num_tcoords; *tcoord_pos += *num_tcoords; if ( *tcoord_pos > tcoord_max ) return 34; if ( *ycoord_pos >= ycoord_max ) return 35; memcpy( &(ycoord_base[ *ycoord_pos ]), prime->ycoords, sizeof( int ) * prime->num_ycoords ); *num_ycoords = prime->num_ycoords; *ycoord_pos += *num_ycoords; if ( *ycoord_pos > ycoord_max ) return 36; return 0;}TRACE_EXPORTint TRACE_Peek_next_composite( const TRACE_file fp, double *start_time, double *end_time, int *num_primitives, int *num_bytes ){ DRAW_Category *type; DRAW_Composite *cmplx; char typename[10]; int type_idx; int line_pos; char *newline; char *info_A, *info_B; char composite_format[] = "%s TimeBBox(%lf,%lf) Category=%d " "NumPrimes=%d %n"; double starttime, endtime; int num_primes; int infovals[2]; int idx; sscanf( fp->line, composite_format, typename, &starttime, &endtime, &type_idx, &num_primes, &line_pos );#if defined( DEBUG ) printf( "%s %lf %lf %d %d ", typename, starttime, endtime, type_idx, num_primes );#endif newline = (char *) (fp->line+line_pos); /* Search for the valid Category in the category table */ type = NULL; for ( idx = 0; idx < fp->num_types; idx++ ) { if ( fp->types[ idx ]->hdr->index == type_idx ) { type = fp->types[ idx ]; break; } }/* if ( type == NULL ) { fprintf( stderr, "TRACE_Peek_next_composite(): Cannot locate " "CATEGORY in catgeory table.\n" ); return 20; }*/ *num_bytes = 0; info_A = NULL; info_B = NULL; if ( ( info_A = strstr( newline, "< " ) ) != NULL && ( info_B = strstr( info_A, " >" ) ) != NULL && type != NULL ) { info_A = (char *) (info_A + 2); sprintf( info_B, "%c", '\0' ); sscanf( info_A, type->label, &infovals[0], &infovals[1] );#if defined( DEBUG ) printf( "<[0]=%d [1]=%d>", infovals[0], infovals[1] );#endif *num_bytes = 8; }#if defined( DEBUG ) printf( "\n" );#endif *start_time = starttime; *end_time = endtime; *num_primitives = num_primes; /* Allocate a new Composite */ cmplx = Composite_alloc( num_primes ); cmplx->starttime = *start_time; cmplx->endtime = *end_time; cmplx->type_idx = type_idx; if ( *num_bytes > 0 ) { cmplx->num_info = *num_bytes; cmplx->info = (char *) malloc( cmplx->num_info * sizeof(char) ); memcpy( cmplx->info, infovals, cmplx->num_info );#if ! defined( WORDS_BIGENDIAN ) bswp_byteswap( 2, sizeof( int ), cmplx->info );#endif } cmplx->num_primes = num_primes; /* Fetch next "num_primes" primitive record from file to be parsed later */ for ( idx = 0; idx < cmplx->num_primes; idx++ ) { if ( fgets( cmplx->lines[ idx ], MAX_LINE_LEN, fp->fd ) == NULL ) { fprintf( stderr, "TRACE_Peek_next_composite(): Unexpected EOF " "while reading Composite's Primitive[%d].\n", idx ); return 49; } } /* Set up accessment index to the primitive line records */ cmplx->idx2prime = 0; /* Free the previous allocated Composite stored at TRACE_file */ Composite_free( fp->cmplx ); fp->cmplx = cmplx; return 0;}TRACE_EXPORTint TRACE_Get_next_composite( const TRACE_file fp, int *category_index, int *num_bytes, char byte_base[], int *byte_pos, const int byte_max ){ DRAW_Composite *cmplx; if ( fp->cmplx == NULL ) { fprintf( stderr, "TRACE_Get_next_composite(): Cannot locate " "Composite in TRACE_file.\n" ); return 40; } cmplx = fp->cmplx; *category_index = cmplx->type_idx; if ( cmplx->num_info > 0 ) { if ( *byte_pos >= byte_max ) return 41; memcpy( &(byte_base[ *byte_pos ]), cmplx->info, sizeof( char ) * cmplx->num_info ); *num_bytes = cmplx->num_info; *byte_pos += *num_bytes; if ( *byte_pos > byte_max ) return 42; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -