main.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /****************************************************************************
  2. *
  3. * MODULE: d.mapgraph
  4. * AUTHOR(S): James Westervelt (original contributor)
  5. * Markus Neteler <neteler itc.it>,
  6. * Roberto Flor <flor itc.it>,
  7. * Bernhard Reiter <bernhard intevation.de>,
  8. * Cedric Shock <cedricgrass shockfamily.net>,
  9. * Huidae Cho <grass4u gmail.com>,
  10. * Eric G. Miller <egm2 jps.net>,
  11. * Glynn Clements <glynn gclements.plus.com>,
  12. * Hamish Bowman <hamish_nospam yahoo.com>,
  13. * Jan-Oliver Wagner <jan intevation.de>
  14. * PURPOSE: draws graphs - now superceded by d.graph
  15. * COPYRIGHT: (C) 1999-2007 by the GRASS Development Team
  16. *
  17. * This program is free software under the GNU General Public
  18. * License (>=v2). Read the file COPYING that comes with GRASS
  19. * for details.
  20. *
  21. *****************************************************************************/
  22. #include <stdlib.h>
  23. #include <unistd.h>
  24. #include <grass/gis.h>
  25. #include <grass/display.h>
  26. #include <grass/raster.h>
  27. #include <grass/colors.h>
  28. #include <grass/glocale.h>
  29. #define MAIN
  30. #include "options.h"
  31. #include "local_proto.h"
  32. struct Cell_head window ;
  33. int
  34. main (int argc, char **argv)
  35. {
  36. struct GModule *module;
  37. struct Option *opt1, *opt2/*, *opt3, *opt4*/ ;
  38. int R, G, B, color = 0;
  39. /* Initialize the GIS calls */
  40. G_gisinit(argv[0]) ;
  41. module = G_define_module();
  42. module->keywords = _("display");
  43. module->description =
  44. _("Generates and displays simple graphics on map "
  45. "layers drawn in the active graphics monitor display frame.");
  46. opt1 = G_define_option() ;
  47. opt1->key = "input" ;
  48. opt1->type = TYPE_STRING ;
  49. opt1->required = NO ;
  50. opt1->description= _("Unix file containg graphing instructions, "
  51. "if not given reads from standard input");
  52. opt1->gisprompt = "old_file,file,input";
  53. opt2 = G_define_option() ;
  54. opt2->key = "color" ;
  55. opt2->type = TYPE_STRING ;
  56. opt2->required = NO;
  57. opt2->answer = DEFAULT_FG_COLOR ;
  58. opt2->description= _("Color to draw with, either a standard GRASS color "
  59. "or R:G:B triplet (separated by colons)");
  60. opt2->gisprompt = GISPROMPT_COLOR ;
  61. /*
  62. opt3 = G_define_option() ;
  63. opt3->key = "vsize" ;
  64. opt3->type = TYPE_DOUBLE;
  65. opt3->answer = "5.0" ;
  66. opt3->options = "0-100" ;
  67. opt3->description= "Vertical text height as % of display frame height" ;
  68. opt4 = G_define_option() ;
  69. opt4->key = "hsize" ;
  70. opt4->type = TYPE_DOUBLE;
  71. opt4->answer = "5.0" ;
  72. opt4->options = "0-100" ;
  73. opt4->description= "Horizontal text width as % of display frame width" ;
  74. */
  75. /* Check command line */
  76. if (G_parser(argc, argv))
  77. exit(1);
  78. G_warning("This module is superseded. Please use 'd.graph -m' instead.");
  79. if (opt1->answer != NULL)
  80. {
  81. /* 1/4/91 jmoorman
  82. mapset = G_find_file ("mapgraph", opt1->answer, "");
  83. if (mapset == NULL)
  84. {
  85. G_usage() ;
  86. G_fatal_error("Mapgraph file [%s] not available", opt1->answer);
  87. }
  88. Infile = G_fopen_old ("mapgraph", opt1->answer, mapset);
  89. if (Infile == NULL)
  90. {
  91. G_usage() ;
  92. G_fatal_error ("Graph file <%s> not available", opt1->answer);
  93. }
  94. */
  95. /* using fopen instead to facilitate finding the file */
  96. if ((Infile = fopen(opt1->answer,"r")) == NULL)
  97. {
  98. G_usage() ;
  99. G_fatal_error ("Mapgraph file [%s] not available", opt1->answer);
  100. }
  101. }
  102. else
  103. {
  104. Infile = stdin ;
  105. if (isatty(0))
  106. fprintf (stdout,"\nEnter mapgraph commands; terminate with a ^D\n\n") ;
  107. }
  108. /* Parse and select color */
  109. if (opt2->answer != NULL) {
  110. color = G_str_to_color(opt2->answer, &R, &G, &B);
  111. if(color == 0)
  112. G_fatal_error("[%s]: No such color", opt2->answer);
  113. if(color == 1)
  114. R_RGB_color(R, G, B);
  115. /* (color==2) is "none", noop */
  116. }
  117. /*
  118. sscanf(opt3->answer,"%lf",&temp);
  119. vsize = temp ;
  120. sscanf(opt4->answer,"%lf",&temp);
  121. hsize = temp ;
  122. */
  123. vsize = hsize = 5.0 ;
  124. if (R_open_driver() != 0)
  125. G_fatal_error ("No graphics device selected");
  126. D_setup(0);
  127. G_get_set_window(&window) ;
  128. R_move_abs(
  129. (int)(D_get_d_west() + D_get_d_east() / 2.0),
  130. (int)(D_get_d_north() + D_get_d_south() / 2.0)) ;
  131. set_text_size() ;
  132. /* Do the graphics */
  133. G_setup_plot (
  134. D_get_d_north(), D_get_d_south(), D_get_d_west(), D_get_d_east(),
  135. D_move_abs, D_cont_abs);
  136. graphics () ;
  137. /* Add this command to list */
  138. /*
  139. if(argc > 1)
  140. {
  141. D_add_to_list(G_recreate_command()) ;
  142. }
  143. */
  144. R_close_driver();
  145. exit (0);
  146. }