int main(int argc, const char **argv) { int ret = -1; void *zdbhandle = NULL; NetworkConfig Netconfig; WifiConfig WifiParam; InitWifiParam(&WifiParam); InitNetworkConfig(&Netconfig); if(ZDBOpen(Z_UTIL_ZQDEV,DBfile,&zdbhandle) != Z_SUCCESS){ ZCommandResponseError(SETNETWORKCONFIGURATION,1); return 1; } ret = GetNetworkConfig(&Netconfig, &WifiParam); if(ret != 0) { ZCommandResponseError(ZCOMMAND,1); goto funcOut; } ret = CheckNetConfig(&Netconfig); switch(ret) { case 1: ZCommandResponseError(SETNETWORKCONFIGURATION,6); goto funcOut; case 2: ZCommandResponseError(SETNETWORKCONFIGURATION,7); goto funcOut; case 3: ZCommandResponseError(SETNETWORKCONFIGURATION,8); goto funcOut; case 4: ZCommandResponseError(SETNETWORKCONFIGURATION,9); goto funcOut; case 5: ZCommandResponseError(SETNETWORKCONFIGURATION,10); goto funcOut; case 6: ZCommandResponseError(SETNETWORKCONFIGURATION,11); goto funcOut; } if(ret) { ZCommandResponseError(ZCOMMAND,3); goto funcOut; } ret = UpDateDataBase(zdbhandle, &Netconfig); UpDateWifiParam(zdbhandle,&WifiParam); if(ret != 0) { ZCommandResponseError(SETNETWORKCONFIGURATION,3); goto funcOut; } if(Netconfig.WireConfig.Enabled){ if(strcmp(Netconfig.WireConfig.Enabled,"1") == 0){ ret = BringUpNetwork(zdbhandle, &Netconfig.WireConfig, WIRE_NETWORK , NULL); if(ret != 0) { ZCommandResponseError(SETNETWORKCONFIGURATION,4); goto funcOut; } } } if(Netconfig.WifiConfig.Enabled){ if(strcmp(Netconfig.WifiConfig.Enabled,"1") == 0){ ret = BringUpNetwork(zdbhandle, &Netconfig.WifiConfig, WIFI_NETWORK , &WifiParam); if(ret != 0) { ZCommandResponseError(SETNETWORKCONFIGURATION,5); goto funcOut; } } } ret = WriteDNS(Netconfig.IPDNS1 ,0); ret = WriteDNS(Netconfig.IPDNS2 ,1); /* if(ret != 0) {*/ /* ZCommandResponseError(SETNETWORKCONFIGURATION,3);*/ /* goto funcOut;*/ /* } */ ZCommandResponseError(ZCOMMAND,0); funcOut: ZDBClose(zdbhandle); FreeWifiParam(&WifiParam); ConfigFree(&Netconfig); return ret; }
int main(int argc, char** argv) { int response; igraph_t graph; igraph_vector_ptr_t complist; iclust_collection * collection = NULL; time_t time_start, time_end; /* turn on attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); double minimal_weight; unsigned int maximal_steps_delimieter; char graphncol[1024], logconfig[1024]; Config *cfg = ConfigNew(); const char * configuration = getopt_configfile(argc, argv, "./graphtocluster.conf"); massert((ConfigReadFile(configuration, &cfg) == CONFIG_OK), "Configuration file is not readable"); ConfigReadString(cfg, "sources", "graphncol", graphncol, sizeof(graphncol), 0); ConfigReadString(cfg, "sources", "logconfig", logconfig, sizeof(logconfig), 0); ConfigReadDouble(cfg, "limits", "minimal_weight", &minimal_weight, 0); ConfigReadUnsignedInt(cfg, "limits", "maximal_steps_delimieter", &maximal_steps_delimieter, 1); massert((maximal_steps_delimieter > 0), "Delimiter can not be equal to zero"); ConfigFree(cfg); logger_init(logconfig, "graphtocluster"); logger_info("File:\t configuration %s", configuration); logger_info("File:\t configuration logger %s", logconfig); logger_info("File:\t ncol graph source %s", graphncol); logger_info("Min:\t edge weight %f", minimal_weight); logger_info("Max:\t step delimeter %u", maximal_steps_delimieter); FILE *graph_source = fopen(graphncol, "r"); response = igraph_read_graph_ncol(&graph, graph_source, NULL, true, IGRAPH_ADD_WEIGHTS_YES, 0); massert((response == IGRAPH_SUCCESS), "Can not read a graph"); logger_info("Count:\t edges at start: %d", igraph_ecount(&graph)); fclose(graph_source); time(&time_start); igraph_edges_remove_by(&graph, "weight", minimal_weight, double_lt); time(&time_end); logger_info("Time:\t remove edges: %f", difftime(time_end, time_start)); logger_info("Count:\t edges after remove: %d", igraph_ecount(&graph)); response = igraph_vector_ptr_init(&complist, 0); massert((response == IGRAPH_SUCCESS), "Can not initialize vector pointer"); response = igraph_decompose(&graph, &complist, IGRAPH_WEAK, -1, 0); massert((response == IGRAPH_SUCCESS), "Can not decompose graph"); unsigned int n = igraph_vector_ptr_size(&complist); collection = iclust_collection_new(); massert((collection != NULL), "Cluster collection object can not be empty"); time(&time_start); for (unsigned int i = 0; i < n; i++) { igraph_t *subgraph = VECTOR(complist)[i]; massert((subgraph != NULL), "Subgraph object can not be empty"); iclust_collection_fill_leading_eigenvector(collection, subgraph, (i + 1), maximal_steps_delimieter); igraph_destroy(subgraph); } time(&time_end); logger_info("Time:\t cluster: %f", difftime(time_end, time_start)); /* Sort collection by cluster id to be * able to build a second column correct*/ time(&time_start); iclust_collection_sort(collection); time(&time_end); logger_info("Time:\t cluster sorting: %f", difftime(time_end, time_start)); unsigned long cluster_index = 1, cluster = 0; for (unsigned long i = 0; i < collection->length; i++) { iclust_collection_element * element = collection->collection[i]; massert((element != NULL), "Cluster collection element object can not be empty"); if (element->cluster != cluster) { cluster = element->cluster; cluster_index = 0; } printf("%lu\t%lu\t%s\n", cluster, ++cluster_index, element->name); } iclust_collection_destroy(collection); igraph_vector_ptr_destroy(&complist); igraph_destroy(&graph); logger_destroy(); return EXIT_SUCCESS; }