print.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include <string.h>
  2. #include <grass/gis.h>
  3. #include <grass/display.h>
  4. #include "local_proto.h"
  5. static int max(int a, int b)
  6. {
  7. return a > b ? a : b;
  8. }
  9. int print_coor(struct Cell_head *window, double north, double east)
  10. {
  11. char buffer[200];
  12. int len_n, len_s, len_e, len_w, t;
  13. len_n = len_s = len_e = len_w = 0;
  14. G_limit_north(&north, window->proj);
  15. G_limit_east(&east, window->proj);
  16. t = (window->north - north) / window->ns_res;
  17. north = window->north - (t) * window->ns_res;
  18. t = (window->east - east) / window->ew_res;
  19. east = window->east - (t) * window->ew_res;
  20. strcpy(buffer, "?");
  21. G_format_northing(north, buffer, window->proj);
  22. len_n = max(len_n, strlen(buffer));
  23. fprintf(stderr, "%-*s(N) ", len_n, buffer);
  24. strcpy(buffer, "?");
  25. G_format_easting(east, buffer, window->proj);
  26. len_e = max(len_e, strlen(buffer));
  27. fprintf(stderr, "%-*s(E) ", len_e, buffer);
  28. fprintf(stderr, "\r");
  29. fflush(stderr);
  30. return 1;
  31. }
  32. int print_win(struct Cell_head *window, double north, double south,
  33. double east, double west)
  34. {
  35. char buffer[200];
  36. int len_n, len_s, len_e, len_w, t;
  37. len_n = len_s = len_e = len_w = 0;
  38. G_limit_north(&north, window->proj);
  39. G_limit_south(&south, window->proj);
  40. G_limit_east(&east, window->proj);
  41. G_limit_west(&west, window->proj);
  42. t = (window->north - north) / window->ns_res;
  43. north = window->north - (t) * window->ns_res;
  44. t = (south - window->south) / window->ns_res;
  45. south = window->south + (t) * window->ns_res;
  46. t = (window->east - east) / window->ew_res;
  47. east = window->east - (t) * window->ew_res;
  48. t = (west - window->west) / window->ew_res;
  49. west = window->west + (t) * window->ew_res;
  50. strcpy(buffer, "?");
  51. G_format_northing(north, buffer, window->proj);
  52. len_n = max(len_n, strlen(buffer));
  53. fprintf(stderr, "north: %-*s ", len_n, buffer);
  54. strcpy(buffer, "?");
  55. G_format_northing(south, buffer, window->proj);
  56. len_s = max(len_s, strlen(buffer));
  57. fprintf(stderr, "south: %-*s ", len_s, buffer);
  58. strcpy(buffer, "?");
  59. G_format_easting(east, buffer, window->proj);
  60. len_e = max(len_e, strlen(buffer));
  61. fprintf(stderr, "east: %-*s ", len_e, buffer);
  62. strcpy(buffer, "?");
  63. G_format_easting(west, buffer, window->proj);
  64. len_w = max(len_w, strlen(buffer));
  65. fprintf(stderr, "west: %-*s ", len_w, buffer);
  66. fprintf(stderr, "\r");
  67. fflush(stderr);
  68. return 1;
  69. }
  70. int print_limit(struct Cell_head *window, struct Cell_head *defwin)
  71. {
  72. char buffer[1000];
  73. int limit = 0;
  74. if (window->north > defwin->north) {
  75. sprintf(buffer, "North");
  76. limit = 1;
  77. }
  78. if (window->south < defwin->south) {
  79. if (limit)
  80. sprintf(buffer, "%s, south", buffer);
  81. else
  82. sprintf(buffer, "South");
  83. limit = 1;
  84. }
  85. if (window->east > defwin->east) {
  86. if (limit)
  87. sprintf(buffer, "%s, east", buffer);
  88. else
  89. sprintf(buffer, "East");
  90. limit = 1;
  91. }
  92. if (window->west < defwin->west) {
  93. if (limit)
  94. sprintf(buffer, "%s, west", buffer);
  95. else
  96. sprintf(buffer, "West");
  97. limit = 1;
  98. }
  99. if (limit) {
  100. fprintf(stderr, "%s limit of default region reached.\n", buffer);
  101. }
  102. return (limit);
  103. }