#include #include #include "delta.h" /*************************************************************************** GetNeighbors() This function creates an array of all the neighbors to a given (x,y) pair of points. Value of -9 indicates a neighbor outside the grid. Arguments: struct Basin *basin pointer to basin parameters int x center x int y, center y Return Value: pointer to array of neighbor (x,y) pairs. ****************************************************************************/ void GetNeighbors(struct Basin *basin, struct Local *local, int x, int y) { int i, j, k; struct Local neighbors[8]; if(y > basin->ymax[0] || x > basin->xmax[0]) { printf("\nCoordinates for GetNeighbor lie outside grid:"); exit(EXIT_FAILURE); } for(k = 0; k < 8; k++) { neighbors[k].x[0] = -9; neighbors[k].y[0] = -9; } for(k = 0, i = (y-1); i < (y+2); i++) { for(j = (x-1); j < (x+2); j++, k++, local++) { local->y[0] = neighbors[k].y[0] = i; local->x[0] = neighbors[k].x[0] = j; if(i >= basin->ymax[0] || j >= basin->xmax[0] || i < 0 || j < 0) { local->y[0] = neighbors[k].y[0] = -9; local->x[0] = neighbors[k].x[0] = -9; k--; local--; } if(i == y && j == x) { k--; local--; } } } }