~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/raster3d/windowio.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <sys/types.h>
 
4
#include <sys/stat.h>
 
5
#include <unistd.h>
 
6
#include <string.h>
 
7
#include <grass/gis.h>
 
8
#include "raster3d_intern.h"
 
9
 
 
10
/*---------------------------------------------------------------------------*/
 
11
 
 
12
static int
 
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,
 
17
                    double *tb_res)
 
18
{
 
19
    int returnVal;
 
20
    int (*windowInt) (), (*windowDouble) ();
 
21
 
 
22
    if (doRead) {
 
23
        windowDouble = Rast3d_key_get_double;
 
24
        windowInt = Rast3d_key_get_int;
 
25
    }
 
26
    else {
 
27
        windowDouble = Rast3d_key_set_double;
 
28
        windowInt = Rast3d_key_set_int;
 
29
    }
 
30
 
 
31
    returnVal = 1;
 
32
    returnVal &= windowInt(windowKeys, RASTER3D_REGION_PROJ, proj);
 
33
    returnVal &= windowInt(windowKeys, RASTER3D_REGION_ZONE, zone);
 
34
 
 
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);
 
41
 
 
42
    returnVal &= windowInt(windowKeys, RASTER3D_REGION_ROWS, rows);
 
43
    returnVal &= windowInt(windowKeys, RASTER3D_REGION_COLS, cols);
 
44
    returnVal &= windowInt(windowKeys, RASTER3D_REGION_DEPTHS, depths);
 
45
 
 
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);
 
49
 
 
50
    if (returnVal)
 
51
        return 1;
 
52
 
 
53
    Rast3d_error("Rast3d_readWriteWindow: error writing window");
 
54
    return 0;
 
55
}
 
56
 
 
57
/*
 
58
 * If windowName == NULL -> RASTER3D_WINDOW_ELEMENT ("$MAPSET/WIND3")
 
59
 * otherwise RASTER3D_WINDOW_DATABASE ("$MAPSET/windows3d/$NAME")
 
60
 */
 
61
static void Rast3d_getFullWindowPath(char *path, const char *windowName)
 
62
{
 
63
    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
 
64
 
 
65
    if (windowName == NULL) {
 
66
        G_file_name(path, "", RASTER3D_WINDOW_ELEMENT, G_mapset());
 
67
        return;
 
68
    }
 
69
 
 
70
    while (*windowName == ' ')
 
71
        windowName++;
 
72
 
 
73
    if (strchr(windowName, GRASS_DIRSEP) || strchr(windowName, HOST_DIRSEP)) {
 
74
        sprintf(path, "%s", windowName);
 
75
        return;
 
76
    }
 
77
 
 
78
    if (G_name_is_fully_qualified(windowName, xname, xmapset)) {
 
79
        G_file_name(path, RASTER3D_WINDOW_DATABASE, xname, xmapset);
 
80
        return;
 
81
    }
 
82
 
 
83
    G_file_name(path, RASTER3D_WINDOW_DATABASE, windowName, G_mapset());
 
84
}
 
85
 
 
86
/*---------------------------------------------------------------------------*/
 
87
/*
 
88
   static void
 
89
   Rast3d_getWindowLocation (path, windowName)
 
90
 
 
91
   char path[1024];
 
92
   char *windowName;
 
93
 
 
94
   {
 
95
   char xname[512], xmapset[512];
 
96
   char *p, *slash;
 
97
 
 
98
   if (windowName == NULL) {
 
99
   G_file_name (path, "", "", G_mapset ());
 
100
   return;
 
101
   }
 
102
 
 
103
   while (*windowName == ' ') windowName++;
 
104
 
 
105
   if ((*windowName != '/') && (*windowName != '.')) {
 
106
   if (G_name_is_fully_qualified (windowName, xname, xmapset)) 
 
107
   G_file_name (path, RASTER3D_WINDOW_DATABASE, xname, xmapset);
 
108
   else
 
109
   G_file_name (path, RASTER3D_WINDOW_DATABASE, windowName, G_mapset ());
 
110
   } else
 
111
   sprintf (path, "%s", windowName);
 
112
   p = path;
 
113
   slash = NULL;
 
114
   while (*p != 0) {
 
115
   if (*p == '/') slash = p;
 
116
   p++;
 
117
   }
 
118
   if (slash != NULL) *slash = 0;
 
119
   }
 
120
 */
 
