/* * PEF: Polar Exchange Format * * Simple PEF file access routines. * * Performance depends on the buffered i/o functions of the * C-library and the operating system. * Assumes random block sequence in PEF file. * * Created: 5/1996 Martin Hepperle */ /*** standard includes ***/ #include #include #include /*** C does not know what's true and what's false ***/ #define TRUE 1 #define FALSE 0 typedef unsigned int BOOL; /*** PEF access function ***/ BOOL PEFGetKeyValue ( char * pPEFFileName, char * pBlockName, char * pKeyName, char * pReturnBuffer, int nBufferSize ); /*** internal working routines ***/ static BOOL _PEFLocateBlock ( FILE * fp, char * pBlockName ); static BOOL _PEFGetValue ( FILE * fp, char * pKeyName, char * pReturnBuffer, int nBufferSize ); /*** sample parse function ***/ void ParsePEF ( char * pFileName ); void main () { ParsePEF ( "mh62.pef" ); } void ParsePEF ( char * pFileName ) { char szBuffer[80]; if ( PEFGetKeyValue ( pFileName, "Airfoil", "Description1", szBuffer, sizeof(szBuffer) ) ) { fprintf ( stdout, "Name: %s", szBuffer ); /* read the number of data sets in this file */ if ( PEFGetKeyValue ( pFileName, "Airfoil", "NumberSets", szBuffer, sizeof(szBuffer) ) ) { int nSet; int nSets = atoi ( szBuffer ); /* sweep through data sets */ for ( nSet=0 ; nSet< nSets ; nSet++ ) { char szBlockName[64]; char szKeyName[64]; int nPolars; fprintf ( stdout, "Set %d\n", nSet+1 ); /* read the number of polars in this set */ sprintf ( szBlockName, "Set%d", nSet+1 ); if ( PEFGetKeyValue ( pFileName, szBlockName, "NumberPolars", szBuffer, sizeof(szBuffer) ) ) { int nPolar; int nPolars = atoi ( szBuffer ); /* sweep through polars of this data set */ for ( nPolar=0 ; nPolar