split_str.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "Gwater.h"
  2. CELL
  3. split_stream(int row, int col, int new_r[], int new_c[], int ct,
  4. CELL basin_num, double stream_length, CELL old_elev)
  5. {
  6. CELL downdir, old_basin, new_elev, aspect;
  7. double slope, easting, northing;
  8. int doit, ctr, updir, splitdir[9];
  9. int thisdir, leftflag, riteflag;
  10. int r, c, rr, cc;
  11. new_elev = 0;
  12. for (ctr = 1; ctr <= ct; ctr++)
  13. splitdir[ctr] = drain[row - new_r[ctr] + 1][col - new_c[ctr] + 1];
  14. updir = splitdir[1];
  15. downdir = asp[SEG_INDEX(asp_seg, row, col)];
  16. if (downdir < 0)
  17. downdir = -downdir;
  18. riteflag = leftflag = 0;
  19. for (r = row - 1, rr = 0; rr < 3; r++, rr++) {
  20. for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
  21. if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
  22. if (r == row && c == col)
  23. continue;
  24. aspect = asp[SEG_INDEX(asp_seg, r, c)];
  25. if (aspect == drain[rr][cc]) {
  26. doit = 1;
  27. thisdir = updrain[rr][cc];
  28. for (ctr = 1; ctr <= ct; ctr++) {
  29. if (thisdir == splitdir[ctr]) {
  30. doit = 0;
  31. ctr = ct;
  32. }
  33. }
  34. if (doit) {
  35. thisdir = updrain[rr][cc];
  36. switch (haf_basin_side
  37. (updir, (int) downdir, thisdir)) {
  38. case LEFT:
  39. overland_cells(r, c, basin_num, basin_num - 1,
  40. &new_elev);
  41. leftflag++;
  42. break;
  43. case RITE:
  44. overland_cells(r, c, basin_num, basin_num,
  45. &new_elev);
  46. riteflag++;
  47. break;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. if (leftflag >= riteflag) {
  55. haf[SEG_INDEX(haf_seg, row, col)] = basin_num - 1;
  56. }
  57. else {
  58. haf[SEG_INDEX(haf_seg, row, col)] = basin_num;
  59. }
  60. old_basin = basin_num;
  61. if (arm_flag) {
  62. new_elev = alt[SEG_INDEX(alt_seg, row, col)];
  63. if ((slope = (new_elev - old_elev) / stream_length) < MIN_SLOPE)
  64. slope = MIN_SLOPE;
  65. fprintf(fp, " %f %f\n", slope, stream_length);
  66. }
  67. for (r = 1; r <= ct; r++) {
  68. basin_num += 2;
  69. if (arm_flag) {
  70. easting = window.west + (new_c[r] + .5) * window.ew_res;
  71. northing = window.north - (new_r[r] + .5) * window.ns_res;
  72. fprintf(fp, "%5d drains into %5d at %3d %3d %.3f %.3f",
  73. (int)basin_num, old_basin, new_r[r], new_c[r], easting,
  74. northing);
  75. }
  76. if (new_r[r] != row && new_c[r] != col)
  77. basin_num =
  78. def_basin(new_r[r], new_c[r], basin_num, diag, new_elev);
  79. else if (new_r[r] != row)
  80. basin_num =
  81. def_basin(new_r[r], new_c[r], basin_num, window.ns_res,
  82. new_elev);
  83. else
  84. basin_num =
  85. def_basin(new_r[r], new_c[r], basin_num, window.ew_res,
  86. new_elev);
  87. }
  88. return (basin_num);
  89. }