gisinit.c

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  *   G_gisinit(pgm)
00004  *      char *pgm        Name to be associated with current program
00005  *
00006  *  Does some program initialization.  Read comments in this file
00007  *  for details.
00008  **********************************************************************/
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <unistd.h>
00013 #include <sys/stat.h>
00014 #include <grass/gis.h>
00015 #include "G.h"
00016 #include <grass/glocale.h>
00017 
00018 struct G__ G__ ;
00019 static int initialized = 0;
00020 static int gisinit(void);
00021 
00022 int G_gisinit(const char *pgm)
00023 {
00024     char *mapset;
00025     char msg[100];
00026 
00027     if ( initialized )
00028         return 0;
00029 
00030     G_set_program_name (pgm);
00031 
00032    /* Make sure location and mapset are set */
00033     G_location_path();
00034     switch (G__mapset_permissions (mapset = G_mapset()))
00035     {
00036     case 1:
00037             break;
00038     case 0:
00039             sprintf(msg,_("MAPSET %s - permission denied"), mapset);
00040             G_fatal_error (msg);
00041             exit(-1);
00042             break;
00043     default:
00044             sprintf(msg,_("MAPSET %s not found"), mapset);
00045             G_fatal_error (msg);
00046             exit(-1);
00047             break;
00048     }
00049 
00050     gisinit();
00051 
00052     return 0;
00053 }
00054 
00055 int G_no_gisinit(void)
00056 {
00057     if ( initialized )
00058         return 0;
00059 
00060     gisinit();
00061 
00062     return 0;
00063 }
00064 
00065 int G__check_gisinit(void)
00066 {
00067     if (initialized) return 1;
00068     fprintf (stderr, _("\7ERROR: System not initialized. Programmer forgot to call G_gisinit()\n"));
00069     G_sleep(3);
00070     exit(-1);
00071 }
00072 
00073 static int gisinit(void)
00074 {
00075     int i ;
00076 
00077 /* Mark window as not set */
00078     G__.window_set = 0 ;
00079 
00080 /* no histograms */
00081     G__.want_histogram = 0;
00082 
00083 /* Set compressed data buffer size to zero */
00084     G__.compressed_buf_size = 0;
00085     G__.work_buf_size = 0;
00086     G__.null_buf_size = 0;
00087     G__.mask_buf_size = 0;
00088     G__.temp_buf_size = 0;
00089     /* mask buf we always want to keep allocated */
00090     G__reallocate_mask_buf();
00091 
00092 /* set the write type for floating maps */
00093     G__.fp_type = FCELL_TYPE;
00094     G__.fp_nbytes = XDR_FLOAT_NBYTES;
00095 
00096 /* Set masking flag unknown */
00097     G__.auto_mask = -1 ;
00098 
00099 /* set architecture dependant bit patterns for embeded null vals */
00100     G__init_null_patterns();
00101 
00102     initialized = 1;
00103 
00104     return 0;
00105 }

Generated on Fri Nov 21 11:02:18 2008 for GRASS by  doxygen 1.5.1