Commit 4deaaa85 by Alan Mishchenko

Data reading procedure.

parent 30e2b727
......@@ -460,6 +460,54 @@ void Abc_TtStoreLoadSave( char * pFileName )
/**Function*************************************************************
Synopsis [Read truth tables in binary text form and write them into file as binary data.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_TtStoreLoadSaveBin( char * pFileName )
{
unsigned * pTruth = ABC_CALLOC( unsigned, (1 << 11) );
char * pBuffer = ABC_CALLOC( char, (1 << 16) );
char * pFileInput = pFileName;
char * pFileOutput = Extra_FileNameGenericAppend(pFileName, "_binary.data");
FILE * pFileI = fopen( pFileInput, "rb" );
FILE * pFileO = fopen( pFileOutput, "wb" );
int i, Value, nVarsAll = -1;
if ( pFileI == NULL )
return;
while ( fgets(pBuffer, (1 << 16), pFileI) )
{
int Len = strlen(pBuffer)-1; // subtract 1 for end-of-line
int nVars = Abc_Base2Log(Len);
int nInts = Abc_BitWordNum(Len);
assert( Len == (1 << nVars) );
if ( nVarsAll == -1 )
nVarsAll = nVars;
else
assert( nVarsAll == nVars );
memset( pTruth, 0, sizeof(int)*nInts );
for ( i = 0; i < Len; i++ )
if ( pBuffer[i] == '1' )
Abc_InfoSetBit( pTruth, i );
else
assert( pBuffer[i] == '0' );
Value = fwrite( pTruth, 1, sizeof(int) * nInts, pFileO );
assert( Value == (int)sizeof(int) * nInts );
}
ABC_FREE( pTruth );
ABC_FREE( pBuffer );
fclose( pFileI );
fclose( pFileO );
printf( "Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
}
/**Function*************************************************************
Synopsis [Read truth tables from input file and write them into output file.]
Description []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment