-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconverseg.c
152 lines (129 loc) · 3.74 KB
/
converseg.c
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
/* converseg.c version 2.0; B D McKay, Jun 2015. */
#define USAGE "converseg [-q] [infile [outfile]]"
#define HELPTEXT \
" Take the converse digraphs of a file of directed graphs.\n\
\n\
The output file has a header if and only if the input file does.\n\
Undirected graphs are passed through without change, while\n\
directed graphs are written in digraph6 format.\n\
\n\
-q Suppress auxiliary information.\n"
/*************************************************************************/
#include "gtools.h"
/**************************************************************************/
static void
conv(graph *g, int m, int n)
/* Replace g by its converse */
{
int i,j;
graph *gi,*gj;
for (i = 0, gi = g; i < n; ++i, gi += m)
for (j = i+1, gj = gi+m; j < n; ++j, gj += m)
if ((ISELEMENT(gi,j)!=0) + (ISELEMENT(gj,i)!=0) == 1)
{
FLIPELEMENT(gi,j);
FLIPELEMENT(gj,i);
}
}
/**************************************************************************/
int
main(int argc, char *argv[])
{
char *infilename,*outfilename;
FILE *infile,*outfile;
boolean badargs,quiet;
boolean digraph;
int j,m,n,argnum;
int codetype,outcode;
graph *g;
// size_t ii,ned,nedc,nn,loops,loopsc,gwords;
nauty_counter nin;
char *arg,sw;
double t;
HELP; PUTVERSION;
infilename = outfilename = NULL;
badargs = FALSE;
quiet = FALSE;
argnum = 0;
badargs = FALSE;
for (j = 1; !badargs && j < argc; ++j)
{
arg = argv[j];
if (arg[0] == '-' && arg[1] != '\0')
{
++arg;
while (*arg != '\0')
{
sw = *arg++;
SWBOOLEAN('q',quiet)
else badargs = TRUE;
}
}
else
{
++argnum;
if (argnum == 1) infilename = arg;
else if (argnum == 2) outfilename = arg;
else badargs = TRUE;
}
}
if (badargs)
{
fprintf(stderr,">E Usage: %s\n",USAGE);
GETHELP;
exit(1);
}
if (!quiet)
{
fprintf(stderr,">A converseg");
if (argnum > 0) fprintf(stderr," %s",infilename);
if (argnum > 1) fprintf(stderr," %s",outfilename);
fprintf(stderr,"\n");
fflush(stderr);
}
if (infilename && infilename[0] == '-') infilename = NULL;
infile = opengraphfile(infilename,&codetype,FALSE,1);
if (!infile) exit(1);
if (!infilename) infilename = "stdin";
if (!outfilename || outfilename[0] == '-')
{
outfilename = "stdout";
outfile = stdout;
}
else if ((outfile = fopen(outfilename,"w")) == NULL)
{
fprintf(stderr,"Can't open output file %s\n",outfilename);
gt_abort(NULL);
}
if (codetype&SPARSE6) outcode = SPARSE6;
else if (codetype&DIGRAPH6) outcode = DIGRAPH6;
else outcode = GRAPH6;
if (codetype&HAS_HEADER)
{
if (outcode == SPARSE6) writeline(outfile,SPARSE6_HEADER);
else if (outcode == DIGRAPH6) writeline(outfile,DIGRAPH6_HEADER);
else writeline(outfile,GRAPH6_HEADER);
}
gtools_check(WORDSIZE,1,1,NAUTYVERSIONID);
nin = 0;
t = CPUTIME;
while (TRUE)
{
if ((g = readgg(infile,NULL,0,&m,&n,&digraph)) == NULL) break;
++nin;
if (!digraph)
writelast(outfile);
else
{
conv(g,m,n);
writed6(outfile,g,m,n);
}
FREES(g);
}
t = CPUTIME - t;
if (!quiet)
fprintf(stderr,">Z " COUNTER_FMT
" graphs converted from %s to %s in %3.2f sec.\n",
nin,infilename,outfilename,t);
exit(0);
}