Skip to content

Commit

Permalink
r.geomorphon: Declutter local_proto.h
Browse files Browse the repository at this point in the history
Remove unused macros, two variables and a typedef. Move variables that
only main() uses into main(). Move a few typedefs to the only files that
use them. Make a function static and remove declarations for functions
that do not exist.
  • Loading branch information
infrastation authored and wenzeslaus committed Oct 28, 2020
1 parent d024f3c commit f1616d1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 69 deletions.
71 changes: 3 additions & 68 deletions raster/r.geomorphon/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,10 @@
#define PI2 (2*atan(1))
#endif

#ifndef PI4 /* PI/4 */
#define PI4 (atan(1))
#endif

#ifndef PI
#define PI (4*atan(1))
#endif

#ifndef M2PI /* 2*PI */
#define M2PI (8*atan(1))
#endif

#ifndef GRADE
#define GRADE (atan(1)/45)
#endif


#ifndef PI2PERCENT
#define PI2PERCENT (50/atan(1))
#endif

#ifndef UNKNOWN
#define UNKNOWN -1
#endif


#define DEGREE2RAD(a) ((a)/(180/PI))
#define RAD2DEGREE(a) ((a)*(180/PI))

Expand All @@ -59,8 +37,6 @@
/* Number of cardinal directions. */
#define NUM_DIRS 8

typedef char *STRING;

typedef struct
{
char elevname[150];
Expand All @@ -69,24 +45,6 @@ typedef struct
int fd; /* file descriptor */
} MAPS;

typedef struct
{ /* struct is used both for interface and output */
char *name;
int required;
char *description;
char *gui;
RASTER_MAP_TYPE out_data_type;
int fd;
void *buffer;
} IO;

typedef struct
{
char name[100];
int fd;
CELL *forms_buffer;
} MULTI;

typedef struct
{
int num_positives;
Expand Down Expand Up @@ -125,33 +83,19 @@ typedef struct
char *label;
} CATCOLORS;

typedef struct
{
double cat;
int r;
int g;
int b;
char *label;
} FCOLORS;

/* main */
GLOBAL MAPS elevation;
GLOBAL int nrows, ncols, row_radius_size, row_buffer_size;
GLOBAL int search_cells, skip_cells, step_cells, start_cells;
GLOBAL int num_of_steps;
GLOBAL double search_distance, skip_distance, flat_distance;
GLOBAL double start_distance, step_distance; /* multiresolution mode */
GLOBAL int ncols, row_radius_size, row_buffer_size;
GLOBAL int skip_cells;
GLOBAL double search_distance, flat_distance;
GLOBAL double flat_threshold, flat_threshold_height;
GLOBAL double H, V;
GLOBAL struct Cell_head window;
GLOBAL int cell_step;
GLOBAL unsigned int global_ternary_codes[6562];

/* memory */
int open_map(MAPS * rast);
int create_maps(void);
int shift_buffers(int row);
int get_cell(int col, float *buf_row, void *buf, RASTER_MAP_TYPE raster_type);
int free_map(FCELL ** map, int n);
int write_form_cat_colors(char *raster, CATCOLORS * ccolors);
int write_contrast_colors(char *);
Expand All @@ -173,13 +117,4 @@ int shape(PATTERN * pattern, int pattern_size, float *azimuth,
float *elongation, float *width);
float extends(PATTERN * pattern, int pattern_size);
int radial2cartesian(PATTERN *);

/* multires */
int reset_multi_patterns(void);
int calc_multi_patterns(int row, int cur_row, int col);
int update_pattern(int k, int i,
double zenith_height, double zenith_distance,
double zenith_angle, double nadir_height,
double nadir_distance, double nadir_angle);

#endif
26 changes: 26 additions & 0 deletions raster/r.geomorphon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@

#define MAIN
#include "local_proto.h"

#define UNKNOWN -1

typedef enum
{ i_dem, o_forms, o_ternary, o_positive, o_negative, o_intensity,
o_exposition,
o_range, o_variance, o_elongation, o_azimuth, o_extend, o_width, io_size
} outputs;

typedef struct
{ /* struct is used both for interface and output */
char *name;
int required;
char *description;
char *gui;
RASTER_MAP_TYPE out_data_type;
int fd;
void *buffer;
} IO;

typedef struct
{
char name[100];
int fd;
CELL *forms_buffer;
} MULTI;

int main(int argc, char **argv)
{
IO rasters[] = { /* rasters stores output buffers */
Expand Down Expand Up @@ -91,7 +112,12 @@ int main(int argc, char **argv)
int i;
int meters = 0, multires = 0, extended = 0; /* flags */
int row, cur_row, col;
int nrows;
int pattern_size;
int search_cells, step_cells, start_cells;
int num_of_steps;
double start_distance, step_distance; /* multiresolution mode */
double skip_distance;
double max_resolution;
char prefix[20];

Expand Down
13 changes: 12 additions & 1 deletion raster/r.geomorphon/memory.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#include "local_proto.h"

typedef struct
{
double cat;
int r;
int g;
int b;
char *label;
} FCOLORS;

static int get_cell(int, float *, void *, RASTER_MAP_TYPE);

int open_map(MAPS * rast)
{

Expand Down Expand Up @@ -35,7 +46,7 @@ int open_map(MAPS * rast)
return 0;
}

int get_cell(int col, float *buf_row, void *buf, RASTER_MAP_TYPE raster_type)
static int get_cell(int col, float *buf_row, void *buf, RASTER_MAP_TYPE raster_type)
{

switch (raster_type) {
Expand Down

0 comments on commit f1616d1

Please sign in to comment.