main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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(_("monitors"));
  29. module->label =
  30. _("Displays information about the active display monitor.");
  31. module->description =
  32. _("Display monitors are maintained by d.mon.");
  33. rflag = G_define_flag();
  34. rflag->key = 'r';
  35. rflag->description =
  36. _("Display screen rectangle (left, right, top, bottom)");
  37. dflag = G_define_flag();
  38. dflag->key = 'd';
  39. dflag->description = _("Display screen dimensions (width, height)");
  40. fflag = G_define_flag();
  41. fflag->key = 'f';
  42. fflag->description = _("Display active frame rectangle");
  43. bflag = G_define_flag();
  44. bflag->key = 'b';
  45. bflag->description = _("Display screen rectangle of current region");
  46. gflag = G_define_flag();
  47. gflag->key = 'g';
  48. gflag->description =
  49. _("Display geographic coordinates and resolution of entire screen");
  50. if (G_parser(argc, argv))
  51. exit(EXIT_FAILURE);
  52. if (!rflag->answer && !dflag->answer &&
  53. !fflag->answer && !bflag->answer && !gflag->answer) {
  54. G_fatal_error(_("No flag given"));
  55. }
  56. if (D_open_driver() != 0)
  57. G_fatal_error(_("No graphics device selected. "
  58. "Use d.mon to select graphics device."));
  59. if (rflag->answer || dflag->answer || fflag->answer)
  60. D_get_window(&t, &b, &l, &r);
  61. if (rflag->answer)
  62. fprintf(stdout, "rectangle: %f %f %f %f\n", l, r, t, b);
  63. if (dflag->answer)
  64. fprintf(stdout, "dimensions: %f %f\n", r - l, b - t);
  65. if (fflag->answer)
  66. fprintf(stdout, "frame: %f %f %f %f\n", l, r, t, b);
  67. if (bflag->answer) {
  68. D_setup(0);
  69. l = D_get_d_west();
  70. r = D_get_d_east();
  71. t = D_get_d_north();
  72. b = D_get_d_south();
  73. fprintf(stdout, "region: %f %f %f %f\n", l, r, t, b);
  74. }
  75. if (gflag->answer) {
  76. /* outer bounds of the screen (including margins) */
  77. D_setup(0);
  78. n = D_get_u_north();
  79. s = D_get_u_south();
  80. w = D_get_u_west();
  81. e = D_get_u_east();
  82. fprintf(stdout, "n=%f\n", n );
  83. fprintf(stdout, "s=%f\n", s );
  84. fprintf(stdout, "w=%f\n", w );
  85. fprintf(stdout, "e=%f\n", e );
  86. fprintf(stdout, "ewres=%.15g\n", (e-w)/(r-l) );
  87. fprintf(stdout, "nsres=%.15g\n", (n-s)/(b-t) );
  88. }
  89. D_close_driver();
  90. exit(EXIT_SUCCESS);
  91. }