GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gisinit.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <unistd.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/stat.h>
22 #include <locale.h>
23 
24 #include <grass/gis.h>
25 #include "G.h"
26 #include <grass/glocale.h>
27 
28 struct G__ G__;
29 
30 static int initialized = 0;
31 static int gisinit(void);
32 
33 
44 int G__gisinit(const char *version, const char *pgm)
45 {
46  char *mapset;
47 
48  if (initialized)
49  return 0;
50 
51  G_set_program_name(pgm);
52 
53  if (strcmp(version, GIS_H_VERSION) != 0)
54  G_fatal_error(_("Module built against version %s but "
55  "trying to use version %s. "
56  "You need to rebuild GRASS GIS or untangle multiple installations."),
57  version, GIS_H_VERSION);
58 
59  /* Make sure location and mapset are set */
61  switch (G__mapset_permissions(mapset = G_mapset())) {
62  case 1:
63  break;
64  case 0:
65  G_fatal_error(_("MAPSET %s - permission denied"), mapset);
66  break;
67  default:
68  G_fatal_error(_("MAPSET %s not found at %s"), mapset, G_location_path());
69  break;
70  }
71 
72  gisinit();
73 
74  return 0;
75 }
76 
77 
86 int G__no_gisinit(const char *version)
87 {
88  if (initialized)
89  return 0;
90 
91  if (strcmp(version, GIS_H_VERSION) != 0)
92  G_fatal_error(_("Module built against version %s but "
93  "trying to use version %s. "
94  "You need to rebuild GRASS GIS or untangle multiple installations."),
95  version, GIS_H_VERSION);
96  gisinit();
97 
98  return 0;
99 }
100 
101 
110 {
111  if (initialized)
112  return 1;
113  G_warning(_("System not initialized. Programmer forgot to call G_gisinit()."));
114  G_sleep(3);
115  exit(EXIT_FAILURE);
116 }
117 
118 
119 static int gisinit(void)
120 {
121  /* Mark window as not set */
122  G__.window_set = 0;
123 
124  /* no histograms */
125  G__.want_histogram = 0;
126 
127  /* Set compressed data buffer size to zero */
129  G__.work_buf_size = 0;
130  G__.null_buf_size = 0;
131  G__.mask_buf_size = 0;
132  G__.temp_buf_size = 0;
133  /* mask buf we always want to keep allocated */
135 
136  /* set the write type for floating maps */
137  G__.fp_type = FCELL_TYPE;
139 
140  /* Set masking flag unknown */
141  G__.auto_mask = -1;
142 
143  initialized = 1;
144 
145  setlocale(LC_NUMERIC, "C");
146 
147  return 0;
148 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
int want_histogram
Definition: G.h:92
int G__mapset_permissions(const char *mapset)
Check for user mapset permission.
Definition: mapset_msc.c:115
int auto_mask
Definition: G.h:81
int null_buf_size
Definition: G.h:89
int mask_buf_size
Definition: G.h:90
int compressed_buf_size
Definition: G.h:86
int G__no_gisinit(const char *version)
Initialize GRASS GIS engine.
Definition: gisinit.c:86
def version
Get GRASS version as dictionary.
Definition: core.py:1199
int work_buf_size
Definition: G.h:88
int temp_buf_size
Definition: G.h:91
Definition: G.h:74
char * G_location_path(void)
Get current location directory.
Definition: location.c:37
void G_sleep(unsigned int seconds)
Definition: sleep.c:11
int window_set
Definition: G.h:79
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int fp_nbytes
Definition: G.h:76
int G__reallocate_mask_buf(void)
Allocate/enlarge the mask buffer needed by get_map_row()
Definition: opencell.c:885
int G_set_program_name(const char *s)
Definition: progrm_nme.c:38
RASTER_MAP_TYPE fp_type
Definition: G.h:77
int G__check_gisinit(void)
Checks to see if GIS engine is initialized.
Definition: gisinit.c:109
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int G__gisinit(const char *version, const char *pgm)
Initialize GRASS GIS engine.
Definition: gisinit.c:44
#define XDR_FLOAT_NBYTES
Definition: G.h:9