print.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "watershed.h"
  2. #include "string.h"
  3. int print_output(OUTPUT * output)
  4. {
  5. double cell_size;
  6. int b, c;
  7. CAT *do_cat;
  8. char *cat_name, area[32];
  9. cell_size = output->window.ns_res * output->window.ew_res;
  10. for (c = output->num_basins - 1; c >= 0; c--) {
  11. if (output->basin_facts[c].valid == 1)
  12. fprintf(output->out_file,
  13. "\nValid Basin: %-5d flows into basin: %-5d at: E=%.1f N=%.1f\n",
  14. (c + 1) * 2, (output->basin_facts[c].down_basin + 1) * 2,
  15. output->basin_facts[c].easting,
  16. output->basin_facts[c].northing);
  17. else
  18. fprintf(output->out_file,
  19. "\nInvalid basin: %-5d flows into basin: %-5d at: E=%.1f N=%.1f\n",
  20. (c + 1) * 2, (output->basin_facts[c].down_basin + 1) * 2,
  21. output->basin_facts[c].easting,
  22. output->basin_facts[c].northing);
  23. fprintf(output->out_file,
  24. " Str. length:%-.3f meters, %-.3f feet; Str. slope:%-.4f\n",
  25. output->basin_facts[c].str_length,
  26. (double)(output->basin_facts[c].str_length * METER_TO_FOOT),
  27. output->basin_facts[c].str_slope);
  28. switch (output->type_area) {
  29. case 1:
  30. fprintf(output->out_file, " Basin Area acres: %-16.4f",
  31. output->basin_facts[c].num_cells * cell_size *
  32. METERSQ_TO_ACRE);
  33. break;
  34. case 2:
  35. fprintf(output->out_file, " Basin Area sq. meters: %-11.3f",
  36. output->basin_facts[c].num_cells * cell_size);
  37. break;
  38. case 3:
  39. fprintf(output->out_file, " Basin Area miles sq: %-16.5f",
  40. output->basin_facts[c].num_cells * cell_size *
  41. METERSQ_TO_MILESQ);
  42. break;
  43. case 4:
  44. fprintf(output->out_file, " Basin Area hectareas: %-14.4f",
  45. output->basin_facts[c].num_cells * cell_size *
  46. METERSQ_TO_HECTACRE);
  47. break;
  48. case 5:
  49. fprintf(output->out_file, " Basin Area kilometers: %-13.4f",
  50. output->basin_facts[c].num_cells * cell_size *
  51. METERSQ_TO_KILOSQ);
  52. break;
  53. case 6:
  54. fprintf(output->out_file, " Basin Area in cells: %-16d",
  55. output->basin_facts[c].num_cells);
  56. break;
  57. }
  58. fprintf(output->out_file, " Area Percent Basin\n");
  59. for (b = 0; b < output->num_maps; b++) {
  60. fprintf(output->out_file,
  61. "<< %20s >> map layer, average catagory value: %.2f\n",
  62. output->maps[b].name,
  63. ((double)output->maps[b].basins[c].sum_values) /
  64. output->basin_facts[c].num_cells);
  65. do_cat = &(output->maps[b].basins[c].first_cat);
  66. while ((output->maps[b].do_cats != 0) && do_cat) {
  67. cat_name =
  68. Rast_get_c_cat(&(do_cat->cat_val), &(output->maps[b].cats));
  69. switch (output->type_area) {
  70. case 1:
  71. sprintf(area, "%.3f acres",
  72. METERSQ_TO_ACRE * cell_size * do_cat->num_cat);
  73. break;
  74. case 2:
  75. sprintf(area, "%.2f sq. meters",
  76. cell_size * do_cat->num_cat);
  77. break;
  78. case 3:
  79. sprintf(area, "%.4f sq. miles",
  80. METERSQ_TO_MILESQ * cell_size * do_cat->num_cat);
  81. break;
  82. case 4:
  83. sprintf(area, "%.3f hectacres",
  84. METERSQ_TO_HECTACRE * cell_size *
  85. do_cat->num_cat);
  86. break;
  87. case 5:
  88. sprintf(area, "%.3f sq. km.",
  89. METERSQ_TO_KILOSQ * cell_size * do_cat->num_cat);
  90. break;
  91. case 6:
  92. sprintf(area, "%6d cells", do_cat->num_cat);
  93. break;
  94. }
  95. fprintf(output->out_file, "%3d %-43s %16s %-.4f\n",
  96. do_cat->cat_val, cat_name, area,
  97. ((double)do_cat->num_cat) /
  98. output->basin_facts[c].num_cells);
  99. do_cat = do_cat->nxt;
  100. }
  101. }
  102. }
  103. return 0;
  104. }