r.flow.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /****************************************************************************
  2. ** Written by Maros Zlocha, Jaroslav Hofierka, Helena Mitasova, Winter 1992
  3. ** Comenius University, Bratislava, Slovakia and
  4. ** US Army Construction Engineering Research Laboratories, Champaign, IL,USA.
  5. ** Copyright Maros Zlocha, Jaroslav Hofierka, Helena Mitasova, USA-CERL 1992
  6. ** Drastically re-engineered by Joshua Caplan, Spring, 1994
  7. ** Continued improvements by Mark Ruesink, Fall, 1995
  8. *****************************************************************************/
  9. /*
  10. * changes from version 6: lg matrix changed to single cell row buffer
  11. * x, y components of point structure are now exact coordinates
  12. * r, c reflect file structure (i.e. r = distance in ns-res units from N)
  13. * changes from version 7: next_point changed to eliminate arctangent
  14. * theta and other angles kept in degrees instead of radians
  15. * changes from version 8: tangents replaced by lookup table
  16. * bounding box re-introduced to reduce number of truncations
  17. * changes from version 9: source code split into separate modules
  18. * aspect optionally computed internally (aspin no longer required)
  19. * aspect optionally computed on the fly, eliminating o matrix
  20. * resolution no longer used to compute distances (allows lat/long proj)
  21. * downslope flag now the default, new options "bound", "-z", "-q" added
  22. * diagnostic/verbose output --> stderr; debugging output --> stdout
  23. * epsilon introduced to defeat quantization errors
  24. * changes from version 10: segmentation "-M" added, "-z" renamed to "-3"
  25. * further modularization and abstraction
  26. * changes from version 11: replaced function pointers get, put, ... by macros
  27. * changes from version 12: updated to read FP data, writing of lg file broken
  28. * changes from version 13: offset option added, fixed output of FP lg
  29. */
  30. #include <math.h>
  31. #include <grass/gis.h>
  32. #include <grass/raster.h>
  33. #include <grass/segment.h>
  34. #include <grass/vector.h>
  35. #include <grass/bitmap.h>
  36. #ifndef hypot
  37. #define hypot(x,y) (sqrt((x)*(x)+(y)*(y)))
  38. #endif
  39. #define ROUND(x) (int) ((x) + 0.5)
  40. #define D_PI 180.
  41. #define D2_PI 360.
  42. #define DEG2RAD M_D2R
  43. #define UNDEF 365. /* change to undefined when available */
  44. #define UNDEFZ 0. /* change to undefined when available */
  45. #define HORIZ 1 /* magic */
  46. #define VERT 0 /* numbers */
  47. typedef struct
  48. {
  49. char *elevin; /* name of input elevation file */
  50. char *aspin; /* name of input aspect file */
  51. char *barin; /* name of barrier input file */
  52. char *flout; /* name of output flowline file */
  53. char *lgout; /* name of output length file */
  54. char *dsout; /* name of output density file */
  55. int skip; /* cells between flowlines output */
  56. int bound; /* constant bound on path length */
  57. /* double offset; magnitude of random grid offset */
  58. char up; /* direction to compute lines */
  59. char l3d; /* three-dimensional length */
  60. char mem; /* always recompute aspect */
  61. char seg; /* use segmented arrays */
  62. }
  63. params;
  64. typedef struct
  65. {
  66. DCELL **buf; /* internal row storage */
  67. SEGMENT *seg; /* state for segment library */
  68. int sfd; /* file descriptor for segment file */
  69. int row_offset, /* border widths of buf (for */
  70. col_offset; /* extrapolating border data) */
  71. char *name; /* for error messages */
  72. }
  73. layer;
  74. /******************************* GLOBALS ********************************/
  75. extern struct Cell_head region;
  76. extern struct Map_info fl;
  77. extern struct BM *bitbar;
  78. extern int lgfd;
  79. extern char string[1024];
  80. extern layer el, as, ds;
  81. extern double *ew_dist;
  82. extern double *epsilon[2];
  83. extern params parm;