• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

MakefileH A D10-Oct-2021175 116

READMEH A D10-Oct-20215.8 KiB129103

dopolys.cH A D10-Oct-20212.4 KiB10580

filldir.cH A D10-Oct-20214.1 KiB192152

local.hH A D10-Oct-2021224 65

main.cH A D10-Oct-202110.3 KiB371259

ppupdate.cH A D10-Oct-20215.4 KiB221170

resolve.cH A D10-Oct-20215 KiB214171

tinf.cH A D10-Oct-20216.9 KiB390316

tinf.hH A D10-Oct-20212.3 KiB9869

wtrshed.cH A D10-Oct-20215.7 KiB232165

README

1Date: Wed, 09 May 2001 22:49:03 -0600
2From: "Roger S. Miller" <rgrmill@rt66.com>
3To: Markus Neteler <neteler@geog.uni-hannover.de>
4Subject: r.fill.dir
5
6Markus,
7
8I think I finally completed all the changes I was going to make on
9r.fill.dir.
10I haven't had time yet to set up CVS or get a CVS account.  The modified
11code is in the attached zip file, along with the little shell script
12that I've been using to compile it.
13
14There's a short description in the last half of this letter about the
15methods I used to handle CELL, FCELL and DCELL maps.
16
17The program is now entirely in C and uses the gislib functions for all
18input and output.  It handles CELL, FCELL and DCELL rasters and I think
19it handles nulls correctly.
20
21I completely rewrote all of the larger code segments and the program now
22runs about 3 times faster than the original fortran version.  It also
23uses less memory and uses only three temp files.
24
25I've added a flag and an option to produce a third output file,
26otherwise the command line is identical to the original.  The new output
27file is a map of any areas that have not been filled.  The flag "f"
28instructs the program to fill single-cell pits but otherwise to just
29find the undrained areas and exit. With the "f" flag set the program
30writes an elevation map with just single-cell pits filled, a direction
31map with unresolved problems and a map of the undrained areas that were
32found but not filled.
33
34I included these options because I found while running test cases that
35filling DEMs was often not the best way to solve a drainage problem.
36The new options let the user get a partially-fixed elevation map,
37identify the remaining problems and fix the problems appropriately.
38
39I used a couple USGS 1-degree DEMS to benchmark the new code against the
40old one.  The results are substantially identical except for three
41cases:
42
431) The original code didn't consider the two outer rows and columns
44around the edge of the map.  The new code only neglects the outer-most
45row and column.  As a result, the two codes gave results that sometimes
46differed at the edge of the map.
47
482) The new code was able to solve problems that the old code would not
49solve.
50
513) The new code may require several repeated runs (using output from one
52run as input to the next run) to completely solve the elevation map.  In
53the only case where this happened the old code didn't solve the problem
54at all.
55
56As a final test for the new code I used a part of the gtopo30 dem that
57covers the southwestern US.  The part I extracted covered New Mexico,
58about half of Colorado, large parts of Kansas, Oklahoma and Texas, and
59adjoining areas in Mexico.  The modified code found more than 10,000
60areas to fill, and got them all filled in 5 runs.  I didn't even try
61that problem with the original code.  I doubt seriously that it would
62have run it at all.
63
64I took an approach to writing the code to handle CELL, FCELL and DCELL
65maps that you might find interesting.  I don't know all of the methods
66that others use, so it may not be new.  The file "tinf.c" (for Type
67INdependent Functions) contains functions for executing simple
68operations.  There are three versions of each function, one for CELL,
69one for FCELL and one for DCELL.  The file "tinf.h" contains the
70prototypes for those functions, plus the declarations for a number of
71function pointers.  The file "tinf.c" also contains a function named
72"set_func_pointers" that assigns the correct function to the function
73pointer.  The code to read, write or process a raster file is written
74using the function pointers, not the original function.
75
76For example, tinf.c contains three functions that calculate the
77difference between two values.  These are diff_c (for CELL values)
78diff_f (for FCELL values) and diff_d (for DCELL values).  All three
79functions have the same prototypes except for their names.  tinf.h
80contains the prototypes for those functions, plus the declaration for a
81function pointer "diff".  When the program runs it checks to see the
82type of the input raster map, then calls set_func_pointers to assign the
83correct function to the pointer "diff"; if the input is a CELL map then
84"diff" points to diff_c, if it's an FCELL map then "diff" points to
85diff_f and if it's a DCELL map then "diff" points to diff_d.  The rest
86of the code is written using the function pointer diff, rather than the
87actual function.
88
89This method really works out well for i/o.  Look at the simple method
90used in main.c to read and write the input and output maps.  Other
91operations are also simplified, though the difference isn't as
92outstanding.
93
94Instead of:
95   if(type==CELL)cellvalue1-=cellvalue2;
96   else if(type==FCELL)fcellvalue1-=fcellvalue2;
97   else if(type==DCELL)dcellvalue1-=dcellvalue2;
98
99
100one can write just the single line:
101   diff((void *)&value1,(void *)&value2);
102
103This works regardless of the type of value1 and value2, as long as they
104are both the same type.
105
106With this method the program only tests once for the type of the input
107map, and that's done with a call to set_func_pointers.  The program
108never passes the map type to a function and the program doesn't include
109duplicate code to account for different map types.  All the
110type-dependent coding is already done.
111
112The disadvantage is that most of the parameters passed to the
113type-independent functions and most of the values returned by them must
114be void pointers, and that leads to some cumbersome expressions.  Also,
115it generally isn't possible to use "=" in any expression.  Instead you
116have to use "memcpy" or something similar to move values around.
117
118The tinf.c and tinf.h files contain functions to handle basic raster
119i/o, simple math operations, variable initializations, testing for
120greater than and less than and a few other things.  A few more general
121functions might also be useful, and some applications will require
122specialized functions.
123
124This might make it considerably easier to write programs that have to
125read, handle and write maps of variable types.
126
127
128Roger
129