1 /*  testSimple.c  */
2 
3 #include "../SemiImplMtx.h"
4 #include "../../timings.h"
5 
6 /*--------------------------------------------------------------------*/
7 int
main(int argc,char * argv[])8 main ( int argc, char *argv[] )
9 /*
10    -------------------------------------------------
11    (1) read in a FrontMtx from a file,
12    (2) read in an IV object that has the domain/schur complement
13        information for the fronts
14    (3) create the SemiImplMtx object
15 
16    created -- 98oct16, cca
17    -------------------------------------------------
18 */
19 {
20 char          *inFrontMtxFileName, *inInpMtxFileName, *inIVfileName ;
21 double        t1, t2 ;
22 FILE          *msgFile ;
23 FrontMtx      *frontmtx ;
24 InpMtx        *inpmtx ;
25 int           msglvl, rc ;
26 IV            *frontmapIV ;
27 SemiImplMtx   *semimtx ;
28 
29 if ( argc != 6 ) {
30    fprintf(stdout,
31 "\n\n usage : %s msglvl msgFile inFrontMtxFile inInpMtxFile inIVfile"
32 "\n    msglvl         -- message level"
33 "\n    msgFile        -- message file"
34 "\n    inFrontMtxFile -- input file, must be *.frontmtxf or *.frontmtxb"
35 "\n    inInpMtxFile   -- input file, must be *.inpmtxf or *.inpmtxb"
36 "\n    inIVfile       -- input file, must be *.ivf or *.ivb"
37 "\n", argv[0]) ;
38    return(0) ;
39 }
40 msglvl = atoi(argv[1]) ;
41 if ( strcmp(argv[2], "stdout") == 0 ) {
42    msgFile = stdout ;
43 } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
44    fprintf(stderr, "\n fatal error in %s"
45            "\n unable to open file %s\n",
46            argv[0], argv[2]) ;
47    return(-1) ;
48 }
49 inFrontMtxFileName = argv[3] ;
50 inInpMtxFileName   = argv[4] ;
51 inIVfileName       = argv[5] ;
52 fprintf(msgFile,
53         "\n %s "
54         "\n msglvl         -- %d"
55         "\n msgFile        -- %s"
56         "\n inFrontMtxFile -- %s"
57         "\n inInpMtxFile   -- %s"
58         "\n inIVfile       -- %s"
59         "\n",
60         argv[0], msglvl, argv[2], inFrontMtxFileName,
61         inInpMtxFileName, inIVfileName) ;
62 fflush(msgFile) ;
63 /*
64    ---------------------------
65    read in the FrontMtx object
66    ---------------------------
67 */
68 if ( strcmp(inFrontMtxFileName, "none") == 0 ) {
69    fprintf(msgFile, "\n no file to read from") ;
70    exit(0) ;
71 }
72 frontmtx = FrontMtx_new() ;
73 MARKTIME(t1) ;
74 rc = FrontMtx_readFromFile(frontmtx, inFrontMtxFileName) ;
75 MARKTIME(t2) ;
76 fprintf(msgFile, "\n CPU %9.5f : read in frontmtx from file %s",
77         t2 - t1, inFrontMtxFileName) ;
78 if ( rc != 1 ) {
79    fprintf(msgFile,
80            "\n return value %d from FrontMtx_readFromFile(%p,%s)",
81            rc, frontmtx, inFrontMtxFileName) ;
82    exit(-1) ;
83 }
84 fprintf(msgFile, "\n\n after reading FrontMtx object from file %s",
85         inFrontMtxFileName) ;
86 if ( msglvl > 2 ) {
87    FrontMtx_writeForHumanEye(frontmtx, msgFile) ;
88 } else {
89    FrontMtx_writeStats(frontmtx, msgFile) ;
90 }
91 fflush(msgFile) ;
92 /*
93    ---------------------------
94    read in the InpMtx object
95    ---------------------------
96 */
97 if ( strcmp(inInpMtxFileName, "none") == 0 ) {
98    fprintf(msgFile, "\n no file to read from") ;
99    exit(0) ;
100 }
101 inpmtx = InpMtx_new() ;
102 MARKTIME(t1) ;
103 rc = InpMtx_readFromFile(inpmtx, inInpMtxFileName) ;
104 MARKTIME(t2) ;
105 fprintf(msgFile, "\n CPU %9.5f : read in inpmtx from file %s",
106         t2 - t1, inInpMtxFileName) ;
107 if ( rc != 1 ) {
108    fprintf(msgFile,
109            "\n return value %d from InpMtx_readFromFile(%p,%s)",
110            rc, inpmtx, inInpMtxFileName) ;
111    exit(-1) ;
112 }
113 fprintf(msgFile, "\n\n after reading InpMtx object from file %s",
114         inInpMtxFileName) ;
115 if ( msglvl > 2 ) {
116    InpMtx_writeForHumanEye(inpmtx, msgFile) ;
117 } else {
118    InpMtx_writeStats(inpmtx, msgFile) ;
119 }
120 fflush(msgFile) ;
121 /*
122    ---------------------------------
123    read in the fronts' map IV object
124    ---------------------------------
125 */
126 if ( strcmp(inIVfileName, "none") == 0 ) {
127    fprintf(msgFile, "\n no file to read from") ;
128    exit(0) ;
129 }
130 frontmapIV = IV_new() ;
131 MARKTIME(t1) ;
132 rc = IV_readFromFile(frontmapIV, inIVfileName) ;
133 MARKTIME(t2) ;
134 fprintf(msgFile, "\n CPU %9.5f : read in frontmapIV from file %s",
135         t2 - t1, inIVfileName) ;
136 if ( rc != 1 ) {
137    fprintf(msgFile,
138            "\n return value %d from IV_readFromFile(%p,%s)",
139            rc, frontmapIV, inIVfileName) ;
140    exit(-1) ;
141 }
142 fprintf(msgFile, "\n\n after reading IV object from file %s",
143         inIVfileName) ;
144 if ( msglvl > 2 ) {
145    IV_writeForHumanEye(frontmapIV, msgFile) ;
146 } else {
147    IV_writeStats(frontmapIV, msgFile) ;
148 }
149 fflush(msgFile) ;
150 /*
151    -------------------------------
152    create the semi-implicit matrix
153    -------------------------------
154 */
155 semimtx = SemiImplMtx_new() ;
156 rc = SemiImplMtx_initFromFrontMtx(semimtx, frontmtx, inpmtx,
157                                   frontmapIV, msglvl, msgFile) ;
158 fprintf(msgFile, "\n\n Semi-implicit matrix") ;
159 SemiImplMtx_writeForHumanEye(semimtx, msgFile) ;
160 /*
161    ------------------------
162    free the working storage
163    ------------------------
164 */
165 {
166 ETree   *etree ;
167 IVL     *symbfacIVL ;
168 
169 etree = frontmtx->frontETree ;
170 symbfacIVL = frontmtx->symbfacIVL ;
171 FrontMtx_free(frontmtx) ;
172 ETree_free(etree) ;
173 IVL_free(symbfacIVL) ;
174 }
175 SemiImplMtx_free(semimtx) ;
176 InpMtx_free(inpmtx) ;
177 IV_free(frontmapIV) ;
178 
179 fprintf(msgFile, "\n") ;
180 fclose(msgFile) ;
181 
182 return(1) ; }
183 
184 /*--------------------------------------------------------------------*/
185