main.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. ************************************************************
  3. * MODULE: r.le.setup/main.c *
  4. * Version 5.0beta Oct. 1, 2001 *
  5. * *
  6. * AUTHOR: W.L. Baker, University of Wyoming *
  7. * BAKERWL@UWYO.EDU *
  8. * *
  9. * PURPOSE: To set up sampling areas, which can can then *
  10. * be used to obtain data using the r.le.dist, *
  11. * r.le.patch, and r.le.pixel programs. The *
  12. * main.c code queries the user for the name of *
  13. * maps to be used during the setup operation *
  14. * *
  15. * COPYRIGHT: (C) 2001 by W.L. Baker *
  16. * *
  17. * This program is free software under the GNU General *
  18. * Public License(>=v2). Read the file COPYING that comes *
  19. * with GRASS for details *
  20. * *
  21. ************************************************************/
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <sys/types.h>
  26. #include <dirent.h>
  27. #include <grass/config.h>
  28. #include <grass/gis.h>
  29. #include <grass/display.h>
  30. #include <grass/glocale.h>
  31. #include "setup.h"
  32. static void get_pwd(void);
  33. jmp_buf jmp;
  34. /* MAIN PROGRAM */
  35. int main(int argc, char *argv[])
  36. {
  37. struct GModule *module;
  38. struct Option *input, *vect;
  39. struct Cell_head window;
  40. int bot, right, t0, b0, l0, r0, clear = 0;
  41. double Rw_l, Rscr_wl;
  42. char *map_name = NULL, *v_name = NULL, *s_name = NULL;
  43. /* Initialize the GIS calls */
  44. G_gisinit(argv[0]);
  45. module = G_define_module();
  46. G_add_keyword(_("raster"));
  47. module->description =
  48. _("Interactive tool used to setup the sampling and analysis framework "
  49. "that will be used by the other r.le programs.");
  50. input = G_define_standard_option(G_OPT_R_MAP);
  51. input->description = _("Raster map to use to setup sampling");
  52. vect = G_define_standard_option(G_OPT_V_INPUT);
  53. vect->key = "vect";
  54. vect->description = _("Vector map to overlay");
  55. vect->required = NO;
  56. if (G_parser(argc, argv))
  57. exit(EXIT_FAILURE);
  58. setbuf(stdout, NULL); /* unbuffered */
  59. setbuf(stderr, NULL);
  60. G_sleep_on_error(1); /* error messages get lost on clear screen */
  61. map_name = input->answer;
  62. v_name = vect->answer;
  63. s_name = NULL; /* sites not used in GRASS 6 */
  64. /* setup the r.le.para directory */
  65. get_pwd();
  66. /* query for the map to be setup */
  67. if (R_open_driver() != 0)
  68. G_fatal_error("No graphics device selected");
  69. /* setup the current window for display & clear screen */
  70. D_setup(1);
  71. Rw_l = (double)Rast_window_cols() / Rast_window_rows();
  72. /*R_open_driver(); */
  73. /* R_font("romant"); */
  74. G_get_set_window(&window);
  75. t0 = R_screen_top();
  76. b0 = R_screen_bot();
  77. l0 = R_screen_left();
  78. r0 = R_screen_rite();
  79. Rscr_wl = (double)(r0 - l0) / (b0 - t0);
  80. if (Rscr_wl > Rw_l) {
  81. bot = b0;
  82. right = l0 + (b0 - t0) * Rw_l;
  83. }
  84. else {
  85. right = r0;
  86. bot = t0 + (r0 - l0) / Rw_l;
  87. }
  88. D_new_window("a", t0, bot, l0, right);
  89. D_set_cur_wind("a");
  90. D_show_window(D_translate_color("green"));
  91. D_setup(clear);
  92. R_close_driver();
  93. /* invoke the setup modules */
  94. set_map(map_name, v_name, s_name, window, t0, bot, l0, right);
  95. return (EXIT_SUCCESS);
  96. }
  97. /* SETUP THE R.LE.PARA DIRECTORY */
  98. static void get_pwd(void)
  99. {
  100. DIR *dp;
  101. if (!(dp = opendir("r.le.para")))
  102. G_mkdir("r.le.para");
  103. else
  104. closedir(dp);
  105. return;
  106. }