int main(int argc, char **argv) { graph *g; struct arguments args; argp_parse (&argp, argc, argv, 0, 0, &args); /* parse command line */ logfile = fopen(args.logfile,"w"); if (logfile==NULL) { perror("could not open log file for writing"); exit(-4); } fprintf(logfile, "file to read: %s\n", args.filename); fprintf(logfile, "number of eigenpairs to be computed: %u\n", args.nev); g = graph_from_file(args.filename); if (g == NULL) { fprintf(stderr, "could not build network from file %s\n", args.filename); exit(-2); } /* check if the graph is connected */ if (!connected_graph(g)) { fprintf(stderr, "The network is not connected: exiting\n"); exit(-5); } /* check nev */ if (args.nev<3 || args.nev>=g->n) { fprintf(stderr, "number of eigenpairs out of range:\n"); fprintf(stderr, "it must be larger than 2 and smaller than the number of nodes\n"); exit(-1); } find_comm(g,args.nev,args.flag); freegraph(g); fclose(logfile); exit(0); }
int main() { char line[BUFSIZ]; int row[BUFSIZ]; int opt = 0; FILE* file= NULL; //char* fn = NULL; int ncol= 0; int tmp = 0; graph* g = NULL; int* ap = NULL; // pointer within g->adjmtx router* r = NULL; int fromto[2] = { 0, 0 }; for (;;) { printf("\n%s\n", menu); switch (readNat(&opt)) { case 0: freegraph(&g); goto END; case 1: printf("%s\n", prompt1); //fn = readFilename(); if ((file = fopen(readFilename(), "r")) == NULL) { printf("File not found.\n"); break; } // file is opened while (getaline(line, BUFSIZ, file)) {//printf("while ...\n"); tmp = 0; if ((tmp = linetoints(line, row)) > 0) { if (ncol == 0) {// 1st row ncol = tmp; if (g != NULL) freegraph(&g); // g == NULL g = makegraph(ncol); ap = g->adjmtx + intcpy(g->adjmtx, row, ncol); } else if (ncol == tmp) { ap += intcpy(ap, row, ncol); } else { printf("File content invalid: different number of elements on different rows.\n"); break; } } } ncol = 0; fclose(file); //if (isvalidgraph(g)) {// graph is created printf("Original routing table is as follows:\n"); printgraph(g); /*} else { freegraph(&g); printf("File content invalid: elements on upper-left to bottom-right diagonal are not all-zero, "); printf("or, the upper-right half of the matrix and the bottom-left half are not symmetric.\n"); }*/ break; case 2: if (g == NULL) { printf("There is no data currently.\nPlease use option 1 to read a routing table data file first.\n"); break; } printf("%s\n", prompt2); if (readNat(&tmp) < 0 || tmp > g->size) { printf("Not a valid router id.\n"); break; } r = makerouter(tmp, g->size); buildtable(r, g); printf("The routing table for router %d is:\n", r->id); printrouter(r); freerouter(r); break; case 3: if (g == NULL) { printf("There is no data currently.\nPlease use option 1 to read a routing table data file first.\n"); break; } printf("%s\n", prompt3); if (read2Nats(fromto) < 0 || fromto[0] > g->size || fromto[1] > g->size) { printf("Invalid input. Please follow the format:\n\tvalid_src_router_id valid_dest_router_id.\n"); break; } // fromto[2] is valid r = makerouter(fromto[0], g->size); dijkstra(g, r->id, r->varray); printpath(r, fromto[1]); freerouter(r); break; default: printf("%s\n", prompt0); break; } } END: return 0; }