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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
*************************************************************************
* G_get_window (window)
* struct Cell_head *window
*
* read the current mapset window
* dies if error
*
*************************************************************************
* G_get_default_window (window)
* struct Cell_head *window
*
* read the default window for the location
* dies if error
*
*************************************************************************
* char *
* G__get_window (window, element, name, mapset)
* read the window 'name' in 'element' in 'mapset'
* returns NULL if ok, error message if not
************************************************************************/
#include <stdlib.h>
#include "G.h"
#include "gis.h"
#include "glocale.h"
/*!
* \brief read the database region
*
* Reads the database region as stored in the WIND file in the user's
* current mapset <b>into region.</b>
* 3D values are set to defaults if not available in WIND file.
* An error message is printed and exit( ) is called if there is a problem reading
* the region.
* <b>Note.</b> GRASS applications that read or write raster files should not
* use this routine since its use implies that the active module region will not
* be used. Programs that read or write raster file data (or vector data) can
* query the active module region <i>using G_window_rows and
* G_window_cols..</i>
*
* \param region
* \return int
*/
int G_get_window (struct Cell_head *window )
{
static int first = 1;
static struct Cell_head dbwindow ;
if (first)
{
char *err;
if(err = G__get_window (&dbwindow,"","WIND",G_mapset()))
{
G_fatal_error (_("region for current mapset %s\nrun \"g.region\""), err);
G_free (err);
}
}
first = 0;
G_copy ((char *) window, (char *) &dbwindow, sizeof(dbwindow) ) ;
if (!G__.window_set)
{
G__.window_set = 1;
G_copy((char *) &G__.window, (char *) &dbwindow, sizeof(dbwindow) ) ;
}
return 1;
}
/*!
* \brief read the default region
*
* Reads the default region for the location into <b>region.</b>
* 3D values are set to defaults if not available in WIND file.
* An error message is printed and exit( ) is called if there is a problem
* reading the default region.
*
* \param region
* \return int
*/
int G_get_default_window ( struct Cell_head *window )
{
char *err;
if ((err = G__get_window (window,"","DEFAULT_WIND","PERMANENT")))
{
G_fatal_error (_("default region %s"), err);
G_free (err);
}
return 1;
}
char *G__get_window ( struct Cell_head *window,
char *element, char *name, char *mapset)
{
FILE *fd ;
char *err;
char *G__read_Cell_head();
G_zero ((char *) window, sizeof (struct Cell_head));
if (!(fd = G_fopen_old (element, name, mapset) ))
{
/*
char path[1024];
G__file_name (path,element,name,mapset);
fprintf (stderr, "G__get_window(%s)\n",path);
*/
return G_store (_("is not set"));
}
err = G__read_Cell_head(fd, window, 0);
fclose (fd);
if (err)
{
char msg[1024];
sprintf (msg, _("is invalid\n%s"), err);
G_free (err);
return G_store (msg);
}
return NULL;
}
|