init.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * \file gisinit.c
  3. *
  4. * \brief GIS 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/Rast.h>
  23. #include <grass/glocale.h>
  24. #include "../raster/G.h"
  25. struct G__ G__;
  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. if (initialized)
  40. return;
  41. init();
  42. }
  43. /**
  44. * \brief Checks to see if GIS engine is initialized.
  45. *
  46. * \return
  47. */
  48. void Rast__check_init(void)
  49. {
  50. if (initialized)
  51. return;
  52. G_fatal_error(_("Raster library not initialized. Programmer forgot to call Rast_init()."));
  53. }
  54. static int init(void)
  55. {
  56. /* Mark window as not set */
  57. G__.window_set = 0;
  58. /* no histograms */
  59. G__.want_histogram = 0;
  60. /* set the write type for floating maps */
  61. G__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
  62. /* Set masking flag unknown */
  63. G__.auto_mask = -1;
  64. G__.nbytes = sizeof(CELL);
  65. G__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
  66. initialized = 1;
  67. return 0;
  68. }
  69. void Rast_init_all(void)
  70. {
  71. Rast__check_for_auto_masking();
  72. Rast_init_gdal();
  73. }