00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <unistd.h>
00038 #include <errno.h>
00039 #include <igraph/igraph.h>
00040
00041 #ifndef DEPLOY_SENSORS_FILE
00042 #define DEPLOY_SENSORS_FILE "deploy_sensors.R"
00043 #endif
00044
00045
00046 int EuclideanNeighbors(const char *network,
00047 unsigned int x, unsigned int y, unsigned int radius,
00048 igraph_t *neighbor_graph)
00049 {
00050 const char *R_file = DEPLOY_SENSORS_FILE;
00051 const char *neighborhood = ".tmp.gml";
00052 FILE *neighborhood_file;
00053 int err, stat;
00054 char cmd[512];
00055 const char *redirect = " &> /dev/null";
00056 #ifdef DEBUG
00057 redirect = "";
00058 #endif
00059
00060 sprintf(cmd, "Rscript %s \'SaveNeighborGraph(\"%s\", %u, %u, %u, \"%s\")\'%s",
00061 R_file, network, x, y, radius, neighborhood, redirect);
00062 #ifdef DEBUG
00063 fprintf(stderr, "Executing: %s\n", cmd);
00064 #endif
00065 if ((stat = system(cmd)) < 0)
00066 return -1;
00067 if (!WIFEXITED(stat) || WEXITSTATUS(stat) < 0)
00068 return -1;
00069
00070 if ((neighborhood_file = fopen(neighborhood, "r")) == NULL) {
00071 perror("fopen");
00072 return -errno;
00073 }
00074 if ((err = igraph_read_graph_gml(neighbor_graph, neighborhood_file)) < 0) {
00075 perror("igraph_read_graph_gml");
00076 return err;
00077 }
00078 fclose(neighborhood_file);
00079 unlink(neighborhood);
00080
00081 return 0;
00082 }