123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /**
- * \file gisinit.c
- *
- * \brief GIS Library - Handles program initialization.
- *
- * (C) 2001-2008 by the GRASS Development Team
- *
- * This program is free software under the GNU General Public License
- * (>=v2). Read the file COPYING that comes with GRASS for details.
- *
- * \author GRASS GIS Development Team
- *
- * \date 2000-2008
- */
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/stat.h>
- #include <locale.h>
- #include <grass/gis.h>
- #include "G.h"
- #include <grass/glocale.h>
- struct G__ G__;
- static int initialized = 0; /** Is set when engine is initialized */
- static int gisinit(void);
- /**
- * \brief Initialize GRASS GIS engine.
- *
- * Initializes GIS engine and ensures a valid mapset is available.
- *
- * \param[in] pgm Program (module) name
- * \return always returns 0 on success
- * \return exit() is called on error
- */
- void G__gisinit(const char *version, const char *pgm)
- {
- char *mapset;
- if (initialized)
- return;
- G_set_program_name(pgm);
- if (strcmp(version, GIS_H_VERSION) != 0)
- G_fatal_error(_("Incompatible library version for module"));
- /* Make sure location and mapset are set */
- G_location_path();
- switch (G__mapset_permissions(mapset = G_mapset())) {
- case 1:
- break;
- case 0:
- G_fatal_error(_("MAPSET %s - permission denied"), mapset);
- break;
- default:
- G_fatal_error(_("MAPSET %s not found"), mapset);
- break;
- }
- gisinit();
- }
- /**
- * \brief Initialize GRASS GIS engine.
- *
- * Initializes GIS engine, but does not check for a valid mapset.
- *
- * \return
- */
- void G__no_gisinit(const char *version)
- {
- if (initialized)
- return;
- if (strcmp(version, GIS_H_VERSION) != 0)
- G_fatal_error(_("Incompatible library version for module"));
- gisinit();
- }
- /**
- * \brief Checks to see if GIS engine is initialized.
- *
- * \return
- */
- void G__check_gisinit(void)
- {
- if (initialized)
- return;
- G_warning(_("System not initialized. Programmer forgot to call G_gisinit()."));
- G_sleep(3);
- exit(EXIT_FAILURE);
- }
- static int gisinit(void)
- {
- /* Mark window as not set */
- G__.window_set = 0;
- /* no histograms */
- G__.want_histogram = 0;
- /* set the write type for floating maps */
- G__.fp_type = -1;
- /* Set masking flag unknown */
- G__.auto_mask = -1;
- G__.nbytes = sizeof(CELL);
- G__.compression_type = 0;
- initialized = 1;
- setlocale(LC_NUMERIC, "C");
- return 0;
- }
- void G_init_all(void)
- {
- G__check_gisinit();
- G_init_env();
- G_init_logging();
- G__init_window();
- G_get_fp_type();
- G_get_compression_type();
- G__check_for_auto_masking();
- G_init_locale();
- G_init_debug();
- G_verbose();
- G_init_tempfile();
- G_init_gdal();
- G_get_list_of_mapsets();
- G__home();
- G__machine_name();
- G_whoami();
- G_read_datum_table();
- G_read_ellipsoid_table(0);
- }
|