init.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. * \param[in] pgm Program (module) name
  34. * \return always returns 0 on success
  35. * \return exit() is called on error
  36. */
  37. void Rast_init(void)
  38. {
  39. Rast__init();
  40. }
  41. /**
  42. * \brief Checks to see if GIS engine is initialized.
  43. *
  44. * \return
  45. */
  46. void Rast__check_init(void)
  47. {
  48. if (initialized)
  49. return;
  50. G_fatal_error(_("Raster library not initialized. Programmer forgot to call Rast_init()."));
  51. }
  52. void Rast__init(void)
  53. {
  54. if (G_is_initialized(&initialized))
  55. return;
  56. init();
  57. G_initialize_done(&initialized);
  58. }
  59. void Rast__error_handler(void *p)
  60. {
  61. Rast__unopen_all();
  62. }
  63. static int init(void)
  64. {
  65. Rast__init_window();
  66. /* byte order */
  67. R__.little_endian = G_is_little_endian();
  68. /* no histograms */
  69. R__.want_histogram = 0;
  70. /* set the write type for floating maps */
  71. R__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
  72. /* Set masking flag unknown */
  73. R__.auto_mask = -1;
  74. R__.mask_fd = -1;
  75. R__.nbytes = sizeof(CELL);
  76. R__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
  77. G_add_error_handler(Rast__error_handler, NULL);
  78. initialized = 1;
  79. return 0;
  80. }
  81. void Rast_init_all(void)
  82. {
  83. Rast__init();
  84. Rast__check_for_auto_masking();
  85. Rast_init_gdal();
  86. }