1 /*
2  * Copyright 1997, Regents of the University of Minnesota
3  *
4  * graphchk.c
5  *
6  * This file checks the validity of a graph
7  *
8  * Started 8/28/94
9  * George
10  *
11  * $Id: graphchk.c 9982 2011-05-25 17:18:00Z karypis $
12  *
13  */
14 
15 #include "metisbin.h"
16 
17 
18 
19 /*************************************************************************/
20 /*! Let entry point of the checker */
21 /*************************************************************************/
main(int argc,char * argv[])22 int main(int argc, char *argv[])
23 {
24   graph_t *graph, *fgraph;
25   char filename[256];
26   idx_t wgtflag;
27   params_t params;
28 
29   if (argc != 2 && argc != 3) {
30     printf("Usage: %s <GraphFile> [FixedGraphFile (for storing the fixed graph)]\n", argv[0]);
31     exit(0);
32   }
33 
34   memset((void *)&params, 0, sizeof(params_t));
35   params.filename = gk_strdup(argv[1]);
36 
37   graph = ReadGraph(&params);
38   if (graph->nvtxs == 0) {
39     printf("Empty graph!\n");
40     exit(0);
41   }
42 
43   printf("**********************************************************************\n");
44   printf("%s", METISTITLE);
45   printf(" (HEAD: %s, Built on: %s, %s)\n", SVNINFO, __DATE__, __TIME__);
46   printf(" size of idx_t: %zubits, real_t: %zubits, idx_t *: %zubits\n",
47       8*sizeof(idx_t), 8*sizeof(real_t), 8*sizeof(idx_t *));
48   printf("\n");
49   printf("Graph Information ---------------------------------------------------\n");
50   printf("  Name: %s, #Vertices: %"PRIDX", #Edges: %"PRIDX"\n\n",
51       params.filename, graph->nvtxs, graph->nedges/2);
52   printf("Checking Graph... ---------------------------------------------------\n");
53 
54   if (CheckGraph(graph, 1, 1)) {
55     printf("   The format of the graph is correct!\n");
56   }
57   else {
58     printf("   The format of the graph is incorrect!\n");
59     if (argc == 3) {
60       fgraph = FixGraph(graph);
61       WriteGraph(fgraph, argv[2]);
62       FreeGraph(&fgraph);
63       printf("   A corrected version was stored at %s\n", argv[2]);
64     }
65   }
66 
67   printf("\n**********************************************************************\n");
68 
69 
70   FreeGraph(&graph);
71   gk_free((void **)&params.filename, &params.tpwgtsfile, &params.tpwgts, LTERM);
72 }
73 
74 
75