report.c 5.3 KB

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