GRASS Programmer's Manual 6.4.1(2011)
|
00001 00017 #include <stdio.h> 00018 #include <unistd.h> 00019 #include <stdlib.h> 00020 #include <string.h> 00021 #include <sys/stat.h> 00022 #include <locale.h> 00023 00024 #include <grass/gis.h> 00025 #include "G.h" 00026 #include <grass/glocale.h> 00027 00028 struct G__ G__; 00029 00030 static int initialized = 0; 00031 static int gisinit(void); 00032 00033 00044 int G__gisinit(const char *version, const char *pgm) 00045 { 00046 char *mapset; 00047 00048 if (initialized) 00049 return 0; 00050 00051 G_set_program_name(pgm); 00052 00053 if (strcmp(version, GIS_H_VERSION) != 0) 00054 G_fatal_error(_("Incompatible library version for module. " 00055 "You need to rebuild GRASS or untangle multiple installations.")); 00056 00057 /* Make sure location and mapset are set */ 00058 G_location_path(); 00059 switch (G__mapset_permissions(mapset = G_mapset())) { 00060 case 1: 00061 break; 00062 case 0: 00063 G_fatal_error(_("MAPSET %s - permission denied"), mapset); 00064 break; 00065 default: 00066 G_fatal_error(_("MAPSET %s not found"), mapset); 00067 break; 00068 } 00069 00070 gisinit(); 00071 00072 return 0; 00073 } 00074 00075 00084 int G__no_gisinit(const char *version) 00085 { 00086 if (initialized) 00087 return 0; 00088 00089 if (strcmp(version, GIS_H_VERSION) != 0) 00090 G_fatal_error(_("Incompatible library version for module. " 00091 "You need to rebuild GRASS or untangle multiple installations.")); 00092 00093 gisinit(); 00094 00095 return 0; 00096 } 00097 00098 00106 int G__check_gisinit(void) 00107 { 00108 if (initialized) 00109 return 1; 00110 G_warning(_("System not initialized. Programmer forgot to call G_gisinit().")); 00111 G_sleep(3); 00112 exit(EXIT_FAILURE); 00113 } 00114 00115 00116 static int gisinit(void) 00117 { 00118 /* Mark window as not set */ 00119 G__.window_set = 0; 00120 00121 /* no histograms */ 00122 G__.want_histogram = 0; 00123 00124 /* Set compressed data buffer size to zero */ 00125 G__.compressed_buf_size = 0; 00126 G__.work_buf_size = 0; 00127 G__.null_buf_size = 0; 00128 G__.mask_buf_size = 0; 00129 G__.temp_buf_size = 0; 00130 /* mask buf we always want to keep allocated */ 00131 G__reallocate_mask_buf(); 00132 00133 /* set the write type for floating maps */ 00134 G__.fp_type = FCELL_TYPE; 00135 G__.fp_nbytes = XDR_FLOAT_NBYTES; 00136 00137 /* Set masking flag unknown */ 00138 G__.auto_mask = -1; 00139 00140 /* set architecture dependent bit patterns for embeded null vals */ 00141 G__init_null_patterns(); 00142 00143 initialized = 1; 00144 00145 setlocale(LC_NUMERIC, "C"); 00146 00147 return 0; 00148 }