report.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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_FD:
  58. if (G_verbose() > G_verbose_min())
  59. fprintf(stdout, "cat%sfd\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_PERIMETER:
  64. if (G_verbose() > G_verbose_min())
  65. fprintf(stdout, "cat%sperimeter\n", options.fs);
  66. for (i = 0; i < vstat.rcat; i++)
  67. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  68. break;
  69. case O_LENGTH:
  70. if (options.print) {
  71. if (G_verbose() > G_verbose_min())
  72. fprintf(stdout, "cat%slength\n", options.fs);
  73. for (i = 0; i < vstat.rcat; i++)
  74. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  75. }
  76. if (options.total) {
  77. double sum = 0.0;
  78. for (i = 0; i < vstat.rcat; i++) {
  79. sum += Values[i].d1;
  80. }
  81. fprintf(stdout, "total length%s%.15g\n", options.fs, sum);
  82. }
  83. break;
  84. case O_SLOPE:
  85. if (G_verbose() > G_verbose_min())
  86. fprintf(stdout, "cat%sslope\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_SINUOUS:
  91. if (G_verbose() > G_verbose_min())
  92. fprintf(stdout, "cat%ssinuous\n", options.fs);
  93. for (i = 0; i < vstat.rcat; i++)
  94. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  95. break;
  96. case O_COOR:
  97. case O_START:
  98. case O_END:
  99. if (G_verbose() > G_verbose_min())
  100. fprintf(stdout, "cat%sx%sy%sz\n", options.fs, options.fs, options.fs);
  101. for (i = 0; i < vstat.rcat; i++) {
  102. if (Values[i].count1 == 1)
  103. fprintf(stdout, "%d%s%.15g%s%.15g%s%.15g\n", Values[i].cat, options.fs,
  104. Values[i].d1, options.fs, Values[i].d2, options.fs, Values[i].d3);
  105. }
  106. break;
  107. case O_SIDES:
  108. if (G_verbose() > G_verbose_min())
  109. fprintf(stdout, "cat%sleft%sright\n", options.fs, options.fs);
  110. for (i = 0; i < vstat.rcat; i++) {
  111. if (Values[i].count1 == 1) {
  112. if (Values[i].i1 >= 0)
  113. sprintf(left, "%d", Values[i].i1);
  114. else
  115. sprintf(left, "-1"); /* NULL, no area/cat */
  116. }
  117. else if (Values[i].count1 > 1) {
  118. sprintf(left, "-");
  119. }
  120. else { /* Values[i].count1 == 0 */
  121. /* It can be OK if the category is assigned to an element
  122. type which is not GV_BOUNDARY */
  123. /* -> TODO: print only if there is boundary with that cat */
  124. sprintf(left, "-");
  125. }
  126. if (Values[i].count2 == 1) {
  127. if (Values[i].i2 >= 0)
  128. sprintf(right, "%d", Values[i].i2);
  129. else
  130. sprintf(right, "-1"); /* NULL, no area/cat */
  131. }
  132. else if (Values[i].count2 > 1) {
  133. sprintf(right, "-");
  134. }
  135. else { /* Values[i].count1 == 0 */
  136. sprintf(right, "-");
  137. }
  138. fprintf(stdout, "%d%s%s%s%s\n", Values[i].cat, options.fs, left, options.fs, right);
  139. }
  140. break;
  141. case O_QUERY:
  142. if (G_verbose() > G_verbose_min())
  143. fprintf(stdout, "cat%squery\n", options.fs);
  144. for (i = 0; i < vstat.rcat; i++) {
  145. if (Values[i].null) {
  146. fprintf(stdout, "%d|-\n", Values[i].cat);
  147. }
  148. else {
  149. switch (vstat.qtype) {
  150. case (DB_C_TYPE_INT):
  151. fprintf(stdout, "%d%s%d\n", Values[i].cat, options.fs, Values[i].i1);
  152. break;
  153. case (DB_C_TYPE_DOUBLE):
  154. fprintf(stdout, "%d%s%15g\n", Values[i].cat, options.fs, Values[i].d1);
  155. break;
  156. case (DB_C_TYPE_STRING):
  157. fprintf(stdout, "%d%s%s\n", Values[i].cat, options.fs, Values[i].str1);
  158. break;
  159. }
  160. }
  161. }
  162. break;
  163. case O_AZIMUTH:
  164. if (G_verbose() > G_verbose_min())
  165. fprintf(stdout, "cat%sazimuth\n", options.fs);
  166. for (i = 0; i < vstat.rcat; i++)
  167. fprintf(stdout, "%d%s%.15g\n", Values[i].cat, options.fs, Values[i].d1);
  168. break;
  169. }
  170. return 0;
  171. }
  172. int print_stat(void)
  173. {
  174. if (vstat.rcat > 0) {
  175. int rcat_report;
  176. if(find_cat(-1, 0) != -1)
  177. rcat_report = vstat.rcat - 1;
  178. else
  179. rcat_report = vstat.rcat;
  180. G_message(_("%d categories read from vector map (layer %d)"),
  181. rcat_report, options.field); /* don't report cat -1 */
  182. }
  183. if (vstat.select > 0)
  184. G_message(_("%d records selected from table (layer %d)"),
  185. vstat.select, options.qfield);
  186. if (vstat.exist > 0)
  187. G_message(_("%d categories read from vector map exist in selection from table"),
  188. vstat.exist);
  189. if (vstat.notexist > 0)
  190. G_message(_("%d categories read from vector map don't exist in selection from table"),
  191. vstat.notexist);
  192. G_message(_("%d records updated/inserted (layer %d)"),
  193. vstat.update, options.field);
  194. if (vstat.error > 0)
  195. G_message(_("%d update/insert errors (layer %d)"),
  196. vstat.error, options.field);
  197. if (vstat.dupl > 0)
  198. G_message(_("%d categories with more points (coordinates not loaded)"),
  199. vstat.dupl);
  200. return 0;
  201. }