no_stream.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "Gwater.h"
  2. int no_stream(int row, int col, CELL basin_num,
  3. double stream_length, CELL old_elev)
  4. {
  5. int r, rr, c, cc, uprow = 0, upcol = 0;
  6. double slope;
  7. CELL downdir, asp_value, hih_ele, new_ele, aspect;
  8. DCELL dvalue, max_drain; /* flow acc is now DCELL */
  9. int updir, riteflag, leftflag, thisdir;
  10. while (1) {
  11. bas[SEG_INDEX(bas_seg, row, col)] = basin_num;
  12. max_drain = -1;
  13. for (r = row - 1, rr = 0; r <= row + 1; r++, rr++) {
  14. for (c = col - 1, cc = 0; c <= col + 1; c++, cc++) {
  15. if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
  16. aspect = asp[SEG_INDEX(asp_seg, r, c)];
  17. if (aspect == drain[rr][cc]) {
  18. dvalue = wat[SEG_INDEX(wat_seg, r, c)];
  19. if (dvalue < 0)
  20. dvalue = -dvalue;
  21. if (dvalue > max_drain) {
  22. uprow = r;
  23. upcol = c;
  24. max_drain = dvalue;
  25. }
  26. }
  27. }
  28. }
  29. }
  30. if (max_drain > -1) {
  31. updir = drain[row - uprow + 1][col - upcol + 1];
  32. downdir = asp[SEG_INDEX(asp_seg, row, col)];
  33. if (downdir < 0)
  34. downdir = -downdir;
  35. if (arm_flag) {
  36. if (sides == 8) {
  37. if (uprow != row && upcol != col)
  38. stream_length += diag;
  39. else if (uprow != row)
  40. stream_length += window.ns_res;
  41. else
  42. stream_length += window.ew_res;
  43. }
  44. else { /* sides == 4 */
  45. asp_value = asp[SEG_INDEX(asp_seg, uprow, upcol)];
  46. if (downdir == 2 || downdir == 6) {
  47. if (asp_value == 2 || asp_value == 6)
  48. stream_length += window.ns_res;
  49. else
  50. stream_length += diag;
  51. }
  52. else { /* downdir == 4,8 */
  53. if (asp_value == 4 || asp_value == 8)
  54. stream_length += window.ew_res;
  55. else
  56. stream_length += diag;
  57. }
  58. }
  59. }
  60. riteflag = leftflag = 0;
  61. for (r = row - 1, rr = 0; rr < 3; r++, rr++) {
  62. for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
  63. if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
  64. aspect = asp[SEG_INDEX(asp_seg, r, c)];
  65. if (aspect == drain[rr][cc]) {
  66. thisdir = updrain[rr][cc];
  67. switch (haf_basin_side
  68. (updir, (int) downdir, thisdir)) {
  69. case LEFT:
  70. overland_cells(r, c, basin_num, basin_num - 1,
  71. &new_ele);
  72. leftflag++;
  73. break;
  74. case RITE:
  75. overland_cells(r, c, basin_num, basin_num,
  76. &new_ele);
  77. riteflag++;
  78. break;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. if (leftflag > riteflag)
  85. haf[SEG_INDEX(haf_seg, row, col)] = basin_num - 1;
  86. else
  87. haf[SEG_INDEX(haf_seg, row, col)] = basin_num;
  88. row = uprow;
  89. col = upcol;
  90. }
  91. else {
  92. if (arm_flag) {
  93. hih_ele = alt[SEG_INDEX(alt_seg, row, col)];
  94. slope = (hih_ele - old_elev) / stream_length;
  95. if (slope < MIN_SLOPE)
  96. slope = MIN_SLOPE;
  97. fprintf(fp, " %f %f\n", slope, stream_length);
  98. }
  99. haf[SEG_INDEX(haf_seg, row, col)] = basin_num;
  100. return 0;
  101. }
  102. }
  103. }