1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard street, Cambridge, MA 02139 USA
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25
26 #include "test_utilities.inc"
27
print_attributes(const igraph_t * g)28 int print_attributes(const igraph_t *g) {
29
30 igraph_vector_t gtypes, vtypes, etypes;
31 igraph_strvector_t gnames, vnames, enames;
32 long int i;
33
34 igraph_vector_init(>ypes, 0);
35 igraph_vector_init(&vtypes, 0);
36 igraph_vector_init(&etypes, 0);
37 igraph_strvector_init(&gnames, 0);
38 igraph_strvector_init(&vnames, 0);
39 igraph_strvector_init(&enames, 0);
40
41 igraph_cattribute_list(g, &gnames, >ypes, &vnames, &vtypes,
42 &enames, &etypes);
43
44 for (i = 0; i < igraph_vcount(g); i++) {
45 long int j;
46 printf("Vertex %li: ", i);
47 for (j = 0; j < igraph_strvector_size(&vnames); j++) {
48 printf("%s=", STR(vnames, j));
49 if (VECTOR(vtypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
50 igraph_real_printf(VAN(g, STR(vnames, j), i));
51 putchar(' ');
52 } else {
53 printf("\"%s\" ", VAS(g, STR(vnames, j), i));
54 }
55 }
56 printf("\n");
57 }
58
59 for (i = 0; i < igraph_ecount(g); i++) {
60 long int j;
61 printf("Edge %li (%i-%i): ", i, (int)IGRAPH_FROM(g, i), (int)IGRAPH_TO(g, i));
62 for (j = 0; j < igraph_strvector_size(&enames); j++) {
63 printf("%s=", STR(enames, j));
64 if (VECTOR(etypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
65 igraph_real_printf(EAN(g, STR(enames, j), i));
66 putchar(' ');
67 } else {
68 printf("\"%s\" ", EAS(g, STR(enames, j), i));
69 }
70 }
71 printf("\n");
72 }
73
74 igraph_strvector_destroy(&enames);
75 igraph_strvector_destroy(&vnames);
76 igraph_strvector_destroy(&gnames);
77 igraph_vector_destroy(&etypes);
78 igraph_vector_destroy(&vtypes);
79 igraph_vector_destroy(>ypes);
80
81 return 0;
82 }
83
main()84 int main() {
85 igraph_t graph;
86 FILE *input;
87
88 /* turn on attribute handling */
89 igraph_set_attribute_table(&igraph_cattribute_table);
90
91 input = fopen("pajek_signed.net", "r");
92 if (input == 0) {
93 return 1;
94 }
95
96 igraph_read_graph_pajek(&graph, input);
97 fclose(input);
98
99 print_attributes(&graph);
100
101 igraph_destroy(&graph);
102
103 VERIFY_FINALLY_STACK();
104
105 return 0;
106 }
107