main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: d.info
  5. * AUTHOR(S): Glynn Clements
  6. * PURPOSE: Display information about the active display monitor
  7. * COPYRIGHT: (C) 2004, 2012 by the GRASS Development Team
  8. *
  9. * This program is free software under the GNU General Public
  10. * License (>=v2). Read the file COPYING that comes with GRASS
  11. * for details.
  12. *
  13. *****************************************************************************/
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <grass/gis.h>
  17. #include <grass/display.h>
  18. #include <grass/glocale.h>
  19. int main(int argc, char *argv[])
  20. {
  21. struct GModule *module;
  22. struct Flag *rflag, *dflag, *fflag, *bflag, *gflag;
  23. double t, b, l, r;
  24. double n, s, e, w;
  25. G_gisinit(argv[0]);
  26. module = G_define_module();
  27. G_add_keyword(_("display"));
  28. G_add_keyword(_("graphics"));
  29. G_add_keyword(_("monitors"));
  30. module->label =
  31. _("Displays information about the active display monitor.");
  32. module->description =
  33. _("Display monitors are maintained by d.mon.");
  34. rflag = G_define_flag();
  35. rflag->key = 'r';
  36. rflag->description =
  37. _("Display screen rectangle (left, right, top, bottom)");
  38. dflag = G_define_flag();
  39. dflag->key = 'd';
  40. dflag->description = _("Display screen dimensions (width, height)");
  41. fflag = G_define_flag();
  42. fflag->key = 'f';
  43. fflag->description = _("Display active frame rectangle");
  44. bflag = G_define_flag();
  45. bflag->key = 'b';
  46. bflag->description = _("Display screen rectangle of current region");
  47. gflag = G_define_flag();
  48. gflag->key = 'g';
  49. gflag->description =
  50. _("Display geographic coordinates and resolution of entire screen");
  51. if (G_parser(argc, argv))
  52. exit(EXIT_FAILURE);
  53. if (!rflag->answer && !dflag->answer &&
  54. !fflag->answer && !bflag->answer && !gflag->answer) {
  55. G_fatal_error(_("No flag given"));
  56. }
  57. if (D_open_driver() != 0)
  58. G_fatal_error(_("No graphics device selected. "
  59. "Use d.mon to select graphics device."));
  60. if (rflag->answer || dflag->answer || fflag->answer)
  61. D_get_window(&t, &b, &l, &r);
  62. if (rflag->answer)
  63. fprintf(stdout, "rectangle: %f %f %f %f\n", l, r, t, b);
  64. if (dflag->answer)
  65. fprintf(stdout, "dimensions: %f %f\n", r - l, b - t);
  66. if (fflag->answer)
  67. fprintf(stdout, "frame: %f %f %f %f\n", l, r, t, b);
  68. if (bflag->answer) {
  69. D_setup(0);
  70. l = D_get_d_west();
  71. r = D_get_d_east();
  72. t = D_get_d_north();
  73. b = D_get_d_south();
  74. fprintf(stdout, "region: %f %f %f %f\n", l, r, t, b);
  75. }
  76. if (gflag->answer) {
  77. /* outer bounds of the screen (including margins) */
  78. D_setup(0);
  79. n = D_get_u_north();
  80. s = D_get_u_south();
  81. w = D_get_u_west();
  82. e = D_get_u_east();
  83. fprintf(stdout, "n=%f\n", n );
  84. fprintf(stdout, "s=%f\n", s );
  85. fprintf(stdout, "w=%f\n", w );
  86. fprintf(stdout, "e=%f\n", e );
  87. fprintf(stdout, "ewres=%.15g\n", (e-w)/(r-l) );
  88. fprintf(stdout, "nsres=%.15g\n", (n-s)/(b-t) );
  89. }
  90. D_close_driver();
  91. exit(EXIT_SUCCESS);
  92. }