1 /* testIO.c */
2
3 #include "../DV.h"
4 #include "../../timings.h"
5
6 /*--------------------------------------------------------------------*/
7 int
main(int argc,char * argv[])8 main ( int argc, char *argv[] )
9 /*
10 ----------------------------------------------
11 test DV_readFromFile and DV_writeToFile,
12 useful for translating between formatted *.dvf
13 and binary *.dvb files.
14
15 created -- 98jun02, cca
16 ----------------------------------------------
17 */
18 {
19 char *inDVFileName, *outDVFileName ;
20 double t1, t2 ;
21 int msglvl, rc ;
22 DV *dvobj ;
23 FILE *msgFile ;
24
25 if ( argc != 5 ) {
26 fprintf(stdout,
27 "\n\n usage : %s msglvl msgFile inFile outFile"
28 "\n msglvl -- message level"
29 "\n msgFile -- message file"
30 "\n inFile -- input file, must be *.dvf or *.dvb"
31 "\n outFile -- output file, must be *.dvf or *.dvb"
32 "\n", argv[0]) ;
33 return(0) ;
34 }
35 msglvl = atoi(argv[1]) ;
36 if ( strcmp(argv[2], "stdout") == 0 ) {
37 msgFile = stdout ;
38 } else if ( (msgFile = fopen(argv[2], "a")) == NULL ) {
39 fprintf(stderr, "\n fatal error in %s"
40 "\n unable to open file %s\n",
41 argv[0], argv[2]) ;
42 return(-1) ;
43 }
44 inDVFileName = argv[3] ;
45 outDVFileName = argv[4] ;
46 fprintf(msgFile,
47 "\n %s "
48 "\n msglvl -- %d"
49 "\n msgFile -- %s"
50 "\n inFile -- %s"
51 "\n outFile -- %s"
52 "\n",
53 argv[0], msglvl, argv[2], inDVFileName, outDVFileName) ;
54 fflush(msgFile) ;
55 /*
56 ---------------------
57 read in the DV object
58 ---------------------
59 */
60 if ( strcmp(inDVFileName, "none") == 0 ) {
61 fprintf(msgFile, "\n no file to read from") ;
62 exit(0) ;
63 }
64 dvobj = DV_new() ;
65 MARKTIME(t1) ;
66 rc = DV_readFromFile(dvobj, inDVFileName) ;
67 MARKTIME(t2) ;
68 fprintf(msgFile, "\n CPU %9.5f : read in iv from file %s",
69 t2 - t1, inDVFileName) ;
70 if ( rc != 1 ) {
71 fprintf(msgFile, "\n return value %d from DV_readFromFile(%p,%s)",
72 rc, dvobj, inDVFileName) ;
73 exit(-1) ;
74 }
75 fprintf(msgFile, "\n\n after reading DV object from file %s",
76 inDVFileName) ;
77 if ( msglvl > 2 ) {
78 DV_writeForHumanEye(dvobj, msgFile) ;
79 } else {
80 DV_writeStats(dvobj, msgFile) ;
81 }
82 fflush(msgFile) ;
83 /*
84 -----------------------
85 write out the DV object
86 -----------------------
87 */
88 if ( strcmp(outDVFileName, "none") != 0 ) {
89 MARKTIME(t1) ;
90 rc = DV_writeToFile(dvobj, outDVFileName) ;
91 MARKTIME(t2) ;
92 fprintf(msgFile, "\n CPU %9.5f : write iv to file %s",
93 t2 - t1, outDVFileName) ;
94 }
95 if ( rc != 1 ) {
96 fprintf(msgFile, "\n return value %d from DV_writeToFile(%p,%s)",
97 rc, dvobj, outDVFileName) ;
98 }
99 /*
100 ------------------
101 free the DV object
102 ------------------
103 */
104 DV_free(dvobj) ;
105
106 fprintf(msgFile, "\n") ;
107 fclose(msgFile) ;
108
109 return(1) ; }
110
111 /*--------------------------------------------------------------------*/
112