bpminterface/get_header.c

Go to the documentation of this file.
00001 
00006 #include <bpm/bpm_interface.h>
00007 #include <bpm/bpm_messages.h>
00008 
00009 int get_header( FILE *file, double *version, int *num_structs ){
00010 
00011   if ( ! file ) {
00012     bpm_error( "Invalid file pointer in get_header(...)",
00013                __FILE__, __LINE__ );
00014     return BPM_FAILURE;
00015   }
00016 
00017   if ( ! version ) {
00018     bpm_error( "Invalid version pointer in get_header(...)",
00019                __FILE__, __LINE__ );
00020     return BPM_FAILURE;
00021   }
00022 
00023   if ( ! num_structs ) {
00024     bpm_error( "Invalid number pointer in get_header(...)",
00025                __FILE__, __LINE__ );
00026     return BPM_FAILURE;
00027   }
00028 
00029   /*--------------------------------------------------------------------------
00030     Keep loading in lines until a non-comment is found and assume this is the header
00031     --------------------------------------------------------------------------
00032   */
00033   
00034   char line[255];
00035   char *tok;
00036   *version = 0;
00037   *num_structs = 0;
00038 
00039   while ( fgets( line, 255, file ) != NULL ) {
00040 
00041     // Check for comments
00042     tok = strtok( line, " " );
00043     if (tok[0] == '#') continue;
00044 
00045     // Assume this is the header
00046     *version = atof( tok );
00047     tok = strtok( NULL, " " );
00048     *num_structs = atoi( tok );
00049     break;
00050 
00051   }
00052 
00053   // Check for sensible values
00054   if ( *version <= 0 ) {
00055     char buf[255];
00056 
00057     sprintf( buf, "Strange value for the version (\"%d\") found in get_header(...)",
00058              *version );
00059     bpm_error( buf, __FILE__, __LINE__ );
00060 
00061     return BPM_FAILURE;
00062   }
00063 
00064   if ( *num_structs <= 0 ) {
00065     char buf[255];
00066 
00067     sprintf( buf, "Strange value for the number of structs (\"%d\") found in get_header(...)",
00068              *num_structs );
00069     bpm_error( buf, __FILE__, __LINE__ );
00070 
00071     return BPM_FAILURE;
00072   }
00073       
00074   return BPM_SUCCESS;
00075 }

Generated on Thu Jan 10 10:18:04 2008 for libbpm by  doxygen 1.5.1