1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <time.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7
8 #include "cgns_io.h"
9
10 #if CG_HAVE_STAT64_STRUCT
11 #ifdef _WIN32
12 #define stat _stat64
13 #else
14 #define stat stat64
15 #endif
16 #endif
17
main(int argc,char ** argv)18 int main (int argc, char **argv)
19 {
20 char *inpfile, *outfile;
21 int inpcg;
22 size_t inpsize, outsize;
23 struct stat st;
24
25 if (argc < 2 || argc > 3) {
26 fprintf(stderr, "usage: cgnscompress InputFile [OutputFile]\n");
27 exit(1);
28 }
29 inpfile = argv[1];
30 outfile = argv[argc-1];
31
32 if (stat(inpfile, &st)) {
33 fprintf (stderr, "can't stat %s\n", inpfile);
34 exit (1);
35 }
36 inpsize = st.st_size;
37
38 if (cgio_open_file (inpfile, 'r', CGIO_FILE_NONE, &inpcg))
39 cgio_error_exit("cgio_open_file");
40 if (cgio_compress_file (inpcg, outfile))
41 cgio_error_exit("cgio_compress_file");
42
43 if (stat(outfile, &st)) {
44 fprintf (stderr, "can't stat %s\n", outfile);
45 exit (1);
46 }
47 outsize = st.st_size;
48
49 if (outsize < inpsize)
50 printf ("file size reduced from %.3g Mb to %.3g Mb (%d percent)\n",
51 (double)inpsize / 1048576.0, (double)outsize / 1048576.0,
52 (int)(100.0 * (double)(inpsize - outsize) / (double)inpsize));
53 else
54 printf ("no reduction in file size\n");
55 return 0;
56 }
57
58