main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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, *eflag, *bflag, *gflag;
  23. double st, sb, sl, sr;
  24. double ft, fb, fl, fr;
  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. eflag = G_define_flag();
  45. eflag->key = 'e';
  46. eflag->description = _("Display frame dimensions (width, height)");
  47. bflag = G_define_flag();
  48. bflag->key = 'b';
  49. bflag->description = _("Display screen rectangle of current region");
  50. gflag = G_define_flag();
  51. gflag->key = 'g';
  52. gflag->description =
  53. _("Display geographic coordinates and resolution of entire frame");
  54. G_option_required(rflag, dflag, fflag, eflag, bflag, gflag, NULL);
  55. if (G_parser(argc, argv))
  56. exit(EXIT_FAILURE);
  57. D_open_driver();
  58. if (rflag->answer || dflag->answer)
  59. D_get_screen(&st, &sb, &sl, &sr);
  60. if (fflag->answer || eflag->answer || gflag->answer)
  61. D_get_frame(&ft, &fb, &fl, &fr);
  62. if (rflag->answer)
  63. fprintf(stdout, "screen rectangle: %f %f %f %f\n", sl, sr, st, sb);
  64. if (dflag->answer)
  65. fprintf(stdout, "screen dimensions: %f %f\n", sr - sl, sb - st);
  66. if (fflag->answer)
  67. fprintf(stdout, "frame rectangle: %f %f %f %f\n", fl, fr, ft, fb);
  68. if (eflag->answer)
  69. fprintf(stdout, "frame dimensions: %f %f\n", fr - fl, fb - ft);
  70. if (bflag->answer) {
  71. double t, b, l, r;
  72. D_setup(0);
  73. l = D_get_d_west();
  74. r = D_get_d_east();
  75. t = D_get_d_north();
  76. b = D_get_d_south();
  77. fprintf(stdout, "region: %f %f %f %f\n", l, r, t, b);
  78. }
  79. if (gflag->answer) {
  80. /* outer bounds of the screen (including margins) */
  81. double n, s, e, w;
  82. D_setup(0);
  83. n = D_d_to_u_row(ft);
  84. s = D_d_to_u_row(fb);
  85. w = D_d_to_u_col(fl);
  86. e = D_d_to_u_col(fr);
  87. fprintf(stdout, "n=%f\n", n );
  88. fprintf(stdout, "s=%f\n", s );
  89. fprintf(stdout, "w=%f\n", w );
  90. fprintf(stdout, "e=%f\n", e );
  91. fprintf(stdout, "ewres=%.15g\n", D_get_d_to_u_xconv() );
  92. fprintf(stdout, "nsres=%.15g\n", -D_get_d_to_u_yconv() );
  93. }
  94. D_close_driver();
  95. exit(EXIT_SUCCESS);
  96. }