report.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include <grass/dbmi.h>
  2. #include <grass/glocale.h>
  3. #include "global.h"
  4. int report(void)
  5. {
  6. int i;
  7. char left[20], right[20];
  8. if (!options.print && !(options.option == O_COUNT ||
  9. options.option == O_LENGTH ||
  10. options.option == O_AREA)) {
  11. G_warning(_("No totals for selected option"));
  12. return 0;
  13. }
  14. switch (options.option) {
  15. case O_CAT:
  16. if (G_verbose() > G_verbose_min())
  17. fprintf(stdout, "cat\n");
  18. for (i = 0; i < vstat.rcat; i++)
  19. fprintf(stdout, "%d\n", Values[i].cat);
  20. break;
  21. case O_COUNT:
  22. if (options.print) {
  23. if (G_verbose() > G_verbose_min())
  24. fprintf(stdout, "cat%scount\n", options.fs);
  25. for (i = 0; i < vstat.rcat; i++)
  26. fprintf(stdout, "%d%s%d\n", Values[i].cat, options.fs, Values[i].count1);
  27. }
  28. if (options.total) {
  29. int sum = 0;
  30. for (i = 0; i < vstat.rcat; i++) {
  31. sum += Values[i].count1;
  32. }
  33. fprintf(stdout, "total count%s%d\n", options.fs, sum);
  34. }
  35. break;
  36. case O_AREA:
  37. if (options.print) {
  38. if (G_verbose() > G_verbose_min())
  39. fprintf(stdout, "cat%sarea\n", options.fs);
  40. for (i = 0; i < vstat.rcat; i++)
  41. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  42. }
  43. if (options.total) {
  44. double sum = 0.0;
  45. for (i = 0; i < vstat.rcat; i++) {
  46. sum += Values[i].d1;
  47. }
  48. fprintf(stdout, "total area%s%.15g\n", options.fs, sum);
  49. }
  50. break;
  51. case O_COMPACT:
  52. if (G_verbose() > G_verbose_min())
  53. fprintf(stdout, "cat%scompact\n", options.fs);
  54. for (i = 0; i < vstat.rcat; i++)
  55. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  56. break;
  57. case O_PERIMETER:
  58. if (G_verbose() > G_verbose_min())
  59. fprintf(stdout, "cat%sperimeter\n", options.fs);
  60. for (i = 0; i < vstat.rcat; i++)
  61. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  62. break;
  63. case O_LENGTH:
  64. if (options.print) {
  65. if (G_verbose() > G_verbose_min())
  66. fprintf(stdout, "cat%slength\n", options.fs);
  67. for (i = 0; i < vstat.rcat; i++)
  68. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  69. }
  70. if (options.total) {
  71. double sum = 0.0;
  72. for (i = 0; i < vstat.rcat; i++) {
  73. sum += Values[i].d1;
  74. }
  75. fprintf(stdout, "total length%s%.15g\n", options.fs, sum);
  76. }
  77. break;
  78. case O_SLOPE:
  79. if (G_verbose() > G_verbose_min())
  80. fprintf(stdout, "cat%sslope\n", options.fs);
  81. for (i = 0; i < vstat.rcat; i++)
  82. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  83. break;
  84. case O_SINUOUS:
  85. if (G_verbose() > G_verbose_min())
  86. fprintf(stdout, "cat%ssinuous\n", options.fs);
  87. for (i = 0; i < vstat.rcat; i++)
  88. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  89. break;
  90. case O_COOR:
  91. case O_START:
  92. case O_END:
  93. if (G_verbose() > G_verbose_min())
  94. fprintf(stdout, "cat%sx%sy%sz\n", options.fs, options.fs, options.fs);
  95. for (i = 0; i < vstat.rcat; i++) {
  96. if (Values[i].count1 == 1)
  97. fprintf(stdout, "%d%s%.15g%s%.15g%s%.15g\n", Values[i].cat, options.fs,
  98. Values[i].d1, options.fs, Values[i].d2, options.fs, Values[i].d3);
  99. }
  100. break;
  101. case O_SIDES:
  102. if (G_verbose() > G_verbose_min())
  103. fprintf(stdout, "cat%sleft%sright\n", options.fs, options.fs);
  104. for (i = 0; i < vstat.rcat; i++) {
  105. if (Values[i].count1 == 1) {
  106. if (Values[i].i1 >= 0)
  107. sprintf(left, "%d", Values[i].i1);
  108. else
  109. sprintf(left, "-1"); /* NULL, no area/cat */
  110. }
  111. else if (Values[i].count1 > 1) {
  112. sprintf(left, "-");
  113. }
  114. else { /* Values[i].count1 == 0 */
  115. /* It can be OK if the category is assigned to an element
  116. type which is not GV_BOUNDARY */
  117. /* -> TODO: print only if there is boundary with that cat */
  118. sprintf(left, "-");
  119. }
  120. if (Values[i].count2 == 1) {
  121. if (Values[i].i2 >= 0)
  122. sprintf(right, "%d", Values[i].i2);
  123. else
  124. sprintf(right, "-1"); /* NULL, no area/cat */
  125. }
  126. else if (Values[i].count2 > 1) {
  127. sprintf(right, "-");
  128. }
  129. else { /* Values[i].count1 == 0 */
  130. sprintf(right, "-");
  131. }
  132. fprintf(stdout, "%d%s%s%s%s\n", Values[i].cat, options.fs, left, options.fs, right);
  133. }
  134. break;
  135. case O_QUERY:
  136. if (G_verbose() > G_verbose_min())
  137. fprintf(stdout, "cat%squery\n", options.fs);
  138. for (i = 0; i < vstat.rcat; i++) {
  139. if (Values[i].null) {
  140. fprintf(stdout, "%d|-\n", Values[i].cat);
  141. }
  142. else {
  143. switch (vstat.qtype) {
  144. case (DB_C_TYPE_INT):
  145. fprintf(stdout, "%d%s%d\n", Values[i].cat, options.fs, Values[i].i1);
  146. break;
  147. case (DB_C_TYPE_DOUBLE):
  148. fprintf(stdout, "%d%s%15g\n", Values[i].cat, options.fs, Values[i].d1);
  149. break;
  150. case (DB_C_TYPE_STRING):
  151. fprintf(stdout, "%d%s%s\n", Values[i].cat, options.fs, Values[i].str1);
  152. break;
  153. }
  154. }
  155. }
  156. break;
  157. case O_AZIMUTH:
  158. if (G_verbose() > G_verbose_min())
  159. fprintf(stdout, "cat%sazimuth\n", options.fs);
  160. for (i = 0; i < vstat.rcat; i++)
  161. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  162. break;
  163. }
  164. return 0;
  165. }
  166. int print_stat(void)
  167. {
  168. if (vstat.rcat > 0) {
  169. int rcat_report;
  170. if(find_cat(-1, 0) != -1)
  171. rcat_report = vstat.rcat - 1;
  172. else
  173. rcat_report = vstat.rcat;
  174. G_message(_("%d categories read from vector map (layer %d)"),
  175. rcat_report, options.field); /* don't report cat -1 */
  176. }
  177. if (vstat.select > 0)
  178. G_message(_("%d records selected from table (layer %d)"),
  179. vstat.select, options.qfield);
  180. if (vstat.exist > 0)
  181. G_message(_("%d categories read from vector map exist in selection from table"),
  182. vstat.exist);
  183. if (vstat.notexist > 0)
  184. G_message(_("%d categories read from vector map don't exist in selection from table"),
  185. vstat.notexist);
  186. G_message(_("%d records updated/inserted (layer %d)"),
  187. vstat.update, options.field);
  188. if (vstat.error > 0)
  189. G_message(_("%d update/insert errors (layer %d)"),
  190. vstat.error, options.field);
  191. if (vstat.dupl > 0)
  192. G_message(_("%d categories with more points (coordinates not loaded)"),
  193. vstat.dupl);
  194. return 0;
  195. }