summaryrefslogtreecommitdiffstats
path: root/src/base/abci/abcDec.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2019-11-20 22:45:29 +0800
committerAlan Mishchenko <alanmi@berkeley.edu>2019-11-20 22:45:29 +0800
commit4deaaa852a1a6cb9d06a88b3b81133330a350c7e (patch)
tree0cf08580d5173c88a17a495a00cde60517e918a9 /src/base/abci/abcDec.c
parent30e2b727a1b941bdc968da3e09ed7655124b217b (diff)
downloadabc-4deaaa852a1a6cb9d06a88b3b81133330a350c7e.tar.gz
abc-4deaaa852a1a6cb9d06a88b3b81133330a350c7e.tar.bz2
abc-4deaaa852a1a6cb9d06a88b3b81133330a350c7e.zip
Data reading procedure.
Diffstat (limited to 'src/base/abci/abcDec.c')
-rw-r--r--src/base/abci/abcDec.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/base/abci/abcDec.c b/src/base/abci/abcDec.c
index dee773ab..7803f539 100644
--- a/src/base/abci/abcDec.c
+++ b/src/base/abci/abcDec.c
@@ -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 []