8
#include "raster3d_intern.h"
10
/*---------------------------------------------------------------------------*/
13
Rast3d_readWriteWindow(struct Key_Value *windowKeys, int doRead, int *proj,
14
int *zone, double *north, double *south, double *east,
15
double *west, double *top, double *bottom, int *rows,
16
int *cols, int *depths, double *ew_res, double *ns_res,
20
int (*windowInt) (), (*windowDouble) ();
23
windowDouble = Rast3d_key_get_double;
24
windowInt = Rast3d_key_get_int;
27
windowDouble = Rast3d_key_set_double;
28
windowInt = Rast3d_key_set_int;
32
returnVal &= windowInt(windowKeys, RASTER3D_REGION_PROJ, proj);
33
returnVal &= windowInt(windowKeys, RASTER3D_REGION_ZONE, zone);
35
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_NORTH, north);
36
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_SOUTH, south);
37
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_EAST, east);
38
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_WEST, west);
39
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_TOP, top);
40
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_BOTTOM, bottom);
42
returnVal &= windowInt(windowKeys, RASTER3D_REGION_ROWS, rows);
43
returnVal &= windowInt(windowKeys, RASTER3D_REGION_COLS, cols);
44
returnVal &= windowInt(windowKeys, RASTER3D_REGION_DEPTHS, depths);
46
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_EWRES, ew_res);
47
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_NSRES, ns_res);
48
returnVal &= windowDouble(windowKeys, RASTER3D_REGION_TBRES, tb_res);
53
Rast3d_error("Rast3d_readWriteWindow: error writing window");
58
* If windowName == NULL -> RASTER3D_WINDOW_ELEMENT ("$MAPSET/WIND3")
59
* otherwise RASTER3D_WINDOW_DATABASE ("$MAPSET/windows3d/$NAME")
61
static void Rast3d_getFullWindowPath(char *path, const char *windowName)
63
char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
65
if (windowName == NULL) {
66
G_file_name(path, "", RASTER3D_WINDOW_ELEMENT, G_mapset());
70
while (*windowName == ' ')
73
if (strchr(windowName, GRASS_DIRSEP) || strchr(windowName, HOST_DIRSEP)) {
74
sprintf(path, "%s", windowName);
78
if (G_name_is_fully_qualified(windowName, xname, xmapset)) {
79
G_file_name(path, RASTER3D_WINDOW_DATABASE, xname, xmapset);
83
G_file_name(path, RASTER3D_WINDOW_DATABASE, windowName, G_mapset());
86
/*---------------------------------------------------------------------------*/
89
Rast3d_getWindowLocation (path, windowName)
95
char xname[512], xmapset[512];
98
if (windowName == NULL) {
99
G_file_name (path, "", "", G_mapset ());
103
while (*windowName == ' ') windowName++;
105
if ((*windowName != '/') && (*windowName != '.')) {
106
if (G_name_is_fully_qualified (windowName, xname, xmapset))
107
G_file_name (path, RASTER3D_WINDOW_DATABASE, xname, xmapset);
109
G_file_name (path, RASTER3D_WINDOW_DATABASE, windowName, G_mapset ());
111
sprintf (path, "%s", windowName);
115
if (*p == '/') slash = p;
118
if (slash != NULL) *slash = 0;
122
/*---------------------------------------------------------------------------*/
129
* <em>window</em> from the file specified by <em>windowName</em>. The name is
130
* converted by the rules defined in window defaults. A NULL pointer indicates
131
* the <em>WIND3</em> file in the current mapset.
135
* \return 1 ... if successful
139
int Rast3d_read_window(RASTER3D_Region * window, const char *windowName)
141
struct Cell_head win;
142
struct Key_Value *windowKeys;
143
char path[GPATH_MAX];
146
if (windowName == NULL) {
149
window->proj = win.proj;
150
window->zone = win.zone;
151
window->north = win.north;
152
window->south = win.south;
153
window->east = win.east;
154
window->west = win.west;
155
window->top = win.top;
156
window->bottom = win.bottom;
157
window->rows = win.rows3;
158
window->cols = win.cols3;
159
window->depths = win.depths;
160
window->ns_res = win.ns_res3;
161
window->ew_res = win.ew_res3;
162
window->tb_res = win.tb_res;
165
Rast3d_getFullWindowPath(path, windowName);
167
if (access(path, R_OK) != 0) {
168
G_warning("Rast3d_read_window: unable to find [%s].", path);
172
windowKeys = G_read_key_value_file(path);
174
if (!Rast3d_readWriteWindow(windowKeys, 1,
175
&(window->proj), &(window->zone),
176
&(window->north), &(window->south),
177
&(window->east), &(window->west),
178
&(window->top), &(window->bottom),
179
&(window->rows), &(window->cols),
180
&(window->depths), &(window->ew_res),
181
&(window->ns_res), &(window->tb_res))) {
183
("Rast3d_read_window: error extracting window key(s) of file %s",
188
G_free_key_value(windowKeys);
194
/*---------------------------------------------------------------------------*/
195
/* modified version of G__make_mapset_element */
198
Rast3d_createPath (thePath)
204
char *path, *p, *pOld;
206
if (*thePath == 0) return 0;
208
strcpy (path = command, "mkdir ");
209
while (*path) path++;
212
/* now append element, one directory at a time, to path */
215
if (*thePath == '/') *p++ = *thePath++;
217
while ((*thePath) && (*thePath != '/')) *p++ = *thePath++;
220
if (p == pOld) return 1;
222
if (access (path, 0) != 0) mkdir (path,0777);
223
if (access (path, 0) != 0) system (command);
224
if (access (path, 0) != 0) {
226
sprintf (err, "can't make mapset element %s (%s)", thePath, path);
234
/*---------------------------------------------------------------------------*/
241
* Writes <em>window</em> to the file specified by <em>windowName</em>. The name
242
* is converted by the rules defined in window defaults. A NULL pointer
243
* indicates the <em>WIND3</em> file in the current mapset.
247
* \return 1 ... if successful
253
Rast3d_writeWindow (window, windowName)
255
RASTER3D_Region *window;
263
/*---------------------------------------------------------------------------*/
269
* Allows the window to be set at run-time via the <em>region3</em>
270
* command line argument. This function has to be called before
271
* <em>G_parser ()</em>. See also window defaults.
276
void Rast3d_use_window_params(void)
278
Rast3d_set_window_params();