File: gisinit.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (112 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**********************************************************************
 *
 *   G_gisinit(pgm)
 *      char *pgm        Name to be associated with current program
 *
 *  Does some program initialization.  Read comments in this file
 *  for details.
 **********************************************************************/

#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include "gis.h"
#include "G.h"
#include "version.h"
#include "glocale.h"

struct G__ G__ ;
static int initialized = 0;
static int gisinit();

int G_gisinit( char *pgm)
{
    char *mapset;
    char msg[100];

    if ( initialized )
	return 0;

    G_set_program_name (pgm);

   /* Make sure location and mapset are set */
    G_location_path();
    switch (G__mapset_permissions (mapset = G_mapset()))
    {
    case 1:
	    break;
    case 0:
	    sprintf(msg,_("MAPSET %s - permission denied"), mapset);
	    G_fatal_error (msg);
	    exit(-1);
	    break;
    default:
	    sprintf(msg,_("MAPSET %s not found"), mapset);
	    G_fatal_error (msg);
	    exit(-1);
	    break;
    }

    gisinit();

    return 0;
}

int G_no_gisinit(void)
{
    if ( initialized )
	return 0;

    gisinit();

    return 0;
}

int G__check_gisinit()
{
    if (initialized) return 1;
    fprintf (stderr, _("\7ERROR: System not initialized. Programmer forgot to call G_gisinit()\n"));
    sleep(3);
    exit(-1);
}

static int gisinit()
{
    int i ;

/* Mark window as not set */
    G__.window_set = 0 ;

/* no histograms */
    G__.want_histogram = 0;

/* Mark all cell files as closed */
    for (i = 0; i < MAXFILES; i++)
    {
	G__.fileinfo[i].open_mode = -1;
    }

/* Set compressed data buffer size to zero */
    G__.compressed_buf_size = 0;
    G__.work_buf_size = 0;
    G__.null_buf_size = 0;
    G__.mask_buf_size = 0;
    G__.temp_buf_size = 0;
    /* mask buf we always want to keep allocated */
    G__reallocate_mask_buf();

/* set the write type for floating maps */
    G__.fp_type = FCELL_TYPE;
    G__.fp_nbytes = XDR_FLOAT_NBYTES;

/* Set masking flag unknown */
    G__.auto_mask = -1 ;

/* set architecture dependant bit patterns for embeded null vals */
    G__init_null_patterns();

    initialized = 1;
    umask(022);

    return 0;
}