Slope Filter Code

/*

** slope.c

**

** DEM slope calculation filters:

**

** slope_deg - slope as a degree from 0 to 90 degrees

**

*/

#include "ERS.h"

#include "math.h"

static void local_init();

static double local_cell_size_x;

static double local_cell_size_y;

extern double sqrt();


/* * * * * * * * * * * * * * * * * * * */

double slope_deg(nr_rows, nr_cols, array)

int nr_rows;

int nr_cols;

double **array;

{

double dx1, dx2, dx3;

double dy1, dy2, dy3;

double dx, dy;

double slope;

dx1 = array[0][0] - array[2][0];

dx2 = array[0][1] - array[2][1];

dx3 = array[0][2] - array[2][2];

dy1 = array[0][2] - array[0][0];

dy2 = array[1][2] - array[1][0];

dy3 = array[2][2] - array[2][0];

dx = (dx1 + dx2 + dx3) / (3.0*local_cell_size_x);

dy = (dy1 + dy2 + dy3) / (3.0*local_cell_size_y);

slope = sqrt((dx*dx) + (dy*dy)) / 2.0;

slope = atan(slope) * (180.0 / M_PI);

return(slope);

}

/* * * * * * * * * * * * * * * * * * * */