121
 
 
122
/*---------------------------------------------------------------------------*/
 
123
 
 
124
 
 
125
/*!
 
126
 * \brief 
 
127
 *
 
128
 *  Reads
 
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.
 
132
 *
 
133
 *  \param window
 
134
 *  \param windowName
 
135
 *  \return 1 ... if successful
 
136
 *          0 ... otherwise.
 
137
 */
 
138
 
 
139
int Rast3d_read_window(RASTER3D_Region * window, const char *windowName)
 
140
{
 
141
    struct Cell_head win;
 
142
    struct Key_Value *windowKeys;
 
143
    char path[GPATH_MAX];
 
144
 
 
145
 
 
146
    if (windowName == NULL) {
 
147
        G_get_window(&win);
 
148
 
 
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;
 
163
    }
 
164
    else {
 
165
        Rast3d_getFullWindowPath(path, windowName);
 
166
 
 
167
        if (access(path, R_OK) != 0) {
 
168
            G_warning("Rast3d_read_window: unable to find [%s].", path);
 
169
            return 0;
 
170
        }
 
171
 
 
172
        windowKeys = G_read_key_value_file(path);
 
173
 
 
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))) {
 
182
            Rast3d_error
 
183
                ("Rast3d_read_window: error extracting window key(s) of file %s",
 
184
                 path);
 
185
            return 0;
 
186
        }
 
187
 
 
188
        G_free_key_value(windowKeys);
 
189
    }
 
190
 
 
191
    return 1;
 
192
}
 
193
 
 
194
/*---------------------------------------------------------------------------*/
 
195
/* modified version of G__make_mapset_element */
 
196
/*
 
197
   static int
 
198
   Rast3d_createPath (thePath)
 
199
 
 
200
   char *thePath;
 
201
 
 
202
   {
 
203
   char command[1024];
 
204
   char *path, *p, *pOld;
 
205
 
 
206
   if (*thePath == 0) return 0;
 
207
 
 
208
   strcpy (path = command, "mkdir ");
 
209
   while (*path) path++;
 
210
   p = path;
 
211
 */
 
212
  /* now append element, one directory at a time, to path */
 
213
/*
 
214
   while (1) {
 
215
   if (*thePath == '/') *p++ = *thePath++;
 
216
   pOld = p;
 
217
   while ((*thePath) && (*thePath != '/')) *p++ = *thePath++;
 
218
   *p = 0;
 
219
 
 
220
   if (p == pOld) return 1;
 
221
 
 
222
   if (access (path, 0) != 0) mkdir (path,0777);
 
223
   if (access (path, 0) != 0) system (command);
 
224
   if (access (path, 0) != 0) {
 
225
   char err[1024];
 
226
   sprintf (err, "can't make mapset element %s (%s)", thePath, path);
 
227
   G_fatal_error (err);
 
228
   exit(1);
 
229
   }
 
230
   }
 
231
   }
 
232
 */
 
233
 
 
234
/*---------------------------------------------------------------------------*/
 
235
 
 
236
 
 
237
/*!
 
238
 * \brief 
 
239
 *
 
240
 * 
 
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.
 
244
 *
 
245
 *  \param window
 
246
 *  \param windowName
 
247
 *  \return 1 ... if successful
 
248
 *          0 ... otherwise.
 
249
 */
 
250
 
 
251
/*
 
252
   int
 
253
   Rast3d_writeWindow (window, windowName)
 
254
 
 
255
   RASTER3D_Region *window;
 
256
   char *windowName;
 
257
 
 
258
   {
 
259
   return 0;
 
260
   }
 
261
 */
 
262
 
 
263
/*---------------------------------------------------------------------------*/
 
264
 
 
265
 
 
266
/*!
 
267
 * \brief 
 
268
 *
 
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.
 
272
 *
 
273
 *  \return void
 
274
 */
 
275
 
 
276
void Rast3d_use_window_params(void)
 
277
{
 
278
    Rast3d_set_window_params();
 
279
}