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 <unistd.h>
00012 #include <sys/stat.h>
00013 #include "gis.h"
00014 #include "G.h"
00015 #include "version.h"
00016 #include "glocale.h"
00017 
00018 struct G__ G__ ;
00019 static int initialized = 0;
00020 static int gisinit();
00021 
00022 int G_gisinit( 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()
00066 {
00067     if (initialized) return 1;
00068     fprintf (stderr, _("\7ERROR: System not initialized. Programmer forgot to call G_gisinit()\n"));
00069     sleep(3);
00070     exit(-1);
00071 }
00072 
00073 static int gisinit()
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 /* Mark all cell files as closed */
00084     for (i = 0; i < MAXFILES; i++)
00085     {
00086         G__.fileinfo[i].open_mode = -1;
00087     }
00088 
00089 /* Set compressed data buffer size to zero */
00090     G__.compressed_buf_size = 0;
00091     G__.work_buf_size = 0;
00092     G__.null_buf_size = 0;
00093     G__.mask_buf_size = 0;
00094     G__.temp_buf_size = 0;
00095     /* mask buf we always want to keep allocated */
00096     G__reallocate_mask_buf();
00097 
00098 /* set the write type for floating maps */
00099     G__.fp_type = FCELL_TYPE;
00100     G__.fp_nbytes = XDR_FLOAT_NBYTES;
00101 
00102 /* Set masking flag unknown */
00103     G__.auto_mask = -1 ;
00104 
00105 /* set architecture dependant bit patterns for embeded null vals */
00106     G__init_null_patterns();
00107 
00108     initialized = 1;
00109     umask(022);
00110 
00111     return 0;
00112 }

Generated on Sat Jul 22 22:06:14 2006 for GRASS by  doxygen 1.4.7