diff options
author | Jaron Kent-Dobias <jkentdobias@g.hmc.edu> | 2016-08-22 10:11:14 -0400 |
---|---|---|
committer | Jaron Kent-Dobias <jkentdobias@g.hmc.edu> | 2016-08-22 10:11:14 -0400 |
commit | 2bb0740b68fdb62d45adc00204b3990ca42ade77 (patch) | |
tree | a52975e3460da781467ddb70aaa8d76840d01bb4 /src/bin_values.c | |
download | fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.tar.gz fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.tar.bz2 fuse_networks-2bb0740b68fdb62d45adc00204b3990ca42ade77.zip |
started repo again without all the data files gunking the works
Diffstat (limited to 'src/bin_values.c')
-rw-r--r-- | src/bin_values.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/bin_values.c b/src/bin_values.c new file mode 100644 index 0000000..2cb9cf6 --- /dev/null +++ b/src/bin_values.c @@ -0,0 +1,23 @@ + +#include "fracture.h" + +double *bin_values(fnet *network, unsigned int width, double *values) { + double *binned = calloc(pow(width, 2), sizeof(double)); + unsigned int *num_binned = calloc(pow(width, 2), sizeof(unsigned int)); + for (unsigned int i = 0; i < network->num_edges; i++) { + if (values[i] != 0) { + unsigned int x = ((int)(network->edge_coords[2 * i] * width)) % width; + unsigned int y = ((int)(network->edge_coords[2 * i + 1] * width)) % width; + binned[width * x + y] += fabs(values[i]); + num_binned[width * x + y]++; + } + } + + for (unsigned int i = 0; i < pow(width, 2); i++) { + if (num_binned[i] != 0) { + binned[i] /= num_binned[i]; + } + } + + return binned; +} |