emergency commit
[cl-cudd.git] / distr / dddmp / dddmpConvert.c
blobc24292e8cb2a68a4eff0847e894b26a8e4997208
1 /**CFile**********************************************************************
3 FileName [dddmpConvert.c]
5 PackageName [dddmp]
7 Synopsis [Conversion between ASCII and binary formats]
9 Description [Conversion between ASCII and binary formats is presently
10 supported by loading a BDD in the source format and storing it
11 in the target one. We plan to introduce ad hoc procedures
12 avoiding explicit BDD node generation.
15 Author [Gianpiero Cabodi and Stefano Quer]
17 Copyright [
18 Copyright (c) 2004 by Politecnico di Torino.
19 All Rights Reserved. This software is for educational purposes only.
20 Permission is given to academic institutions to use, copy, and modify
21 this software and its documentation provided that this introductory
22 message is not removed, that this software and its documentation is
23 used for the institutions' internal research and educational purposes,
24 and that no monies are exchanged. No guarantee is expressed or implied
25 by the distribution of this code.
26 Send bug-reports and/or questions to:
27 {gianpiero.cabodi,stefano.quer}@polito.it.
30 ******************************************************************************/
32 #include "dddmpInt.h"
34 /*---------------------------------------------------------------------------*/
35 /* Stucture declarations */
36 /*---------------------------------------------------------------------------*/
38 /*---------------------------------------------------------------------------*/
39 /* Type declarations */
40 /*---------------------------------------------------------------------------*/
42 /*---------------------------------------------------------------------------*/
43 /* Variable declarations */
44 /*---------------------------------------------------------------------------*/
46 /*---------------------------------------------------------------------------*/
47 /* Macro declarations */
48 /*---------------------------------------------------------------------------*/
50 /**AutomaticStart*************************************************************/
52 /*---------------------------------------------------------------------------*/
53 /* Static function prototypes */
54 /*---------------------------------------------------------------------------*/
57 /**AutomaticEnd***************************************************************/
60 /*---------------------------------------------------------------------------*/
61 /* Definition of exported functions */
62 /*---------------------------------------------------------------------------*/
64 /**Function********************************************************************
66 Synopsis [Converts from ASCII to binary format]
68 Description [Converts from ASCII to binary format. A BDD array is loaded and
69 and stored to the target file.]
71 SideEffects [None]
73 SeeAlso [Dddmp_Bin2Text()]
75 ******************************************************************************/
77 int
78 Dddmp_Text2Bin (
79 char *filein /* IN: name of ASCII file */,
80 char *fileout /* IN: name of binary file */
83 DdManager *ddMgr; /* pointer to DD manager */
84 DdNode **roots; /* array of BDD roots to be loaded */
85 int nRoots; /* number of BDD roots */
86 int retValue;
88 ddMgr = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
89 if (ddMgr == NULL) {
90 return (0);
93 nRoots = Dddmp_cuddBddArrayLoad(ddMgr,DDDMP_ROOT_MATCHLIST,NULL,
94 DDDMP_VAR_MATCHIDS,NULL,NULL,NULL,
95 DDDMP_MODE_TEXT,filein,NULL,&roots);
97 Dddmp_CheckAndGotoLabel (nRoots<=0,
98 "Negative Number of Roots.", failure);
100 retValue = Dddmp_cuddBddArrayStore (ddMgr,NULL,nRoots,roots,NULL,
101 NULL,NULL,DDDMP_MODE_BINARY,DDDMP_VARIDS,fileout,NULL);
103 Dddmp_CheckAndGotoLabel (retValue<=0,
104 "Error code returned.", failure);
106 Cudd_Quit(ddMgr);
107 return (1);
109 failure:
110 printf("error converting BDD format\n");
111 Cudd_Quit(ddMgr);
112 return (0);
115 /**Function********************************************************************
117 Synopsis [Converts from binary to ASCII format]
119 Description [Converts from binary to ASCII format. A BDD array is loaded and
120 and stored to the target file.]
122 SideEffects [None]
124 SeeAlso [Dddmp_Text2Bin()]
126 ******************************************************************************/
129 Dddmp_Bin2Text (
130 char *filein /* IN: name of binary file */,
131 char *fileout /* IN: name of ASCII file */
134 DdManager *ddMgr; /* pointer to DD manager */
135 DdNode **roots; /* array of BDD roots to be loaded */
136 int nRoots; /* number of BDD roots */
137 int retValue;
139 ddMgr = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0);
140 if (ddMgr == NULL) {
141 return (0);
144 nRoots = Dddmp_cuddBddArrayLoad(ddMgr,DDDMP_ROOT_MATCHLIST,NULL,
145 DDDMP_VAR_MATCHIDS,NULL,NULL,NULL,
146 DDDMP_MODE_BINARY,filein,NULL,&roots);
148 Dddmp_CheckAndGotoLabel (nRoots<=0,
149 "Negative Number of Roots.", failure);
151 retValue = Dddmp_cuddBddArrayStore (ddMgr,NULL,nRoots,roots,NULL,
152 NULL,NULL,DDDMP_MODE_TEXT,DDDMP_VARIDS,fileout,NULL);
154 Dddmp_CheckAndGotoLabel (retValue<=0,
155 "Error code returned.", failure);
157 Cudd_Quit(ddMgr);
158 return (1);
160 failure:
161 printf("error converting BDD format\n");
162 Cudd_Quit(ddMgr);
163 return (0);
166 /*---------------------------------------------------------------------------*/
167 /* Definition of internal functions */
168 /*---------------------------------------------------------------------------*/
171 /*---------------------------------------------------------------------------*/
172 /* Definition of static functions */
173 /*---------------------------------------------------------------------------*/
176 /*---------------------------------------------------------------------------*/
177 /* Static function prototypes */
178 /*---------------------------------------------------------------------------*/