File: testIO.c

package info (click to toggle)
spooles 2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 19,012 kB
  • sloc: ansic: 146,834; csh: 3,615; makefile: 2,040; perl: 74
file content (169 lines) | stat: -rw-r--r-- 4,885 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*  testIO.c  */

#include "../SubMtx.h"
#include "../../timings.h"

/*--------------------------------------------------------------------*/
int
main ( int argc, char *argv[] )
/*
   ------------------------------------------------------
   test SubMtx_readFromFile and SubMtx_writeToFile,
   useful for translating between formatted *.submtxf
   and binary *.submtxb files.

   created -- 98may04, cca
   ------------------------------------------------------
*/
{
char       *inSubMtxFileName, *matlabFileName, *outSubMtxFileName ;
double     t1, t2 ;
int        msglvl, rc ;
SubMtx     *mtx ;
FILE       *fp, *msgFile ;

if ( argc != 6 ) {
   fprintf(stdout, 
     "\n\n usage : %s msglvl msgFile inFile outFile matlabFile"
     "\n    msglvl     -- message level"
     "\n    msgFile    -- message file"
     "\n    inFile     -- input file, must be *.dmtxf or *.dmtxb"
     "\n    outFile    -- output file, must be *.dmtxf or *.dmtxb"
     "\n    matlabFile -- output file, must be *.m"
     "\n", argv[0]) ;
   return(0) ;
}
msglvl = atoi(argv[1]) ;
if ( strcmp(argv[2], "stdout") == 0 ) {
   msgFile = stdout ;
} else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
   fprintf(stderr, "\n fatal error in %s"
           "\n unable to open file %s\n",
           argv[0], argv[2]) ;
   return(-1) ;
}
inSubMtxFileName  = argv[3] ;
outSubMtxFileName = argv[4] ;
matlabFileName      = argv[5] ;
fprintf(msgFile, 
        "\n %s "
        "\n msglvl     -- %d" 
        "\n msgFile    -- %s" 
        "\n inFile     -- %s" 
        "\n outFile    -- %s" 
        "\n matlabFile -- %s" 
        "\n",
        argv[0], msglvl, argv[2], 
        inSubMtxFileName, outSubMtxFileName, matlabFileName) ;
fflush(msgFile) ;
/*
   ----------------------------
   read in the SubMtx object
   ----------------------------
*/
if ( strcmp(inSubMtxFileName, "none") == 0 ) { fprintf(msgFile, "\n no file to read from") ;
   exit(0) ;
}
mtx = SubMtx_new() ;
MARKTIME(t1) ;
rc = SubMtx_readFromFile(mtx, inSubMtxFileName) ;
MARKTIME(t2) ;
fprintf(msgFile, "\n CPU %9.5f : read in dmtx from file %s",
        t2 - t1, inSubMtxFileName) ;
if ( rc != 1 ) {
   fprintf(msgFile, 
           "\n return value %d from SubMtx_readFromFile(%p,%s)",
           rc, mtx, inSubMtxFileName) ;
   exit(-1) ;
}
fprintf(msgFile, "\n\n after reading SubMtx object from file %s",
        inSubMtxFileName) ;
fflush(msgFile) ;
if ( msglvl > 2 ) {
   SubMtx_writeForHumanEye(mtx, msgFile) ;
} else {
   SubMtx_writeStats(mtx, msgFile) ;
}
fflush(msgFile) ;
/*
   ----------------------------------------------
   hack to convert from row major to column major
   ----------------------------------------------
*/
/*
{
SubMtx   *mtx2 ;
double   *ent1, *ent2, *pXij, *pYij ;
int      *colind, *colind2, *rowind, *rowind2 ;
int      inc1, inc2, irow, jcol, ncol, nrow ;

mtx2 = SubMtx_new() ;
SubMtx_init(mtx2, DMTX_DENSE_COLUMNS, 0, 0, 
          mtx->nrow, mtx->ncol, mtx->nent) ;
SubMtx_denseInfo(mtx, &nrow, &ncol, &inc1, &inc2, &ent1) ;
SubMtx_denseInfo(mtx2, &nrow, &ncol, &inc1, &inc2, &ent2) ;
SubMtx_rowIndices(mtx, &nrow, &rowind) ;
SubMtx_rowIndices(mtx2, &nrow, &rowind2) ;
IVcopy(nrow, rowind2, rowind) ;
SubMtx_columnIndices(mtx, &ncol, &colind) ;
SubMtx_columnIndices(mtx2, &ncol, &colind2) ;
IVcopy(ncol, colind2, colind) ;
for ( jcol = 0 ; jcol < ncol ; jcol++ ) {
   for ( irow = 0 ; irow < nrow ; irow++ ) {
      pXij = SubMtx_locationOfEntry(mtx,  irow, jcol) ;
      pYij = SubMtx_locationOfEntry(mtx2, irow, jcol) ;
      *pYij = *pXij ;
   }
}
SubMtx_free(mtx) ;
mtx = mtx2 ;
}
*/
/*
   ----------------------------
   write out the SubMtx object
   ----------------------------
*/
if ( strcmp(outSubMtxFileName, "none") != 0 ) {
   MARKTIME(t1) ;
   rc = SubMtx_writeToFile(mtx, outSubMtxFileName) ;
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %9.5f : write mtx to file %s",
           t2 - t1, outSubMtxFileName) ;
}
if ( rc != 1 ) {
   fprintf(msgFile, 
           "\n return value %d from SubMtx_writeToFile(%p,%s)",
           rc, mtx, outSubMtxFileName) ;
}
/*
   ----------------------------------------------
   write out the SubMtx object to a matlab file
   ----------------------------------------------
*/
if ( strcmp(matlabFileName, "none") != 0 ) {
   if ( (fp = fopen(matlabFileName, "a")) == NULL ) {
      fprintf(stderr, "\n fatal error in %s"
              "\n unable to open file %s\n",
              argv[0], matlabFileName) ;
      return(-1) ;
   }
   MARKTIME(t1) ;
   SubMtx_writeForMatlab(mtx, "rhs", fp) ;
   MARKTIME(t2) ;
   fprintf(msgFile, "\n CPU %9.5f : write mtx to file %s",
           t2 - t1, matlabFileName) ;
}
/*
   -------------------------
   free the SubMtx object
   -------------------------
*/
SubMtx_free(mtx) ;

fprintf(msgFile, "\n") ;
fclose(msgFile) ;

return(1) ; }

/*--------------------------------------------------------------------*/