init.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * \file lib/raster/init.c
  3. *
  4. * \brief Raster Library - Handles program initialization.
  5. *
  6. * (C) 2001-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public License
  9. * (>=v2). Read the file COPYING that comes with GRASS for details.
  10. *
  11. * \author GRASS GIS Development Team
  12. *
  13. * \date 2000-2008
  14. */
  15. #include <stdio.h>
  16. #include <unistd.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <sys/stat.h>
  20. #include <locale.h>
  21. #include <grass/gis.h>
  22. #include <grass/raster.h>
  23. #include <grass/glocale.h>
  24. #include "R.h"
  25. struct R__ R__;
  26. static int initialized = 0; /** Is set when engine is initialized */
  27. static int init(void);
  28. /**
  29. * \brief Initialize GRASS GIS engine.
  30. *
  31. * Initializes GIS engine and ensures a valid mapset is available.
  32. *
  33. * \return always returns 0 on success
  34. * \return exit() is called on error
  35. */
  36. void Rast_init(void)
  37. {
  38. Rast__init();
  39. }
  40. /**
  41. * \brief Checks to see if GIS engine is initialized.
  42. *
  43. * \return
  44. */
  45. void Rast__check_init(void)
  46. {
  47. if (initialized)
  48. return;
  49. G_fatal_error(_("Raster library not initialized. Programmer forgot to call Rast_init()."));
  50. }
  51. void Rast__init(void)
  52. {
  53. if (G_is_initialized(&initialized))
  54. return;
  55. init();
  56. G_initialize_done(&initialized);
  57. }
  58. void Rast__error_handler(void *p)
  59. {
  60. Rast__unopen_all();
  61. }
  62. static int init(void)
  63. {
  64. Rast__init_window();
  65. /* no histograms */
  66. R__.want_histogram = 0;
  67. /* set the write type for floating maps */
  68. R__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
  69. /* Set masking flag unknown */
  70. R__.auto_mask = -1;
  71. R__.mask_fd = -1;
  72. R__.nbytes = sizeof(CELL);
  73. R__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
  74. G_add_error_handler(Rast__error_handler, NULL);
  75. initialized = 1;
  76. return 0;
  77. }
  78. void Rast_init_all(void)
  79. {
  80. Rast__init();
  81. Rast__check_for_auto_masking();
  82. Rast_init_gdal();
  83. }