|
@@ -42,7 +42,6 @@ int main(int argc, char *argv[])
|
|
|
struct Cell_head window;
|
|
|
int bot, right, t0, b0, l0, r0, clear = 0;
|
|
|
double Rw_l, Rscr_wl;
|
|
|
- char tmp[20];
|
|
|
void set_map();
|
|
|
|
|
|
setbuf(stdout, NULL); /* unbuffered */
|
|
@@ -62,8 +61,7 @@ int main(int argc, char *argv[])
|
|
|
user_input(argc, argv);
|
|
|
|
|
|
/* setup the current window for display */
|
|
|
- G_system(" d.colormode float");
|
|
|
- G_system(" d.frame -e");
|
|
|
+ G_system("d.frame -e");
|
|
|
Rw_l = (double)Rast_window_cols() / Rast_window_rows();
|
|
|
R_open_driver();
|
|
|
R_font("romant");
|
|
@@ -108,14 +106,13 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
|
|
- /* DISPLAY A MESSAGE AND THE MAP, THEN
|
|
|
- TRACE THE PATCHES AND DISPLAY THEM */
|
|
|
+ /* DISPLAY A MESSAGE AND THE MAP, THEN
|
|
|
+ TRACE THE PATCHES AND DISPLAY THEM */
|
|
|
|
|
|
void set_map(char *name, struct Cell_head window, int top, int bot, int left,
|
|
|
int right, char *fn)
|
|
|
{
|
|
|
char cmd[30];
|
|
|
- int i, k = 0, j, btn, d, class;
|
|
|
double msc[2];
|
|
|
void scr_cell(), cell_clip_drv(), show_patch();
|
|
|
|
|
@@ -124,9 +121,8 @@ void set_map(char *name, struct Cell_head window, int top, int bot, int left,
|
|
|
|
|
|
G_system("clear");
|
|
|
puts("\n\nR.LE.TRACE IS WORKING...\n");
|
|
|
- G_system("d.colormode mode=fixed");
|
|
|
- sprintf(cmd, "d.rast %s", name);
|
|
|
G_system("d.erase");
|
|
|
+ sprintf(cmd, "d.rast %s", name);
|
|
|
G_system(cmd);
|
|
|
|
|
|
/* setup the screen-cell array coordinate
|
|
@@ -149,14 +145,11 @@ void set_map(char *name, struct Cell_head window, int top, int bot, int left,
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- /* DISPLAY THE PATCH INFORMATION */
|
|
|
+ /* DISPLAY THE PATCH INFORMATION */
|
|
|
|
|
|
void show_patch(char *fn, double *msc, char *cmd)
|
|
|
{
|
|
|
PATCH *tmp, *tmp0;
|
|
|
- register int i;
|
|
|
int num;
|
|
|
char c;
|
|
|
void draw_patch(), patch_attr();
|
|
@@ -276,7 +269,7 @@ void show_patch(char *fn, double *msc, char *cmd)
|
|
|
}
|
|
|
|
|
|
|
|
|
- /* DISPLAY PATCH ATTRIBUTES ON THE SCREEN */
|
|
|
+ /* DISPLAY PATCH ATTRIBUTES ON THE SCREEN */
|
|
|
|
|
|
void patch_attr(FILE * fp, PATCH * p, int show)
|
|
|
{
|
|
@@ -328,7 +321,7 @@ void patch_attr(FILE * fp, PATCH * p, int show)
|
|
|
|
|
|
|
|
|
|
|
|
- /* PLACE PATCH NUMBERS ON THE SCREEN */
|
|
|
+ /* PLACE PATCH NUMBERS ON THE SCREEN */
|
|
|
|
|
|
void draw_patch(PATCH * p, double *m)
|
|
|
{
|
|
@@ -370,8 +363,8 @@ void scr_cell(struct Cell_head *wind, int top, int bot, int left, int right,
|
|
|
|
|
|
|
|
|
|
|
|
- /* DRIVER FOR CELL CLIPPING, TRACING,
|
|
|
- AND CALCULATIONS */
|
|
|
+ /* DRIVER FOR CELL CLIPPING, TRACING,
|
|
|
+ AND CALCULATIONS */
|
|
|
|
|
|
void cell_clip_drv(int col0, int row0, int ncols, int nrows, double **value,
|
|
|
int index)
|
|
@@ -429,11 +422,12 @@ void cell_clip_drv(int col0, int row0, int ncols, int nrows, double **value,
|
|
|
list_head = point to the patch list
|
|
|
*/
|
|
|
|
|
|
+ pat = NULL;
|
|
|
|
|
|
total_patches = 0;
|
|
|
|
|
|
name = choice->fn;
|
|
|
- mapset = G_mapset();
|
|
|
+ mapset = G_find_raster2(name, "");
|
|
|
data_type = Rast_map_type(name, mapset);
|
|
|
|
|
|
/* dynamically allocate storage for the
|
|
@@ -495,8 +489,8 @@ void cell_clip_drv(int col0, int row0, int ncols, int nrows, double **value,
|
|
|
|
|
|
|
|
|
|
|
|
- /* OPEN THE RASTER FILE TO BE CLIPPED,
|
|
|
- AND DO THE CLIPPING */
|
|
|
+ /* OPEN THE RASTER FILE TO BE CLIPPED,
|
|
|
+ AND DO THE CLIPPING */
|
|
|
|
|
|
void cell_clip(DCELL ** buf, DCELL ** null_buf, int row0, int col0, int nrows,
|
|
|
int ncols, int index, int *centernull)
|
|
@@ -505,7 +499,7 @@ void cell_clip(DCELL ** buf, DCELL ** null_buf, int row0, int col0, int nrows,
|
|
|
FCELL *ftmp;
|
|
|
DCELL *dtmp;
|
|
|
void *rastptr;
|
|
|
- char *tmpname;
|
|
|
+ char *tmpname, *name, *mapset;
|
|
|
int fr, x;
|
|
|
register int i, j;
|
|
|
double center_row = 0.0, center_col = 0.0;
|
|
@@ -551,22 +545,13 @@ void cell_clip(DCELL ** buf, DCELL ** null_buf, int row0, int col0, int nrows,
|
|
|
/* check for input raster map and open it; this
|
|
|
map remains open on finput while all the programs
|
|
|
run, so it is globally available */
|
|
|
+ name = choice->fn;
|
|
|
|
|
|
- if (0 > (finput = Rast_open_old(choice->fn, G_mapset()))) {
|
|
|
- fprintf(stderr, "\n");
|
|
|
- fprintf(stderr,
|
|
|
- " ********************************************************\n");
|
|
|
- fprintf(stderr,
|
|
|
- " The raster map you specified with the 'map=' parameter \n");
|
|
|
- fprintf(stderr,
|
|
|
- " was not found in your mapset. \n");
|
|
|
- fprintf(stderr,
|
|
|
- " ********************************************************\n");
|
|
|
- exit(1);
|
|
|
- }
|
|
|
+ if (0 > (finput = Rast_open_old(name, "")))
|
|
|
+ G_fatal_error(_("Unable to open raster map <%s>"), name);
|
|
|
|
|
|
- else
|
|
|
- data_type = Rast_map_type(choice->fn, G_mapset());
|
|
|
+ mapset = G_find_raster2(name, "");
|
|
|
+ data_type = Rast_map_type(name, mapset);
|
|
|
|
|
|
/* allocate memory to store a row of the
|
|
|
raster map, depending on the type of
|
|
@@ -727,14 +712,15 @@ void cell_clip(DCELL ** buf, DCELL ** null_buf, int row0, int col0, int nrows,
|
|
|
|
|
|
|
|
|
|
|
|
- /* DRIVER TO LOOK FOR NEW PATCHES, CALL
|
|
|
- THE TRACING ROUTINE, AND ADD NEW PATCHES
|
|
|
- TO THE PATCH LIST */
|
|
|
|
|
|
-void trace(int nrows, int ncols, DCELL ** buf, DCELL ** null_buf, CELL ** pat)
|
|
|
+ /* DRIVER TO LOOK FOR NEW PATCHES, CALL
|
|
|
+ THE TRACING ROUTINE, AND ADD NEW PATCHES
|
|
|
+ TO THE PATCH LIST */
|
|
|
+
|
|
|
+void trace(int nrows, int ncols, DCELL **buf, DCELL **null_buf, CELL **pat)
|
|
|
{
|
|
|
double class = 0.0;
|
|
|
- register int i, j, x;
|
|
|
+ register int i, j;
|
|
|
PATCH *tmp, *find_any, *list_head;
|
|
|
|
|
|
/*
|
|
@@ -744,20 +730,20 @@ void trace(int nrows, int ncols, DCELL ** buf, DCELL ** null_buf, CELL ** pat)
|
|
|
nrows = total number of rows in the area where tracing will occur
|
|
|
ncols = total number of cols in the area where tracing will occur
|
|
|
buf = pointer to array containing only the pixels inside the area
|
|
|
- that was clipped and within which tracing will now occur, so
|
|
|
- a smaller array than the original raster map
|
|
|
+ that was clipped and within which tracing will now occur, so
|
|
|
+ a smaller array than the original raster map
|
|
|
null_buf = pointer to array containing 0.0 if pixel in input raster map is
|
|
|
- not null and 1.0 if pixel in input raster map is null
|
|
|
+ not null and 1.0 if pixel in input raster map is null
|
|
|
pat = pointer to array containing the map of patch numbers; this map
|
|
|
- can only be integer
|
|
|
+ can only be integer
|
|
|
INTERNAL:
|
|
|
class = the attribute of each pixel
|
|
|
i, j = counts the row and column as the program goes through the area
|
|
|
tmp = pointer to a member of the PATCH list data structure, used to
|
|
|
- advance through the patch list
|
|
|
+ advance through the patch list
|
|
|
find_any = pointer to a member of the patch list to hold the results after
|
|
|
- routine get_bd is called to trace the boundary of the patch and
|
|
|
- save the patch information in the PATCH data structure
|
|
|
+ routine get_bd is called to trace the boundary of the patch and
|
|
|
+ save the patch information in the PATCH data structure
|
|
|
list_head = pointer to the first member of the patch list
|
|
|
*/
|
|
|
|
|
@@ -786,7 +772,7 @@ void trace(int nrows, int ncols, DCELL ** buf, DCELL ** null_buf, CELL ** pat)
|
|
|
|
|
|
list_head = patch_list;
|
|
|
|
|
|
- if (find_any = get_bd(i, j, nrows, ncols, class, buf, null_buf, list_head, pat)) { /*4 */
|
|
|
+ if ((find_any = get_bd(i, j, nrows, ncols, class, buf, null_buf, list_head, pat))) { /*4 */
|
|
|
|
|
|
/* if the first patch, make tmp point to
|
|
|
the patch list and add the first patch
|
|
@@ -840,11 +826,9 @@ void trace(int nrows, int ncols, DCELL ** buf, DCELL ** null_buf, CELL ** pat)
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- /* TRACE THE BOUNDARY OF A PATCH AND
|
|
|
- SAVE THE PATCH CHARACTERISTICS IN
|
|
|
- THE PATCH STRUCTURE */
|
|
|
+ /* TRACE THE BOUNDARY OF A PATCH AND
|
|
|
+ SAVE THE PATCH CHARACTERISTICS IN
|
|
|
+ THE PATCH STRUCTURE */
|
|
|
|
|
|
PATCH *get_bd(int row0, int col0, int nrows, int ncols, double class,
|
|
|
DCELL ** buf, DCELL ** null_buf, PATCH * p_list, CELL ** pat)
|