#include #include int igraph_read_graph_extended_weighted_edgelist(igraph_t *graph, FILE *instream, igraph_integer_t n, igraph_bool_t directed) { igraph_vector_t edges=IGRAPH_VECTOR_NULL; igraph_vector_t ws=IGRAPH_VECTOR_NULL; igraph_vector_t ls=IGRAPH_VECTOR_NULL; igraph_vector_t vs=IGRAPH_VECTOR_NULL; long int id, label, value, nvertices; long int from, to, w; long int i; int c, read; igraph_vector_ptr_t weight; igraph_vector_ptr_t *pweight=0; igraph_vector_ptr_t vertexattr; igraph_vector_ptr_t *pvertexattr=0; igraph_i_attribute_record_t weightrec; igraph_i_attribute_record_t labelrec; igraph_i_attribute_record_t valuerec; IGRAPH_VECTOR_INIT_FINALLY(&ls, 0); IGRAPH_CHECK(igraph_vector_reserve(&ls, 100)); IGRAPH_VECTOR_INIT_FINALLY(&vs, 0); IGRAPH_CHECK(igraph_vector_reserve(&vs, 100)); IGRAPH_VECTOR_INIT_FINALLY(&edges, 0); IGRAPH_CHECK(igraph_vector_reserve(&edges, 100)); IGRAPH_VECTOR_INIT_FINALLY(&ws, 0); IGRAPH_CHECK(igraph_vector_reserve(&ws, 100)); /* skip all whitespace */ do { c = getc (instream); } while (isspace (c)); ungetc (c, instream); read=fscanf(instream, "*Vertices %li", &nvertices); if (read != 1) { IGRAPH_ERROR("parsing edgelist file failed 1", IGRAPH_PARSEERROR); } do { c = getc (instream); } while (isspace (c)); ungetc (c, instream); while (c != '*') { IGRAPH_ALLOW_INTERRUPTION(); read=fscanf(instream, "%li", &id); if (read != 1) { IGRAPH_ERROR("parsing edgelist file failed 2", IGRAPH_PARSEERROR); } read=fscanf(instream, "%li", &label); if (read != 1) { IGRAPH_ERROR("parsing edgelist file failed 3", IGRAPH_PARSEERROR); } read=fscanf(instream, "%li", &value); if (read != 1) { IGRAPH_ERROR("parsing edgelist file failed 4", IGRAPH_PARSEERROR); } IGRAPH_CHECK(igraph_vector_push_back(&ls, label)); IGRAPH_CHECK(igraph_vector_push_back(&vs, value)); /* skip all whitespace */ do { c = getc (instream); } while (isspace (c)); ungetc (c, instream); } /* Skip one line */ do { c=getc(instream); } while (c != '\n' && c != '\r'); do { c = getc (instream); } while (isspace (c)); ungetc (c, instream); while (!feof(instream)) { IGRAPH_ALLOW_INTERRUPTION(); read=fscanf(instream, "%li", &from); if (read != 1) { IGRAPH_ERROR("parsing edgelist file failed 6", IGRAPH_PARSEERROR); } read=fscanf(instream, "%li", &to); if (read != 1) { IGRAPH_ERROR("parsing edgelist file failed 7", IGRAPH_PARSEERROR); } read=fscanf(instream, "%li", &w); if (read != 1) { IGRAPH_ERROR("parsing edgelist file failed 8", IGRAPH_PARSEERROR); } IGRAPH_CHECK(igraph_vector_push_back(&edges, from)); IGRAPH_CHECK(igraph_vector_push_back(&edges, to)); IGRAPH_CHECK(igraph_vector_push_back(&ws, w)); /* skip all whitespace */ do { c = getc (instream); } while (isspace (c)); ungetc (c, instream); } IGRAPH_CHECK(igraph_empty(graph, 0, directed)); IGRAPH_FINALLY(igraph_destroy, graph); IGRAPH_CHECK(igraph_vector_ptr_init(&vertexattr, 2)); IGRAPH_FINALLY(igraph_vector_ptr_destroy, &vertexattr); pvertexattr=&vertexattr; labelrec.name="Label"; labelrec.type=IGRAPH_ATTRIBUTE_NUMERIC; labelrec.value=&ls; VECTOR(vertexattr)[0]=&labelrec; valuerec.name="Value"; valuerec.type=IGRAPH_ATTRIBUTE_NUMERIC; valuerec.value=&vs; VECTOR(vertexattr)[1]=&valuerec; IGRAPH_CHECK(igraph_add_vertices(graph, nvertices, pvertexattr)); IGRAPH_CHECK(igraph_vector_ptr_init(&weight, 1)); IGRAPH_FINALLY(igraph_vector_ptr_destroy, &weight); pweight=&weight; weightrec.name="Weight"; weightrec.type=IGRAPH_ATTRIBUTE_NUMERIC; weightrec.value=&ws; VECTOR(weight)[0]=&weightrec; IGRAPH_CHECK(igraph_add_edges(graph, &edges, pweight)); if (pweight) { igraph_vector_ptr_destroy(pweight); IGRAPH_FINALLY_CLEAN(1); } if (pvertexattr) { igraph_vector_ptr_destroy(pvertexattr); IGRAPH_FINALLY_CLEAN(1); } igraph_vector_destroy(&edges); igraph_vector_destroy(&ws); igraph_vector_destroy(&ls); igraph_vector_destroy(&vs); IGRAPH_FINALLY_CLEAN(1); return 0; } int print_attributes(const igraph_t *g) { igraph_vector_t gtypes, vtypes, etypes; igraph_strvector_t gnames, vnames, enames; long int i; igraph_vector_t vec; igraph_strvector_t svec; long int j; igraph_vector_init(>ypes, 0); igraph_vector_init(&vtypes, 0); igraph_vector_init(&etypes, 0); igraph_strvector_init(&gnames, 0); igraph_strvector_init(&vnames, 0); igraph_strvector_init(&enames, 0); igraph_cattribute_list(g, &gnames, >ypes, &vnames, &vtypes, &enames, &etypes); /* Graph attributes */ for (i=0; i